PostgreSQL Source Code  git master
readfuncs.c File Reference
#include "postgres.h"
#include <math.h>
#include "miscadmin.h"
#include "nodes/bitmapset.h"
#include "nodes/readfuncs.h"
#include "readfuncs.funcs.c"
#include "readfuncs.switch.c"
Include dependency graph for readfuncs.c:

Go to the source code of this file.

Macros

#define READ_LOCALS_NO_FIELDS(nodeTypeName)    nodeTypeName *local_node = makeNode(nodeTypeName)
 
#define READ_TEMP_LOCALS()
 
#define READ_LOCALS(nodeTypeName)
 
#define READ_INT_FIELD(fldname)
 
#define READ_UINT_FIELD(fldname)
 
#define READ_UINT64_FIELD(fldname)
 
#define READ_LONG_FIELD(fldname)
 
#define READ_OID_FIELD(fldname)
 
#define READ_CHAR_FIELD(fldname)
 
#define READ_ENUM_FIELD(fldname, enumtype)
 
#define READ_FLOAT_FIELD(fldname)
 
#define READ_BOOL_FIELD(fldname)
 
#define READ_STRING_FIELD(fldname)
 
#define READ_LOCATION_FIELD(fldname)
 
#define READ_NODE_FIELD(fldname)
 
#define READ_BITMAPSET_FIELD(fldname)
 
#define READ_ATTRNUMBER_ARRAY(fldname, len)
 
#define READ_OID_ARRAY(fldname, len)
 
#define READ_INT_ARRAY(fldname, len)
 
#define READ_BOOL_ARRAY(fldname, len)
 
#define READ_DONE()    return local_node
 
#define atoui(x)   ((unsigned int) strtoul((x), NULL, 10))
 
#define strtobool(x)   ((*(x) == 't') ? true : false)
 
#define MATCH(tokname, namelen)    (length == namelen && memcmp(token, tokname, namelen) == 0)
 
#define READ_SCALAR_ARRAY(fnname, datatype, convfunc)
 

Functions

static char * nullable_string (const char *token, int length)
 
static Bitmapset_readBitmapset (void)
 
BitmapsetreadBitmapset (void)
 
static Const_readConst (void)
 
static BoolExpr_readBoolExpr (void)
 
static A_Const_readA_Const (void)
 
static Constraint_readConstraint (void)
 
static RangeTblEntry_readRangeTblEntry (void)
 
static A_Expr_readA_Expr (void)
 
static ExtensibleNode_readExtensibleNode (void)
 
NodeparseNodeString (void)
 
Datum readDatum (bool typbyval)
 

Macro Definition Documentation

◆ atoui

#define atoui (   x)    ((unsigned int) strtoul((x), NULL, 10))

Definition at line 177 of file readfuncs.c.

◆ MATCH

#define MATCH (   tokname,
  namelen 
)     (length == namelen && memcmp(token, tokname, namelen) == 0)

◆ READ_ATTRNUMBER_ARRAY

#define READ_ATTRNUMBER_ARRAY (   fldname,
  len 
)
Value:
token = pg_strtok(&length); /* skip :fldname */ \
local_node->fldname = readAttrNumberCols(len)
#define token
Definition: indent_globs.h:126
int16 * readAttrNumberCols(int numCols)
const void size_t len
const char * pg_strtok(int *length)
Definition: read.c:153

Definition at line 147 of file readfuncs.c.

◆ READ_BITMAPSET_FIELD

#define READ_BITMAPSET_FIELD (   fldname)
Value:
token = pg_strtok(&length); /* skip :fldname */ \
(void) token; /* in case not used elsewhere */ \
local_node->fldname = _readBitmapset()
static Bitmapset * _readBitmapset(void)
Definition: readfuncs.c:203

Definition at line 141 of file readfuncs.c.

◆ READ_BOOL_ARRAY

#define READ_BOOL_ARRAY (   fldname,
  len 
)
Value:
token = pg_strtok(&length); /* skip :fldname */ \
local_node->fldname = readBoolCols(len)
bool * readBoolCols(int numCols)

Definition at line 162 of file readfuncs.c.

◆ READ_BOOL_FIELD

#define READ_BOOL_FIELD (   fldname)
Value:
token = pg_strtok(&length); /* skip :fldname */ \
token = pg_strtok(&length); /* get field value */ \
local_node->fldname = strtobool(token)
#define strtobool(x)
Definition: readfuncs.c:179

Definition at line 109 of file readfuncs.c.

◆ READ_CHAR_FIELD

#define READ_CHAR_FIELD (   fldname)
Value:
token = pg_strtok(&length); /* skip :fldname */ \
token = pg_strtok(&length); /* get field value */ \
/* avoid overhead of calling debackslash() for one char */ \
local_node->fldname = (length == 0) ? '\0' : (token[0] == '\\' ? token[1] : token[0])

Definition at line 90 of file readfuncs.c.

◆ READ_DONE

#define READ_DONE ( )     return local_node

Definition at line 167 of file readfuncs.c.

◆ READ_ENUM_FIELD

