PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
oid.c File Reference
#include "postgres.h"
#include <ctype.h>
#include <limits.h>
#include "catalog/pg_type.h"
#include "libpq/pqformat.h"
#include "nodes/value.h"
#include "utils/array.h"
#include "utils/builtins.h"
Include dependency graph for oid.c:

Go to the source code of this file.

Macros

#define OidVectorSize(n)   (offsetof(oidvector, values) + (n) * sizeof(Oid))
 

Functions

static Oid oidin_subr (const char *s, char **endloc)
 
Datum oidin (PG_FUNCTION_ARGS)
 
Datum oidout (PG_FUNCTION_ARGS)
 
Datum oidrecv (PG_FUNCTION_ARGS)
 
Datum oidsend (PG_FUNCTION_ARGS)
 
oidvectorbuildoidvector (const Oid *oids, int n)
 
Datum oidvectorin (PG_FUNCTION_ARGS)
 
Datum oidvectorout (PG_FUNCTION_ARGS)
 
Datum oidvectorrecv (PG_FUNCTION_ARGS)
 
Datum oidvectorsend (PG_FUNCTION_ARGS)
 
Oid oidparse (Node *node)
 
int oid_cmp (const void *p1, const void *p2)
 
Datum oideq (PG_FUNCTION_ARGS)
 
Datum oidne (PG_FUNCTION_ARGS)
 
Datum oidlt (PG_FUNCTION_ARGS)
 
Datum oidle (PG_FUNCTION_ARGS)
 
Datum oidge (PG_FUNCTION_ARGS)
 
Datum oidgt (PG_FUNCTION_ARGS)
 
Datum oidlarger (PG_FUNCTION_ARGS)
 
Datum oidsmaller (PG_FUNCTION_ARGS)
 
Datum oidvectoreq (PG_FUNCTION_ARGS)
 
Datum oidvectorne (PG_FUNCTION_ARGS)
 
Datum oidvectorlt (PG_FUNCTION_ARGS)
 
Datum oidvectorle (PG_FUNCTION_ARGS)
 
Datum oidvectorge (PG_FUNCTION_ARGS)
 
Datum oidvectorgt (PG_FUNCTION_ARGS)
 

Macro Definition Documentation

#define OidVectorSize (   n)    (offsetof(oidvector, values) + (n) * sizeof(Oid))

Definition at line 27 of file oid.c.

Referenced by buildoidvector(), and oidvectorin().

Function Documentation

oidvector* buildoidvector ( const Oid oids,
int  n 
)

Definition at line 167 of file oid.c.

References oidvector::dataoffset, oidvector::dim1, oidvector::elemtype, oidvector::lbound1, oidvector::ndim, OIDOID, OidVectorSize, palloc0(), result, SET_VARSIZE, and oidvector::values.

Referenced by CreateProceduralLanguage(), DefineAggregate(), interpret_function_parameter_list(), makeRangeConstructors(), StorePartitionKey(), and UpdateIndexRelation().

168 {
169  oidvector *result;
170 
171  result = (oidvector *) palloc0(OidVectorSize(n));
172 
173  if (n > 0 && oids)
174  memcpy(result->values, oids, n * sizeof(Oid));
175 
176  /*
177  * Attach standard array header. For historical reasons, we set the index
178  * lower bound to 0 not 1.
179  */
180  SET_VARSIZE(result, OidVectorSize(n));
181  result->ndim = 1;
182  result->dataoffset = 0; /* never any nulls */
183  result->elemtype = OIDOID;
184  result->dim1 = n;
185  result->lbound1 = 0;
186 
187  return result;
188 }
Definition: c.h:478
#define OIDOID
Definition: pg_type.h:328
int32 dataoffset
Definition: c.h:482
return result
Definition: formatting.c:1618
unsigned int Oid
Definition: postgres_ext.h:31
#define OidVectorSize(n)
Definition: oid.c:27
Oid values[FLEXIBLE_ARRAY_MEMBER]
Definition: c.h:486
int dim1
Definition: c.h:484
void * palloc0(Size size)
Definition: mcxt.c:878
int lbound1
Definition: c.h:485
Oid elemtype
Definition: c.h:483
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:328
int ndim
Definition: c.h:481
int oid_cmp ( const void *  p1,
const void *  p2 
)

Definition at line 336 of file oid.c.

Referenced by aclmembers(), AlterSubscription_refresh(), EnumValuesCreate(), and find_inheritance_children().

