Header And Logo

PostgreSQL
| The world's most advanced open source database.

postgres.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * postgres.h
00004  *    Primary include file for PostgreSQL server .c files
00005  *
00006  * This should be the first file included by PostgreSQL backend modules.
00007  * Client-side code should include postgres_fe.h instead.
00008  *
00009  *
00010  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00011  * Portions Copyright (c) 1995, Regents of the University of California
00012  *
00013  * src/include/postgres.h
00014  *
00015  *-------------------------------------------------------------------------
00016  */
00017 /*
00018  *----------------------------------------------------------------
00019  *   TABLE OF CONTENTS
00020  *
00021  *      When adding stuff to this file, please try to put stuff
00022  *      into the relevant section, or add new sections as appropriate.
00023  *
00024  *    section   description
00025  *    -------   ------------------------------------------------
00026  *      1)      variable-length datatypes (TOAST support)
00027  *      2)      datum type + support macros
00028  *      3)      exception handling backend support
00029  *
00030  *   NOTES
00031  *
00032  *  In general, this file should contain declarations that are widely needed
00033  *  in the backend environment, but are of no interest outside the backend.
00034  *
00035  *  Simple type definitions live in c.h, where they are shared with
00036  *  postgres_fe.h.  We do that since those type definitions are needed by
00037  *  frontend modules that want to deal with binary data transmission to or
00038  *  from the backend.  Type definitions in this file should be for
00039  *  representations that never escape the backend, such as Datum or
00040  *  TOASTed varlena objects.
00041  *
00042  *----------------------------------------------------------------
00043  */
00044 #ifndef POSTGRES_H
00045 #define POSTGRES_H
00046 
00047 #include "c.h"
00048 #include "utils/elog.h"
00049 #include "utils/palloc.h"
00050 
00051 /* ----------------------------------------------------------------
00052  *              Section 1:  variable-length datatypes (TOAST support)
00053  * ----------------------------------------------------------------
00054  */
00055 
00056 /*
00057  * struct varatt_external is a "TOAST pointer", that is, the information
00058  * needed to fetch a stored-out-of-line Datum.  The data is compressed
00059  * if and only if va_extsize < va_rawsize - VARHDRSZ.  This struct must not
00060  * contain any padding, because we sometimes compare pointers using memcmp.
00061  *
00062  * Note that this information is stored unaligned within actual tuples, so
00063  * you need to memcpy from the tuple into a local struct variable before
00064  * you can look at these fields!  (The reason we use memcmp is to avoid
00065  * having to do that just to detect equality of two TOAST pointers...)
00066  */
00067 struct varatt_external
00068 {
00069     int32       va_rawsize;     /* Original data size (includes header) */
00070     int32       va_extsize;     /* External saved size (doesn't) */
00071     Oid         va_valueid;     /* Unique ID of value within TOAST table */
00072     Oid         va_toastrelid;  /* RelID of TOAST table containing it */
00073 };
00074 
00075 /*
00076  * These structs describe the header of a varlena object that may have been
00077  * TOASTed.  Generally, don't reference these structs directly, but use the
00078  * macros below.
00079  *
00080  * We use separate structs for the aligned and unaligned cases because the
00081  * compiler might otherwise think it could generate code that assumes
00082  * alignment while touching fields of a 1-byte-header varlena.
00083  */
00084 typedef union
00085 {
00086     struct                      /* Normal varlena (4-byte length) */
00087     {
00088         uint32      va_header;
00089         char        va_data[1];
00090     }           va_4byte;
00091     struct                      /* Compressed-in-line format */
00092     {
00093         uint32      va_header;
00094         uint32      va_rawsize; /* Original data size (excludes header) */
00095         char        va_data[1]; /* Compressed data */
00096     }           va_compressed;
00097 } varattrib_4b;
00098 
00099 typedef struct
00100 {
00101     uint8       va_header;
00102     char        va_data[1];     /* Data begins here */
00103 } varattrib_1b;
00104 
00105 typedef struct
00106 {
00107     uint8       va_header;      /* Always 0x80 or 0x01 */
00108     uint8       va_len_1be;     /* Physical length of datum */
00109     char        va_data[1];     /* Data (for now always a TOAST pointer) */
00110 } varattrib_1b_e;
00111 
00112 /*
00113  * Bit layouts for varlena headers on big-endian machines:
00114  *
00115  * 00xxxxxx 4-byte length word, aligned, uncompressed data (up to 1G)
00116  * 01xxxxxx 4-byte length word, aligned, *compressed* data (up to 1G)
00117  * 10000000 1-byte length word, unaligned, TOAST pointer
00118  * 1xxxxxxx 1-byte length word, unaligned, uncompressed data (up to 126b)
00119  *
00120  * Bit layouts for varlena headers on little-endian machines:
00121  *
00122  * xxxxxx00 4-byte length word, aligned, uncompressed data (up to 1G)
00123  * xxxxxx10 4-byte length word, aligned, *compressed* data (up to 1G)
00124  * 00000001 1-byte length word, unaligned, TOAST pointer
00125  * xxxxxxx1 1-byte length word, unaligned, uncompressed data (up to 126b)
00126  *
00127  * The "xxx" bits are the length field (which includes itself in all cases).
00128  * In the big-endian case we mask to extract the length, in the little-endian
00129  * case we shift.  Note that in both cases the flag bits are in the physically
00130  * first byte.  Also, it is not possible for a 1-byte length word to be zero;
00131  * this lets us disambiguate alignment padding bytes from the start of an
00132  * unaligned datum.  (We now *require* pad bytes to be filled with zero!)
00133  */
00134 
00135 /*
00136  * Endian-dependent macros.  These are considered internal --- use the
00137  * external macros below instead of using these directly.
00138  *
00139  * Note: IS_1B is true for external toast records but VARSIZE_1B will return 0
00140  * for such records. Hence you should usually check for IS_EXTERNAL before
00141  * checking for IS_1B.
00142  */
00143 
00144 #ifdef WORDS_BIGENDIAN
00145 
00146 #define VARATT_IS_4B(PTR) \
00147     ((((varattrib_1b *) (PTR))->va_header & 0x80) == 0x00)
00148 #define VARATT_IS_4B_U(PTR) \
00149     ((((varattrib_1b *) (PTR))->va_header & 0xC0) == 0x00)
00150 #define VARATT_IS_4B_C(PTR) \
00151     ((((varattrib_1b *) (PTR))->va_header & 0xC0) == 0x40)
00152 #define VARATT_IS_1B(PTR) \
00153     ((((varattrib_1b *) (PTR))->va_header & 0x80) == 0x80)
00154 #define VARATT_IS_1B_E(PTR) \
00155     ((((varattrib_1b *) (PTR))->va_header) == 0x80)
00156 #define VARATT_NOT_PAD_BYTE(PTR) \
00157     (*((uint8 *) (PTR)) != 0)
00158 
00159 /* VARSIZE_4B() should only be used on known-aligned data */
00160 #define VARSIZE_4B(PTR) \
00161     (((varattrib_4b *) (PTR))->va_4byte.va_header & 0x3FFFFFFF)
00162 #define VARSIZE_1B(PTR) \
00163     (((varattrib_1b *) (PTR))->va_header & 0x7F)
00164 #define VARSIZE_1B_E(PTR) \
00165     (((varattrib_1b_e *) (PTR))->va_len_1be)
00166 
00167 #define SET_VARSIZE_4B(PTR,len) \
00168     (((varattrib_4b *) (PTR))->va_4byte.va_header = (len) & 0x3FFFFFFF)
00169 #define SET_VARSIZE_4B_C(PTR,len) \
00170     (((varattrib_4b *) (PTR))->va_4byte.va_header = ((len) & 0x3FFFFFFF) | 0x40000000)
00171 #define SET_VARSIZE_1B(PTR,len) \
00172     (((varattrib_1b *) (PTR))->va_header = (len) | 0x80)
00173 #define SET_VARSIZE_1B_E(PTR,len) \
00174     (((varattrib_1b_e *) (PTR))->va_header = 0x80, \
00175      ((varattrib_1b_e *) (PTR))->va_len_1be = (len))
00176 #else                           /* !WORDS_BIGENDIAN */
00177 
00178 #define VARATT_IS_4B(PTR) \
00179     ((((varattrib_1b *) (PTR))->va_header & 0x01) == 0x00)
00180 #define VARATT_IS_4B_U(PTR) \
00181     ((((varattrib_1b *) (PTR))->va_header & 0x03) == 0x00)
00182 #define VARATT_IS_4B_C(PTR) \
00183     ((((varattrib_1b *) (PTR))->va_header & 0x03) == 0x02)
00184 #define VARATT_IS_1B(PTR) \
00185     ((((varattrib_1b *) (PTR))->va_header & 0x01) == 0x01)
00186 #define VARATT_IS_1B_E(PTR) \
00187     ((((varattrib_1b *) (PTR))->va_header) == 0x01)
00188 #define VARATT_NOT_PAD_BYTE(PTR) \
00189     (*((uint8 *) (PTR)) != 0)
00190 
00191 /* VARSIZE_4B() should only be used on known-aligned data */
00192 #define VARSIZE_4B(PTR) \
00193     ((((varattrib_4b *) (PTR))->va_4byte.va_header >> 2) & 0x3FFFFFFF)
00194 #define VARSIZE_1B(PTR) \
00195     ((((varattrib_1b *) (PTR))->va_header >> 1) & 0x7F)
00196 #define VARSIZE_1B_E(PTR) \
00197     (((varattrib_1b_e *) (PTR))->va_len_1be)
00198 
00199 #define SET_VARSIZE_4B(PTR,len) \
00200     (((varattrib_4b *) (PTR))->va_4byte.va_header = (((uint32) (len)) << 2))
00201 #define SET_VARSIZE_4B_C(PTR,len) \
00202     (((varattrib_4b *) (PTR))->va_4byte.va_header = (((uint32) (len)) << 2) | 0x02)
00203 #define SET_VARSIZE_1B(PTR,len) \
00204     (((varattrib_1b *) (PTR))->va_header = (((uint8) (len)) << 1) | 0x01)
00205 #define SET_VARSIZE_1B_E(PTR,len) \
00206     (((varattrib_1b_e *) (PTR))->va_header = 0x01, \
00207      ((varattrib_1b_e *) (PTR))->va_len_1be = (len))
00208 #endif   /* WORDS_BIGENDIAN */
00209 
00210 #define VARHDRSZ_SHORT          1
00211 #define VARATT_SHORT_MAX        0x7F
00212 #define VARATT_CAN_MAKE_SHORT(PTR) \
00213     (VARATT_IS_4B_U(PTR) && \
00214      (VARSIZE(PTR) - VARHDRSZ + VARHDRSZ_SHORT) <= VARATT_SHORT_MAX)
00215 #define VARATT_CONVERTED_SHORT_SIZE(PTR) \
00216     (VARSIZE(PTR) - VARHDRSZ + VARHDRSZ_SHORT)
00217 
00218 #define VARHDRSZ_EXTERNAL       2
00219 
00220 #define VARDATA_4B(PTR)     (((varattrib_4b *) (PTR))->va_4byte.va_data)
00221 #define VARDATA_4B_C(PTR)   (((varattrib_4b *) (PTR))->va_compressed.va_data)
00222 #define VARDATA_1B(PTR)     (((varattrib_1b *) (PTR))->va_data)
00223 #define VARDATA_1B_E(PTR)   (((varattrib_1b_e *) (PTR))->va_data)
00224 
00225 #define VARRAWSIZE_4B_C(PTR) \
00226     (((varattrib_4b *) (PTR))->va_compressed.va_rawsize)
00227 
00228 /* Externally visible macros */
00229 
00230 /*
00231  * VARDATA, VARSIZE, and SET_VARSIZE are the recommended API for most code
00232  * for varlena datatypes.  Note that they only work on untoasted,
00233  * 4-byte-header Datums!
00234  *
00235  * Code that wants to use 1-byte-header values without detoasting should
00236  * use VARSIZE_ANY/VARSIZE_ANY_EXHDR/VARDATA_ANY.  The other macros here
00237  * should usually be used only by tuple assembly/disassembly code and
00238  * code that specifically wants to work with still-toasted Datums.
00239  *
00240  * WARNING: It is only safe to use VARDATA_ANY() -- typically with
00241  * PG_DETOAST_DATUM_PACKED() -- if you really don't care about the alignment.
00242  * Either because you're working with something like text where the alignment
00243  * doesn't matter or because you're not going to access its constituent parts
00244  * and just use things like memcpy on it anyways.
00245  */
00246 #define VARDATA(PTR)                        VARDATA_4B(PTR)
00247 #define VARSIZE(PTR)                        VARSIZE_4B(PTR)
00248 
00249 #define VARSIZE_SHORT(PTR)                  VARSIZE_1B(PTR)
00250 #define VARDATA_SHORT(PTR)                  VARDATA_1B(PTR)
00251 
00252 #define VARSIZE_EXTERNAL(PTR)               VARSIZE_1B_E(PTR)
00253 #define VARDATA_EXTERNAL(PTR)               VARDATA_1B_E(PTR)
00254 
00255 #define VARATT_IS_COMPRESSED(PTR)           VARATT_IS_4B_C(PTR)
00256 #define VARATT_IS_EXTERNAL(PTR)             VARATT_IS_1B_E(PTR)
00257 #define VARATT_IS_SHORT(PTR)                VARATT_IS_1B(PTR)
00258 #define VARATT_IS_EXTENDED(PTR)             (!VARATT_IS_4B_U(PTR))
00259 
00260 #define SET_VARSIZE(PTR, len)               SET_VARSIZE_4B(PTR, len)
00261 #define SET_VARSIZE_SHORT(PTR, len)         SET_VARSIZE_1B(PTR, len)
00262 #define SET_VARSIZE_COMPRESSED(PTR, len)    SET_VARSIZE_4B_C(PTR, len)
00263 #define SET_VARSIZE_EXTERNAL(PTR, len)      SET_VARSIZE_1B_E(PTR, len)
00264 
00265 #define VARSIZE_ANY(PTR) \
00266     (VARATT_IS_1B_E(PTR) ? VARSIZE_1B_E(PTR) : \
00267      (VARATT_IS_1B(PTR) ? VARSIZE_1B(PTR) : \
00268       VARSIZE_4B(PTR)))
00269 
00270 #define VARSIZE_ANY_EXHDR(PTR) \
00271     (VARATT_IS_1B_E(PTR) ? VARSIZE_1B_E(PTR)-VARHDRSZ_EXTERNAL : \
00272      (VARATT_IS_1B(PTR) ? VARSIZE_1B(PTR)-VARHDRSZ_SHORT : \
00273       VARSIZE_4B(PTR)-VARHDRSZ))
00274 
00275 /* caution: this will not work on an external or compressed-in-line Datum */
00276 /* caution: this will return a possibly unaligned pointer */
00277 #define VARDATA_ANY(PTR) \
00278      (VARATT_IS_1B(PTR) ? VARDATA_1B(PTR) : VARDATA_4B(PTR))
00279 
00280 
00281 /* ----------------------------------------------------------------
00282  *              Section 2:  datum type + support macros
00283  * ----------------------------------------------------------------
00284  */
00285 
00286 /*
00287  * Port Notes:
00288  *  Postgres makes the following assumptions about datatype sizes:
00289  *
00290  *  sizeof(Datum) == sizeof(void *) == 4 or 8
00291  *  sizeof(char) == 1
00292  *  sizeof(short) == 2
00293  *
00294  * When a type narrower than Datum is stored in a Datum, we place it in the
00295  * low-order bits and are careful that the DatumGetXXX macro for it discards
00296  * the unused high-order bits (as opposed to, say, assuming they are zero).
00297  * This is needed to support old-style user-defined functions, since depending
00298  * on architecture and compiler, the return value of a function returning char
00299  * or short may contain garbage when called as if it returned Datum.
00300  */
00301 
00302 typedef uintptr_t Datum;
00303 
00304 #define SIZEOF_DATUM SIZEOF_VOID_P
00305 
00306 typedef Datum *DatumPtr;
00307 
00308 #define GET_1_BYTE(datum)   (((Datum) (datum)) & 0x000000ff)
00309 #define GET_2_BYTES(datum)  (((Datum) (datum)) & 0x0000ffff)
00310 #define GET_4_BYTES(datum)  (((Datum) (datum)) & 0xffffffff)
00311 #if SIZEOF_DATUM == 8
00312 #define GET_8_BYTES(datum)  ((Datum) (datum))
00313 #endif
00314 #define SET_1_BYTE(value)   (((Datum) (value)) & 0x000000ff)
00315 #define SET_2_BYTES(value)  (((Datum) (value)) & 0x0000ffff)
00316 #define SET_4_BYTES(value)  (((Datum) (value)) & 0xffffffff)
00317 #if SIZEOF_DATUM == 8
00318 #define SET_8_BYTES(value)  ((Datum) (value))
00319 #endif
00320 
00321 /*
00322  * DatumGetBool
00323  *      Returns boolean value of a datum.
00324  *
00325  * Note: any nonzero value will be considered TRUE, but we ignore bits to
00326  * the left of the width of bool, per comment above.
00327  */
00328 
00329 #define DatumGetBool(X) ((bool) (((bool) (X)) != 0))
00330 
00331 /*
00332  * BoolGetDatum
00333  *      Returns datum representation for a boolean.
00334  *
00335  * Note: any nonzero value will be considered TRUE.
00336  */
00337 
00338 #define BoolGetDatum(X) ((Datum) ((X) ? 1 : 0))
00339 
00340 /*
00341  * DatumGetChar
00342  *      Returns character value of a datum.
00343  */
00344 
00345 #define DatumGetChar(X) ((char) GET_1_BYTE(X))
00346 
00347 /*
00348  * CharGetDatum
00349  *      Returns datum representation for a character.
00350  */
00351 
00352 #define CharGetDatum(X) ((Datum) SET_1_BYTE(X))
00353 
00354 /*
00355  * Int8GetDatum
00356  *      Returns datum representation for an 8-bit integer.
00357  */
00358 
00359 #define Int8GetDatum(X) ((Datum) SET_1_BYTE(X))
00360 
00361 /*
00362  * DatumGetUInt8
00363  *      Returns 8-bit unsigned integer value of a datum.
00364  */
00365 
00366 #define DatumGetUInt8(X) ((uint8) GET_1_BYTE(X))
00367 
00368 /*
00369  * UInt8GetDatum
00370  *      Returns datum representation for an 8-bit unsigned integer.
00371  */
00372 
00373 #define UInt8GetDatum(X) ((Datum) SET_1_BYTE(X))
00374 
00375 /*
00376  * DatumGetInt16
00377  *      Returns 16-bit integer value of a datum.
00378  */
00379 
00380 #define DatumGetInt16(X) ((int16) GET_2_BYTES(X))
00381 
00382 /*
00383  * Int16GetDatum
00384  *      Returns datum representation for a 16-bit integer.
00385  */
00386 
00387 #define Int16GetDatum(X) ((Datum) SET_2_BYTES(X))
00388 
00389 /*
00390  * DatumGetUInt16
00391  *      Returns 16-bit unsigned integer value of a datum.
00392  */
00393 
00394 #define DatumGetUInt16(X) ((uint16) GET_2_BYTES(X))
00395 
00396 /*
00397  * UInt16GetDatum
00398  *      Returns datum representation for a 16-bit unsigned integer.
00399  */
00400 
00401 #define UInt16GetDatum(X) ((Datum) SET_2_BYTES(X))
00402 
00403 /*
00404  * DatumGetInt32
00405  *      Returns 32-bit integer value of a datum.
00406  */
00407 
00408 #define DatumGetInt32(X) ((int32) GET_4_BYTES(X))
00409 
00410 /*
00411  * Int32GetDatum
00412  *      Returns datum representation for a 32-bit integer.
00413  */
00414 
00415 #define Int32GetDatum(X) ((Datum) SET_4_BYTES(X))
00416 
00417 /*
00418  * DatumGetUInt32
00419  *      Returns 32-bit unsigned integer value of a datum.
00420  */
00421 
00422 #define DatumGetUInt32(X) ((uint32) GET_4_BYTES(X))
00423 
00424 /*
00425  * UInt32GetDatum
00426  *      Returns datum representation for a 32-bit unsigned integer.
00427  */
00428 
00429 #define UInt32GetDatum(X) ((Datum) SET_4_BYTES(X))
00430 
00431 /*
00432  * DatumGetObjectId
00433  *      Returns object identifier value of a datum.
00434  */
00435 
00436 #define DatumGetObjectId(X) ((Oid) GET_4_BYTES(X))
00437 
00438 /*
00439  * ObjectIdGetDatum
00440  *      Returns datum representation for an object identifier.
00441  */
00442 
00443 #define ObjectIdGetDatum(X) ((Datum) SET_4_BYTES(X))
00444 
00445 /*
00446  * DatumGetTransactionId
00447  *      Returns transaction identifier value of a datum.
00448  */
00449 
00450 #define DatumGetTransactionId(X) ((TransactionId) GET_4_BYTES(X))
00451 
00452 /*
00453  * TransactionIdGetDatum
00454  *      Returns datum representation for a transaction identifier.
00455  */
00456 
00457 #define TransactionIdGetDatum(X) ((Datum) SET_4_BYTES((X)))
00458 
00459 /*
00460  * MultiXactIdGetDatum
00461  *      Returns datum representation for a multixact identifier.
00462  */
00463 
00464 #define MultiXactIdGetDatum(X) ((Datum) SET_4_BYTES((X)))
00465 
00466 /*
00467  * DatumGetCommandId
00468  *      Returns command identifier value of a datum.
00469  */
00470 
00471 #define DatumGetCommandId(X) ((CommandId) GET_4_BYTES(X))
00472 
00473 /*
00474  * CommandIdGetDatum
00475  *      Returns datum representation for a command identifier.
00476  */
00477 
00478 #define CommandIdGetDatum(X) ((Datum) SET_4_BYTES(X))
00479 
00480 /*
00481  * DatumGetPointer
00482  *      Returns pointer value of a datum.
00483  */
00484 
00485 #define DatumGetPointer(X) ((Pointer) (X))
00486 
00487 /*
00488  * PointerGetDatum
00489  *      Returns datum representation for a pointer.
00490  */
00491 
00492 #define PointerGetDatum(X) ((Datum) (X))
00493 
00494 /*
00495  * DatumGetCString
00496  *      Returns C string (null-terminated string) value of a datum.
00497  *
00498  * Note: C string is not a full-fledged Postgres type at present,
00499  * but type input functions use this conversion for their inputs.
00500  */
00501 
00502 #define DatumGetCString(X) ((char *) DatumGetPointer(X))
00503 
00504 /*
00505  * CStringGetDatum
00506  *      Returns datum representation for a C string (null-terminated string).
00507  *
00508  * Note: C string is not a full-fledged Postgres type at present,
00509  * but type output functions use this conversion for their outputs.
00510  * Note: CString is pass-by-reference; caller must ensure the pointed-to
00511  * value has adequate lifetime.
00512  */
00513 
00514 #define CStringGetDatum(X) PointerGetDatum(X)
00515 
00516 /*
00517  * DatumGetName
00518  *      Returns name value of a datum.
00519  */
00520 
00521 #define DatumGetName(X) ((Name) DatumGetPointer(X))
00522 
00523 /*
00524  * NameGetDatum
00525  *      Returns datum representation for a name.
00526  *
00527  * Note: Name is pass-by-reference; caller must ensure the pointed-to
00528  * value has adequate lifetime.
00529  */
00530 
00531 #define NameGetDatum(X) PointerGetDatum(X)
00532 
00533 /*
00534  * DatumGetInt64
00535  *      Returns 64-bit integer value of a datum.
00536  *
00537  * Note: this macro hides whether int64 is pass by value or by reference.
00538  */
00539 
00540 #ifdef USE_FLOAT8_BYVAL
00541 #define DatumGetInt64(X) ((int64) GET_8_BYTES(X))
00542 #else
00543 #define DatumGetInt64(X) (* ((int64 *) DatumGetPointer(X)))
00544 #endif
00545 
00546 /*
00547  * Int64GetDatum
00548  *      Returns datum representation for a 64-bit integer.
00549  *
00550  * Note: if int64 is pass by reference, this function returns a reference
00551  * to palloc'd space.
00552  */
00553 
00554 #ifdef USE_FLOAT8_BYVAL
00555 #define Int64GetDatum(X) ((Datum) SET_8_BYTES(X))
00556 #else
00557 extern Datum Int64GetDatum(int64 X);
00558 #endif
00559 
00560 /*
00561  * DatumGetFloat4
00562  *      Returns 4-byte floating point value of a datum.
00563  *
00564  * Note: this macro hides whether float4 is pass by value or by reference.
00565  */
00566 
00567 #ifdef USE_FLOAT4_BYVAL
00568 extern float4 DatumGetFloat4(Datum X);
00569 #else
00570 #define DatumGetFloat4(X) (* ((float4 *) DatumGetPointer(X)))
00571 #endif
00572 
00573 /*
00574  * Float4GetDatum
00575  *      Returns datum representation for a 4-byte floating point number.
00576  *
00577  * Note: if float4 is pass by reference, this function returns a reference
00578  * to palloc'd space.
00579  */
00580 
00581 extern Datum Float4GetDatum(float4 X);
00582 
00583 /*
00584  * DatumGetFloat8
00585  *      Returns 8-byte floating point value of a datum.
00586  *
00587  * Note: this macro hides whether float8 is pass by value or by reference.
00588  */
00589 
00590 #ifdef USE_FLOAT8_BYVAL
00591 extern float8 DatumGetFloat8(Datum X);
00592 #else
00593 #define DatumGetFloat8(X) (* ((float8 *) DatumGetPointer(X)))
00594 #endif
00595 
00596 /*
00597  * Float8GetDatum
00598  *      Returns datum representation for an 8-byte floating point number.
00599  *
00600  * Note: if float8 is pass by reference, this function returns a reference
00601  * to palloc'd space.
00602  */
00603 
00604 extern Datum Float8GetDatum(float8 X);
00605 
00606 
00607 /*
00608  * Int64GetDatumFast
00609  * Float8GetDatumFast
00610  * Float4GetDatumFast
00611  *
00612  * These macros are intended to allow writing code that does not depend on
00613  * whether int64, float8, float4 are pass-by-reference types, while not
00614  * sacrificing performance when they are.  The argument must be a variable
00615  * that will exist and have the same value for as long as the Datum is needed.
00616  * In the pass-by-ref case, the address of the variable is taken to use as
00617  * the Datum.  In the pass-by-val case, these will be the same as the non-Fast
00618  * macros.
00619  */
00620 
00621 #ifdef USE_FLOAT8_BYVAL
00622 #define Int64GetDatumFast(X)  Int64GetDatum(X)
00623 #define Float8GetDatumFast(X) Float8GetDatum(X)
00624 #else
00625 #define Int64GetDatumFast(X)  PointerGetDatum(&(X))
00626 #define Float8GetDatumFast(X) PointerGetDatum(&(X))
00627 #endif
00628 
00629 #ifdef USE_FLOAT4_BYVAL
00630 #define Float4GetDatumFast(X) Float4GetDatum(X)
00631 #else
00632 #define Float4GetDatumFast(X) PointerGetDatum(&(X))
00633 #endif
00634 
00635 
00636 /* ----------------------------------------------------------------
00637  *              Section 3:  exception handling backend support
00638  * ----------------------------------------------------------------
00639  */
00640 
00641 /*
00642  * These declarations supports the assertion-related macros in c.h.
00643  * assert_enabled is here because that file doesn't have PGDLLIMPORT in the
00644  * right place, and ExceptionalCondition must be present, for the backend only,
00645  * even when assertions are not enabled.
00646  */
00647 extern PGDLLIMPORT bool assert_enabled;
00648 
00649 extern void ExceptionalCondition(const char *conditionName,
00650                      const char *errorType,
00651              const char *fileName, int lineNumber) __attribute__((noreturn));
00652 
00653 #endif   /* POSTGRES_H */