#define READ_ENUM_FIELD (   fldname,
  enumtype 
)
Value:
token = pg_strtok(&length); /* skip :fldname */ \
token = pg_strtok(&length); /* get field value */ \
local_node->fldname = (enumtype) atoi(token)

Definition at line 97 of file readfuncs.c.

◆ READ_FLOAT_FIELD

#define READ_FLOAT_FIELD (   fldname)
Value:
token = pg_strtok(&length); /* skip :fldname */ \
token = pg_strtok(&length); /* get field value */ \
local_node->fldname = atof(token)

Definition at line 103 of file readfuncs.c.

◆ READ_INT_ARRAY

#define READ_INT_ARRAY (   fldname,
  len 
)
Value:
token = pg_strtok(&length); /* skip :fldname */ \
local_node->fldname = readIntCols(len)
int * readIntCols(int numCols)

Definition at line 157 of file readfuncs.c.

◆ READ_INT_FIELD

#define READ_INT_FIELD (   fldname)
Value:
token = pg_strtok(&length); /* skip :fldname */ \
token = pg_strtok(&length); /* get field value */ \
local_node->fldname = atoi(token)

Definition at line 60 of file readfuncs.c.

◆ READ_LOCALS

#define READ_LOCALS (   nodeTypeName)
Value:
READ_LOCALS_NO_FIELDS(nodeTypeName); \
READ_TEMP_LOCALS()
#define READ_LOCALS_NO_FIELDS(nodeTypeName)
Definition: readfuncs.c:46

Definition at line 55 of file readfuncs.c.

◆ READ_LOCALS_NO_FIELDS

#define READ_LOCALS_NO_FIELDS (   nodeTypeName)     nodeTypeName *local_node = makeNode(nodeTypeName)

Definition at line 46 of file readfuncs.c.

◆ READ_LOCATION_FIELD

#define READ_LOCATION_FIELD (   fldname)
Value:
token = pg_strtok(&length); /* skip :fldname */ \
token = pg_strtok(&length); /* get field value */ \
(void) token; /* in case not used elsewhere */ \
local_node->fldname = -1 /* set field to "unknown" */

Definition at line 127 of file readfuncs.c.

◆ READ_LONG_FIELD

#define READ_LONG_FIELD (   fldname)
Value:
token = pg_strtok(&length); /* skip :fldname */ \
token = pg_strtok(&length); /* get field value */ \
local_node->fldname = atol(token)

Definition at line 78 of file readfuncs.c.

◆ READ_NODE_FIELD

#define READ_NODE_FIELD (   fldname)
Value:
token = pg_strtok(&length); /* skip :fldname */ \
(void) token; /* in case not used elsewhere */ \
local_node->fldname = nodeRead(NULL, 0)
void * nodeRead(const char *token, int tok_len)
Definition: read.c:320

Definition at line 135 of file readfuncs.c.

◆ READ_OID_ARRAY

#define READ_OID_ARRAY (   fldname,
  len 
)
Value:
token = pg_strtok(&length); /* skip :fldname */ \
local_node->fldname = readOidCols(len)
Oid * readOidCols(int numCols)

Definition at line 152 of file readfuncs.c.

◆ READ_OID_FIELD

#define READ_OID_FIELD (   fldname)
Value:
token = pg_strtok(&length); /* skip :fldname */ \
token = pg_strtok(&length); /* get field value */ \
local_node->fldname = atooid(token)
#define atooid(x)
Definition: postgres_ext.h:42

Definition at line 84 of file readfuncs.c.

◆ READ_SCALAR_ARRAY

#define READ_SCALAR_ARRAY (   fnname,
  datatype,
  convfunc 
)
Value:
datatype * \
fnname(int numCols) \
{ \
datatype *vals; \
READ_TEMP_LOCALS(); \
token = pg_strtok(&length); \
if (token == NULL) \
elog(ERROR, "incomplete scalar array"); \
if (length == 0) \
return NULL; /* it was "<>", so return NULL pointer */ \
if (length != 1 || token[0] != '(') \
elog(ERROR, "unrecognized token: \"%.*s\"", length, token); \
vals = (datatype *) palloc(numCols * sizeof(datatype)); \
for (int i = 0; i < numCols; i++) \
{ \
token = pg_strtok(&length); \
if (token == NULL || token[0] == ')') \
elog(ERROR, "incomplete scalar array"); \
vals[i] = convfunc(token); \
} \
token = pg_strtok(&length); \
if (token == NULL || length != 1 || token[0] != ')') \
elog(ERROR, "incomplete scalar array"); \
return vals; \
}
#define ERROR
Definition: elog.h:39
int i
Definition: isn.c:73
void * palloc(Size size)
Definition: mcxt.c:1226

Definition at line 793 of file readfuncs.c.

◆ READ_STRING_FIELD

#define READ_STRING_FIELD (   fldname)
Value:
token = pg_strtok(&length); /* skip :fldname */ \
token = pg_strtok(&length); /* get field value */ \
local_node->fldname = nullable_string(token, length)
static char * nullable_string(const char *token, int length)
Definition: readfuncs.c:182