337 {
338  Oid v1 = *((const Oid *) p1);
339  Oid v2 = *((const Oid *) p2);
340 
341  if (v1 < v2)
342  return -1;
343  if (v1 > v2)
344  return 1;
345  return 0;
346 }
unsigned int Oid
Definition: postgres_ext.h:31
Datum oideq ( PG_FUNCTION_ARGS  )

Definition at line 354 of file oid.c.

References PG_GETARG_OID, and PG_RETURN_BOOL.

355 {
356  Oid arg1 = PG_GETARG_OID(0);
357  Oid arg2 = PG_GETARG_OID(1);
358 
359  PG_RETURN_BOOL(arg1 == arg2);
360 }
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
Datum oidge ( PG_FUNCTION_ARGS  )

Definition at line 390 of file oid.c.

References PG_GETARG_OID, and PG_RETURN_BOOL.

391 {
392  Oid arg1 = PG_GETARG_OID(0);
393  Oid arg2 = PG_GETARG_OID(1);
394 
395  PG_RETURN_BOOL(arg1 >= arg2);
396 }
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
Datum oidgt ( PG_FUNCTION_ARGS  )

Definition at line 399 of file oid.c.

References PG_GETARG_OID, and PG_RETURN_BOOL.

400 {
401  Oid arg1 = PG_GETARG_OID(0);
402  Oid arg2 = PG_GETARG_OID(1);
403 
404  PG_RETURN_BOOL(arg1 > arg2);
405 }
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
Datum oidin ( PG_FUNCTION_ARGS  )

Definition at line 117 of file oid.c.

References NULL, oidin_subr(), PG_GETARG_CSTRING, PG_RETURN_OID, and result.

Referenced by make_tuple_from_result_row(), NextCopyFrom(), regclassin(), regconfigin(), regdictionaryin(), regnamespacein(), regoperatorin(), regoperin(), regprocedurein(), regprocin(), regrolein(), and regtypein().

118 {
119  char *s = PG_GETARG_CSTRING(0);
120  Oid result;
121 
122  result = oidin_subr(s, NULL);
123  PG_RETURN_OID(result);
124 }
static Oid oidin_subr(const char *s, char **endloc)
Definition: oid.c:35
return result
Definition: formatting.c:1618
unsigned int Oid
Definition: postgres_ext.h:31
#define NULL
Definition: c.h:229
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:242
#define PG_RETURN_OID(x)
Definition: fmgr.h:320
static Oid oidin_subr ( const char *  s,
char **  endloc 
)
static

Definition at line 35 of file oid.c.

References ereport, errcode(), errmsg(), ERROR, and result.

Referenced by oidin(), oidparse(), and oidvectorin().

36 {
37  unsigned long cvt;
38  char *endptr;
39  Oid result;
40 
41  if (*s == '\0')
42  ereport(ERROR,
43  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
44  errmsg("invalid input syntax for type %s: \"%s\"",
45  "oid", s)));
46 
47  errno = 0;
48  cvt = strtoul(s, &endptr, 10);
49 
50  /*
51  * strtoul() normally only sets ERANGE. On some systems it also may set
52  * EINVAL, which simply means it couldn't parse the input string. This is
53  * handled by the second "if" consistent across platforms.
54  */
55  if (errno && errno != ERANGE && errno != EINVAL)
56  ereport(ERROR,
57  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
58  errmsg("invalid input syntax for type %s: \"%s\"",
59  "oid", s)));
60 
61  if (endptr == s && *s != '\0')
62  ereport(ERROR,
63  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
64  errmsg("invalid input syntax for type %s: \"%s\"",
65  "oid", s)));
66 
67  if (errno == ERANGE)
68  ereport(ERROR,
69  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
70  errmsg("value \"%s\" is out of range for type %s",
71  s, "oid")));
72 
73  if (endloc)
74  {
75  /* caller wants to deal with rest of string */
76  *endloc = endptr;
77  }
78  else
79  {
80  /* allow only whitespace after number */
81  while (*endptr && isspace((unsigned char) *endptr))
82  endptr++;
83  if (*endptr)
84  ereport(ERROR,
85  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
86  errmsg("invalid input syntax for type %s: \"%s\"",
87  "oid", s)));
88  }
89 
90  result = (Oid) cvt;
91 
92  /*
93  * Cope with possibility that unsigned long is wider than Oid, in which
94  * case strtoul will not raise an error for some values that are out of
95  * the range of Oid.
96  *
97  * For backwards compatibility, we want to accept inputs that are given
98  * with a minus sign, so allow the input value if it matches after either
99  * signed or unsigned extension to long.
100  *
101  * To ensure consistent results on 32-bit and 64-bit platforms, make sure
102  * the error message is the same as if strtoul() had returned ERANGE.
103  */
104 #if OID_MAX != ULONG_MAX
105  if (cvt != (unsigned long) result &&
106  cvt != (unsigned long) ((int) result))
107  ereport(ERROR,
108  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
109  errmsg("value \"%s\" is out of range for type %s",
110  s, "oid")));
111 #endif
112 
113  return result;
114 }
int errcode(int sqlerrcode)
Definition: elog.c:575
return result
Definition: formatting.c:1618
unsigned int Oid
Definition: postgres_ext.h:31
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
Datum oidlarger ( PG_FUNCTION_ARGS  )

