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