Definition at line 115 of file readfuncs.c.

◆ READ_TEMP_LOCALS

#define READ_TEMP_LOCALS ( )
Value:
const char *token; \
int length

Definition at line 50 of file readfuncs.c.

◆ READ_UINT64_FIELD

#define READ_UINT64_FIELD (   fldname)
Value:
token = pg_strtok(&length); /* skip :fldname */ \
token = pg_strtok(&length); /* get field value */ \
local_node->fldname = strtou64(token, NULL, 10)
#define strtou64(str, endptr, base)
Definition: c.h:1308

Definition at line 72 of file readfuncs.c.

◆ READ_UINT_FIELD

#define READ_UINT_FIELD (   fldname)
Value:
token = pg_strtok(&length); /* skip :fldname */ \
token = pg_strtok(&length); /* get field value */ \
local_node->fldname = atoui(token)
#define atoui(x)
Definition: readfuncs.c:177

Definition at line 66 of file readfuncs.c.

◆ strtobool

#define strtobool (   x)    ((*(x) == 't') ? true : false)

Definition at line 179 of file readfuncs.c.

Function Documentation

◆ _readA_Const()

static A_Const* _readA_Const ( void  )
static

Definition at line 304 of file readfuncs.c.

305 {
307 
308  /* We expect either NULL or :val here */
309  token = pg_strtok(&length);
310  if (length == 4 && strncmp(token, "NULL", 4) == 0)
311  local_node->isnull = true;
312  else
313  {
314  union ValUnion *tmp = nodeRead(NULL, 0);
315 
316  /* To forestall valgrind complaints, copy only the valid data */
317  switch (nodeTag(tmp))
318  {
319  case T_Integer:
320  memcpy(&local_node->val, tmp, sizeof(Integer));
321  break;
322  case T_Float:
323  memcpy(&local_node->val, tmp, sizeof(Float));
324  break;
325  case T_Boolean:
326  memcpy(&local_node->val, tmp, sizeof(Boolean));
327  break;
328  case T_String:
329  memcpy(&local_node->val, tmp, sizeof(String));
330  break;
331  case T_BitString:
332  memcpy(&local_node->val, tmp, sizeof(BitString));
333  break;
334  default:
335  elog(ERROR, "unrecognized node type: %d",
336  (int) nodeTag(tmp));
337  break;
338  }
339  }
340 
341  READ_LOCATION_FIELD(location);
342 
343  READ_DONE();
344 }
#define nodeTag(nodeptr)
Definition: nodes.h:133
#define READ_LOCATION_FIELD(fldname)
Definition: readfuncs.c:127
#define READ_LOCALS(nodeTypeName)
Definition: readfuncs.c:55
#define READ_DONE()
Definition: readfuncs.c:167
Definition: value.h:56
Definition: value.h:48
Definition: value.h:29
Definition: value.h:64

References elog(), ERROR, nodeRead(), nodeTag, pg_strtok(), READ_DONE, READ_LOCALS, READ_LOCATION_FIELD, and token.

◆ _readA_Expr()

static A_Expr* _readA_Expr ( void  )
static

Definition at line 582 of file readfuncs.c.

