PostgreSQL Source Code
git master
Main Page
Namespaces
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
postgres.h
Go to the documentation of this file.
1
/*-------------------------------------------------------------------------
2
*
3
* postgres.h
4
* Primary include file for PostgreSQL server .c files
5
*
6
* This should be the first file included by PostgreSQL backend modules.
7
* Client-side code should include postgres_fe.h instead.
8
*
9
*
10
* Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group
11
* Portions Copyright (c) 1995, Regents of the University of California
12
*
13
* src/include/postgres.h
14
*
15
*-------------------------------------------------------------------------
16
*/
17
/*
18
*----------------------------------------------------------------
19
* TABLE OF CONTENTS
20
*
21
* When adding stuff to this file, please try to put stuff
22
* into the relevant section, or add new sections as appropriate.
23
*
24
* section description
25
* ------- ------------------------------------------------
26
* 1) variable-length datatypes (TOAST support)
27
* 2) datum type + support macros
28
* 3) exception handling backend support
29
*
30
* NOTES
31
*
32
* In general, this file should contain declarations that are widely needed
33
* in the backend environment, but are of no interest outside the backend.
34
*
35
* Simple type definitions live in c.h, where they are shared with
36
* postgres_fe.h. We do that since those type definitions are needed by
37
* frontend modules that want to deal with binary data transmission to or
38
* from the backend. Type definitions in this file should be for
39
* representations that never escape the backend, such as Datum or
40
* TOASTed varlena objects.
41
*
42
*----------------------------------------------------------------
43
*/
44
#ifndef POSTGRES_H
45
#define POSTGRES_H
46
47
#include "
c.h
"
48
#include "
utils/elog.h
"
49
#include "
utils/palloc.h
"
50
51
/* ----------------------------------------------------------------
52
* Section 1: variable-length datatypes (TOAST support)
53
* ----------------------------------------------------------------
54
*/
55
56
/*
57
* struct varatt_external is a "TOAST pointer", that is, the information needed
58
* to fetch a Datum stored in an out-of-line on-disk Datum. The data is
59
* compressed if and only if va_extsize < va_rawsize - VARHDRSZ. This struct
60
* must not contain any padding, because we sometimes compare pointers using
61
* memcmp.
62
*
63
* Note that this information is stored unaligned within actual tuples, so
64
* you need to memcpy from the tuple into a local struct variable before
65
* you can look at these fields! (The reason we use memcmp is to avoid
66
* having to do that just to detect equality of two TOAST pointers...)
67
*/
68
typedef
struct
varatt_external
69
{
70
int32
va_rawsize
;
/* Original data size (includes header) */
71
int32
va_extsize
;
/* External saved size (doesn't) */
72
Oid
va_valueid
;
/* Unique ID of value within TOAST table */
73
Oid
va_toastrelid
;
/* RelID of TOAST table containing it */
74
}
varatt_external
;
75
76
/*
77
* Out-of-line Datum thats stored in memory in contrast to varatt_external
78
* pointers which points to data in an external toast relation.
79
*
80
* Note that just as varatt_external's this is stored unaligned within the
81
* tuple.
82
*/
83
typedef
struct
varatt_indirect
84
{
85
struct
varlena
*
pointer
;
/* Pointer to in-memory varlena */
86
}
varatt_indirect
;
87
88
89
/*
90
* Type of external toast datum stored. The peculiar value for VARTAG_ONDISK
91
* comes from the requirement for on-disk compatibility with the older
92
* definitions of varattrib_1b_e where v_tag was named va_len_1be...
93
*/
94
typedef
enum
vartag_external
95
{
96
VARTAG_INDIRECT
= 1,
97
VARTAG_ONDISK
= 18
98
}
vartag_external
;
99
100
#define VARTAG_SIZE(tag) \
101
((tag) == VARTAG_INDIRECT ? sizeof(varatt_indirect) : \
102
(tag) == VARTAG_ONDISK ? sizeof(varatt_external) : \
103
TrapMacro(true, "unknown vartag"))
104
105
/*
106
* These structs describe the header of a varlena object that may have been
107
* TOASTed. Generally, don't reference these structs directly, but use the
108
* macros below.
109
*
110
* We use separate structs for the aligned and unaligned cases because the
111
* compiler might otherwise think it could generate code that assumes
112
* alignment while touching fields of a 1-byte-header varlena.
113
*/
114
typedef
union
115
{
116
struct
/* Normal varlena (4-byte length) */
117
{
118
uint32
va_header
;
119
char
va_data[1];
120
} va_4byte;
121
struct
/* Compressed-in-line format */
122
{
123
uint32
va_header;
124
uint32
va_rawsize
;
/* Original data size (excludes header) */
125
char
va_data[1];
/* Compressed data */
126
} va_compressed;
127
}
varattrib_4b
;
128
129
typedef
struct
130
{
131
uint8
va_header
;
132
char
va_data[1];
/* Data begins here */
133
}
varattrib_1b
;
134
135
/* inline portion of a short varlena pointing to an external resource */
136
typedef
struct
137
{
138
uint8
va_header
;
/* Always 0x80 or 0x01 */
139
uint8
va_tag
;
/* Type of datum */
140
char
va_data[1];
/* Data (of the type indicated by va_tag) */
141
}
varattrib_1b_e
;
142
143
/*
144
* Bit layouts for varlena headers on big-endian machines:
145
*
146
* 00xxxxxx 4-byte length word, aligned, uncompressed data (up to 1G)
147
* 01xxxxxx 4-byte length word, aligned, *compressed* data (up to 1G)
148
* 10000000 1-byte length word, unaligned, TOAST pointer
149
* 1xxxxxxx 1-byte length word, unaligned, uncompressed data (up to 126b)
150
*
151
* Bit layouts for varlena headers on little-endian machines:
152
*
153
* xxxxxx00 4-byte length word, aligned, uncompressed data (up to 1G)
154
* xxxxxx10 4-byte length word, aligned, *compressed* data (up to 1G)
155
* 00000001 1-byte length word, unaligned, TOAST pointer
156
* xxxxxxx1 1-byte length word, unaligned, uncompressed data (up to 126b)
157
*
158
* The "xxx" bits are the length field (which includes itself in all cases).
159
* In the big-endian case we mask to extract the length, in the little-endian
160
* case we shift. Note that in both cases the flag bits are in the physically
161
* first byte. Also, it is not possible for a 1-byte length word to be zero;
162
* this lets us disambiguate alignment padding bytes from the start of an
163
* unaligned datum. (We now *require* pad bytes to be filled with zero!)
164
*
165
* In TOAST datums the tag field in varattrib_1b_e is used to discern whether
166
* its an indirection pointer or more commonly an on-disk tuple.
167
*/
168
169
/*
170
* Endian-dependent macros. These are considered internal --- use the
171
* external macros below instead of using these directly.
172
*
173
* Note: IS_1B is true for external toast records but VARSIZE_1B will return 0
174
* for such records. Hence you should usually check for IS_EXTERNAL before
175
* checking for IS_1B.
176
*/
177
178
#ifdef WORDS_BIGENDIAN
179
180
#define VARATT_IS_4B(PTR) \
181
((((varattrib_1b *) (PTR))->va_header & 0x80) == 0x00)
182
#define VARATT_IS_4B_U(PTR) \
183
((((varattrib_1b *) (PTR))->va_header & 0xC0) == 0x00)
184
#define VARATT_IS_4B_C(PTR) \
185
((((varattrib_1b *) (PTR))->va_header & 0xC0) == 0x40)
186
#define VARATT_IS_1B(PTR) \
187
((((varattrib_1b *) (PTR))->va_header & 0x80) == 0x80)
188
#define VARATT_IS_1B_E(PTR) \
189
((((varattrib_1b *) (PTR))->va_header) == 0x80)
190
#define VARATT_NOT_PAD_BYTE(PTR) \
191
(*((uint8 *) (PTR)) != 0)
192
193
/* VARSIZE_4B() should only be used on known-aligned data */
194
#define VARSIZE_4B(PTR) \
195
(((varattrib_4b *) (PTR))->va_4byte.va_header & 0x3FFFFFFF)
196
#define VARSIZE_1B(PTR) \
197
(((varattrib_1b *) (PTR))->va_header & 0x7F)
198
#define VARTAG_1B_E(PTR) \
199
(((varattrib_1b_e *) (PTR))->va_tag)
200
201
#define SET_VARSIZE_4B(PTR,len) \
202
(((varattrib_4b *) (PTR))->va_4byte.va_header = (len) & 0x3FFFFFFF)
203
#define SET_VARSIZE_4B_C(PTR,len) \
204
(((varattrib_4b *) (PTR))->va_4byte.va_header = ((len) & 0x3FFFFFFF) | 0x40000000)
205
#define SET_VARSIZE_1B(PTR,len) \
206
(((varattrib_1b *) (PTR))->va_header = (len) | 0x80)
207
#define SET_VARTAG_1B_E(PTR,tag) \
208
(((varattrib_1b_e *) (PTR))->va_header = 0x80, \
209
((varattrib_1b_e *) (PTR))->va_tag = (tag))
210
#else
/* !WORDS_BIGENDIAN */
211
212
#define VARATT_IS_4B(PTR) \
213
((((varattrib_1b *) (PTR))->va_header & 0x01) == 0x00)
214
#define VARATT_IS_4B_U(PTR) \
215
((((varattrib_1b *) (PTR))->va_header & 0x03) == 0x00)
216
#define VARATT_IS_4B_C(PTR) \
217
((((varattrib_1b *) (PTR))->va_header & 0x03) == 0x02)
218
#define VARATT_IS_1B(PTR) \
219
((((varattrib_1b *) (PTR))->va_header & 0x01) == 0x01)
220
#define VARATT_IS_1B_E(PTR) \
221
((((varattrib_1b *) (PTR))->va_header) == 0x01)
222
#define VARATT_NOT_PAD_BYTE(PTR) \
223
(*((uint8 *) (PTR)) != 0)
224
225
/* VARSIZE_4B() should only be used on known-aligned data */
226
#define VARSIZE_4B(PTR) \
227
((((varattrib_4b *) (PTR))->va_4byte.va_header >> 2) & 0x3FFFFFFF)
228
#define VARSIZE_1B(PTR) \
229
((((varattrib_1b *) (PTR))->va_header >> 1) & 0x7F)
230
#define VARTAG_1B_E(PTR) \
231
(((varattrib_1b_e *) (PTR))->va_tag)
232
233
#define SET_VARSIZE_4B(PTR,len) \
234
(((varattrib_4b *) (PTR))->va_4byte.va_header = (((uint32) (len)) << 2))
235
#define SET_VARSIZE_4B_C(PTR,len) \
236
(((varattrib_4b *) (PTR))->va_4byte.va_header = (((uint32) (len)) << 2) | 0x02)
237
#define SET_VARSIZE_1B(PTR,len) \
238
(((varattrib_1b *) (PTR))->va_header = (((uint8) (len)) << 1) | 0x01)
239
#define SET_VARTAG_1B_E(PTR,tag) \
240
(((varattrib_1b_e *) (PTR))->va_header = 0x01, \
241
((varattrib_1b_e *) (PTR))->va_tag = (tag))
242
#endif
/* WORDS_BIGENDIAN */
243
244
#define VARHDRSZ_SHORT offsetof(varattrib_1b, va_data)
245
#define VARATT_SHORT_MAX 0x7F
246
#define VARATT_CAN_MAKE_SHORT(PTR) \
247
(VARATT_IS_4B_U(PTR) && \
248
(VARSIZE(PTR) - VARHDRSZ + VARHDRSZ_SHORT) <= VARATT_SHORT_MAX)
249
#define VARATT_CONVERTED_SHORT_SIZE(PTR) \
250
(VARSIZE(PTR) - VARHDRSZ + VARHDRSZ_SHORT)
251
252
#define VARHDRSZ_EXTERNAL offsetof(varattrib_1b_e, va_data)
253
254
#define VARDATA_4B(PTR) (((varattrib_4b *) (PTR))->va_4byte.va_data)
255
#define VARDATA_4B_C(PTR) (((varattrib_4b *) (PTR))->va_compressed.va_data)
256
#define VARDATA_1B(PTR) (((varattrib_1b *) (PTR))->va_data)
257
#define VARDATA_1B_E(PTR) (((varattrib_1b_e *) (PTR))->va_data)
258
259
#define VARRAWSIZE_4B_C(PTR) \
260
(((varattrib_4b *) (PTR))->va_compressed.va_rawsize)
261
262
/* Externally visible macros */
263
264
/*
265
* VARDATA, VARSIZE, and SET_VARSIZE are the recommended API for most code
266
* for varlena datatypes. Note that they only work on untoasted,
267
* 4-byte-header Datums!
268
*
269
* Code that wants to use 1-byte-header values without detoasting should
270
* use VARSIZE_ANY/VARSIZE_ANY_EXHDR/VARDATA_ANY. The other macros here
271
* should usually be used only by tuple assembly/disassembly code and
272
* code that specifically wants to work with still-toasted Datums.
273
*
274
* WARNING: It is only safe to use VARDATA_ANY() -- typically with
275
* PG_DETOAST_DATUM_PACKED() -- if you really don't care about the alignment.
276
* Either because you're working with something like text where the alignment
277
* doesn't matter or because you're not going to access its constituent parts
278
* and just use things like memcpy on it anyways.
279
*/
280
#define VARDATA(PTR) VARDATA_4B(PTR)
281
#define VARSIZE(PTR) VARSIZE_4B(PTR)
282
283
#define VARSIZE_SHORT(PTR) VARSIZE_1B(PTR)
284
#define VARDATA_SHORT(PTR) VARDATA_1B(PTR)
285
286
#define VARTAG_EXTERNAL(PTR) VARTAG_1B_E(PTR)
287
#define VARSIZE_EXTERNAL(PTR) (VARHDRSZ_EXTERNAL + VARTAG_SIZE(VARTAG_EXTERNAL(PTR)))
288
#define VARDATA_EXTERNAL(PTR) VARDATA_1B_E(PTR)
289
290
#define VARATT_IS_COMPRESSED(PTR) VARATT_IS_4B_C(PTR)
291
#define VARATT_IS_EXTERNAL(PTR) VARATT_IS_1B_E(PTR)
292
#define VARATT_IS_EXTERNAL_ONDISK(PTR) \
293
(VARATT_IS_EXTERNAL(PTR) && VARTAG_EXTERNAL(PTR) == VARTAG_ONDISK)
294
#define VARATT_IS_EXTERNAL_INDIRECT(PTR) \
295
(VARATT_IS_EXTERNAL(PTR) && VARTAG_EXTERNAL(PTR) == VARTAG_INDIRECT)
296
#define VARATT_IS_SHORT(PTR) VARATT_IS_1B(PTR)
297
#define VARATT_IS_EXTENDED(PTR) (!VARATT_IS_4B_U(PTR))
298
299
#define SET_VARSIZE(PTR, len) SET_VARSIZE_4B(PTR, len)
300
#define SET_VARSIZE_SHORT(PTR, len) SET_VARSIZE_1B(PTR, len)
301
#define SET_VARSIZE_COMPRESSED(PTR, len) SET_VARSIZE_4B_C(PTR, len)
302
303
#define SET_VARTAG_EXTERNAL(PTR, tag) SET_VARTAG_1B_E(PTR, tag)
304
305
#define VARSIZE_ANY(PTR) \
306
(VARATT_IS_1B_E(PTR) ? VARSIZE_EXTERNAL(PTR) : \
307
(VARATT_IS_1B(PTR) ? VARSIZE_1B(PTR) : \
308
VARSIZE_4B(PTR)))
309
310
/* Size of a varlena data, excluding header */
311
#define VARSIZE_ANY_EXHDR(PTR) \
312
(VARATT_IS_1B_E(PTR) ? VARSIZE_EXTERNAL(PTR)-VARHDRSZ_EXTERNAL : \
313
(VARATT_IS_1B(PTR) ? VARSIZE_1B(PTR)-VARHDRSZ_SHORT : \
314
VARSIZE_4B(PTR)-VARHDRSZ))
315
316
/* caution: this will not work on an external or compressed-in-line Datum */
317
/* caution: this will return a possibly unaligned pointer */
318
#define VARDATA_ANY(PTR) \
319
(VARATT_IS_1B(PTR) ? VARDATA_1B(PTR) : VARDATA_4B(PTR))
320
321
322
/* ----------------------------------------------------------------
323
* Section 2: datum type + support macros
324
* ----------------------------------------------------------------
325
*/
326
327
/*
328
* Port Notes:
329
* Postgres makes the following assumptions about datatype sizes:
330
*
331
* sizeof(Datum) == sizeof(void *) == 4 or 8
332
* sizeof(char) == 1
333
* sizeof(short) == 2
334
*
335
* When a type narrower than Datum is stored in a Datum, we place it in the
336
* low-order bits and are careful that the DatumGetXXX macro for it discards
337
* the unused high-order bits (as opposed to, say, assuming they are zero).
338
* This is needed to support old-style user-defined functions, since depending
339
* on architecture and compiler, the return value of a function returning char
340
* or short may contain garbage when called as if it returned Datum.
341
*/
342
343
typedef
uintptr_t
Datum
;
344
345
#define SIZEOF_DATUM SIZEOF_VOID_P
346
347
typedef
Datum
*
DatumPtr
;
348
349
#define GET_1_BYTE(datum) (((Datum) (datum)) & 0x000000ff)
350
#define GET_2_BYTES(datum) (((Datum) (datum)) & 0x0000ffff)
351
#define GET_4_BYTES(datum) (((Datum) (datum)) & 0xffffffff)
352
#if SIZEOF_DATUM == 8
353
#define GET_8_BYTES(datum) ((Datum) (datum))
354
#endif
355
#define SET_1_BYTE(value) (((Datum) (value)) & 0x000000ff)
356
#define SET_2_BYTES(value) (((Datum) (value)) & 0x0000ffff)
357
#define SET_4_BYTES(value) (((Datum) (value)) & 0xffffffff)
358
#if SIZEOF_DATUM == 8
359
#define SET_8_BYTES(value) ((Datum) (value))
360
#endif
361
362
/*
363
* DatumGetBool
364
* Returns boolean value of a datum.
365
*
366
* Note: any nonzero value will be considered TRUE, but we ignore bits to
367
* the left of the width of bool, per comment above.
368
*/
369
370
#define DatumGetBool(X) ((bool) (((bool) (X)) != 0))
371
372
/*
373
* BoolGetDatum
374
* Returns datum representation for a boolean.
375
*
376
* Note: any nonzero value will be considered TRUE.
377
*/
378
379
#define BoolGetDatum(X) ((Datum) ((X) ? 1 : 0))
380
381
/*
382
* DatumGetChar
383
* Returns character value of a datum.
384
*/
385
386
#define DatumGetChar(X) ((char) GET_1_BYTE(X))
387
388
/*
389
* CharGetDatum
390
* Returns datum representation for a character.
391
*/
392
393
#define CharGetDatum(X) ((Datum) SET_1_BYTE(X))
394
395
/*
396
* Int8GetDatum
397
* Returns datum representation for an 8-bit integer.
398
*/
399
400
#define Int8GetDatum(X) ((Datum) SET_1_BYTE(X))
401
402
/*
403
* DatumGetUInt8
404
* Returns 8-bit unsigned integer value of a datum.
405
*/
406
407
#define DatumGetUInt8(X) ((uint8) GET_1_BYTE(X))
408
409
/*
410
* UInt8GetDatum
411
* Returns datum representation for an 8-bit unsigned integer.
412
*/
413
414
#define UInt8GetDatum(X) ((Datum) SET_1_BYTE(X))
415
416
/*
417
* DatumGetInt16
418
* Returns 16-bit integer value of a datum.
419
*/
420
421
#define DatumGetInt16(X) ((int16) GET_2_BYTES(X))
422
423
/*
424
* Int16GetDatum
425
* Returns datum representation for a 16-bit integer.
426
*/
427
428
#define Int16GetDatum(X) ((Datum) SET_2_BYTES(X))
429
430
/*
431
* DatumGetUInt16
432
* Returns 16-bit unsigned integer value of a datum.
433
*/
434
435
#define DatumGetUInt16(X) ((uint16) GET_2_BYTES(X))
436
437
/*
438
* UInt16GetDatum
439
* Returns datum representation for a 16-bit unsigned integer.
440
*/
441
442
#define UInt16GetDatum(X) ((Datum) SET_2_BYTES(X))
443
444
/*
445
* DatumGetInt32
446
* Returns 32-bit integer value of a datum.
447
*/
448
449
#define DatumGetInt32(X) ((int32) GET_4_BYTES(X))
450
451
/*
452
* Int32GetDatum
453
* Returns datum representation for a 32-bit integer.
454
*/
455
456
#define Int32GetDatum(X) ((Datum) SET_4_BYTES(X))
457
458
/*
459
* DatumGetUInt32
460
* Returns 32-bit unsigned integer value of a datum.
461
*/
462
463
#define DatumGetUInt32(X) ((uint32) GET_4_BYTES(X))
464
465
/*
466
* UInt32GetDatum
467
* Returns datum representation for a 32-bit unsigned integer.
468
*/
469
470
#define UInt32GetDatum(X) ((Datum) SET_4_BYTES(X))
471
472
/*
473
* DatumGetObjectId
474
* Returns object identifier value of a datum.
475
*/
476
477
#define DatumGetObjectId(X) ((Oid) GET_4_BYTES(X))
478
479
/*
480
* ObjectIdGetDatum
481
* Returns datum representation for an object identifier.
482
*/
483
484
#define ObjectIdGetDatum(X) ((Datum) SET_4_BYTES(X))
485
486
/*
487
* DatumGetTransactionId
488
* Returns transaction identifier value of a datum.
489
*/
490
491
#define DatumGetTransactionId(X) ((TransactionId) GET_4_BYTES(X))
492
493
/*
494
* TransactionIdGetDatum
495
* Returns datum representation for a transaction identifier.
496
*/
497
498
#define TransactionIdGetDatum(X) ((Datum) SET_4_BYTES((X)))
499
500
/*
501
* MultiXactIdGetDatum
502
* Returns datum representation for a multixact identifier.
503
*/
504
505
#define MultiXactIdGetDatum(X) ((Datum) SET_4_BYTES((X)))
506
507
/*
508
* DatumGetCommandId
509
* Returns command identifier value of a datum.
510
*/
511
512
#define DatumGetCommandId(X) ((CommandId) GET_4_BYTES(X))
513
514
/*
515
* CommandIdGetDatum
516
* Returns datum representation for a command identifier.
517
*/
518
519
#define CommandIdGetDatum(X) ((Datum) SET_4_BYTES(X))
520
521
/*
522
* DatumGetPointer
523
* Returns pointer value of a datum.
524
*/
525
526
#define DatumGetPointer(X) ((Pointer) (X))
527
528
/*
529
* PointerGetDatum
530
* Returns datum representation for a pointer.
531
*/
532
533
#define PointerGetDatum(X) ((Datum) (X))
534
535
/*
536
* DatumGetCString
537
* Returns C string (null-terminated string) value of a datum.
538
*
539
* Note: C string is not a full-fledged Postgres type at present,
540
* but type input functions use this conversion for their inputs.
541
*/
542
543
#define DatumGetCString(X) ((char *) DatumGetPointer(X))
544
545
/*
546
* CStringGetDatum
547
* Returns datum representation for a C string (null-terminated string).
548
*
549
* Note: C string is not a full-fledged Postgres type at present,
550
* but type output functions use this conversion for their outputs.
551
* Note: CString is pass-by-reference; caller must ensure the pointed-to
552
* value has adequate lifetime.
553
*/
554
555
#define CStringGetDatum(X) PointerGetDatum(X)
556
557
/*
558
* DatumGetName
559
* Returns name value of a datum.
560
*/
561
562
#define DatumGetName(X) ((Name) DatumGetPointer(X))
563
564
/*
565
* NameGetDatum
566
* Returns datum representation for a name.
567
*
568
* Note: Name is pass-by-reference; caller must ensure the pointed-to
569
* value has adequate lifetime.
570
*/
571
572
#define NameGetDatum(X) PointerGetDatum(X)
573
574
/*
575
* DatumGetInt64
576
* Returns 64-bit integer value of a datum.
577
*
578
* Note: this macro hides whether int64 is pass by value or by reference.
579
*/
580
581
#ifdef USE_FLOAT8_BYVAL
582
#define DatumGetInt64(X) ((int64) GET_8_BYTES(X))
583
#else
584
#define DatumGetInt64(X) (* ((int64 *) DatumGetPointer(X)))
585
#endif
586
587
/*
588
* Int64GetDatum
589
* Returns datum representation for a 64-bit integer.
590
*
591
* Note: if int64 is pass by reference, this function returns a reference
592
* to palloc'd space.
593
*/
594
595
#ifdef USE_FLOAT8_BYVAL
596
#define Int64GetDatum(X) ((Datum) SET_8_BYTES(X))
597
#else
598
extern
Datum
Int64GetDatum
(int64 X);
599
#endif
600
601
/*
602
* DatumGetFloat4
603
* Returns 4-byte floating point value of a datum.
604
*
605
* Note: this macro hides whether float4 is pass by value or by reference.
606
*/
607
608
#ifdef USE_FLOAT4_BYVAL
609
extern
float4
DatumGetFloat4
(
Datum
X);
610
#else
611
#define DatumGetFloat4(X) (* ((float4 *) DatumGetPointer(X)))
612
#endif
613
614
/*
615
* Float4GetDatum
616
* Returns datum representation for a 4-byte floating point number.
617
*
618
* Note: if float4 is pass by reference, this function returns a reference
619
* to palloc'd space.
620
*/
621
622
extern
Datum
Float4GetDatum
(
float4
X);
623
624
/*
625
* DatumGetFloat8
626
* Returns 8-byte floating point value of a datum.
627
*
628
* Note: this macro hides whether float8 is pass by value or by reference.
629
*/
630
631
#ifdef USE_FLOAT8_BYVAL
632
extern
float8
DatumGetFloat8
(
Datum
X);
633
#else
634
#define DatumGetFloat8(X) (* ((float8 *) DatumGetPointer(X)))
635
#endif
636
637
/*
638
* Float8GetDatum
639
* Returns datum representation for an 8-byte floating point number.
640
*
641
* Note: if float8 is pass by reference, this function returns a reference
642
* to palloc'd space.
643
*/
644
645
extern
Datum
Float8GetDatum
(
float8
X);
646
647
648
/*
649
* Int64GetDatumFast
650
* Float8GetDatumFast
651
* Float4GetDatumFast
652
*
653
* These macros are intended to allow writing code that does not depend on
654
* whether int64, float8, float4 are pass-by-reference types, while not
655
* sacrificing performance when they are. The argument must be a variable
656
* that will exist and have the same value for as long as the Datum is needed.
657
* In the pass-by-ref case, the address of the variable is taken to use as
658
* the Datum. In the pass-by-val case, these will be the same as the non-Fast
659
* macros.
660
*/
661
662
#ifdef USE_FLOAT8_BYVAL
663
#define Int64GetDatumFast(X) Int64GetDatum(X)
664
#define Float8GetDatumFast(X) Float8GetDatum(X)
665
#else
666
#define Int64GetDatumFast(X) PointerGetDatum(&(X))
667
#define Float8GetDatumFast(X) PointerGetDatum(&(X))
668
#endif
669
670
#ifdef USE_FLOAT4_BYVAL
671
#define Float4GetDatumFast(X) Float4GetDatum(X)
672
#else
673
#define Float4GetDatumFast(X) PointerGetDatum(&(X))
674
#endif
675
676
677
/* ----------------------------------------------------------------
678
* Section 3: exception handling backend support
679
* ----------------------------------------------------------------
680
*/
681
682
/*
683
* These declarations supports the assertion-related macros in c.h.
684
* assert_enabled is here because that file doesn't have PGDLLIMPORT in the
685
* right place, and ExceptionalCondition must be present, for the backend only,
686
* even when assertions are not enabled.
687
*/
688
extern
PGDLLIMPORT
bool
assert_enabled
;
689
690
extern
void
ExceptionalCondition
(
const
char
*conditionName,
691
const
char
*errorType,
692
const
char
*fileName,
int
lineNumber)
__attribute__
((
noreturn
));
693
694
#endif
/* POSTGRES_H */
src
include
postgres.h
Generated on Fri Apr 25 2014 06:14:18 for PostgreSQL Source Code by
1.8.1.2