1 /*-------------------------------------------------------------------------
4 * definition of (and support for) postgres system types.
5 * this file is included by almost every .c in the system
7 * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
8 * Portions Copyright (c) 1995, Regents of the University of California
10 * $Id: postgres.h,v 1.40 2000/06/02 15:57:40 momjian Exp $
12 *-------------------------------------------------------------------------
16 * this file will eventually contain the definitions for the
17 * following (and perhaps other) system types:
19 * int2 int4 float4 float8
20 * Oid regproc RegProcedure
23 * int2vector oidvector
28 * 1) simple type definitions
29 * 2) varlena and array types
30 * 3) TransactionId and CommandId
31 * 4) genbki macros used by catalog/pg_xxx.h files
34 * ----------------------------------------------------------------
39 #include "postgres_ext.h"
41 #include "utils/elog.h"
42 #include "utils/mcxt.h"
43 #include "utils/palloc.h"
45 /* ----------------------------------------------------------------
46 * Section 1: simple type definitions
47 * ----------------------------------------------------------------
53 #define OidIsValid(objectId) ((bool) ((objectId) != InvalidOid))
55 /* unfortunately, both regproc and RegProcedure are used */
57 typedef Oid RegProcedure;
59 #define RegProcedureIsValid(p) OidIsValid(p)
61 /* ----------------------------------------------------------------
62 * Section 2: variable length and array types
63 * ----------------------------------------------------------------
75 #define VARSIZE(PTR) (((struct varlena *)(PTR))->vl_len)
76 #define VARDATA(PTR) (((struct varlena *)(PTR))->vl_dat)
77 #define VARHDRSZ ((int32) sizeof(int32))
79 typedef struct varlena bytea;
80 typedef struct varlena text;
82 typedef int2 int2vector[INDEX_MAX_KEYS];
83 typedef Oid oidvector[INDEX_MAX_KEYS];
87 * Proposed new layout for variable length attributes
88 * DO NOT USE YET - Jan
90 #undef TUPLE_TOASTER_ACTIVE
91 #undef TUPLE_TOASTER_ALL_TYPES
93 #ifdef TUPLE_TOASTER_ACTIVE
94 typedef struct varattrib
96 int32 va_header; /* External/compressed storage */
97 /* flags and item size */
102 int32 va_rawsize; /* Plain data size */
103 } va_compressed; /* Compressed stored attribute */
107 int32 va_rawsize; /* Plain data size */
108 Oid va_valueid; /* Unique identifier of value */
109 Oid va_longrelid; /* RelID where to find chunks */
110 Oid va_rowid; /* Main tables row Oid */
111 int16 va_attno; /* Main tables attno */
112 } va_external;/* External stored attribute */
114 char va_data[1]; /* Plain stored attribute */
118 #define VARATT_FLAG_EXTERNAL 0x8000
119 #define VARATT_FLAG_COMPRESSED 0x4000
120 #define VARATT_MASK_FLAGS 0xc000
121 #define VARATT_MASK_SIZE 0x3fff
123 #define VARATT_SIZEP(_PTR) (((varattrib *)(_PTR))->va_header)
124 #define VARATT_SIZE(PTR) (VARATT_SIZEP(PTR) & VARATT_MASK_SIZE)
125 #define VARATT_DATA(PTR) (((varattrib *)(PTR))->va_content.va_data)
127 #define VARATT_IS_EXTENDED(PTR) \
128 ((VARATT_SIZEP(PTR) & VARATT_MASK_FLAGS) != 0)
129 #define VARATT_IS_EXTERNAL(PTR) \
130 ((VARATT_SIZEP(PTR) & VARATT_FLAG_EXTERNAL) != 0)
131 #define VARATT_IS_COMPRESSED(PTR) \
132 ((VARATT_SIZEP(PTR) & VARATT_FLAG_COMPRESSED) != 0)
135 * This is regularly declared in access/tuptoaster.h,
136 * but we don't want to include that into every source,
137 * so we (evil evil evil) declare it here once more.
140 extern varattrib *heap_tuple_untoast_attr(varattrib * attr);
142 #define VARATT_GETPLAIN(_ARG,_VAR) { \
143 if (VARATTR_IS_EXTENDED(_ARG)) \
144 (_VAR) = (void *)heap_tuple_untoast_attr(_ARG); \
148 #define VARATT_FREE(_ARG,VAR) do { \
149 if ((void *)(_VAR) != (void *)(_ARG)) \
150 pfree((void *)(_VAR)); \
152 #else /* TUPLE_TOASTER_ACTIVE */
153 #define VARATT_SIZE(__PTR) VARSIZE(__PTR)
154 #define VARATT_SIZEP(__PTR) VARSIZE(__PTR)
155 #endif /* TUPLE_TOASTER_ACTIVE */
158 /* We want NameData to have length NAMEDATALEN and int alignment,
159 * because that's how the data type 'name' is defined in pg_type.
160 * Use a union to make sure the compiler agrees.
162 typedef union nameData
164 char data[NAMEDATALEN];
167 typedef NameData *Name;
169 #define NameStr(name) ((name).data)
171 /* ----------------------------------------------------------------
172 * Section 3: TransactionId and CommandId
173 * ----------------------------------------------------------------
176 typedef uint32 TransactionId;
178 #define InvalidTransactionId 0
179 typedef uint32 CommandId;
181 #define FirstCommandId 0
183 /* ----------------------------------------------------------------
184 * Section 4: genbki macros used by the
185 * catalog/pg_xxx.h files
186 * ----------------------------------------------------------------
189 typedef struct CppConcat(FormData_,x)
192 #define DATA(x) extern int errno
193 #define DESCR(x) extern int errno
194 #define DECLARE_INDEX(x) extern int errno
195 #define DECLARE_UNIQUE_INDEX(x) extern int errno
197 #define BUILD_INDICES
203 /* ----------------------------------------------------------------
204 * Section 5: random stuff
205 * CSIGNBIT, STATUS...
206 * ----------------------------------------------------------------
209 /* msb for int/unsigned */
210 #define ISIGNBIT (0x80000000)
211 #define WSIGNBIT (0x8000)
214 #define CSIGNBIT (0x80)
216 #define STATUS_OK (0)
217 #define STATUS_ERROR (-1)
218 #define STATUS_NOT_FOUND (-2)
219 #define STATUS_INVALID (-3)
220 #define STATUS_UNCATALOGUED (-4)
221 #define STATUS_REPLACED (-5)
222 #define STATUS_NOT_DONE (-6)
223 #define STATUS_BAD_PACKET (-7)
224 #define STATUS_FOUND (1)
227 * Cyrillic on the fly charsets recode
231 extern void SetCharSet();
232 #endif /* CYR_RECODE */
234 #endif /* POSTGRES_H */