583 {
585 
586  token = pg_strtok(&length);
587 
588  if (length == 3 && strncmp(token, "ANY", 3) == 0)
589  {
590  local_node->kind = AEXPR_OP_ANY;
592  }
593  else if (length == 3 && strncmp(token, "ALL", 3) == 0)
594  {
595  local_node->kind = AEXPR_OP_ALL;
597  }
598  else if (length == 8 && strncmp(token, "DISTINCT", 8) == 0)
599  {
600  local_node->kind = AEXPR_DISTINCT;
602  }
603  else if (length == 12 && strncmp(token, "NOT_DISTINCT", 12) == 0)
604  {
605  local_node->kind = AEXPR_NOT_DISTINCT;
607  }
608  else if (length == 6 && strncmp(token, "NULLIF", 6) == 0)
609  {
610  local_node->kind = AEXPR_NULLIF;
612  }
613  else if (length == 2 && strncmp(token, "IN", 2) == 0)
614  {
615  local_node->kind = AEXPR_IN;
617  }
618  else if (length == 4 && strncmp(token, "LIKE", 4) == 0)
619  {
620  local_node->kind = AEXPR_LIKE;
622  }
623  else if (length == 5 && strncmp(token, "ILIKE", 5) == 0)
624  {
625  local_node->kind = AEXPR_ILIKE;
627  }
628  else if (length == 7 && strncmp(token, "SIMILAR", 7) == 0)
629  {
630  local_node->kind = AEXPR_SIMILAR;
632  }
633  else if (length == 7 && strncmp(token, "BETWEEN", 7) == 0)
634  {
635  local_node->kind = AEXPR_BETWEEN;
637  }
638  else if (length == 11 && strncmp(token, "NOT_BETWEEN", 11) == 0)
639  {
640  local_node->kind = AEXPR_NOT_BETWEEN;
642  }
643  else if (length == 11 && strncmp(token, "BETWEEN_SYM", 11) == 0)
644  {
645  local_node->kind = AEXPR_BETWEEN_SYM;
647  }
648  else if (length == 15 && strncmp(token, "NOT_BETWEEN_SYM", 15) == 0)
649  {
650  local_node->kind = AEXPR_NOT_BETWEEN_SYM;
652  }
653  else if (length == 5 && strncmp(token, ":name", 5) == 0)
654  {
655  local_node->kind = AEXPR_OP;
656  local_node->name = nodeRead(NULL, 0);
657  }
658  else
659  elog(ERROR, "unrecognized A_Expr kind: \"%.*s\"", length, token);
660 
661  READ_NODE_FIELD(lexpr);
662  READ_NODE_FIELD(rexpr);
663  READ_LOCATION_FIELD(location);
664 
665  READ_DONE();
666 }
@ AEXPR_BETWEEN
Definition: parsenodes.h:313
@ AEXPR_NULLIF
Definition: parsenodes.h:308
@ AEXPR_NOT_DISTINCT
Definition: parsenodes.h:307
@ AEXPR_BETWEEN_SYM
Definition: parsenodes.h:315
@ AEXPR_NOT_BETWEEN_SYM
Definition: parsenodes.h:316
@ AEXPR_ILIKE
Definition: parsenodes.h:311
@ AEXPR_IN
Definition: parsenodes.h:309
@ AEXPR_NOT_BETWEEN
Definition: parsenodes.h:314
@ AEXPR_DISTINCT
Definition: parsenodes.h:306
@ AEXPR_SIMILAR
Definition: parsenodes.h:312
@ AEXPR_LIKE
Definition: parsenodes.h:310
@ AEXPR_OP
Definition: parsenodes.h:303
@ AEXPR_OP_ANY
Definition: parsenodes.h:304
@ AEXPR_OP_ALL
Definition: parsenodes.h:305
#define READ_NODE_FIELD(fldname)
Definition: readfuncs.c:135
const char * name

References AEXPR_BETWEEN, AEXPR_BETWEEN_SYM, AEXPR_DISTINCT, AEXPR_ILIKE, AEXPR_IN, AEXPR_LIKE, AEXPR_NOT_BETWEEN, AEXPR_NOT_BETWEEN_SYM, AEXPR_NOT_DISTINCT, AEXPR_NULLIF, AEXPR_OP, AEXPR_OP_ALL, AEXPR_OP_ANY, AEXPR_SIMILAR, elog(), ERROR, name, nodeRead(), pg_strtok(), READ_DONE, READ_LOCALS, READ_LOCATION_FIELD, READ_NODE_FIELD, and token.

◆ _readBitmapset()

static Bitmapset* _readBitmapset ( void  )
static

Definition at line 203 of file readfuncs.c.

204 {
205  Bitmapset *result = NULL;
206 
208 
209  token = pg_strtok(&length);
210  if (token == NULL)
211  elog(ERROR, "incomplete Bitmapset structure");
212  if (length != 1 || token[0] != '(')
213  elog(ERROR, "unrecognized token: \"%.*s\"", length, token);
214 
215  token = pg_strtok(&length);
216  if (token == NULL)
217  elog(ERROR, "incomplete Bitmapset structure");
218  if (length != 1 || token[0] != 'b')
219  elog(ERROR, "unrecognized token: \"%.*s\"", length, token);
220 
221  for (;;)
222  {
223  int val;
224  char *endptr;
225 
226  token = pg_strtok(&length);
227  if (token == NULL)
228  elog(ERROR, "unterminated Bitmapset structure");
229  if (length == 1 && token[0] == ')')
230  break;
231  val = (int) strtol(token, &endptr, 10);
232  if (endptr != token + length)
233  elog(ERROR, "unrecognized integer: \"%.*s\"", length, token);
234  result = bms_add_member(result, val);
235  }
236 
237  return result;
238 }
Bitmapset * bms_add_member(Bitmapset *a, int x)
Definition: bitmapset.c:753
long val
Definition: informix.c:664
#define READ_TEMP_LOCALS()
Definition: readfuncs.c:50

References bms_add_member(), elog(), ERROR, pg_strtok(), READ_TEMP_LOCALS, token, and val.

Referenced by readBitmapset().

◆ _readBoolExpr()

static BoolExpr* _readBoolExpr ( void  )
static

Definition at line 281 of file readfuncs.c.

282 {
284 
285  /* do-it-yourself enum representation */
286  token = pg_strtok(&length); /* skip :boolop */
287  token = pg_strtok(&length); /* get field value */
288  if (length == 3 && strncmp(token, "and", 3) == 0)
289  local_node->boolop = AND_EXPR;
290  else if (length == 2 && strncmp(token, "or", 2) == 0)
291  local_node->boolop = OR_EXPR;
292  else if (length == 3 && strncmp(token, "not", 3) == 0)
293  local_node->boolop = NOT_EXPR;
294  else
295  elog(ERROR, "unrecognized boolop \"%.*s\"", length, token);
296 
298  READ_LOCATION_FIELD(location);
299 
300  READ_DONE();
301 }
@ AND_EXPR
Definition: primnodes.h:866
@ OR_EXPR
Definition: primnodes.h:866
@ NOT_EXPR
Definition: primnodes.h:866

