PostgreSQL Source Code  git master
outfuncs.c File Reference
#include "postgres.h"
#include <ctype.h>
#include "access/attnum.h"
#include "common/shortest_dec.h"
#include "lib/stringinfo.h"
#include "miscadmin.h"
#include "nodes/bitmapset.h"
#include "nodes/nodes.h"
#include "nodes/pg_list.h"
#include "utils/datum.h"
#include "outfuncs.funcs.c"
#include "outfuncs.switch.c"
Include dependency graph for outfuncs.c:

Go to the source code of this file.

Macros

#define WRITE_NODE_TYPE(nodelabel)    appendStringInfoString(str, nodelabel)
 
#define WRITE_INT_FIELD(fldname)    appendStringInfo(str, " :" CppAsString(fldname) " %d", node->fldname)
 
#define WRITE_UINT_FIELD(fldname)    appendStringInfo(str, " :" CppAsString(fldname) " %u", node->fldname)
 
#define WRITE_UINT64_FIELD(fldname)
 
#define WRITE_OID_FIELD(fldname)    appendStringInfo(str, " :" CppAsString(fldname) " %u", node->fldname)
 
#define WRITE_LONG_FIELD(fldname)    appendStringInfo(str, " :" CppAsString(fldname) " %ld", node->fldname)
 
#define WRITE_CHAR_FIELD(fldname)
 
#define WRITE_ENUM_FIELD(fldname, enumtype)
 
#define WRITE_FLOAT_FIELD(fldname)
 
#define WRITE_BOOL_FIELD(fldname)
 
#define WRITE_STRING_FIELD(fldname)
 
#define WRITE_LOCATION_FIELD(fldname)    appendStringInfo(str, " :" CppAsString(fldname) " %d", write_location_fields ? node->fldname : -1)
 
#define WRITE_NODE_FIELD(fldname)
 
#define WRITE_BITMAPSET_FIELD(fldname)
 
#define WRITE_NODE_ARRAY(fldname, len)
 
#define WRITE_ATTRNUMBER_ARRAY(fldname, len)
 
#define WRITE_OID_ARRAY(fldname, len)
 
#define WRITE_INDEX_ARRAY(fldname, len)
 
#define WRITE_INT_ARRAY(fldname, len)
 
#define WRITE_BOOL_ARRAY(fldname, len)
 
#define booltostr(x)   ((x) ? "true" : "false")
 
#define WRITE_SCALAR_ARRAY(fnname, datatype, fmtstr, convfunc)
 

Functions

static void outChar (StringInfo str, char c)
 
static void outDouble (StringInfo str, double d)
 
void outToken (StringInfo str, const char *s)
 
static void writeNodeArray (StringInfo str, const Node *const *arr, int len)
 
static void _outList (StringInfo str, const List *node)
 
void outBitmapset (StringInfo str, const Bitmapset *bms)
 
void outDatum (StringInfo str, Datum value, int typlen, bool typbyval)
 
static void _outConst (StringInfo str, const Const *node)
 
static void _outBoolExpr (StringInfo str, const BoolExpr *node)
 
static void _outForeignKeyOptInfo (StringInfo str, const ForeignKeyOptInfo *node)
 
static void _outEquivalenceClass (StringInfo str, const EquivalenceClass *node)
 
static void _outExtensibleNode (StringInfo str, const ExtensibleNode *node)
 
static void _outRangeTblEntry (StringInfo str, const RangeTblEntry *node)
 
static void _outA_Expr (StringInfo str, const A_Expr *node)
 
static void _outInteger (StringInfo str, const Integer *node)
 
static void _outFloat (StringInfo str, const Float *node)
 
static void _outBoolean (StringInfo str, const Boolean *node)
 
static void _outString (StringInfo str, const String *node)
 
static void _outBitString (StringInfo str, const BitString *node)
 
static void _outA_Const (StringInfo str, const A_Const *node)
 
void outNode (StringInfo str, const void *obj)
 
static char * nodeToStringInternal (const void *obj, bool write_loc_fields)
 
char * nodeToString (const void *obj)
 
char * nodeToStringWithLocations (const void *obj)
 
char * bmsToString (const Bitmapset *bms)
 

Variables

static bool write_location_fields = false
 

Macro Definition Documentation

◆ booltostr

#define booltostr (   x)    ((x) ? "true" : "false")

Definition at line 136 of file outfuncs.c.

◆ WRITE_ATTRNUMBER_ARRAY

#define WRITE_ATTRNUMBER_ARRAY (   fldname,
  len 
)
Value:
(appendStringInfoString(str, " :" CppAsString(fldname) " "), \
writeAttrNumberCols(str, node->fldname, len))
#define CppAsString(identifier)
Definition: c.h:326
const char * str
const void size_t len
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:182

Definition at line 112 of file outfuncs.c.

◆ WRITE_BITMAPSET_FIELD

#define WRITE_BITMAPSET_FIELD (   fldname)
Value:
(appendStringInfoString(str, " :" CppAsString(fldname) " "), \
outBitmapset(str, node->fldname))

Definition at line 102 of file outfuncs.c.

◆ WRITE_BOOL_ARRAY