Definition at line 408 of file oid.c.

References PG_GETARG_OID, and PG_RETURN_OID.

409 {
410  Oid arg1 = PG_GETARG_OID(0);
411  Oid arg2 = PG_GETARG_OID(1);
412 
413  PG_RETURN_OID((arg1 > arg2) ? arg1 : arg2);
414 }
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#define PG_RETURN_OID(x)
Definition: fmgr.h:320
Datum oidle ( PG_FUNCTION_ARGS  )

Definition at line 381 of file oid.c.

References PG_GETARG_OID, and PG_RETURN_BOOL.

382 {
383  Oid arg1 = PG_GETARG_OID(0);
384  Oid arg2 = PG_GETARG_OID(1);
385 
386  PG_RETURN_BOOL(arg1 <= arg2);
387 }
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
Datum oidlt ( PG_FUNCTION_ARGS  )

Definition at line 372 of file oid.c.

References PG_GETARG_OID, and PG_RETURN_BOOL.

373 {
374  Oid arg1 = PG_GETARG_OID(0);
375  Oid arg2 = PG_GETARG_OID(1);
376 
377  PG_RETURN_BOOL(arg1 < arg2);
378 }
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
Datum oidne ( PG_FUNCTION_ARGS  )

Definition at line 363 of file oid.c.

References PG_GETARG_OID, and PG_RETURN_BOOL.

364 {
365  Oid arg1 = PG_GETARG_OID(0);
366  Oid arg2 = PG_GETARG_OID(1);
367 
368  PG_RETURN_BOOL(arg1 != arg2);
369 }
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
Datum oidout ( PG_FUNCTION_ARGS  )

Definition at line 127 of file oid.c.

References palloc(), PG_GETARG_OID, PG_RETURN_CSTRING, result, and snprintf().

Referenced by CopyOneRowTo(), plperl_trigger_build_args(), pltcl_trigger_handler(), and PLy_trigger_build_args().

128 {
129  Oid o = PG_GETARG_OID(0);
130  char *result = (char *) palloc(12);
131 
132  snprintf(result, 12, "%u", o);
133  PG_RETURN_CSTRING(result);
134 }
return result
Definition: formatting.c:1618
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:322
void * palloc(Size size)
Definition: mcxt.c:849
Oid oidparse ( Node node)

Definition at line 314 of file oid.c.

References elog, ERROR, intVal, InvalidOid, nodeTag, NULL, oidin_subr(), strVal, T_Float, and T_Integer.

Referenced by get_object_address(), and objectNamesToOids().

315 {
316  switch (nodeTag(node))
317  {
318  case T_Integer:
319  return intVal(node);
320  case T_Float:
321 
322  /*
323  * Values too large for int4 will be represented as Float
324  * constants by the lexer. Accept these if they are valid OID
325  * strings.
326  */
327  return oidin_subr(strVal(node), NULL);
328  default:
329  elog(ERROR, "unrecognized node type: %d", (int) nodeTag(node));
330  }
331  return InvalidOid; /* keep compiler quiet */
332 }
static Oid oidin_subr(const char *s, char **endloc)
Definition: oid.c:35
#define strVal(v)
Definition: value.h:54
#define ERROR
Definition: elog.h:43
#define InvalidOid
Definition: postgres_ext.h:36
#define NULL
Definition: c.h:229
#define nodeTag(nodeptr)
Definition: nodes.h:511
Definition: nodes.h:280
#define intVal(v)
Definition: value.h:52
#define elog
Definition: elog.h:219
Datum oidrecv ( PG_FUNCTION_ARGS  )

Definition at line 140 of file oid.c.