References AND_EXPR, generate_unaccent_rules::args, elog(), ERROR, NOT_EXPR, OR_EXPR, pg_strtok(), READ_DONE, READ_LOCALS, READ_LOCATION_FIELD, READ_NODE_FIELD, and token.

◆ _readConst()

static Const* _readConst ( void  )
static

Definition at line 259 of file readfuncs.c.

260 {
262 
263  READ_OID_FIELD(consttype);
264  READ_INT_FIELD(consttypmod);
265  READ_OID_FIELD(constcollid);
266  READ_INT_FIELD(constlen);
267  READ_BOOL_FIELD(constbyval);
268  READ_BOOL_FIELD(constisnull);
269  READ_LOCATION_FIELD(location);
270 
271  token = pg_strtok(&length); /* skip :constvalue */
272  if (local_node->constisnull)
273  token = pg_strtok(&length); /* skip "<>" */
274  else
275  local_node->constvalue = readDatum(local_node->constbyval);
276 
277  READ_DONE();
278 }
#define READ_INT_FIELD(fldname)
Definition: readfuncs.c:60
#define READ_OID_FIELD(fldname)
Definition: readfuncs.c:84
Datum readDatum(bool typbyval)
Definition: readfuncs.c:732
#define READ_BOOL_FIELD(fldname)
Definition: readfuncs.c:109

References pg_strtok(), READ_BOOL_FIELD, READ_DONE, READ_INT_FIELD, READ_LOCALS, READ_LOCATION_FIELD, READ_OID_FIELD, readDatum(), and token.

◆ _readConstraint()

static Constraint* _readConstraint ( void  )
static

Definition at line 350 of file readfuncs.c.