#define WRITE_BOOL_ARRAY (   fldname,
  len 
)
Value:
(appendStringInfoString(str, " :" CppAsString(fldname) " "), \
writeBoolCols(str, node->fldname, len))

Definition at line 132 of file outfuncs.c.

◆ WRITE_BOOL_FIELD

#define WRITE_BOOL_FIELD (   fldname)
Value:
appendStringInfo(str, " :" CppAsString(fldname) " %s", \
booltostr(node->fldname))
#define booltostr(x)
Definition: outfuncs.c:136
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:97

Definition at line 83 of file outfuncs.c.

◆ WRITE_CHAR_FIELD

#define WRITE_CHAR_FIELD (   fldname)
Value:
(appendStringInfo(str, " :" CppAsString(fldname) " "), \
outChar(str, node->fldname))

Definition at line 68 of file outfuncs.c.

◆ WRITE_ENUM_FIELD

#define WRITE_ENUM_FIELD (   fldname,
  enumtype 
)
Value:
appendStringInfo(str, " :" CppAsString(fldname) " %d", \
(int) node->fldname)

Definition at line 73 of file outfuncs.c.

◆ WRITE_FLOAT_FIELD

#define WRITE_FLOAT_FIELD (   fldname)
Value:
(appendStringInfo(str, " :" CppAsString(fldname) " "), \
outDouble(str, node->fldname))

Definition at line 78 of file outfuncs.c.

◆ WRITE_INDEX_ARRAY

#define WRITE_INDEX_ARRAY (   fldname,
  len 
)
Value:
(appendStringInfoString(str, " :" CppAsString(fldname) " "), \
writeIndexCols(str, node->fldname, len))

Definition at line 122 of file outfuncs.c.

◆ WRITE_INT_ARRAY

#define WRITE_INT_ARRAY (   fldname,
  len 
)
Value:
(appendStringInfoString(str, " :" CppAsString(fldname) " "), \
writeIntCols(str, node->fldname, len))

Definition at line 127 of file outfuncs.c.

◆ WRITE_INT_FIELD

#define WRITE_INT_FIELD (   fldname)     appendStringInfo(str, " :" CppAsString(fldname) " %d", node->fldname)

Definition at line 47 of file outfuncs.c.

◆ WRITE_LOCATION_FIELD

#define WRITE_LOCATION_FIELD (   fldname)     appendStringInfo(str, " :" CppAsString(fldname) " %d", write_location_fields ? node->fldname : -1)

Definition at line 93 of file outfuncs.c.

◆ WRITE_LONG_FIELD

#define WRITE_LONG_FIELD (   fldname)     appendStringInfo(str, " :" CppAsString(fldname) " %ld", node->fldname)

Definition at line 64 of file outfuncs.c.

◆ WRITE_NODE_ARRAY

#define WRITE_NODE_ARRAY (   fldname,
  len 
)
Value:
(appendStringInfoString(str, " :" CppAsString(fldname) " "), \
writeNodeArray(str, (const Node * const *) node->fldname, len))
Definition: nodes.h:129

Definition at line 107 of file outfuncs.c.

◆ WRITE_NODE_FIELD

#define WRITE_NODE_FIELD (   fldname)
Value:
(appendStringInfoString(str, " :" CppAsString(fldname) " "), \
outNode(str, node->fldname))

Definition at line 97 of file outfuncs.c.

◆ WRITE_NODE_TYPE

#define WRITE_NODE_TYPE (   nodelabel)     appendStringInfoString(str, nodelabel)

Definition at line 43 of file outfuncs.c.

◆ WRITE_OID_ARRAY

#define WRITE_OID_ARRAY (   fldname,
  len 
)
Value:
(appendStringInfoString(str, " :" CppAsString(fldname) " "), \
writeOidCols(str, node->fldname, len))

Definition at line 117 of file outfuncs.c.

◆ WRITE_OID_FIELD

#define WRITE_OID_FIELD (   fldname)     appendStringInfo(str, " :" CppAsString(fldname) " %u", node->fldname)

Definition at line 60 of file outfuncs.c.

◆ WRITE_SCALAR_ARRAY

#define WRITE_SCALAR_ARRAY (   fnname,
  datatype,
  fmtstr,
  convfunc 
)
Value:
static void \
fnname(StringInfo str, const datatype *arr, int len) \
{ \
if (arr != NULL) \
{ \
appendStringInfoChar(str, '('); \
for (int i = 0; i < len; i++) \
appendStringInfo(str, fmtstr, convfunc(arr[i])); \
appendStringInfoChar(str, ')'); \
} \
}
int i
Definition: isn.c:73
static void fmtstr(const char *value, int leftjust, int minlen, int maxwidth, int pointflag, PrintfTarget *target)
Definition: snprintf.c:967

Definition at line 227 of file outfuncs.c.

◆ WRITE_STRING_FIELD

#define WRITE_STRING_FIELD (   fldname)
Value:
(appendStringInfoString(str, " :" CppAsString(fldname) " "), \
outToken(str, node->fldname))

Definition at line 88 of file outfuncs.c.

◆ WRITE_UINT64_FIELD

#define WRITE_UINT64_FIELD (   fldname)
Value:
node->fldname)
#define UINT64_FORMAT
Definition: c.h:549

Definition at line 55 of file outfuncs.c.

