ECPG(1)
β¨ NAME β¨
ecpg β embedded SQL C preprocessor. Bestie, this is the ECPG(1) page, and it's literally all about the embedded SQL C preprocessor for C programs. No cap. π
πΈ SYNOPSIS πΈ
ecpg [option...] file...
π DESCRIPTION π
ecpg is the embedded SQL preprocessor for C programs, periodt. It converts C programs with embedded SQL statements to normal C code by replacing the SQL invocations with special function calls. The output files can then be processed with any C compiler tool chain. Slay. β¨
ecpg will convert each input file given on the command line to the corresponding C output file. If an input file name does not have any extension, .pgc is assumed. The file's extension will be replaced by .c to construct the output file name. But the output file name can be overridden using the -o option. π
If an input file name is just -, ecpg reads the program from standard input (and writes to standard output, unless that is overridden with -o). Iconic behavior, honestly. π«Ά
This reference page does not describe the embedded SQL language. See Chapter 36 for more information on that topic. iykyk. π
π OPTIONS π
ecpg accepts the following command-line arguments:
-cβ Automatically generate certain C code from SQL code. Currently, this works forEXEC SQL TYPE.-Cmode β Set a compatibility mode. mode can beINFORMIX,INFORMIX_SE, orORACLE.-Dsymbol[=value] β Define a preprocessor symbol, equivalently to theEXEC SQL DEFINEdirective. If no value is specified, the symbol is defined with the value1.-hβ Process header files. When this option is specified, the output file extension becomes.hnot.c, and the default input file extension is.pghnot.pgc. Also, the-coption is forced on.-iβ Parse system include files as well.-Idirectory β Specify an additional include path, used to find files included viaEXEC SQL INCLUDE. Defaults are.(current directory),/usr/local/include, the PostgreSQL include directory which is defined at compile time (default:/usr/local/pgsql/include), and/usr/include, in that order.-ofilename β Specifies thatecpgshould write all its output to the given filename. Write-o -to send all output to standard output.-roption β Selects run-time behavior. Option can be one of the following:no_indicatorβ Do not use indicators but instead use special values to represent null values. Historically there have been databases using this approach.prepareβ Prepare all statements before using them.Libecpgwill keep a cache of prepared statements and reuse a statement if it gets executed again. If the cache runs full,libecpgwill free the least used statement.questionmarksβ Allow question mark as placeholder for compatibility reasons. This used to be the default long ago.
-tβ Turn on autocommit of transactions. In this mode, each SQL command is automatically committed unless it is inside an explicit transaction block. In the default mode, commands are committed only whenEXEC SQL COMMITis issued.-vβ Print additional information including the version and the"include"path.--versionβ Print theecpgversion and exit.-?,--helpβ Show help aboutecpgcommand line arguments, and exit.
π¦ NOTES π¦
When compiling the preprocessed C code files, the compiler needs to be able to find the ECPG header files in the PostgreSQL include directory. Therefore, you might have to use the -I option when invoking the compiler (e.g., -I/usr/local/pgsql/include). Don't skip this, bestie β it's giving "compiler can't find the headers" energy otherwise. π
Programs using C code with embedded SQL have to be linked against the libecpg library, for example using the linker options -L/usr/local/pgsql/lib -lecpg. Link it up, periodt. π₯
The value of either of these directories that is appropriate for the installation can be found out using pg_config(1). That's your vibe check for the right paths. β¨
π EXAMPLES π
If you have an embedded SQL C source file named prog1.pgc, you can create an executable program using the following sequence of commands:
ecpg prog1.pgc
cc -I/usr/local/pgsql/include -c prog1.c
cc -o prog1 prog1.o -L/usr/local/pgsql/lib -lecpg
Ate. Build complete. π
Later, bestie! π This page is from PostgreSQL 14.24, dated 2026 β that's the source/version and date on the ECPG(1) footer, and we are so done. Mwah! π«Άβ¨
π¦ where this page comes from
- opensuse-leap 16.0: postgresql14-devel 14.24-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql14-devel 14.24-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql14-devel 14.24-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql14-devel 14.24-160000.1.1 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms