sqlpp - SQL preprocessor


sqlpp is a conventional cpp-alike preprocessor taught to understand SQL ( PgSQL, in particular) syntax specificities. In addition to the standard #define/#ifdef/#else/#endif cohort, provides also #perldef for calling arbitrary perl code.


sqlpp [options] filename


  -I path   - include path
  -D var[=value] - define variable
  -o output - output to file ( default to stdout )
  -h,--help - display this text
  -hh       - display man page


Copyright (c) 2005 catpipe Systems ApS. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


#define TAG

Identical to cpp


Not fully identical to cpp, the behavior is slightly different. Concatenation ( a ## b ) and stringification ( # a ) behave similar to as in cpp.

The multiline macro can be declared either tranditionally via CPP backslash line continuation, or a perl's heredoc style. In the latter case, TAG must be prepended with <<.


Analogous to cpp.

Note: EXPRESSION is evaluated via perl runtime engine, and although can execute arbitrary perl code, it is recommended to use simple arithmetic operators. To operate with defines as strings, use double quotes.

The defined() function works like in cpp, not like in perl.

#ifdef, #ifndef, #else, #elif, #endif, #undef, #include, #error

Identical to cpp

#pragma macro(simple|all|off)

Pragma macro defines how defines and macros should be tracked and substituted. The reason is that SQL code may contain non-SQL code that is so complicated that would confuse the macro parser. Such sections can be guarded with #pragma macro(simple)/#pragma macro(all) brackets, for example.

There are three macro modes:


Neither defines nor macros are substituted.


Defines are substituted, macros are not substituted.


Both defines are macros are substituted.

#pragma comments(strip|leave)

Pragma comments tells what to do with # and -- comments. The default is strip these from the output, however, the parts of input that are not SQL, can be guarded from incorrect parsing by #pragma comments(leave)/ #pragma comments(strip) macros. Note that # comments are ineffectual in macro definitions, because # is a macro concatenation symbol.

#pragma lang(sql|perl)

A combination of existing pragmas.


Same as #pragma macro(all) and #pragma comments(strip). These are defaults settings.


Same as #pragma macro(simple) and #pragma comments(leave). Useful if perl code is embedded.


Creates a special define or a macro, where CODE is perl code. PARAMETERS is either a list of perl scalar names ( dollar sign included ), then the code may access the parameters directly. Or, PARAMETERS is the ellipsis (...) string, in which case the code must parse @_ by itself.

The multiline perl code can be declared either tranditionally via CPP backslash line continuation, or a perl's heredoc style. In the latter case, TAG must be prepended with <<.

The perl code is executed in the anonymous subroutine context, and the return values are passed to further processing. Perl print and printf statements may be used to produce direct output into the program output, bypassign the preprocessing.

For the shared storage the code can use %global; for accessing contents of defines and macros, %defines and %macros internal hashes may be used.

Predefined macros


Dmitry Karasik <>