Database Reference
In-Depth Information
PostgreSQL sometimes relies on logically equivalent data items being also the same
for bit-wise comparisons, and even when you set all the items in a structure it is pos-
sible that some alignment issues leave garbage in the areas between structure ele-
ments if any alignment padding was done by the compiler.
If you do not do this then PostgreSQLs hash indexes and hash joins may not work
efficiently or even give wrong results. The planner's constant comparisons may also
be wrong if constants which are logically the same are not the same via bit-wise
equality, resulting in undesirable planning results.
Include files
Most of PostgreSQL internal types are declared in
postgres.h
, and the function
manager interfaces (
PG_MODULE_MAGIC
,
PG_FUNCTION_INFO_V1
,
PG_FUNCTION_ARGS
,
PG_GETARG_<type>
,
PG_RETURN_<type>
, and so on) are
in
fmgr.h
. Therefore, all your C extension modules need to include at least these
two files. It is a good habit to include
postgres.h
first as it gives your code the best
portability by (re)defining some platform dependent constants and macros. Including
postgres.h
also includes
utils/elog.h
and
utils/palloc.h
for you.
There are other useful include files in the
utils/
subdirectory which you also may
need to include like
utils/array.h
used in the last example.
Another often used include directory is
catalog/
which gives you the initial (and by
convention constant) part of most system tables so you do not need to look up things
like
type identifier for int4 data type
, but can use its pre-defined value
INT4OID
directly. As of PostgreSQL 9.2, there are 79 constants for type IDs defined
in
catalog/pgtype
.
The values in
catalog/pg_*
include files are always in sync with what gets put into
the database catalogs by virtue of being
the
definition of the structure and contents
of the system catalog tables. The
.bki
files used when
initdb
command sets up a
new empty database cluster are generated from these
.h
files by
genbki.pl
script.
Public symbol names
It is the programmer's task to make sure that any symbol names visible in the
.so
files do not conflict with those already present in the PostgreSQL backend, including