References buf, PG_GETARG_POINTER, PG_RETURN_OID, and pq_getmsgint().

Referenced by regclassrecv(), regconfigrecv(), regdictionaryrecv(), regnamespacerecv(), regoperatorrecv(), regoperrecv(), regprocedurerecv(), regprocrecv(), regrolerecv(), and regtyperecv().

141 {
143 
144  PG_RETURN_OID((Oid) pq_getmsgint(buf, sizeof(Oid)));
145 }
StringInfoData * StringInfo
Definition: stringinfo.h:46
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
unsigned int Oid
Definition: postgres_ext.h:31
static char * buf
Definition: pg_test_fsync.c:65
unsigned int pq_getmsgint(StringInfo msg, int b)
Definition: pqformat.c:448
#define PG_RETURN_OID(x)
Definition: fmgr.h:320
Datum oidsend ( PG_FUNCTION_ARGS  )

Definition at line 151 of file oid.c.

References buf, PG_GETARG_OID, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), and pq_sendint().

Referenced by regclasssend(), regconfigsend(), regdictionarysend(), regnamespacesend(), regoperatorsend(), regopersend(), regproceduresend(), regprocsend(), regrolesend(), and regtypesend().

152 {
153  Oid arg1 = PG_GETARG_OID(0);
155 
156  pq_begintypsend(&buf);
157  pq_sendint(&buf, arg1, sizeof(Oid));
159 }
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:359
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:329
unsigned int Oid
Definition: postgres_ext.h:31
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:379
static char * buf
Definition: pg_test_fsync.c:65
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
void pq_sendint(StringInfo buf, int i, int b)
Definition: pqformat.c:236
Datum oidsmaller ( PG_FUNCTION_ARGS  )

Definition at line 417 of file oid.c.

References PG_GETARG_OID, and PG_RETURN_OID.

418 {
419  Oid arg1 = PG_GETARG_OID(0);
420  Oid arg2 = PG_GETARG_OID(1);
421 
422  PG_RETURN_OID((arg1 < arg2) ? arg1 : arg2);
423 }
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#define PG_RETURN_OID(x)
Definition: fmgr.h:320
Datum oidvectoreq ( PG_FUNCTION_ARGS  )

Definition at line 426 of file oid.c.

References btoidvectorcmp(), cmp(), DatumGetInt32, and PG_RETURN_BOOL.

427 {
429 
430  PG_RETURN_BOOL(cmp == 0);
431 }
#define DatumGetInt32(X)
Definition: postgres.h:478
signed int int32
Definition: c.h:256
Datum btoidvectorcmp(PG_FUNCTION_ARGS)
Definition: nbtcompare.c:287
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static int cmp(const chr *x, const chr *y, size_t len)
Definition: regc_locale.c:742
Datum oidvectorge ( PG_FUNCTION_ARGS  )

Definition at line 458 of file oid.c.

References btoidvectorcmp(), cmp(), DatumGetInt32, and PG_RETURN_BOOL.

459 {
461 
462  PG_RETURN_BOOL(cmp >= 0);
463 }
#define DatumGetInt32(X)
Definition: postgres.h:478
signed int int32
Definition: c.h:256
Datum btoidvectorcmp(PG_FUNCTION_ARGS)
Definition: nbtcompare.c:287
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static int cmp(const chr *x, const chr *y, size_t len)
Definition: regc_locale.c:742
Datum oidvectorgt ( PG_FUNCTION_ARGS  )

Definition at line 466 of file oid.c.

References btoidvectorcmp(), cmp(), DatumGetInt32, and PG_RETURN_BOOL.

467 {
469 
470  PG_RETURN_BOOL(cmp > 0);
471 }
#define DatumGetInt32(X)
Definition: postgres.h:478
signed int int32
Definition: c.h:256
Datum btoidvectorcmp(PG_FUNCTION_ARGS)
Definition: nbtcompare.c:287
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static int cmp(const chr *x, const chr *y, size_t len)
Definition: regc_locale.c:742
Datum oidvectorin ( PG_FUNCTION_ARGS  )

Definition at line 194 of file oid.c.

References oidvector::dataoffset, oidvector::dim1, oidvector::elemtype, ereport, errcode(), errmsg(), ERROR, FUNC_MAX_ARGS, oidvector::lbound1, oidvector::ndim, oidin_subr(), OIDOID, OidVectorSize, palloc0(), PG_GETARG_CSTRING, PG_RETURN_POINTER, result, SET_VARSIZE, and oidvector::values.