351 {
353 
354  READ_STRING_FIELD(conname);
355  READ_BOOL_FIELD(deferrable);
356  READ_BOOL_FIELD(initdeferred);
357  READ_LOCATION_FIELD(location);
358 
359  token = pg_strtok(&length); /* skip :contype */
360  token = pg_strtok(&length); /* get field value */
361  if (length == 4 && strncmp(token, "NULL", 4) == 0)
362  local_node->contype = CONSTR_NULL;
363  else if (length == 8 && strncmp(token, "NOT_NULL", 8) == 0)
364  local_node->contype = CONSTR_NOTNULL;
365  else if (length == 7 && strncmp(token, "DEFAULT", 7) == 0)
366  local_node->contype = CONSTR_DEFAULT;
367  else if (length == 8 && strncmp(token, "IDENTITY", 8) == 0)
368  local_node->contype = CONSTR_IDENTITY;
369  else if (length == 9 && strncmp(token, "GENERATED", 9) == 0)
370  local_node->contype = CONSTR_GENERATED;
371  else if (length == 5 && strncmp(token, "CHECK", 5) == 0)
372  local_node->contype = CONSTR_CHECK;
373  else if (length == 11 && strncmp(token, "PRIMARY_KEY", 11) == 0)
374  local_node->contype = CONSTR_PRIMARY;
375  else if (length == 6 && strncmp(token, "UNIQUE", 6) == 0)
376  local_node->contype = CONSTR_UNIQUE;
377  else if (length == 9 && strncmp(token, "EXCLUSION", 9) == 0)
378  local_node->contype = CONSTR_EXCLUSION;
379  else if (length == 11 && strncmp(token, "FOREIGN_KEY", 11) == 0)
380  local_node->contype = CONSTR_FOREIGN;
381  else if (length == 15 && strncmp(token, "ATTR_DEFERRABLE", 15) == 0)
382  local_node->contype = CONSTR_ATTR_DEFERRABLE;
383  else if (length == 19 && strncmp(token, "ATTR_NOT_DEFERRABLE", 19) == 0)
384  local_node->contype = CONSTR_ATTR_NOT_DEFERRABLE;
385  else if (length == 13 && strncmp(token, "ATTR_DEFERRED", 13) == 0)
386  local_node->contype = CONSTR_ATTR_DEFERRED;
387  else if (length == 14 && strncmp(token, "ATTR_IMMEDIATE", 14) == 0)
388  local_node->contype = CONSTR_ATTR_IMMEDIATE;
389 
390  switch (local_node->contype)
391  {
392  case CONSTR_NULL:
393  /* no extra fields */
394  break;
395 
396  case CONSTR_NOTNULL:
397  READ_NODE_FIELD(keys);
398  READ_INT_FIELD(inhcount);
399  READ_BOOL_FIELD(is_no_inherit);
400  READ_BOOL_FIELD(skip_validation);
401  READ_BOOL_FIELD(initially_valid);
402  break;
403 
404  case CONSTR_DEFAULT:
405  READ_NODE_FIELD(raw_expr);
406  READ_STRING_FIELD(cooked_expr);
407  break;
408 
409  case CONSTR_IDENTITY:
411  READ_CHAR_FIELD(generated_when);
412  break;
413 
414  case CONSTR_GENERATED:
415  READ_NODE_FIELD(raw_expr);
416  READ_STRING_FIELD(cooked_expr);
417  READ_CHAR_FIELD(generated_when);
418  break;
419 
420  case CONSTR_CHECK:
421  READ_BOOL_FIELD(is_no_inherit);
422  READ_NODE_FIELD(raw_expr);
423  READ_STRING_FIELD(cooked_expr);
424  READ_BOOL_FIELD(skip_validation);
425  READ_BOOL_FIELD(initially_valid);
426  break;
427 
428  case CONSTR_PRIMARY:
429  READ_NODE_FIELD(keys);
430  READ_NODE_FIELD(including);
432  READ_STRING_FIELD(indexname);
433  READ_STRING_FIELD(indexspace);
434  READ_BOOL_FIELD(reset_default_tblspc);
435  /* access_method and where_clause not currently used */
436  break;
437 
438  case CONSTR_UNIQUE:
439  READ_BOOL_FIELD(nulls_not_distinct);
440  READ_NODE_FIELD(keys);
441  READ_NODE_FIELD(including);
443  READ_STRING_FIELD(indexname);
444  READ_STRING_FIELD(indexspace);
445  READ_BOOL_FIELD(reset_default_tblspc);
446  /* access_method and where_clause not currently used */
447  break;
448 
449  case CONSTR_EXCLUSION:
450  READ_NODE_FIELD(exclusions);
451  READ_NODE_FIELD(including);
453  READ_STRING_FIELD(indexname);
454  READ_STRING_FIELD(indexspace);
455  READ_BOOL_FIELD(reset_default_tblspc);
456  READ_STRING_FIELD(access_method);
457  READ_NODE_FIELD(where_clause);
458  break;
459 
460  case CONSTR_FOREIGN:
461  READ_NODE_FIELD(pktable);
462  READ_NODE_FIELD(fk_attrs);
463  READ_NODE_FIELD(pk_attrs);
464  READ_CHAR_FIELD(fk_matchtype);
465  READ_CHAR_FIELD(fk_upd_action);
466  READ_CHAR_FIELD(fk_del_action);
467  READ_NODE_FIELD(fk_del_set_cols);
468  READ_NODE_FIELD(old_conpfeqop);
469  READ_OID_FIELD(old_pktable_oid);
470  READ_BOOL_FIELD(skip_validation);
471  READ_BOOL_FIELD(initially_valid);
472  break;
473 
478  /* no extra fields */
479  break;
480 
481  default:
482  elog(ERROR, "unrecognized ConstrType: %d", (int) local_node->contype);
483  break;
484  }
485 
486  READ_DONE();
487 }
@ CONSTR_FOREIGN
Definition: parsenodes.h:2547
@ CONSTR_ATTR_DEFERRED
Definition: parsenodes.h:2550
@ CONSTR_IDENTITY
Definition: parsenodes.h:2541
@ CONSTR_UNIQUE
Definition: parsenodes.h:2545
@ CONSTR_ATTR_NOT_DEFERRABLE
Definition: parsenodes.h:2549
@ CONSTR_DEFAULT
Definition: parsenodes.h:2540
@ CONSTR_NOTNULL
Definition: parsenodes.h:2539
@ CONSTR_ATTR_IMMEDIATE
Definition: parsenodes.h:2551
@ CONSTR_CHECK
Definition: parsenodes.h:2543
@ CONSTR_NULL
Definition: parsenodes.h:2537
@ CONSTR_GENERATED
Definition: parsenodes.h:2542
@ CONSTR_EXCLUSION
Definition: parsenodes.h:2546
@ CONSTR_ATTR_DEFERRABLE
Definition: parsenodes.h:2548
@ CONSTR_PRIMARY
Definition: parsenodes.h:2544
#define READ_CHAR_FIELD(fldname)
Definition: readfuncs.c:90
#define READ_STRING_FIELD(fldname)
Definition: readfuncs.c:115

References CONSTR_ATTR_DEFERRABLE, CONSTR_ATTR_DEFERRED, CONSTR_ATTR_IMMEDIATE, CONSTR_ATTR_NOT_DEFERRABLE, CONSTR_CHECK, CONSTR_DEFAULT, CONSTR_EXCLUSION, CONSTR_FOREIGN, CONSTR_GENERATED, CONSTR_IDENTITY, CONSTR_NOTNULL, CONSTR_NULL, CONSTR_PRIMARY, CONSTR_UNIQUE, elog(), ERROR, pg_strtok(), READ_BOOL_FIELD, READ_CHAR_FIELD, READ_DONE, READ_INT_FIELD, READ_LOCALS, READ_LOCATION_FIELD, READ_NODE_FIELD, READ_OID_FIELD, READ_STRING_FIELD, and token.

◆ _readExtensibleNode()

static ExtensibleNode* _readExtensibleNode ( void  )
static

Definition at line 669 of file readfuncs.c.

