RefLib

Reference library for AI

Back

postgresql_16:5.3.9.3 ifdef, ifndef, elif, else, and endif Directives

PostgreSQL 16 > Client Interfaces > ECPG — Embedded SQL in C > Preprocessor Directives > ifdef, ifndef, elif, else, and endif Directives

You can use the following directives to compile code sections conditionally: EXEC SQL ifdef *name*; Checks a *name* and processes subsequent lines if *name* has been defined via EXEC SQL define *name*. EXEC SQL ifndef *name*; Checks a *name* and processes subsequent lines if *name* has *not* been defined via EXEC SQL define *name*. EXEC SQL elif *name*; Begins an optional alternative section after an EXEC SQL ifdef *name* or EXEC SQL ifndef *name* directive. Any number of elif sections can appear. Lines following an elif will be processed if *name* has been defined *and* no previous section of the same ifdef/ifndef...endif construct has been processed. EXEC SQL else; Begins an optional, final alternative section after an EXEC SQL ifdef *name* or EXEC SQL ifndef *name* directive. Subsequent lines will be processed if no previous section of the same ifdef/ifndef...endif construct has been processed. EXEC SQL endif; Ends an ifdef/ifndef...endif construct. Subsequent lines are processed normally.

ifdef/ifndef...endif constructs can be nested, up to 127 levels deep.

This example will compile exactly one of the three SET TIMEZONE commands: EXEC SQL ifdef TZVAR; EXEC SQL SET TIMEZONE TO TZVAR; EXEC SQL elif TZNAME; EXEC SQL SET TIMEZONE TO TZNAME; EXEC SQL else; EXEC SQL SET TIMEZONE TO 'GMT'; EXEC SQL endif;

Back