195 {
196  char *oidString = PG_GETARG_CSTRING(0);
197  oidvector *result;
198  int n;
199 
201 
202  for (n = 0; n < FUNC_MAX_ARGS; n++)
203  {
204  while (*oidString && isspace((unsigned char) *oidString))
205  oidString++;
206  if (*oidString == '\0')
207  break;
208  result->values[n] = oidin_subr(oidString, &oidString);
209  }
210  while (*oidString && isspace((unsigned char) *oidString))
211  oidString++;
212  if (*oidString)
213  ereport(ERROR,
214  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
215  errmsg("oidvector has too many elements")));
216 
217  SET_VARSIZE(result, OidVectorSize(n));
218  result->ndim = 1;
219  result->dataoffset = 0; /* never any nulls */
220  result->elemtype = OIDOID;
221  result->dim1 = n;
222  result->lbound1 = 0;
223 
224  PG_RETURN_POINTER(result);
225 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
Definition: c.h:478
#define OIDOID
Definition: pg_type.h:328
static Oid oidin_subr(const char *s, char **endloc)
Definition: oid.c:35
int32 dataoffset
Definition: c.h:482
int errcode(int sqlerrcode)
Definition: elog.c:575
return result
Definition: formatting.c:1618
#define FUNC_MAX_ARGS
#define OidVectorSize(n)
Definition: oid.c:27
#define ERROR
Definition: elog.h:43
Oid values[FLEXIBLE_ARRAY_MEMBER]
Definition: c.h:486
int dim1
Definition: c.h:484
#define ereport(elevel, rest)
Definition: elog.h:122
void * palloc0(Size size)
Definition: mcxt.c:878
int lbound1
Definition: c.h:485
int errmsg(const char *fmt,...)
Definition: elog.c:797
Oid elemtype
Definition: c.h:483
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:242
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:328
int ndim
Definition: c.h:481
Datum oidvectorle ( PG_FUNCTION_ARGS  )

Definition at line 450 of file oid.c.

References btoidvectorcmp(), cmp(), DatumGetInt32, and PG_RETURN_BOOL.

451 {
453 
454  PG_RETURN_BOOL(cmp <= 0);
455 }
#define DatumGetInt32(X)
Definition: postgres.h:478
signed int int32
Definition: c.h:256
Datum btoidvectorcmp(PG_FUNCTION_ARGS)
Definition: nbtcompare.c:287
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static int cmp(const chr *x, const chr *y, size_t len)
Definition: regc_locale.c:742
Datum oidvectorlt ( PG_FUNCTION_ARGS  )

Definition at line 442 of file oid.c.

References btoidvectorcmp(), cmp(), DatumGetInt32, and PG_RETURN_BOOL.

443 {
445 
446  PG_RETURN_BOOL(cmp < 0);
447 }
#define DatumGetInt32(X)
Definition: postgres.h:478
signed int int32
Definition: c.h:256
Datum btoidvectorcmp(PG_FUNCTION_ARGS)
Definition: nbtcompare.c:287
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static int cmp(const chr *x, const chr *y, size_t len)
Definition: regc_locale.c:742
Datum oidvectorne ( PG_FUNCTION_ARGS  )

Definition at line 434 of file oid.c.

References btoidvectorcmp(), cmp(), DatumGetInt32, and PG_RETURN_BOOL.

435 {
437 
438  PG_RETURN_BOOL(cmp != 0);
439 }
#define DatumGetInt32(X)
Definition: postgres.h:478
signed int int32
Definition: c.h:256
Datum btoidvectorcmp(PG_FUNCTION_ARGS)
Definition: nbtcompare.c:287
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static int cmp(const chr *x, const chr *y, size_t len)
Definition: regc_locale.c:742
Datum oidvectorout ( PG_FUNCTION_ARGS  )

Definition at line 231 of file oid.c.

References oidvector::dim1, palloc(), PG_GETARG_POINTER, PG_RETURN_CSTRING, result, and oidvector::values.