670 {
671  const ExtensibleNodeMethods *methods;
672  ExtensibleNode *local_node;
673  const char *extnodename;
674 
676 
677  token = pg_strtok(&length); /* skip :extnodename */
678  token = pg_strtok(&length); /* get extnodename */
679 
680  extnodename = nullable_string(token, length);
681  if (!extnodename)
682  elog(ERROR, "extnodename has to be supplied");
683  methods = GetExtensibleNodeMethods(extnodename, false);
684 
685  local_node = (ExtensibleNode *) newNode(methods->node_size,
686  T_ExtensibleNode);
687  local_node->extnodename = extnodename;
688 
689  /* deserialize the private fields */
690  methods->nodeRead(local_node);
691 
692  READ_DONE();
693 }
const ExtensibleNodeMethods * GetExtensibleNodeMethods(const char *extnodename, bool missing_ok)
Definition: extensible.c:125
#define newNode(size, tag)
Definition: nodes.h:166
void(* nodeRead)(struct ExtensibleNode *node)
Definition: extensible.h:72
const char * extnodename
Definition: extensible.h:37

References elog(), ERROR, ExtensibleNode::extnodename, GetExtensibleNodeMethods(), newNode, ExtensibleNodeMethods::node_size, ExtensibleNodeMethods::nodeRead, nullable_string(), pg_strtok(), READ_DONE, READ_TEMP_LOCALS, and token.

◆ _readRangeTblEntry()

static RangeTblEntry* _readRangeTblEntry ( void  )
static

Definition at line 490 of file readfuncs.c.

491 {
493 
494  /* put alias + eref first to make dump more legible */
495  READ_NODE_FIELD(alias);
496  READ_NODE_FIELD(eref);
497  READ_ENUM_FIELD(rtekind, RTEKind);
498 
499  switch (local_node->rtekind)
500  {
501  case RTE_RELATION:
502  READ_OID_FIELD(relid);
503  READ_CHAR_FIELD(relkind);
504  READ_INT_FIELD(rellockmode);
505  READ_NODE_FIELD(tablesample);
506  READ_UINT_FIELD(perminfoindex);
507  break;
508  case RTE_SUBQUERY:
509  READ_NODE_FIELD(subquery);
510  READ_BOOL_FIELD(security_barrier);
511  /* we re-use these RELATION fields, too: */
512  READ_OID_FIELD(relid);
513  READ_CHAR_FIELD(relkind);
514  READ_INT_FIELD(rellockmode);
515  READ_UINT_FIELD(perminfoindex);
516  break;
517  case RTE_JOIN:
518  READ_ENUM_FIELD(jointype, JoinType);
519  READ_INT_FIELD(joinmergedcols);
520  READ_NODE_FIELD(joinaliasvars);
521  READ_NODE_FIELD(joinleftcols);
522  READ_NODE_FIELD(joinrightcols);
523  READ_NODE_FIELD(join_using_alias);
524  break;
525  case RTE_FUNCTION:
527  READ_BOOL_FIELD(funcordinality);
528  break;
529  case RTE_TABLEFUNC:
530  READ_NODE_FIELD(tablefunc);
531  /* The RTE must have a copy of the column type info, if any */
532  if (local_node->tablefunc)
533  {
534  TableFunc *tf = local_node->tablefunc;
535 
536  local_node->coltypes = tf->coltypes;
537  local_node->coltypmods = tf->coltypmods;
538  local_node->colcollations = tf->colcollations;
539  }
540  break;
541  case RTE_VALUES:
542  READ_NODE_FIELD(values_lists);
543  READ_NODE_FIELD(coltypes);
544  READ_NODE_FIELD(coltypmods);
545  READ_NODE_FIELD(colcollations);
546  break;
547  case RTE_CTE:
548  READ_STRING_FIELD(ctename);
549  READ_UINT_FIELD(ctelevelsup);
550  READ_BOOL_FIELD(self_reference);
551  READ_NODE_FIELD(coltypes);
552  READ_NODE_FIELD(coltypmods);
553  READ_NODE_FIELD(colcollations);
554  break;
555  case RTE_NAMEDTUPLESTORE:
556  READ_STRING_FIELD(enrname);
557  READ_FLOAT_FIELD(enrtuples);
558  READ_NODE_FIELD(coltypes);
559  READ_NODE_FIELD(coltypmods);
560  READ_NODE_FIELD(colcollations);
561  /* we re-use these RELATION fields, too: */
562  READ_OID_FIELD(relid);
563  break;
564  case RTE_RESULT:
565  /* no extra fields */
566  break;
567  default:
568  elog(ERROR, "unrecognized RTE kind: %d",
569  (int) local_node->rtekind);
570  break;
571  }
572 
573  READ_BOOL_FIELD(lateral);
574  READ_BOOL_FIELD(inh);
575  READ_BOOL_FIELD(inFromCl);
576  READ_NODE_FIELD(securityQuals);
577 
578  READ_DONE();
579 }
JoinType
Definition: nodes.h:299
RTEKind
Definition: parsenodes.h:1005
@ RTE_JOIN
Definition: parsenodes.h:1008
@ RTE_CTE
Definition: parsenodes.h:1012
@ RTE_NAMEDTUPLESTORE
Definition: parsenodes.h:1013
@ RTE_VALUES
Definition: parsenodes.h:1011
@ RTE_SUBQUERY
Definition: parsenodes.h:1007
@ RTE_RESULT
Definition: parsenodes.h:1014
@ RTE_FUNCTION
Definition: parsenodes.h:1009
@ RTE_TABLEFUNC
Definition: parsenodes.h:1010
@ RTE_RELATION
Definition: parsenodes.h:1006
#define READ_UINT_FIELD(fldname)
Definition: readfuncs.c:66
#define READ_FLOAT_FIELD(fldname)
Definition: readfuncs.c:103
#define READ_ENUM_FIELD(fldname, enumtype)
Definition: readfuncs.c:97
static const struct fns functions
Definition: regcomp.c:356