◆ WRITE_UINT_FIELD

#define WRITE_UINT_FIELD (   fldname)     appendStringInfo(str, " :" CppAsString(fldname) " %u", node->fldname)

Definition at line 51 of file outfuncs.c.

Function Documentation

◆ _outA_Const()

static void _outA_Const ( StringInfo  str,
const A_Const node 
)
static

Definition at line 696 of file outfuncs.c.

697 {
698  WRITE_NODE_TYPE("A_CONST");
699 
700  if (node->isnull)
701  appendStringInfoString(str, " NULL");
702  else
703  {
704  appendStringInfoString(str, " :val ");
705  outNode(str, &node->val);
706  }
707  WRITE_LOCATION_FIELD(location);
708 }
#define WRITE_NODE_TYPE(nodelabel)
Definition: outfuncs.c:43
void outNode(StringInfo str, const void *obj)
Definition: outfuncs.c:716
#define WRITE_LOCATION_FIELD(fldname)
Definition: outfuncs.c:93
bool isnull
Definition: parsenodes.h:363
union ValUnion val
Definition: parsenodes.h:362

References appendStringInfoString(), A_Const::isnull, outNode(), str, A_Const::val, WRITE_LOCATION_FIELD, and WRITE_NODE_TYPE.

◆ _outA_Expr()

static void _outA_Expr ( StringInfo  str,
const A_Expr node 
)
static

Definition at line 576 of file outfuncs.c.

577 {
578  WRITE_NODE_TYPE("A_EXPR");
579 
580  switch (node->kind)
581  {
582  case AEXPR_OP:
584  break;
585  case AEXPR_OP_ANY:
586  appendStringInfoString(str, " ANY");
588  break;
589  case AEXPR_OP_ALL:
590  appendStringInfoString(str, " ALL");
592  break;
593  case AEXPR_DISTINCT:
594  appendStringInfoString(str, " DISTINCT");
596  break;
597  case AEXPR_NOT_DISTINCT:
598  appendStringInfoString(str, " NOT_DISTINCT");
600  break;
601  case AEXPR_NULLIF:
602  appendStringInfoString(str, " NULLIF");
604  break;
605  case AEXPR_IN:
606  appendStringInfoString(str, " IN");
608  break;
609  case AEXPR_LIKE:
610  appendStringInfoString(str, " LIKE");
612  break;
613  case AEXPR_ILIKE:
614  appendStringInfoString(str, " ILIKE");
616  break;
617  case AEXPR_SIMILAR:
618  appendStringInfoString(str, " SIMILAR");
620  break;
621  case AEXPR_BETWEEN:
622  appendStringInfoString(str, " BETWEEN");
624  break;
625  case AEXPR_NOT_BETWEEN:
626  appendStringInfoString(str, " NOT_BETWEEN");
628  break;
629  case AEXPR_BETWEEN_SYM:
630  appendStringInfoString(str, " BETWEEN_SYM");
632  break;
634  appendStringInfoString(str, " NOT_BETWEEN_SYM");
636  break;
637  default:
638  elog(ERROR, "unrecognized A_Expr_Kind: %d", (int) node->kind);
639  break;
640  }
641 
642  WRITE_NODE_FIELD(lexpr);
643  WRITE_NODE_FIELD(rexpr);
644  WRITE_LOCATION_FIELD(location);
645 }
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:224
#define WRITE_NODE_FIELD(fldname)
Definition: outfuncs.c:97
@ AEXPR_BETWEEN
Definition: parsenodes.h:323
@ AEXPR_NULLIF
Definition: parsenodes.h:318
@ AEXPR_NOT_DISTINCT
Definition: parsenodes.h:317
@ AEXPR_BETWEEN_SYM
Definition: parsenodes.h:325
@ AEXPR_NOT_BETWEEN_SYM
Definition: parsenodes.h:326
@ AEXPR_ILIKE
Definition: parsenodes.h:321
@ AEXPR_IN
Definition: parsenodes.h:319
@ AEXPR_NOT_BETWEEN
Definition: parsenodes.h:324
@ AEXPR_DISTINCT
Definition: parsenodes.h:316
@ AEXPR_SIMILAR
Definition: parsenodes.h:322
@ AEXPR_LIKE
Definition: parsenodes.h:320
@ AEXPR_OP
Definition: parsenodes.h:313
@ AEXPR_OP_ANY
Definition: parsenodes.h:314
@ AEXPR_OP_ALL
Definition: parsenodes.h:315
A_Expr_Kind kind
Definition: parsenodes.h:334
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, appendStringInfoString(), elog, ERROR, A_Expr::kind, name, str, WRITE_LOCATION_FIELD, WRITE_NODE_FIELD, and WRITE_NODE_TYPE.

◆ _outBitString()

static void _outBitString ( StringInfo  str,
const BitString node 
)
static

Definition at line 684 of file outfuncs.c.

685 {
686  /*
687  * The lexer will always produce a string starting with 'b' or 'x'. There
688  * might be characters following that that need escaping, but outToken
689  * won't escape the 'b' or 'x'. This is relied on by nodeTokenType.
690  */
691  Assert(node->bsval[0] == 'b' || node->bsval[0] == 'x');
692  outToken(str, node->bsval);
693 }
#define Assert(condition)
Definition: c.h:858
void outToken(StringInfo str, const char *s)
Definition: outfuncs.c:149
char * bsval
Definition: value.h:76