232 {
233  oidvector *oidArray = (oidvector *) PG_GETARG_POINTER(0);
234  int num,
235  nnums = oidArray->dim1;
236  char *rp;
237  char *result;
238 
239  /* assumes sign, 10 digits, ' ' */
240  rp = result = (char *) palloc(nnums * 12 + 1);
241  for (num = 0; num < nnums; num++)
242  {
243  if (num != 0)
244  *rp++ = ' ';
245  sprintf(rp, "%u", oidArray->values[num]);
246  while (*++rp != '\0')
247  ;
248  }
249  *rp = '\0';
250  PG_RETURN_CSTRING(result);
251 }
Definition: c.h:478
return result
Definition: formatting.c:1618
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
Oid values[FLEXIBLE_ARRAY_MEMBER]
Definition: c.h:486
int dim1
Definition: c.h:484
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:322
void * palloc(Size size)
Definition: mcxt.c:849
Datum oidvectorrecv ( PG_FUNCTION_ARGS  )

Definition at line 257 of file oid.c.

References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, ARR_DIMS, ARR_ELEMTYPE, ARR_HASNULL, ARR_LBOUND, ARR_NDIM, array_recv(), Assert, buf, DatumGetPointer, ereport, errcode(), errmsg(), ERROR, FunctionCallInfoData::flinfo, FUNC_MAX_ARGS, InitFunctionCallInfoData, Int32GetDatum, InvalidOid, FunctionCallInfoData::isnull, NULL, ObjectIdGetDatum, OIDOID, PG_GETARG_POINTER, PG_RETURN_POINTER, PointerGetDatum, and result.

258 {
260  FunctionCallInfoData locfcinfo;
261  oidvector *result;
262 
263  /*
264  * Normally one would call array_recv() using DirectFunctionCall3, but
265  * that does not work since array_recv wants to cache some data using
266  * fcinfo->flinfo->fn_extra. So we need to pass it our own flinfo
267  * parameter.
268  */
269  InitFunctionCallInfoData(locfcinfo, fcinfo->flinfo, 3,
270  InvalidOid, NULL, NULL);
271 
272  locfcinfo.arg[0] = PointerGetDatum(buf);
273  locfcinfo.arg[1] = ObjectIdGetDatum(OIDOID);
274  locfcinfo.arg[2] = Int32GetDatum(-1);
275  locfcinfo.argnull[0] = false;
276  locfcinfo.argnull[1] = false;
277  locfcinfo.argnull[2] = false;
278 
279  result = (oidvector *) DatumGetPointer(array_recv(&locfcinfo));
280 
281  Assert(!locfcinfo.isnull);
282 
283  /* sanity checks: oidvector must be 1-D, 0-based, no nulls */
284  if (ARR_NDIM(result) != 1 ||
285  ARR_HASNULL(result) ||
286  ARR_ELEMTYPE(result) != OIDOID ||
287  ARR_LBOUND(result)[0] != 0)
288  ereport(ERROR,
289  (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
290  errmsg("invalid oidvector data")));
291 
292  /* check length for consistency with oidvectorin() */
293  if (ARR_DIMS(result)[0] > FUNC_MAX_ARGS)
294  ereport(ERROR,
295  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
296  errmsg("oidvector has too many elements")));
297 
298  PG_RETURN_POINTER(result);
299 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
Definition: c.h:478
#define OIDOID
Definition: pg_type.h:328
#define PointerGetDatum(X)
Definition: postgres.h:562
StringInfoData * StringInfo
Definition: stringinfo.h:46
int errcode(int sqlerrcode)
Definition: elog.c:575
return result
Definition: formatting.c:1618
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
Datum array_recv(PG_FUNCTION_ARGS)
Definition: arrayfuncs.c:1254
#define ARR_LBOUND(a)
Definition: array.h:277
#define FUNC_MAX_ARGS
FmgrInfo * flinfo
Definition: fmgr.h:79
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
#define ARR_DIMS(a)
Definition: array.h:275
static char * buf
Definition: pg_test_fsync.c:65
#define ARR_HASNULL(a)
Definition: array.h:272
bool argnull[FUNC_MAX_ARGS]
Definition: fmgr.h:86
#define ereport(elevel, rest)
Definition: elog.h:122
#define InvalidOid
Definition: postgres_ext.h:36
Datum arg[FUNC_MAX_ARGS]
Definition: fmgr.h:85
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:120
#define ARR_NDIM(a)
Definition: array.h:271
#define DatumGetPointer(X)
Definition: postgres.h:555
#define Int32GetDatum(X)
Definition: postgres.h:485
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define ARR_ELEMTYPE(a)
Definition: array.h:273
Datum oidvectorsend ( PG_FUNCTION_ARGS  )

Definition at line 305 of file oid.c.

References array_send().

306 {
307  return array_send(fcinfo);
308 }
Datum array_send(PG_FUNCTION_ARGS)
Definition: arrayfuncs.c:1534