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 for EXEC SQL TYPE. cute ✨
  • -C mode β€” set a compatibility mode. mode can be INFORMIX, INFORMIX_SE, or ORACLE. pick your fighter πŸ’–
  • -D symbol[=value] β€” define a preprocessor symbol, equivalently to the EXEC SQL DEFINE directive. if no value is specified, the symbol gets defined with the value 1. defaults being defaults, love that for us πŸŽ€
  • -h β€” process header files. when this option is specified, the output file extension becomes .h not .c, and the default input file extension is .pgh not .pgc. also, the -c option is forced on. she said "both, actually" πŸ’…
  • -i β€” parse system include files as well. thorough queen πŸ‘‘
  • -I directory β€” specify an additional include path, used to find files included via EXEC 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 🌈
  • -o filename β€” specifies that ecpg should write all its output to the given filename. write -o - to send all output to standard output 🫢
  • -r option β€” 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 when EXEC SQL COMMIT is issued. choose your vibe wisely πŸ’€
  • -v β€” print additional information including the version and the "include" path. nosy but make it useful πŸ™ˆ
  • --version β€” print the ecpg version and exit. quick lil peek πŸ‘€
  • -?, --help β€” show help about ecpg command 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 βœ¨πŸ‘‘πŸ¦‹πŸ’œπŸŽ€πŸ’