References Assert, BitString::bsval, outToken(), and str.

Referenced by outNode().

◆ _outBoolean()

static void _outBoolean ( StringInfo  str,
const Boolean node 
)
static

Definition at line 664 of file outfuncs.c.

665 {
666  appendStringInfoString(str, node->boolval ? "true" : "false");
667 }
bool boolval
Definition: value.h:60

References appendStringInfoString(), Boolean::boolval, and str.

Referenced by outNode().

◆ _outBoolExpr()

static void _outBoolExpr ( StringInfo  str,
const BoolExpr node 
)
static

Definition at line 402 of file outfuncs.c.

403 {
404  char *opstr = NULL;
405 
406  WRITE_NODE_TYPE("BOOLEXPR");
407 
408  /* do-it-yourself enum representation */
409  switch (node->boolop)
410  {
411  case AND_EXPR:
412  opstr = "and";
413  break;
414  case OR_EXPR:
415  opstr = "or";
416  break;
417  case NOT_EXPR:
418  opstr = "not";
419  break;
420  }
421  appendStringInfoString(str, " :boolop ");
422  outToken(str, opstr);
423 
425  WRITE_LOCATION_FIELD(location);
426 }
@ AND_EXPR
Definition: primnodes.h:901
@ OR_EXPR
Definition: primnodes.h:901
@ NOT_EXPR
Definition: primnodes.h:901
BoolExprType boolop
Definition: primnodes.h:909

References AND_EXPR, appendStringInfoString(), generate_unaccent_rules::args, BoolExpr::boolop, NOT_EXPR, OR_EXPR, outToken(), str, WRITE_LOCATION_FIELD, WRITE_NODE_FIELD, and WRITE_NODE_TYPE.

◆ _outConst()

static void _outConst ( StringInfo  str,
const Const node 
)
static

Definition at line 382 of file outfuncs.c.

383 {
384  WRITE_NODE_TYPE("CONST");
385 
386  WRITE_OID_FIELD(consttype);
387  WRITE_INT_FIELD(consttypmod);
388  WRITE_OID_FIELD(constcollid);
389  WRITE_INT_FIELD(constlen);
390  WRITE_BOOL_FIELD(constbyval);
391  WRITE_BOOL_FIELD(constisnull);
392  WRITE_LOCATION_FIELD(location);
393 
394  appendStringInfoString(str, " :constvalue ");
395  if (node->constisnull)
397  else
398  outDatum(str, node->constvalue, node->constlen, node->constbyval);
399 }
#define WRITE_OID_FIELD(fldname)
Definition: outfuncs.c:60
void outDatum(StringInfo str, Datum value, int typlen, bool typbyval)
Definition: outfuncs.c:341
#define WRITE_BOOL_FIELD(fldname)
Definition: outfuncs.c:83
#define WRITE_INT_FIELD(fldname)
Definition: outfuncs.c:47

References appendStringInfoString(), outDatum(), str, WRITE_BOOL_FIELD, WRITE_INT_FIELD, WRITE_LOCATION_FIELD, WRITE_NODE_TYPE, and WRITE_OID_FIELD.

◆ _outEquivalenceClass()

static void _outEquivalenceClass ( StringInfo  str,
const EquivalenceClass node 
)
static

Definition at line 455 of file outfuncs.c.

456 {
457  /*
458  * To simplify reading, we just chase up to the topmost merged EC and
459  * print that, without bothering to show the merge-ees separately.
460  */
461  while (node->ec_merged)
462  node = node->ec_merged;
463 
464  WRITE_NODE_TYPE("EQUIVALENCECLASS");
465 
466  WRITE_NODE_FIELD(ec_opfamilies);
467  WRITE_OID_FIELD(ec_collation);
468  WRITE_NODE_FIELD(ec_members);
469  WRITE_NODE_FIELD(ec_sources);
470  WRITE_NODE_FIELD(ec_derives);
471  WRITE_BITMAPSET_FIELD(ec_relids);
472  WRITE_BOOL_FIELD(ec_has_const);
473  WRITE_BOOL_FIELD(ec_has_volatile);
474  WRITE_BOOL_FIELD(ec_broken);
475  WRITE_UINT_FIELD(ec_sortref);
476  WRITE_UINT_FIELD(ec_min_security);
477  WRITE_UINT_FIELD(ec_max_security);
478 }
#define WRITE_BITMAPSET_FIELD(fldname)
Definition: outfuncs.c:102
#define WRITE_UINT_FIELD(fldname)
Definition: outfuncs.c:51
struct EquivalenceClass * ec_merged
Definition: pathnodes.h:1392

References EquivalenceClass::ec_merged, WRITE_BITMAPSET_FIELD, WRITE_BOOL_FIELD, WRITE_NODE_FIELD, WRITE_NODE_TYPE, WRITE_OID_FIELD, and WRITE_UINT_FIELD.

◆ _outExtensibleNode()

static void _outExtensibleNode ( StringInfo  str,
const ExtensibleNode node 
)
static

Definition at line 481 of file outfuncs.c.

