ECPG(1)
β¨ ECPG(1) β¨
okay bestie, buckle up π this is ecpg, the embedded SQL C preprocessor from the PostgreSQL 18.6 Documentation era. she's giving β¨translatorβ¨ energy and she's literally iconic for it π«Ά
πΈ NAME πΈ
ecpg β the embedded SQL C preprocessor, no cap π
π¦ SYNOPSIS π¦
ecpg [option...] file...
π DESCRIPTION π
so ecpg is the embedded SQL preprocessor for C programs, periodt. what she does is she takes your C programs that have embedded SQL statements inside them and converts them into normal C code by replacing all those SQL invocations with special function calls. then your output files can get processed with literally any C compiler tool chain. slay π₯
ecpg will convert each input file you give her on the command line into the corresponding C output file. here's the tea β if an input file name doesn't have any extension, .pgc is assumed. the file's extension gets replaced by .c to construct the output file name. but bestie, you can override that output file name using the -o option, ngl that's a flex π
and if an input file name is just -, ecpg reads the program from standard input (and writes to standard output, unless that gets overridden with -o). main character energy honestly π
heads up though π¨ this reference page does not describe the embedded SQL language. see Chapter 34 for more info 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. cute β¨-Cmode β set a compatibility mode. mode can beINFORMIX,INFORMIX_SE, orORACLE. pick your fighter π-Dsymbol[=value]β define a preprocessor symbol, equivalently to theEXEC SQL DEFINEdirective. if no value is specified, the symbol gets defined with the value1. defaults being defaults, love that for us π-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. she said "both, actually" π-iβ parse system include files as well. thorough queen π-Idirectory β specify an additional include path, used to find files included viaEXEC SQL INCLUDE. the 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. order matters bestie, respect the lineup π-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. vintage behavior, we respect the heritage π°οΈprepareβ prepare all statements before using them. Libecpg will keep a cache of prepared statements and reuse a statement if it gets executed again. if the cache runs full, libecpg will free the least used statement. efficient icon β¨questionmarksβ allow question mark as placeholder for compatibility reasons. this used to be the default long ago. throwback era π
-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. choose your vibe wisely π-vβ print additional information including the version and the"include"path. nosy but make it useful π--versionβ print theecpgversion and exit. quick lil peek π-?,--helpβ show help aboutecpgcommand line arguments, and exit. when you're lost, she's got you π«Ά
π 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 step bestie, she will not compile without it π
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 her up, she needs her people π
the value of either of these directories that is appropriate for the installation can be found out using pg_config(1). she'll tell you where everything lives, iconic behavior π
π EXAMPLES π
say 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
three steps, zero stress, executable secured π π₯
ok that's the whole page bestie, go forth and preprocess π
PostgreSQL 18.6 Β· 2026 β that's the version and date babes, and yes this was ECPG(1), the one and only β¨ππ¦πππ
π¦ where this page comes from
- alpine 3.23: postgresql18-doc 18.6-r0 Β· PostgreSQL
- alpine 3.24: postgresql18-doc 18.6-r0 Β· PostgreSQL
- arch rolling: postgresql-libs 18.6-4 Β· PostgreSQL
- nixos 26.05: postgresql 18.6
- ubuntu resolute: libecpg-dev 18.6-0ubuntu0.26.04.1 Β· PostgreSQL
- ubuntu stonking: libecpg-dev 18.6-3build2 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms