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-2001, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1995, Regents of the University of California
10 * $Id: postgres.h,v 1.45 2001/01/24 19:43:19 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/palloc.h"
44 /* ----------------------------------------------------------------
45 * Section 1: simple type definitions
46 * ----------------------------------------------------------------
49 #define InvalidOid ((Oid) 0)
50 #define OidIsValid(objectId) ((bool) ((objectId) != InvalidOid))
52 /* unfortunately, both regproc and RegProcedure are used */
54 typedef Oid RegProcedure;
56 #define RegProcedureIsValid(p) OidIsValid(p)
58 typedef int4 aclitem; /* PHONY definition for catalog use only */
60 /* ----------------------------------------------------------------
61 * Section 2: variable length and array types
62 * ----------------------------------------------------------------
74 #define TUPLE_TOASTER_ACTIVE
76 #ifndef TUPLE_TOASTER_ACTIVE
77 #define VARSIZE(PTR) (((struct varlena *)(PTR))->vl_len)
78 #define VARDATA(PTR) (((struct varlena *)(PTR))->vl_dat)
80 #define VARHDRSZ ((int32) sizeof(int32))
83 * These widely-used datatypes are just a varlena header and the data bytes.
84 * There is no terminating null or anything like that --- the data length is
85 * always VARSIZE(ptr) - VARHDRSZ.
87 typedef struct varlena bytea;
88 typedef struct varlena text;
89 typedef struct varlena BpChar; /* blank-padded char, ie SQL char(n) */
90 typedef struct varlena VarChar; /* var-length char, ie SQL varchar(n) */
93 * Proposed new layout for variable length attributes
94 * DO NOT USE YET - Jan
97 #ifdef TUPLE_TOASTER_ACTIVE
98 typedef struct varattrib
100 int32 va_header; /* External/compressed storage */
101 /* flags and item size */
106 int32 va_rawsize; /* Plain data size */
107 char va_data[1]; /* Compressed data */
108 } va_compressed; /* Compressed stored attribute */
112 int32 va_rawsize; /* Plain data size */
113 int32 va_extsize; /* External saved size */
114 Oid va_valueid; /* Unique identifier of value */
115 Oid va_toastrelid; /* RelID where to find chunks */
116 Oid va_toastidxid; /* Main tables row Oid */
117 Oid va_rowid; /* Referencing row Oid */
118 int16 va_attno; /* Main tables attno */
119 } va_external;/* External stored attribute */
121 char va_data[1]; /* Plain stored attribute */
125 #define VARATT_FLAG_EXTERNAL 0x80000000
126 #define VARATT_FLAG_COMPRESSED 0x40000000
127 #define VARATT_MASK_FLAGS 0xc0000000
128 #define VARATT_MASK_SIZE 0x3fffffff
130 #define VARATT_SIZEP(_PTR) (((varattrib *)(_PTR))->va_header)
131 #define VARATT_SIZE(PTR) (VARATT_SIZEP(PTR) & VARATT_MASK_SIZE)
132 #define VARATT_DATA(PTR) (((varattrib *)(PTR))->va_content.va_data)
133 #define VARATT_CDATA(PTR) (((varattrib *)(PTR))->va_content.va_compressed.va_data)
135 #define VARSIZE(__PTR) VARATT_SIZE(__PTR)
136 #define VARDATA(__PTR) VARATT_DATA(__PTR)
138 #define VARATT_IS_EXTENDED(PTR) \
139 ((VARATT_SIZEP(PTR) & VARATT_MASK_FLAGS) != 0)
140 #define VARATT_IS_EXTERNAL(PTR) \
141 ((VARATT_SIZEP(PTR) & VARATT_FLAG_EXTERNAL) != 0)
142 #define VARATT_IS_COMPRESSED(PTR) \
143 ((VARATT_SIZEP(PTR) & VARATT_FLAG_COMPRESSED) != 0)
146 * This is regularly declared in access/tuptoaster.h,
147 * but we don't want to include that into every source,
148 * so we (evil evil evil) declare it here once more.
151 extern varattrib *heap_tuple_untoast_attr(varattrib * attr);
153 #define VARATT_GETPLAIN(_ARG,_VAR) { \
154 if (VARATT_IS_EXTENDED(_ARG)) \
155 (_VAR) = (void *)heap_tuple_untoast_attr(_ARG); \
157 (_VAR) = (void *)(_ARG); \
159 #define VARATT_FREE(_ARG,_VAR) do { \
160 if ((void *)(_VAR) != (void *)(_ARG)) \
161 pfree((void *)(_VAR)); \
163 #else /* TUPLE_TOASTER_ACTIVE */
164 #define VARATT_SIZE(__PTR) VARSIZE(__PTR)
165 #define VARATT_SIZEP(__PTR) VARSIZE(__PTR)
166 #endif /* TUPLE_TOASTER_ACTIVE */
169 /* fixed-length array types (these are not varlena's!) */
171 typedef int2 int2vector[INDEX_MAX_KEYS];
172 typedef Oid oidvector[INDEX_MAX_KEYS];
174 /* We want NameData to have length NAMEDATALEN and int alignment,
175 * because that's how the data type 'name' is defined in pg_type.
176 * Use a union to make sure the compiler agrees.
178 typedef union nameData
180 char data[NAMEDATALEN];
183 typedef NameData *Name;
185 #define NameStr(name) ((name).data)
187 /* ----------------------------------------------------------------
188 * Section 3: TransactionId and CommandId
189 * ----------------------------------------------------------------
192 typedef uint32 TransactionId;
194 #define InvalidTransactionId 0
196 typedef uint32 CommandId;
198 #define FirstCommandId 0
200 /* ----------------------------------------------------------------
201 * Section 4: genbki macros used by the
202 * catalog/pg_xxx.h files
203 * ----------------------------------------------------------------
206 typedef struct CppConcat(FormData_,x)
209 #define DATA(x) extern int errno
210 #define DESCR(x) extern int errno
211 #define DECLARE_INDEX(x) extern int errno
212 #define DECLARE_UNIQUE_INDEX(x) extern int errno
214 #define BUILD_INDICES
220 /* ----------------------------------------------------------------
221 * Section 5: random stuff
222 * CSIGNBIT, STATUS...
223 * ----------------------------------------------------------------
226 /* msb for int/unsigned */
227 #define ISIGNBIT (0x80000000)
228 #define WSIGNBIT (0x8000)
231 #define CSIGNBIT (0x80)
233 #define STATUS_OK (0)
234 #define STATUS_ERROR (-1)
235 #define STATUS_NOT_FOUND (-2)
236 #define STATUS_INVALID (-3)
237 #define STATUS_UNCATALOGUED (-4)
238 #define STATUS_REPLACED (-5)
239 #define STATUS_NOT_DONE (-6)
240 #define STATUS_BAD_PACKET (-7)
241 #define STATUS_FOUND (1)
244 * Cyrillic on the fly charsets recode
248 extern void SetCharSet(void);
249 #endif /* CYR_RECODE */
251 #endif /* POSTGRES_H */