482 {
483  const ExtensibleNodeMethods *methods;
484 
485  methods = GetExtensibleNodeMethods(node->extnodename, false);
486 
487  WRITE_NODE_TYPE("EXTENSIBLENODE");
488 
489  WRITE_STRING_FIELD(extnodename);
490 
491  /* serialize the private fields */
492  methods->nodeOut(str, node);
493 }
const ExtensibleNodeMethods * GetExtensibleNodeMethods(const char *extnodename, bool missing_ok)
Definition: extensible.c:125
#define WRITE_STRING_FIELD(fldname)
Definition: outfuncs.c:88
void(* nodeOut)(struct StringInfoData *str, const struct ExtensibleNode *node)
Definition: extensible.h:70
const char * extnodename
Definition: extensible.h:37

References ExtensibleNode::extnodename, GetExtensibleNodeMethods(), ExtensibleNodeMethods::nodeOut, str, WRITE_NODE_TYPE, and WRITE_STRING_FIELD.

◆ _outFloat()

static void _outFloat ( StringInfo  str,
const Float node 
)
static

Definition at line 654 of file outfuncs.c.

655 {
656  /*
657  * We assume the value is a valid numeric literal and so does not need
658  * quoting.
659  */
661 }
char * fval
Definition: value.h:52

References appendStringInfoString(), Float::fval, and str.

Referenced by outNode().

◆ _outForeignKeyOptInfo()

static void _outForeignKeyOptInfo ( StringInfo  str,
const ForeignKeyOptInfo node 
)
static

Definition at line 429 of file outfuncs.c.

430 {
431  int i;
432 
433  WRITE_NODE_TYPE("FOREIGNKEYOPTINFO");
434 
435  WRITE_UINT_FIELD(con_relid);
436  WRITE_UINT_FIELD(ref_relid);
437  WRITE_INT_FIELD(nkeys);
438  WRITE_ATTRNUMBER_ARRAY(conkey, node->nkeys);
439  WRITE_ATTRNUMBER_ARRAY(confkey, node->nkeys);
440  WRITE_OID_ARRAY(conpfeqop, node->nkeys);
441  WRITE_INT_FIELD(nmatched_ec);
442  WRITE_INT_FIELD(nconst_ec);
443  WRITE_INT_FIELD(nmatched_rcols);
444  WRITE_INT_FIELD(nmatched_ri);
445  /* for compactness, just print the number of matches per column: */
446  appendStringInfoString(str, " :eclass");
447  for (i = 0; i < node->nkeys; i++)
448  appendStringInfo(str, " %d", (node->eclass[i] != NULL));
449  appendStringInfoString(str, " :rinfos");
450  for (i = 0; i < node->nkeys; i++)
451  appendStringInfo(str, " %d", list_length(node->rinfos[i]));
452 }
#define WRITE_ATTRNUMBER_ARRAY(fldname, len)
Definition: outfuncs.c:112
#define WRITE_OID_ARRAY(fldname, len)
Definition: outfuncs.c:117
static int list_length(const List *l)
Definition: pg_list.h:152
struct EquivalenceClass * eclass[INDEX_MAX_KEYS]
Definition: pathnodes.h:1246
List * rinfos[INDEX_MAX_KEYS]
Definition: pathnodes.h:1250

References appendStringInfo(), appendStringInfoString(), ForeignKeyOptInfo::eclass, i, list_length(), ForeignKeyOptInfo::nkeys, ForeignKeyOptInfo::rinfos, str, WRITE_ATTRNUMBER_ARRAY, WRITE_INT_FIELD, WRITE_NODE_TYPE, WRITE_OID_ARRAY, and WRITE_UINT_FIELD.

◆ _outInteger()

static void _outInteger ( StringInfo  str,
const Integer node 
)
static

Definition at line 648 of file outfuncs.c.

649 {
650  appendStringInfo(str, "%d", node->ival);
651 }
int ival
Definition: value.h:33

References appendStringInfo(), Integer::ival, and str.

Referenced by outNode().

◆ _outList()

static void _outList ( StringInfo  str,
const List node 
)
static

Definition at line 275 of file outfuncs.c.

