PostgreSQL Source Code  git master
misc.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * misc.c
4  *
5  *
6  * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  *
10  * IDENTIFICATION
11  * src/backend/utils/adt/misc.c
12  *
13  *-------------------------------------------------------------------------
14  */
15 #include "postgres.h"
16 
17 #include <sys/file.h>
18 #include <dirent.h>
19 #include <math.h>
20 #include <unistd.h>
21 
22 #include "access/sysattr.h"
23 #include "access/table.h"
24 #include "catalog/catalog.h"
25 #include "catalog/pg_tablespace.h"
26 #include "catalog/pg_type.h"
27 #include "commands/dbcommands.h"
28 #include "commands/tablespace.h"
29 #include "common/keywords.h"
30 #include "funcapi.h"
31 #include "miscadmin.h"
32 #include "parser/scansup.h"
33 #include "pgstat.h"
34 #include "postmaster/syslogger.h"
35 #include "rewrite/rewriteHandler.h"
36 #include "storage/fd.h"
37 #include "tcop/tcopprot.h"
38 #include "utils/builtins.h"
39 #include "utils/lsyscache.h"
40 #include "utils/ruleutils.h"
41 #include "utils/timestamp.h"
42 
43 /*
44  * Common subroutine for num_nulls() and num_nonnulls().
45  * Returns true if successful, false if function should return NULL.
46  * If successful, total argument count and number of nulls are
47  * returned into *nargs and *nulls.
48  */
49 static bool
51  int32 *nargs, int32 *nulls)
52 {
53  int32 count = 0;
54  int i;
55 
56  /* Did we get a VARIADIC array argument, or separate arguments? */
57  if (get_fn_expr_variadic(fcinfo->flinfo))
58  {
59  ArrayType *arr;
60  int ndims,
61  nitems,
62  *dims;
63  bits8 *bitmap;
64 
65  Assert(PG_NARGS() == 1);
66 
67  /*
68  * If we get a null as VARIADIC array argument, we can't say anything
69  * useful about the number of elements, so return NULL. This behavior
70  * is consistent with other variadic functions - see concat_internal.
71  */
72  if (PG_ARGISNULL(0))
73  return false;
74 
75  /*
76  * Non-null argument had better be an array. We assume that any call
77  * context that could let get_fn_expr_variadic return true will have
78  * checked that a VARIADIC-labeled parameter actually is an array. So
79  * it should be okay to just Assert that it's an array rather than
80  * doing a full-fledged error check.
81  */
83 
84  /* OK, safe to fetch the array value */
85  arr = PG_GETARG_ARRAYTYPE_P(0);
86 
87  /* Count the array elements */
88  ndims = ARR_NDIM(arr);
89  dims = ARR_DIMS(arr);
90  nitems = ArrayGetNItems(ndims, dims);
91 
92  /* Count those that are NULL */
93  bitmap = ARR_NULLBITMAP(arr);
94  if (bitmap)
95  {
96  int bitmask = 1;
97 
98  for (i = 0; i < nitems; i++)
99  {
100  if ((*bitmap & bitmask) == 0)
101  count++;
102 
103  bitmask <<= 1;
104  if (bitmask == 0x100)
105  {
106  bitmap++;
107  bitmask = 1;
108  }
109  }
110  }
111 
112  *nargs = nitems;
113  *nulls = count;
114  }
115  else
116  {
117  /* Separate arguments, so just count 'em */
118  for (i = 0; i < PG_NARGS(); i++)
119  {
120  if (PG_ARGISNULL(i))
121  count++;
122  }
123 
124  *nargs = PG_NARGS();
125  *nulls = count;
126  }
127 
128  return true;
129 }
130 
131 /*
132  * num_nulls()
133  * Count the number of NULL arguments
134  */
135 Datum
137 {
138  int32 nargs,
139  nulls;
140 
141  if (!count_nulls(fcinfo, &nargs, &nulls))
142  PG_RETURN_NULL();
143 
144  PG_RETURN_INT32(nulls);
145 }
146 
147 /*
148  * num_nonnulls()
149  * Count the number of non-NULL arguments
150  */
151 Datum
153 {
154  int32 nargs,
155  nulls;
156 
157  if (!count_nulls(fcinfo, &nargs, &nulls))
158  PG_RETURN_NULL();
159 
160  PG_RETURN_INT32(nargs - nulls);
161 }
162 
163 
164 /*
165  * current_database()
166  * Expose the current database to the user
167  */
168 Datum
170 {
171  Name db;
172 
173  db = (Name) palloc(NAMEDATALEN);
174 
176  PG_RETURN_NAME(db);
177 }
178 
179 
180 /*
181  * current_query()
182  * Expose the current query to the user (useful in stored procedures)
183  * We might want to use ActivePortal->sourceText someday.
184  */
185 Datum
187 {
188  /* there is no easy way to access the more concise 'query_string' */
189  if (debug_query_string)
191  else
192  PG_RETURN_NULL();
193 }
194 
195 /* Function to find out which databases make use of a tablespace */
196 
197 typedef struct
198 {
199  char *location;
201 } ts_db_fctx;
202 
203 Datum
205 {
206  FuncCallContext *funcctx;
207  struct dirent *de;
208  ts_db_fctx *fctx;
209 
210  if (SRF_IS_FIRSTCALL())
211  {
212  MemoryContext oldcontext;
213  Oid tablespaceOid = PG_GETARG_OID(0);
214 
215  funcctx = SRF_FIRSTCALL_INIT();
216  oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
217 
218  fctx = palloc(sizeof(ts_db_fctx));
219 
220  if (tablespaceOid == GLOBALTABLESPACE_OID)
221  {
222  fctx->dirdesc = NULL;
224  (errmsg("global tablespace never has databases")));
225  }
226  else
227  {
228  if (tablespaceOid == DEFAULTTABLESPACE_OID)
229  fctx->location = psprintf("base");
230  else
231  fctx->location = psprintf("pg_tblspc/%u/%s", tablespaceOid,
233 
234  fctx->dirdesc = AllocateDir(fctx->location);
235 
236  if (!fctx->dirdesc)
237  {
238  /* the only expected error is ENOENT */
239  if (errno != ENOENT)
240  ereport(ERROR,
242  errmsg("could not open directory \"%s\": %m",
243  fctx->location)));
245  (errmsg("%u is not a tablespace OID", tablespaceOid)));
246  }
247  }
248  funcctx->user_fctx = fctx;
249  MemoryContextSwitchTo(oldcontext);
250  }
251 
252  funcctx = SRF_PERCALL_SETUP();
253  fctx = (ts_db_fctx *) funcctx->user_fctx;
254 
255  if (!fctx->dirdesc) /* not a tablespace */
256  SRF_RETURN_DONE(funcctx);
257 
258  while ((de = ReadDir(fctx->dirdesc, fctx->location)) != NULL)
259  {
260  Oid datOid = atooid(de->d_name);
261  char *subdir;
262  bool isempty;
263 
264  /* this test skips . and .., but is awfully weak */
265  if (!datOid)
266  continue;
267 
268  /* if database subdir is empty, don't report tablespace as used */
269 
270  subdir = psprintf("%s/%s", fctx->location, de->d_name);
271  isempty = directory_is_empty(subdir);
272  pfree(subdir);
273 
274  if (isempty)
275  continue; /* indeed, nothing in it */
276 
277  SRF_RETURN_NEXT(funcctx, ObjectIdGetDatum(datOid));
278  }
279 
280  FreeDir(fctx->dirdesc);
281  SRF_RETURN_DONE(funcctx);
282 }
283 
284 
285 /*
286  * pg_tablespace_location - get location for a tablespace
287  */
288 Datum
290 {
291  Oid tablespaceOid = PG_GETARG_OID(0);
292  char sourcepath[MAXPGPATH];
293  char targetpath[MAXPGPATH];
294  int rllen;
295 
296  /*
297  * It's useful to apply this function to pg_class.reltablespace, wherein
298  * zero means "the database's default tablespace". So, rather than
299  * throwing an error for zero, we choose to assume that's what is meant.
300  */
301  if (tablespaceOid == InvalidOid)
302  tablespaceOid = MyDatabaseTableSpace;
303 
304  /*
305  * Return empty string for the cluster's default tablespaces
306  */
307  if (tablespaceOid == DEFAULTTABLESPACE_OID ||
308  tablespaceOid == GLOBALTABLESPACE_OID)
310 
311 #if defined(HAVE_READLINK) || defined(WIN32)
312 
313  /*
314  * Find the location of the tablespace by reading the symbolic link that
315  * is in pg_tblspc/<oid>.
316  */
317  snprintf(sourcepath, sizeof(sourcepath), "pg_tblspc/%u", tablespaceOid);
318 
319  rllen = readlink(sourcepath, targetpath, sizeof(targetpath));
320  if (rllen < 0)
321  ereport(ERROR,
323  errmsg("could not read symbolic link \"%s\": %m",
324  sourcepath)));
325  if (rllen >= sizeof(targetpath))
326  ereport(ERROR,
327  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
328  errmsg("symbolic link \"%s\" target is too long",
329  sourcepath)));
330  targetpath[rllen] = '\0';
331 
332  PG_RETURN_TEXT_P(cstring_to_text(targetpath));
333 #else
334  ereport(ERROR,
335  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
336  errmsg("tablespaces are not supported on this platform")));
337  PG_RETURN_NULL();
338 #endif
339 }
340 
341 /*
342  * pg_sleep - delay for N seconds
343  */
344 Datum
346 {
347  float8 secs = PG_GETARG_FLOAT8(0);
348  float8 endtime;
349 
350  /*
351  * We sleep using WaitLatch, to ensure that we'll wake up promptly if an
352  * important signal (such as SIGALRM or SIGINT) arrives. Because
353  * WaitLatch's upper limit of delay is INT_MAX milliseconds, and the user
354  * might ask for more than that, we sleep for at most 10 minutes and then
355  * loop.
356  *
357  * By computing the intended stop time initially, we avoid accumulation of
358  * extra delay across multiple sleeps. This also ensures we won't delay
359  * less than the specified time when WaitLatch is terminated early by a
360  * non-query-canceling signal such as SIGHUP.
361  */
362 #define GetNowFloat() ((float8) GetCurrentTimestamp() / 1000000.0)
363 
364  endtime = GetNowFloat() + secs;
365 
366  for (;;)
367  {
368  float8 delay;
369  long delay_ms;
370 
372 
373  delay = endtime - GetNowFloat();
374  if (delay >= 600.0)
375  delay_ms = 600000;
376  else if (delay > 0.0)
377  delay_ms = (long) ceil(delay * 1000.0);
378  else
379  break;
380 
381  (void) WaitLatch(MyLatch,
383  delay_ms,
386  }
387 
388  PG_RETURN_VOID();
389 }
390 
391 /* Function to return the list of grammar keywords */
392 Datum
394 {
395  FuncCallContext *funcctx;
396 
397  if (SRF_IS_FIRSTCALL())
398  {
399  MemoryContext oldcontext;
400  TupleDesc tupdesc;
401 
402  funcctx = SRF_FIRSTCALL_INIT();
403  oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
404 
405  tupdesc = CreateTemplateTupleDesc(3);
406  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "word",
407  TEXTOID, -1, 0);
408  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "catcode",
409  CHAROID, -1, 0);
410  TupleDescInitEntry(tupdesc, (AttrNumber) 3, "catdesc",
411  TEXTOID, -1, 0);
412 
413  funcctx->attinmeta = TupleDescGetAttInMetadata(tupdesc);
414 
415  MemoryContextSwitchTo(oldcontext);
416  }
417 
418  funcctx = SRF_PERCALL_SETUP();
419 
420  if (funcctx->call_cntr < ScanKeywords.num_keywords)
421  {
422  char *values[3];
423  HeapTuple tuple;
424 
425  /* cast-away-const is ugly but alternatives aren't much better */
426  values[0] = unconstify(char *,
427  GetScanKeyword(funcctx->call_cntr,
428  &ScanKeywords));
429 
430  switch (ScanKeywordCategories[funcctx->call_cntr])
431  {
432  case UNRESERVED_KEYWORD:
433  values[1] = "U";
434  values[2] = _("unreserved");
435  break;
436  case COL_NAME_KEYWORD:
437  values[1] = "C";
438  values[2] = _("unreserved (cannot be function or type name)");
439  break;
441  values[1] = "T";
442  values[2] = _("reserved (can be function or type name)");
443  break;
444  case RESERVED_KEYWORD:
445  values[1] = "R";
446  values[2] = _("reserved");
447  break;
448  default: /* shouldn't be possible */
449  values[1] = NULL;
450  values[2] = NULL;
451  break;
452  }
453 
454  tuple = BuildTupleFromCStrings(funcctx->attinmeta, values);
455 
456  SRF_RETURN_NEXT(funcctx, HeapTupleGetDatum(tuple));
457  }
458 
459  SRF_RETURN_DONE(funcctx);
460 }
461 
462 
463 /*
464  * Return the type of the argument.
465  */
466 Datum
468 {
469  PG_RETURN_OID(get_fn_expr_argtype(fcinfo->flinfo, 0));
470 }
471 
472 
473 /*
474  * Implementation of the COLLATE FOR expression; returns the collation
475  * of the argument.
476  */
477 Datum
479 {
480  Oid typeid;
481  Oid collid;
482 
483  typeid = get_fn_expr_argtype(fcinfo->flinfo, 0);
484  if (!typeid)
485  PG_RETURN_NULL();
486  if (!type_is_collatable(typeid) && typeid != UNKNOWNOID)
487  ereport(ERROR,
488  (errcode(ERRCODE_DATATYPE_MISMATCH),
489  errmsg("collations are not supported by type %s",
490  format_type_be(typeid))));
491 
492  collid = PG_GET_COLLATION();
493  if (!collid)
494  PG_RETURN_NULL();
496 }
497 
498 
499 /*
500  * pg_relation_is_updatable - determine which update events the specified
501  * relation supports.
502  *
503  * This relies on relation_is_updatable() in rewriteHandler.c, which see
504  * for additional information.
505  */
506 Datum
508 {
509  Oid reloid = PG_GETARG_OID(0);
510  bool include_triggers = PG_GETARG_BOOL(1);
511 
512  PG_RETURN_INT32(relation_is_updatable(reloid, NIL, include_triggers, NULL));
513 }
514 
515 /*
516  * pg_column_is_updatable - determine whether a column is updatable
517  *
518  * This function encapsulates the decision about just what
519  * information_schema.columns.is_updatable actually means. It's not clear
520  * whether deletability of the column's relation should be required, so
521  * we want that decision in C code where we could change it without initdb.
522  */
523 Datum
525 {
526  Oid reloid = PG_GETARG_OID(0);
529  bool include_triggers = PG_GETARG_BOOL(2);
530  int events;
531 
532  /* System columns are never updatable */
533  if (attnum <= 0)
534  PG_RETURN_BOOL(false);
535 
536  events = relation_is_updatable(reloid, NIL, include_triggers,
537  bms_make_singleton(col));
538 
539  /* We require both updatability and deletability of the relation */
540 #define REQ_EVENTS ((1 << CMD_UPDATE) | (1 << CMD_DELETE))
541 
542  PG_RETURN_BOOL((events & REQ_EVENTS) == REQ_EVENTS);
543 }
544 
545 
546 /*
547  * Is character a valid identifier start?
548  * Must match scan.l's {ident_start} character class.
549  */
550 static bool
551 is_ident_start(unsigned char c)
552 {
553  /* Underscores and ASCII letters are OK */
554  if (c == '_')
555  return true;
556  if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
557  return true;
558  /* Any high-bit-set character is OK (might be part of a multibyte char) */
559  if (IS_HIGHBIT_SET(c))
560  return true;
561  return false;
562 }
563 
564 /*
565  * Is character a valid identifier continuation?
566  * Must match scan.l's {ident_cont} character class.
567  */
568 static bool
569 is_ident_cont(unsigned char c)
570 {
571  /* Can be digit or dollar sign ... */
572  if ((c >= '0' && c <= '9') || c == '$')
573  return true;
574  /* ... or an identifier start character */
575  return is_ident_start(c);
576 }
577 
578 /*
579  * parse_ident - parse a SQL qualified identifier into separate identifiers.
580  * When strict mode is active (second parameter), then any chars after
581  * the last identifier are disallowed.
582  */
583 Datum
585 {
586  text *qualname = PG_GETARG_TEXT_PP(0);
587  bool strict = PG_GETARG_BOOL(1);
588  char *qualname_str = text_to_cstring(qualname);
589  ArrayBuildState *astate = NULL;
590  char *nextp;
591  bool after_dot = false;
592 
593  /*
594  * The code below scribbles on qualname_str in some cases, so we should
595  * reconvert qualname if we need to show the original string in error
596  * messages.
597  */
598  nextp = qualname_str;
599 
600  /* skip leading whitespace */
601  while (scanner_isspace(*nextp))
602  nextp++;
603 
604  for (;;)
605  {
606  char *curname;
607  bool missing_ident = true;
608 
609  if (*nextp == '"')
610  {
611  char *endp;
612 
613  curname = nextp + 1;
614  for (;;)
615  {
616  endp = strchr(nextp + 1, '"');
617  if (endp == NULL)
618  ereport(ERROR,
619  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
620  errmsg("string is not a valid identifier: \"%s\"",
621  text_to_cstring(qualname)),
622  errdetail("String has unclosed double quotes.")));
623  if (endp[1] != '"')
624  break;
625  memmove(endp, endp + 1, strlen(endp));
626  nextp = endp;
627  }
628  nextp = endp + 1;
629  *endp = '\0';
630 
631  if (endp - curname == 0)
632  ereport(ERROR,
633  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
634  errmsg("string is not a valid identifier: \"%s\"",
635  text_to_cstring(qualname)),
636  errdetail("Quoted identifier must not be empty.")));
637 
638  astate = accumArrayResult(astate, CStringGetTextDatum(curname),
639  false, TEXTOID, CurrentMemoryContext);
640  missing_ident = false;
641  }
642  else if (is_ident_start((unsigned char) *nextp))
643  {
644  char *downname;
645  int len;
646  text *part;
647 
648  curname = nextp++;
649  while (is_ident_cont((unsigned char) *nextp))
650  nextp++;
651 
652  len = nextp - curname;
653 
654  /*
655  * We don't implicitly truncate identifiers. This is useful for
656  * allowing the user to check for specific parts of the identifier
657  * being too long. It's easy enough for the user to get the
658  * truncated names by casting our output to name[].
659  */
660  downname = downcase_identifier(curname, len, false, false);
661  part = cstring_to_text_with_len(downname, len);
662  astate = accumArrayResult(astate, PointerGetDatum(part), false,
663  TEXTOID, CurrentMemoryContext);
664  missing_ident = false;
665  }
666 
667  if (missing_ident)
668  {
669  /* Different error messages based on where we failed. */
670  if (*nextp == '.')
671  ereport(ERROR,
672  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
673  errmsg("string is not a valid identifier: \"%s\"",
674  text_to_cstring(qualname)),
675  errdetail("No valid identifier before \".\".")));
676  else if (after_dot)
677  ereport(ERROR,
678  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
679  errmsg("string is not a valid identifier: \"%s\"",
680  text_to_cstring(qualname)),
681  errdetail("No valid identifier after \".\".")));
682  else
683  ereport(ERROR,
684  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
685  errmsg("string is not a valid identifier: \"%s\"",
686  text_to_cstring(qualname))));
687  }
688 
689  while (scanner_isspace(*nextp))
690  nextp++;
691 
692  if (*nextp == '.')
693  {
694  after_dot = true;
695  nextp++;
696  while (scanner_isspace(*nextp))
697  nextp++;
698  }
699  else if (*nextp == '\0')
700  {
701  break;
702  }
703  else
704  {
705  if (strict)
706  ereport(ERROR,
707  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
708  errmsg("string is not a valid identifier: \"%s\"",
709  text_to_cstring(qualname))));
710  break;
711  }
712  }
713 
715 }
716 
717 /*
718  * pg_current_logfile
719  *
720  * Report current log file used by log collector by scanning current_logfiles.
721  */
722 Datum
724 {
725  FILE *fd;
726  char lbuffer[MAXPGPATH];
727  char *logfmt;
728  char *log_filepath;
729  char *log_format = lbuffer;
730  char *nlpos;
731 
732  /* The log format parameter is optional */
733  if (PG_NARGS() == 0 || PG_ARGISNULL(0))
734  logfmt = NULL;
735  else
736  {
737  logfmt = text_to_cstring(PG_GETARG_TEXT_PP(0));
738 
739  if (strcmp(logfmt, "stderr") != 0 && strcmp(logfmt, "csvlog") != 0)
740  ereport(ERROR,
741  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
742  errmsg("log format \"%s\" is not supported", logfmt),
743  errhint("The supported log formats are \"stderr\" and \"csvlog\".")));
744  }
745 
747  if (fd == NULL)
748  {
749  if (errno != ENOENT)
750  ereport(ERROR,
752  errmsg("could not read file \"%s\": %m",
754  PG_RETURN_NULL();
755  }
756 
757  /*
758  * Read the file to gather current log filename(s) registered by the
759  * syslogger.
760  */
761  while (fgets(lbuffer, sizeof(lbuffer), fd) != NULL)
762  {
763  /*
764  * Extract log format and log file path from the line; lbuffer ==
765  * log_format, they share storage.
766  */
767  log_filepath = strchr(lbuffer, ' ');
768  if (log_filepath == NULL)
769  {
770  /* Uh oh. No space found, so file content is corrupted. */
771  elog(ERROR,
772  "missing space character in \"%s\"", LOG_METAINFO_DATAFILE);
773  break;
774  }
775 
776  *log_filepath = '\0';
777  log_filepath++;
778  nlpos = strchr(log_filepath, '\n');
779  if (nlpos == NULL)
780  {
781  /* Uh oh. No newline found, so file content is corrupted. */
782  elog(ERROR,
783  "missing newline character in \"%s\"", LOG_METAINFO_DATAFILE);
784  break;
785  }
786  *nlpos = '\0';
787 
788  if (logfmt == NULL || strcmp(logfmt, log_format) == 0)
789  {
790  FreeFile(fd);
791  PG_RETURN_TEXT_P(cstring_to_text(log_filepath));
792  }
793  }
794 
795  /* Close the current log filename file. */
796  FreeFile(fd);
797 
798  PG_RETURN_NULL();
799 }
800 
801 /*
802  * Report current log file used by log collector (1 argument version)
803  *
804  * note: this wrapper is necessary to pass the sanity check in opr_sanity,
805  * which checks that all built-in functions that share the implementing C
806  * function take the same number of arguments
807  */
808 Datum
810 {
811  return pg_current_logfile(fcinfo);
812 }
813 
814 /*
815  * SQL wrapper around RelationGetReplicaIndex().
816  */
817 Datum
819 {
820  Oid reloid = PG_GETARG_OID(0);
821  Oid idxoid;
822  Relation rel;
823 
824  rel = table_open(reloid, AccessShareLock);
825  idxoid = RelationGetReplicaIndex(rel);
827 
828  if (OidIsValid(idxoid))
829  PG_RETURN_OID(idxoid);
830  else
831  PG_RETURN_NULL();
832 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:276
uint64 call_cntr
Definition: funcapi.h:65
#define NIL
Definition: pg_list.h:65
static bool is_ident_start(unsigned char c)
Definition: misc.c:551
Datum pg_get_replica_identity_index(PG_FUNCTION_ARGS)
Definition: misc.c:818
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:133
int errhint(const char *fmt,...)
Definition: elog.c:1069
Datum pg_relation_is_updatable(PG_FUNCTION_ARGS)
Definition: misc.c:507
Datum parse_ident(PG_FUNCTION_ARGS)
Definition: misc.c:584
Oid RelationGetReplicaIndex(Relation relation)
Definition: relcache.c:4556
#define WL_TIMEOUT
Definition: latch.h:127
static bool count_nulls(FunctionCallInfo fcinfo, int32 *nargs, int32 *nulls)
Definition: misc.c:50
TupleDesc CreateTemplateTupleDesc(int natts)
Definition: tupdesc.c:44
#define SRF_IS_FIRSTCALL()
Definition: funcapi.h:282
#define PointerGetDatum(X)
Definition: postgres.h:556
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
int ArrayGetNItems(int ndim, const int *dims)
Definition: arrayutils.c:75
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
#define AccessShareLock
Definition: lockdefs.h:36
Datum pg_collation_for(PG_FUNCTION_ARGS)
Definition: misc.c:478
bool get_fn_expr_variadic(FmgrInfo *flinfo)
Definition: fmgr.c:1936
int errcode(int sqlerrcode)
Definition: elog.c:608
#define LOG_METAINFO_DATAFILE
Definition: syslogger.h:97
char * format_type_be(Oid type_oid)
Definition: format_type.c:326
bool directory_is_empty(const char *path)
Definition: tablespace.c:846
#define FirstLowInvalidHeapAttributeNumber
Definition: sysattr.h:27
const uint8 ScanKeywordCategories[SCANKEYWORDS_NUM_KEYWORDS]
Definition: keywords.c:29
#define UNRESERVED_KEYWORD
Definition: keywords.h:20
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:269
unsigned int Oid
Definition: postgres_ext.h:31
int namestrcpy(Name name, const char *str)
Definition: name.c:250
Definition: dirent.h:9
#define OidIsValid(objectId)
Definition: c.h:645
#define SRF_PERCALL_SETUP()
Definition: funcapi.h:286
static int fd(const char *x, int i)
Definition: preproc-init.c:105
#define PG_GET_COLLATION()
Definition: fmgr.h:193
void ResetLatch(Latch *latch)
Definition: latch.c:519
Datum pg_typeof(PG_FUNCTION_ARGS)
Definition: misc.c:467
char * generate_collation_name(Oid collid)
Definition: ruleutils.c:11156
static const char * GetScanKeyword(int n, const ScanKeywordList *keywords)
Definition: kwlookup.h:39
signed int int32
Definition: c.h:347
Oid MyDatabaseTableSpace
Definition: globals.c:87
int WaitLatch(Latch *latch, int wakeEvents, long timeout, uint32 wait_event_info)
Definition: latch.c:344
HeapTuple BuildTupleFromCStrings(AttInMetadata *attinmeta, char **values)
Definition: execTuples.c:2116
Datum current_database(PG_FUNCTION_ARGS)
Definition: misc.c:169
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
PGDLLIMPORT const ScanKeywordList ScanKeywords
Datum current_query(PG_FUNCTION_ARGS)
Definition: misc.c:186
#define NAMEDATALEN
#define SRF_RETURN_NEXT(_funcctx, _result)
Definition: funcapi.h:288
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
#define GetNowFloat()
void pfree(void *pointer)
Definition: mcxt.c:1056
Datum pg_current_logfile(PG_FUNCTION_ARGS)
Definition: misc.c:723
#define IS_HIGHBIT_SET(ch)
Definition: c.h:1106
Datum pg_tablespace_location(PG_FUNCTION_ARGS)
Definition: misc.c:289
Definition: dirent.c:25
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:492
Datum pg_num_nulls(PG_FUNCTION_ARGS)
Definition: misc.c:136
Oid get_fn_expr_argtype(FmgrInfo *flinfo, int argnum)
Definition: fmgr.c:1802
#define ARR_DIMS(a)
Definition: array.h:282
#define MAXPGPATH
char * get_database_name(Oid dbid)
Definition: dbcommands.c:2155
Definition: c.h:610
#define TYPE_FUNC_NAME_KEYWORD
Definition: keywords.h:22
#define TABLESPACE_VERSION_DIRECTORY
Definition: relpath.h:26
char * c
Bitmapset * bms_make_singleton(int x)
Definition: bitmapset.c:186
#define memmove(d, s, c)
Definition: c.h:1267
text * cstring_to_text_with_len(const char *s, int len)
Definition: varlena.c:183
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
#define readlink(path, buf, size)
Definition: win32_port.h:222
AttInMetadata * attinmeta
Definition: funcapi.h:91
int errdetail(const char *fmt,...)
Definition: elog.c:955
int errcode_for_file_access(void)
Definition: elog.c:631
FILE * AllocateFile(const char *name, const char *mode)
Definition: fd.c:2242
Datum pg_current_logfile_1arg(PG_FUNCTION_ARGS)
Definition: misc.c:809
DIR * AllocateDir(const char *dirname)
Definition: fd.c:2503
Datum pg_sleep(PG_FUNCTION_ARGS)
Definition: misc.c:345
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:603
#define atooid(x)
Definition: postgres_ext.h:42
Datum pg_tablespace_databases(PG_FUNCTION_ARGS)
Definition: misc.c:204
#define ereport(elevel, rest)
Definition: elog.h:141
Datum makeArrayResult(ArrayBuildState *astate, MemoryContext rcontext)
Definition: arrayfuncs.c:5117
int relation_is_updatable(Oid reloid, List *outer_reloids, bool include_triggers, Bitmapset *include_cols)
#define WARNING
Definition: elog.h:40
const char * debug_query_string
Definition: postgres.c:86
#define unconstify(underlying_type, expr)
Definition: c.h:1194
Datum pg_num_nonnulls(PG_FUNCTION_ARGS)
Definition: misc.c:152
uint8 bits8
Definition: c.h:366
int num_keywords
Definition: kwlookup.h:30
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
uintptr_t Datum
Definition: postgres.h:367
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:343
FmgrInfo * flinfo
Definition: fmgr.h:87
Oid MyDatabaseId
Definition: globals.c:85
AttInMetadata * TupleDescGetAttInMetadata(TupleDesc tupdesc)
Definition: execTuples.c:2067
bool scanner_isspace(char ch)
Definition: scansup.c:220
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266
#define REQ_EVENTS
#define RESERVED_KEYWORD
Definition: keywords.h:23
#define InvalidOid
Definition: postgres_ext.h:36
char * downcase_identifier(const char *ident, int len, bool warn, bool truncate)
Definition: scansup.c:139
int16 attnum
Definition: pg_attribute.h:79
#define PG_RETURN_VOID()
Definition: fmgr.h:339
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:361
text * cstring_to_text(const char *s)
Definition: varlena.c:171
#define PG_ARGISNULL(n)
Definition: fmgr.h:204
#define Assert(condition)
Definition: c.h:739
struct dirent * ReadDir(DIR *dir, const char *dirname)
Definition: fd.c:2569
MemoryContext multi_call_memory_ctx
Definition: funcapi.h:101
static bool is_ident_cont(unsigned char c)
Definition: misc.c:569
#define PG_NARGS()
Definition: fmgr.h:198
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:220
#define ARR_NDIM(a)
Definition: array.h:278
#define COL_NAME_KEYWORD
Definition: keywords.h:21
int FreeFile(FILE *file)
Definition: fd.c:2441
static Datum values[MAXATTR]
Definition: bootstrap.c:167
char * text_to_cstring(const text *t)
Definition: varlena.c:204
ArrayBuildState * accumArrayResult(ArrayBuildState *astate, Datum dvalue, bool disnull, Oid element_type, MemoryContext rcontext)
Definition: arrayfuncs.c:5053
Oid get_base_element_type(Oid typid)
Definition: lsyscache.c:2599
void * user_fctx
Definition: funcapi.h:82
void * palloc(Size size)
Definition: mcxt.c:949
int errmsg(const char *fmt,...)
Definition: elog.c:822
#define elog(elevel,...)
Definition: elog.h:228
int i
#define CStringGetTextDatum(s)
Definition: builtins.h:83
struct Latch * MyLatch
Definition: globals.c:54
Definition: c.h:556
#define PG_FUNCTION_ARGS
Definition: fmgr.h:188
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:99
char d_name[MAX_PATH]
Definition: dirent.h:14
Datum pg_get_keywords(PG_FUNCTION_ARGS)
Definition: misc.c:393
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
NameData * Name
Definition: c.h:614
bool type_is_collatable(Oid typid)
Definition: lsyscache.c:2848
#define PG_RETURN_OID(x)
Definition: fmgr.h:350
#define snprintf
Definition: port.h:192
char * location
Definition: misc.c:199
#define WL_LATCH_SET
Definition: latch.h:124
int16 AttrNumber
Definition: attnum.h:21
#define _(x)
Definition: elog.c:87
#define ARR_NULLBITMAP(a)
Definition: array.h:288
DIR * dirdesc
Definition: misc.c:200
#define PG_RETURN_NULL()
Definition: fmgr.h:335
#define PG_RETURN_NAME(x)
Definition: fmgr.h:353
int FreeDir(DIR *dir)
Definition: fd.c:2621
#define WL_EXIT_ON_PM_DEATH
Definition: latch.h:129
Datum pg_column_is_updatable(PG_FUNCTION_ARGS)
Definition: misc.c:524
#define SRF_RETURN_DONE(_funcctx)
Definition: funcapi.h:306
#define SRF_FIRSTCALL_INIT()
Definition: funcapi.h:284