Top
Enterprise Postgres 17 SP1 Application Development Guide

5.4.2 Compiling Applications

Append the extension "pgc" to the name of the source file for the embedded SQL in C.

When the pgc file is precompiled using the ecpg command, C source files will be created, so use the C compiler for the compile.

Precompiling example

ecpg testproc.pgc

If an optimizer hint block comment is specified for the SQL statement, specify the following option in the ecpg command:

--enable-hint

Enables the optimizer hint block comment (hereafter, referred to as the "hint clause"). If this option is not specified, the hint clause will be removed as a result of the ecpg precompile and be disabled.

The SQL statements that can be specified in the hint clause are SELECT, INSERT, UPDATE, and DELETE.

The locations in which the hint clause can be specified are immediately after one of the SELECT, INSERT, UPDATE, DELETE, or WITH keywords. A syntax error will occur if any other location is specified.

Example of specifying the hint clause
EXEC SQL SELECT /*+ IndexScan(prod ix01) */ name_id INTO :name_id FROM prod WHERE id = 1;

See

For basic usage of pg_hint_plan and pg_dbms_stats, see below.

  • Control execution plans with pg_hint_plan

    https://www.postgresql.fastware.com/postgresql-insider-tun-hint-plan

Note

Take the following points into account when using embedded SQL source files:

  • Multibyte codes expressed in SJIS or UTF-16 cannot be included in statements or host variable declarations specified in EXEC SQL.

  • Do not use UTF-8 with a byte order mark (BOM), because an error may occur during compilation if the BOM character is incorrectly recognized as the source code.

  • Multibyte characters cannot be used in host variable names.

  • It is not possible to use a TYPE name that contains multibyte characters, even though it can be defined.


Specify the following paths when compiling a C application output with precompiling.

Refer to your compiler documentation for information on how to specify the path.

Also, when using a shared library, refer to "A.6 How to Build and Run an Application that Uses Shared Libraries".

Table 5.1 Include file and library path

Type of path

Path name

Path of the include file

fujitsuEnterprisePostgresClientInstallDir/include

Path of the library

fujitsuEnterprisePostgresClientInstallDir/lib

Table 5.2 C Library

Type of library

Library name

Note

Dynamic library

libecpg.so

libpgtypes.so

When using the pgtypes library

Static library

libecpg.a

libpgtypes.a

When using the pgtypes library