276 {
277  const ListCell *lc;
278 
280 
281  if (IsA(node, IntList))
283  else if (IsA(node, OidList))
285  else if (IsA(node, XidList))
287 
288  foreach(lc, node)
289  {
290  /*
291  * For the sake of backward compatibility, we emit a slightly
292  * different whitespace format for lists of nodes vs. other types of
293  * lists. XXX: is this necessary?
294  */
295  if (IsA(node, List))
296  {
297  outNode(str, lfirst(lc));
298  if (lnext(node, lc))
300  }
301  else if (IsA(node, IntList))
302  appendStringInfo(str, " %d", lfirst_int(lc));
303  else if (IsA(node, OidList))
304  appendStringInfo(str, " %u", lfirst_oid(lc));
305  else if (IsA(node, XidList))
306  appendStringInfo(str, " %u", lfirst_xid(lc));
307  else
308  elog(ERROR, "unrecognized list node type: %d",
309  (int) node->type);
310  }
311 
313 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:158
#define lfirst(lc)
Definition: pg_list.h:172
#define lfirst_int(lc)
Definition: pg_list.h:173
static ListCell * lnext(const List *l, const ListCell *c)
Definition: pg_list.h:343
#define lfirst_oid(lc)
Definition: pg_list.h:174
#define lfirst_xid(lc)
Definition: pg_list.h:175
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:194
Definition: pg_list.h:54
NodeTag type
Definition: pg_list.h:55

References appendStringInfo(), appendStringInfoChar(), elog, ERROR, IsA, lfirst, lfirst_int, lfirst_oid, lfirst_xid, lnext(), outNode(), str, and List::type.

Referenced by outNode().

◆ _outRangeTblEntry()

static void _outRangeTblEntry ( StringInfo  str,
const RangeTblEntry node 
)
static

Definition at line 496 of file outfuncs.c.

497 {
498  WRITE_NODE_TYPE("RANGETBLENTRY");
499 
500  WRITE_NODE_FIELD(alias);
501  WRITE_NODE_FIELD(eref);
502  WRITE_ENUM_FIELD(rtekind, RTEKind);
503 
504  switch (node->rtekind)
505  {
506  case RTE_RELATION:
507  WRITE_OID_FIELD(relid);
508  WRITE_BOOL_FIELD(inh);
509  WRITE_CHAR_FIELD(relkind);
510  WRITE_INT_FIELD(rellockmode);
511  WRITE_UINT_FIELD(perminfoindex);
512  WRITE_NODE_FIELD(tablesample);
513  break;
514  case RTE_SUBQUERY:
515  WRITE_NODE_FIELD(subquery);
516  WRITE_BOOL_FIELD(security_barrier);
517  /* we re-use these RELATION fields, too: */
518  WRITE_OID_FIELD(relid);
519  WRITE_BOOL_FIELD(inh);
520  WRITE_CHAR_FIELD(relkind);
521  WRITE_INT_FIELD(rellockmode);
522  WRITE_UINT_FIELD(perminfoindex);
523  break;
524  case RTE_JOIN:
525  WRITE_ENUM_FIELD(jointype, JoinType);
526  WRITE_INT_FIELD(joinmergedcols);
527  WRITE_NODE_FIELD(joinaliasvars);
528  WRITE_NODE_FIELD(joinleftcols);
529  WRITE_NODE_FIELD(joinrightcols);
530  WRITE_NODE_FIELD(join_using_alias);
531  break;
532  case RTE_FUNCTION:
534  WRITE_BOOL_FIELD(funcordinality);
535  break;
536  case RTE_TABLEFUNC:
537  WRITE_NODE_FIELD(tablefunc);
538  break;
539  case RTE_VALUES:
540  WRITE_NODE_FIELD(values_lists);
541  WRITE_NODE_FIELD(coltypes);
542  WRITE_NODE_FIELD(coltypmods);
543  WRITE_NODE_FIELD(colcollations);
544  break;
545  case RTE_CTE:
546  WRITE_STRING_FIELD(ctename);
547  WRITE_UINT_FIELD(ctelevelsup);
548  WRITE_BOOL_FIELD(self_reference);
549  WRITE_NODE_FIELD(coltypes);
550  WRITE_NODE_FIELD(coltypmods);
551  WRITE_NODE_FIELD(colcollations);
552  break;
553  case RTE_NAMEDTUPLESTORE:
554  WRITE_STRING_FIELD(enrname);
555  WRITE_FLOAT_FIELD(enrtuples);
556  WRITE_NODE_FIELD(coltypes);
557  WRITE_NODE_FIELD(coltypmods);
558  WRITE_NODE_FIELD(colcollations);
559  /* we re-use these RELATION fields, too: */
560  WRITE_OID_FIELD(relid);
561  break;
562  case RTE_RESULT:
563  /* no extra fields */
564  break;
565  default:
566  elog(ERROR, "unrecognized RTE kind: %d", (int) node->rtekind);
567  break;
568  }
569 
570  WRITE_BOOL_FIELD(lateral);
571  WRITE_BOOL_FIELD(inFromCl);
572  WRITE_NODE_FIELD(securityQuals);
573 }
JoinType
Definition: nodes.h:288
#define WRITE_ENUM_FIELD(fldname, enumtype)
Definition: outfuncs.c:73
#define WRITE_FLOAT_FIELD(fldname)
Definition: outfuncs.c:78
#define WRITE_CHAR_FIELD(fldname)
Definition: outfuncs.c:68
RTEKind
Definition: parsenodes.h:1027
@ RTE_JOIN
Definition: parsenodes.h:1030
@ RTE_CTE
Definition: parsenodes.h:1034
@ RTE_NAMEDTUPLESTORE
Definition: parsenodes.h:1035
@ RTE_VALUES
Definition: parsenodes.h:1033
@ RTE_SUBQUERY
Definition: parsenodes.h:1029
@ RTE_RESULT
Definition: parsenodes.h:1036
@ RTE_FUNCTION
Definition: parsenodes.h:1031
@ RTE_TABLEFUNC
Definition: parsenodes.h:1032
@ RTE_RELATION
Definition: parsenodes.h:1028
static const struct fns functions
Definition: regcomp.c:356
RTEKind rtekind
Definition: parsenodes.h:1057

References elog, ERROR, functions, RTE_CTE, RTE_FUNCTION, RTE_JOIN, RTE_NAMEDTUPLESTORE, RTE_RELATION, RTE_RESULT, RTE_SUBQUERY, RTE_TABLEFUNC, RTE_VALUES, RangeTblEntry::rtekind, WRITE_BOOL_FIELD, WRITE_CHAR_FIELD, WRITE_ENUM_FIELD, WRITE_FLOAT_FIELD, WRITE_INT_FIELD, WRITE_NODE_FIELD, WRITE_NODE_TYPE, WRITE_OID_FIELD, WRITE_STRING_FIELD, and WRITE_UINT_FIELD.

◆ _outString()

static void _outString ( StringInfo  str,
const String node 
)
static

Definition at line 670 of file outfuncs.c.

671 {
672  /*
673  * We use outToken to provide escaping of the string's content, but we
674  * don't want it to convert an empty string to '""', because we're putting
675  * double quotes around the string already.
676  */
678  if (node->sval[0] != '\0')
679  outToken(str, node->sval);
681 }
char * sval
Definition: value.h:68

References appendStringInfoChar(), outToken(), str, and String::sval.

Referenced by outNode().

◆ bmsToString()

char* bmsToString ( const Bitmapset bms)

Definition at line 808 of file outfuncs.c.

809 {
811 
812  /* see stringinfo.h for an explanation of this maneuver */
814  outBitmapset(&str, bms);
815  return str.data;
816 }
void outBitmapset(StringInfo str, const Bitmapset *bms)
Definition: outfuncs.c:325
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59

References initStringInfo(), outBitmapset(), and str.

Referenced by search_indexed_tlist_for_phv(), and search_indexed_tlist_for_var().

◆ nodeToString()

◆ nodeToStringInternal()

static char* nodeToStringInternal ( const void *  obj,
bool  write_loc_fields 
)
static

Definition at line 770 of file outfuncs.c.

771 {
773  bool save_write_location_fields;
774 
775  save_write_location_fields = write_location_fields;
776  write_location_fields = write_loc_fields;
777 
778  /* see stringinfo.h for an explanation of this maneuver */
780  outNode(&str, obj);
781 
782  write_location_fields = save_write_location_fields;
783 
784  return str.data;
785 }
static bool write_location_fields
Definition: outfuncs.c:29

References initStringInfo(), outNode(), str, and write_location_fields.

Referenced by nodeToString(), and nodeToStringWithLocations().

◆ nodeToStringWithLocations()

char* nodeToStringWithLocations ( const void *  obj)

Definition at line 797 of file outfuncs.c.

798 {
799  return nodeToStringInternal(obj, true);
800 }

References nodeToStringInternal().

Referenced by elog_node_display(), pg_parse_query(), pg_plan_query(), pg_rewrite_query(), pprint(), and print().

◆ outBitmapset()

void outBitmapset ( StringInfo  str,
const Bitmapset bms 
)

Definition at line 325 of file outfuncs.c.

326 {
327  int x;
328 
331  x = -1;
332  while ((x = bms_next_member(bms, x)) >= 0)
333  appendStringInfo(str, " %d", x);
335 }
int bms_next_member(const Bitmapset *a, int prevbit)
Definition: bitmapset.c:1306
int x
Definition: isn.c:71

References appendStringInfo(), appendStringInfoChar(), bms_next_member(), str, and x.

Referenced by bmsToString(), and outNode().

◆ outChar()

static void outChar ( StringInfo  str,
char  c 
)
static

Definition at line 190 of file outfuncs.c.

191 {
192  char in[2];
193 
194  /* Traditionally, we've represented \0 as <>, so keep doing that */
195  if (c == '\0')
196  {
198  return;
199  }
200 
201  in[0] = c;
202  in[1] = '\0';
203 
204  outToken(str, in);
205 }
char * c

References appendStringInfoString(), outToken(), and str.

◆ outDatum()

void outDatum ( StringInfo  str,
Datum  value,
int  typlen,
bool  typbyval 
)

Definition at line 341 of file outfuncs.c.

342 {
343  Size length,
344  i;
345  char *s;
346 
347  length = datumGetSize(value, typbyval, typlen);
348 
349  if (typbyval)
350  {
351  s = (char *) (&value);
352  appendStringInfo(str, "%u [ ", (unsigned int) length);
353  for (i = 0; i < (Size) sizeof(Datum); i++)
354  appendStringInfo(str, "%d ", (int) (s[i]));
356  }
357  else
358  {
359  s = (char *) DatumGetPointer(value);
360  if (!PointerIsValid(s))
361  appendStringInfoString(str, "0 [ ]");
362  else
363  {
364  appendStringInfo(str, "%u [ ", (unsigned int) length);
365  for (i = 0; i < length; i++)
366  appendStringInfo(str, "%d ", (int) (s[i]));
368  }
369  }
370 }
#define PointerIsValid(pointer)
Definition: c.h:763
size_t Size
Definition: c.h:605
Size datumGetSize(Datum value, bool typByVal, int typLen)
Definition: datum.c:65
static struct @155 value
uintptr_t Datum
Definition: postgres.h:64
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:312

References appendStringInfo(), appendStringInfoChar(), appendStringInfoString(), DatumGetPointer(), datumGetSize(), i, PointerIsValid, str, and value.

Referenced by _outConst().

◆ outDouble()

static void outDouble ( StringInfo  str,
double  d 
)
static

Definition at line 211 of file outfuncs.c.

212 {
214 
217 }
int double_to_shortest_decimal_buf(double f, char *result)
Definition: d2s.c:1053
static char * buf
Definition: pg_test_fsync.c:73
#define DOUBLE_SHORTEST_DECIMAL_LEN
Definition: shortest_dec.h:44

References appendStringInfoString(), buf, DOUBLE_SHORTEST_DECIMAL_LEN, double_to_shortest_decimal_buf(), and str.

◆ outNode()

void outNode ( StringInfo  str,
const void *  obj 
)

Definition at line 716 of file outfuncs.c.

717 {
718  /* Guard against stack overflow due to overly complex expressions */
720 
721  if (obj == NULL)
723  else if (IsA(obj, List) || IsA(obj, IntList) || IsA(obj, OidList) ||
724  IsA(obj, XidList))
725  _outList(str, obj);
726  /* nodeRead does not want to see { } around these! */
727  else if (IsA(obj, Integer))
728  _outInteger(str, (Integer *) obj);
729  else if (IsA(obj, Float))
730  _outFloat(str, (Float *) obj);
731  else if (IsA(obj, Boolean))
732  _outBoolean(str, (Boolean *) obj);
733  else if (IsA(obj, String))
734  _outString(str, (String *) obj);
735  else if (IsA(obj, BitString))
736  _outBitString(str, (BitString *) obj);
737  else if (IsA(obj, Bitmapset))
738  outBitmapset(str, (Bitmapset *) obj);
739  else
740  {
742  switch (nodeTag(obj))
743  {
744 #include "outfuncs.switch.c"
745 
746  default:
747 
748  /*
749  * This should be an ERROR, but it's too useful to be able to
750  * dump structures that outNode only understands part of.
751  */
752  elog(WARNING, "could not dump unrecognized node type: %d",
753  (int) nodeTag(obj));
754  break;
755  }
757  }
758 }
#define WARNING
Definition: elog.h:36
#define nodeTag(nodeptr)
Definition: nodes.h:133
static void _outString(StringInfo str, const String *node)
Definition: outfuncs.c:670
static void _outInteger(StringInfo str, const Integer *node)
Definition: outfuncs.c:648
static void _outList(StringInfo str, const List *node)
Definition: outfuncs.c:275
static void _outFloat(StringInfo str, const Float *node)
Definition: outfuncs.c:654
static void _outBitString(StringInfo str, const BitString *node)
Definition: outfuncs.c:684
static void _outBoolean(StringInfo str, const Boolean *node)
Definition: outfuncs.c:664
void check_stack_depth(void)
Definition: postgres.c:3531
Definition: value.h:56
Definition: value.h:48
Definition: value.h:29
Definition: value.h:64

References _outBitString(), _outBoolean(), _outFloat(), _outInteger(), _outList(), _outString(), appendStringInfoChar(), appendStringInfoString(), check_stack_depth(), elog, IsA, nodeTag, outBitmapset(), str, and WARNING.

Referenced by _outA_Const(), _outList(), nodeToStringInternal(), and writeNodeArray().

◆ outToken()

void outToken ( StringInfo  str,
const char *  s 
)

Definition at line 149 of file outfuncs.c.

150 {
151  if (s == NULL)
152  {
154  return;
155  }
156  if (*s == '\0')
157  {
158  appendStringInfoString(str, "\"\"");
159  return;
160  }
161 
162  /*
163  * Look for characters or patterns that are treated specially by read.c
164  * (either in pg_strtok() or in nodeRead()), and therefore need a
165  * protective backslash.
166  */
167  /* These characters only need to be quoted at the start of the string */
168  if (*s == '<' ||
169  *s == '"' ||
170  isdigit((unsigned char) *s) ||
171  ((*s == '+' || *s == '-') &&
172  (isdigit((unsigned char) s[1]) || s[1] == '.')))
173  appendStringInfoChar(str, '\\');
174  while (*s)
175  {
176  /* These chars must be backslashed anywhere in the string */
177  if (*s == ' ' || *s == '\n' || *s == '\t' ||
178  *s == '(' || *s == ')' || *s == '{' || *s == '}' ||
179  *s == '\\')
180  appendStringInfoChar(str, '\\');
181  appendStringInfoChar(str, *s++);
182  }
183 }

References appendStringInfoChar(), appendStringInfoString(), and str.

Referenced by _outBitString(), _outBoolExpr(), _outString(), and outChar().

◆ writeNodeArray()

static void writeNodeArray ( StringInfo  str,
const Node *const *  arr,
int  len 
)
static

Definition at line 255 of file outfuncs.c.

256 {
257  if (arr != NULL)
258  {
260  for (int i = 0; i < len; i++)
261  {
263  outNode(str, arr[i]);
264  }
266  }
267  else
269 }

References appendStringInfoChar(), appendStringInfoString(), i, len, outNode(), and str.

Variable Documentation

◆ write_location_fields

bool write_location_fields = false
static

Definition at line 29 of file outfuncs.c.

Referenced by nodeToStringInternal().