References elog(), ERROR, functions, READ_BOOL_FIELD, READ_CHAR_FIELD, READ_DONE, READ_ENUM_FIELD, READ_FLOAT_FIELD, READ_INT_FIELD, READ_LOCALS, READ_NODE_FIELD, READ_OID_FIELD, READ_STRING_FIELD, READ_UINT_FIELD, RTE_CTE, RTE_FUNCTION, RTE_JOIN, RTE_NAMEDTUPLESTORE, RTE_RELATION, RTE_RESULT, RTE_SUBQUERY, RTE_TABLEFUNC, and RTE_VALUES.

◆ nullable_string()

static char* nullable_string ( const char *  token,
int  length 
)
static

Definition at line 182 of file readfuncs.c.

183 {
184  /* outToken emits <> for NULL, and pg_strtok makes that an empty string */
185  if (length == 0)
186  return NULL;
187  /* outToken emits "" for empty string */
188  if (length == 2 && token[0] == '"' && token[1] == '"')
189  return pstrdup("");
190  /* otherwise, we must remove protective backslashes added by outToken */
191  return debackslash(token, length);
192 }
char * pstrdup(const char *in)
Definition: mcxt.c:1644
char * debackslash(const char *token, int length)
Definition: read.c:214

References debackslash(), pstrdup(), and token.

Referenced by _readExtensibleNode().

◆ parseNodeString()

Node* parseNodeString ( void  )

Definition at line 705 of file readfuncs.c.

706 {
708 
709  /* Guard against stack overflow due to overly complex expressions */
711 
712  token = pg_strtok(&length);
713 
714 #define MATCH(tokname, namelen) \
715  (length == namelen && memcmp(token, tokname, namelen) == 0)
716 
717 #include "readfuncs.switch.c"
718 
719  elog(ERROR, "badly formatted node string \"%.32s\"...", token);
720  return NULL; /* keep compiler quiet */
721 }
void check_stack_depth(void)
Definition: postgres.c:3520

References check_stack_depth(), elog(), ERROR, pg_strtok(), READ_TEMP_LOCALS, and token.

Referenced by nodeRead().

◆ readBitmapset()

Bitmapset* readBitmapset ( void  )

Definition at line 245 of file readfuncs.c.

246 {
247  return _readBitmapset();
248 }

References _readBitmapset().

◆ readDatum()

Datum readDatum ( bool  typbyval)

Definition at line 732 of file readfuncs.c.

733 {
734  Size length,
735  i;
736  int tokenLength;
737  const char *token;
738  Datum res;
739  char *s;
740 
741  /*
742  * read the actual length of the value
743  */
744  token = pg_strtok(&tokenLength);
745  length = atoui(token);
746 
747  token = pg_strtok(&tokenLength); /* read the '[' */
748  if (token == NULL || token[0] != '[')
749  elog(ERROR, "expected \"[\" to start datum, but got \"%s\"; length = %zu",
750  token ? token : "[NULL]", length);
751 
752  if (typbyval)
753  {
754  if (length > (Size) sizeof(Datum))
755  elog(ERROR, "byval datum but length = %zu", length);
756  res = (Datum) 0;
757  s = (char *) (&res);
758  for (i = 0; i < (Size) sizeof(Datum); i++)
759  {
760  token = pg_strtok(&tokenLength);
761  s[i] = (char) atoi(token);
762  }
763  }
764  else if (length <= 0)
765  res = (Datum) NULL;
766  else
767  {
768  s = (char *) palloc(length);
769  for (i = 0; i < length; i++)
770  {
771  token = pg_strtok(&tokenLength);
772  s[i] = (char) atoi(token);
773  }
774  res = PointerGetDatum(s);
775  }
776 
777  token = pg_strtok(&tokenLength); /* read the ']' */
778  if (token == NULL || token[0] != ']')
779  elog(ERROR, "expected \"]\" to end datum, but got \"%s\"; length = %zu",
780  token ? token : "[NULL]", length);
781 
782  return res;
783 }
size_t Size
Definition: c.h:594
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:322
uintptr_t Datum
Definition: postgres.h:64

References atoui, elog(), ERROR, i, palloc(), pg_strtok(), PointerGetDatum(), res, and token.

Referenced by _readConst().