3 .\" Author: The PostgreSQL Global Development Group
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
6 .\" Manual: PostgreSQL 18.0 Documentation
7 .\" Source: PostgreSQL 18.0
10 .TH "ECPG" "1" "2025" "PostgreSQL 18.0" "PostgreSQL 18.0 Documentation"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
25 .\" disable justification (adjust text to left margin only)
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
31 ecpg \- embedded SQL C preprocessor
34 \fBecpg\fR [\fIoption\fR...] \fIfile\fR...
38 is the embedded SQL preprocessor for C programs\&. 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\&.
41 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,
43 is assumed\&. The file\*(Aqs extension will be replaced by
45 to construct the output file name\&. But the output file name can be overridden using the
49 If an input file name is just
52 reads the program from standard input (and writes to standard output, unless that is overridden with
55 This reference page does not describe the embedded SQL language\&. See
57 for more information on that topic\&.
61 accepts the following command\-line arguments:
65 Automatically generate certain C code from SQL code\&. Currently, this works for
69 \fB\-C \fR\fB\fImode\fR\fR
71 Set a compatibility mode\&.
79 \fB\-D \fR\fB\fIsymbol\fR\fR\fB[=\fR\fB\fIvalue\fR\fR\fB]\fR
81 Define a preprocessor symbol, equivalently to the
85 is specified, the symbol is defined with the value
91 Process header files\&. When this option is specified, the output file extension becomes
94 \&.c, and the default input file extension is
99 option is forced on\&.
104 Parse system include files as well\&.
107 \fB\-I \fR\fB\fIdirectory\fR\fR
109 Specify an additional include path, used to find files included via
110 EXEC SQL INCLUDE\&. Defaults are
113 /usr/local/include, the
115 include directory which is defined at compile time (default:
116 /usr/local/pgsql/include), and
117 /usr/include, in that order\&.
120 \fB\-o \fR\fB\fIfilename\fR\fR
124 should write all its output to the given
125 \fIfilename\fR\&. Write
127 to send all output to standard output\&.
130 \fB\-r \fR\fB\fIoption\fR\fR
132 Selects run\-time behavior\&.
134 can be one of the following:
138 Do not use indicators but instead use special values to represent null values\&. Historically there have been databases using this approach\&.
143 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\&.
148 Allow question mark as placeholder for compatibility reasons\&. This used to be the default long ago\&.
154 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
155 \fBEXEC SQL COMMIT\fR
161 Print additional information including the version and the "include" path\&.
177 command line arguments, and exit\&.
181 When compiling the preprocessed C code files, the compiler needs to be able to find the
185 include directory\&. Therefore, you might have to use the
187 option when invoking the compiler (e\&.g\&.,
188 \-I/usr/local/pgsql/include)\&.
190 Programs using C code with embedded SQL have to be linked against the
192 library, for example using the linker options
193 \-L/usr/local/pgsql/lib \-lecpg\&.
195 The value of either of these directories that is appropriate for the installation can be found out using
196 \fBpg_config\fR(1)\&.
199 If you have an embedded SQL C source file named
200 prog1\&.pgc, you can create an executable program using the following sequence of commands:
207 cc \-I/usr/local/pgsql/include \-c prog1\&.c
208 cc \-o prog1 prog1\&.o \-L/usr/local/pgsql/lib \-lecpg