PostgreSQL Source Code: src/backend/utils/adt/misc.c Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
16
18#include <sys/stat.h>
20#include <fcntl.h>
21#include <math.h>
23
29#include "catalog/system_fk_info.h"
44#include "utils/fmgroids.h"
50
51
52
53
54
64
68
69
70
71
72
73
74
75
76static bool
79{
81 int i;
82
83
85 {
87 int ndims,
89 *dims;
91
93
94
95
96
97
98
100 return false;
101
102
103
104
105
106
107
108
110
111
113
114
118
119
121 if (bitmap)
122 {
123 int bitmask = 1;
124
126 {
127 if ((*bitmap & bitmask) == 0)
128 count++;
129
130 bitmask <<= 1;
131 if (bitmask == 0x100)
132 {
133 bitmap++;
134 bitmask = 1;
135 }
136 }
137 }
138
140 *nulls = count;
141 }
142 else
143 {
144
146 {
148 count++;
149 }
150
152 *nulls = count;
153 }
154
155 return true;
156}
157
158
159
160
161
164{
166 nulls;
167
168 if ((fcinfo, &nargs, &nulls))
170
172}
173
174
175
176
177
180{
182 nulls;
183
184 if ((fcinfo, &nargs, &nulls))
186
188}
189
190
191
192
193
196{
200 errmsg("null value not allowed")));
201
203}
204
205
206
207
208
219
220
221
222
223
224
225
235
236
237
240{
243 char *location;
244 DIR *dirdesc;
246
248
250 {
252 (errmsg("global tablespace never has databases")));
253
254 return (Datum) 0;
255 }
256
258 location = "base";
259 else
262
264
265 if (!dirdesc)
266 {
267
271 errmsg("could not open directory \"%s\": %m",
272 location)));
274 (errmsg("%u is not a tablespace OID", tablespaceOid)));
275
276 return (Datum) 0;
277 }
278
279 while ((de = ReadDir(dirdesc, location)) != NULL)
280 {
285 bool nulls[1];
286
287
289 continue;
290
291
292
296
298 continue;
299
301 nulls[0] = false;
302
305 }
306
308 return (Datum) 0;
309}
310
311
312
313
314
326
327
328
329
332{
336
337
338
339
340
341
342
345 secs *= USECS_PER_SEC;
348
349
350
351
352
353
354
355
356
357
358
359
360
362
363 for (;;)
364 {
366 long delay_ms;
367
369
372 delay_ms = 600000;
373 else if (delay > 0)
374 delay_ms = (long) ((delay + 999) / 1000);
375 else
376 break;
377
380 delay_ms,
383 }
384
386}
387
388
391{
393
395 {
398
401
403 elog(ERROR, "return type must be a row type");
404 funcctx->tuple_desc = tupdesc;
406
408 }
409
411
413 {
416
417
421
423 {
426 values[3] = _("unreserved");
427 break;
430 values[3] = _("unreserved (cannot be function or type name)");
431 break;
434 values[3] = _("reserved (can be function or type name)");
435 break;
438 values[3] = _("reserved");
439 break;
440 default:
443 break;
444 }
445
447 {
449 values[4] = _("can be bare label");
450 }
451 else
452 {
454 values[4] = _("requires AS");
455 }
456
458
460 }
461
463}
464
465
466
469{
472
474 {
477
480
482 elog(ERROR, "return type must be a row type");
484
485
486
487
488
489
490
494
496 }
497
500
502 {
505 bool nulls[6];
507
508 memset(nulls, false, sizeof(nulls));
509
522
524
526 }
527
529}
530
531
532
533
534
540
541
542
543
544
545
546
547
548
549
550
551
552
553
556{
558
559
560
561
562 for (;;)
563 {
566
572 {
573
575 break;
576 }
577
578 typid = typTup->typbasetype;
580 }
581
583}
584
585
586
587
588
589
592{
593 Oid typeid;
595
597 if (!typeid)
602 errmsg("collations are not supported by type %s",
604
609}
610
611
612
613
614
615
616
617
618
627
628
629
630
631
632
633
634
635
638{
643 int events;
644
645
648
651
652
653#define REQ_EVENTS ((1 << CMD_UPDATE) | (1 << CMD_DELETE))
654
656}
657
658
659
660
661
662
663
664
665
666
669{
673
675 &escontext));
676}
677
678
679
680
681
682
683
684
685
686
689{
695 bool isnull[4];
696
698 elog(ERROR, "return type must be a row type");
699
700
702
704 &escontext))
705 memset(isnull, true, sizeof(isnull));
706 else
707 {
708 char *sqlstate;
709
713
714 memset(isnull, false, sizeof(isnull));
715
717
720 else
721 isnull[1] = true;
722
725 else
726 isnull[2] = true;
727
730 }
731
733}
734
735
736static bool
740{
744
745
746
747
748
751 {
757
759 }
760
761
762
763
764
766 {
768 Oid typoid;
769
770
772
773
774 if (my_extra->typoid != typoid)
775 {
782 }
783 }
784
785
790 (Node *) escontext,
792}
793
794
795
796
797
798
799static bool
801{
802
803 if (c == '_')
804 return true;
805 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
806 return true;
807
809 return true;
810 return false;
811}
812
813
814
815
816
817static bool
819{
820
821 if ((c >= '0' && c <= '9') || c == '$')
822 return true;
823
825}
826
827
828
829
830
831
834{
841
842
843
844
845
846
848
849
852
853 for (;;)
854 {
857
858 if (*nextp == '"')
859 {
861
863 for (;;)
864 {
869 errmsg("string is not a valid identifier: \"%s\"",
871 errdetail("String has unclosed double quotes.")));
872 if (endp[1] != '"')
873 break;
876 }
878 *endp = '\0';
879
883 errmsg("string is not a valid identifier: \"%s\"",
885 errdetail("Quoted identifier must not be empty.")));
886
890 }
892 {
896
900
902
903
904
905
906
907
908
914 }
915
917 {
918
919 if (*nextp == '.')
922 errmsg("string is not a valid identifier: \"%s\"",
924 errdetail("No valid identifier before \".\".")));
928 errmsg("string is not a valid identifier: \"%s\"",
930 errdetail("No valid identifier after \".\".")));
931 else
934 errmsg("string is not a valid identifier: \"%s\"",
936 }
937
940
941 if (*nextp == '.')
942 {
947 }
948 else if (*nextp == '\0')
949 {
950 break;
951 }
952 else
953 {
954 if (strict)
957 errmsg("string is not a valid identifier: \"%s\"",
959 break;
960 }
961 }
962
964}
965
966
967
968
969
970
973{
977
978
981 else
982 {
984
990 errmsg("log format \"%s\" is not supported", logfmt),
991 errhint("The supported log formats are \"stderr\", \"csvlog\", and \"jsonlog\".")));
992 }
993
996 {
1000 errmsg("could not read file \"%s\": %m",
1003 }
1004
1005#ifdef WIN32
1006
1008#endif
1009
1010
1011
1012
1013
1015 {
1019
1020
1024 {
1025
1028 break;
1029 }
1030
1035 {
1036
1039 break;
1040 }
1042
1044 {
1047 }
1048 }
1049
1050
1052
1054}
1055
1056
1057
1058
1059
1060
1061
1062
1068
1069
1070
1071
1074{
1078
1082
1085 else
1087}
1088
1089
1090
1091
#define PG_GETARG_ARRAYTYPE_P(n)
#define ARR_NULLBITMAP(a)
ArrayBuildState * accumArrayResult(ArrayBuildState *astate, Datum dvalue, bool disnull, Oid element_type, MemoryContext rcontext)
Datum makeArrayResult(ArrayBuildState *astate, MemoryContext rcontext)
int ArrayGetNItems(int ndim, const int *dims)
bool directory_is_empty(const char *path)
Datum pg_typeof(PG_FUNCTION_ARGS)
Datum parse_ident(PG_FUNCTION_ARGS)
static bool count_nulls(FunctionCallInfo fcinfo, int32 *nargs, int32 *nulls)
Datum pg_tablespace_databases(PG_FUNCTION_ARGS)
static bool is_ident_cont(unsigned char c)
Datum current_query(PG_FUNCTION_ARGS)
Datum pg_get_catalog_foreign_keys(PG_FUNCTION_ARGS)
static bool pg_input_is_valid_common(FunctionCallInfo fcinfo, text *txt, text *typname, ErrorSaveContext *escontext)
Datum pg_input_error_info(PG_FUNCTION_ARGS)
Datum pg_input_is_valid(PG_FUNCTION_ARGS)
Datum any_value_transfn(PG_FUNCTION_ARGS)
Datum pg_sleep(PG_FUNCTION_ARGS)
Datum pg_get_replica_identity_index(PG_FUNCTION_ARGS)
Datum pg_current_logfile(PG_FUNCTION_ARGS)
Datum pg_get_keywords(PG_FUNCTION_ARGS)
static bool is_ident_start(unsigned char c)
Datum current_database(PG_FUNCTION_ARGS)
Datum pg_column_is_updatable(PG_FUNCTION_ARGS)
Datum pg_num_nulls(PG_FUNCTION_ARGS)
Datum pg_basetype(PG_FUNCTION_ARGS)
Datum pg_current_logfile_1arg(PG_FUNCTION_ARGS)
Datum pg_tablespace_location(PG_FUNCTION_ARGS)
Datum pg_relation_is_updatable(PG_FUNCTION_ARGS)
Datum pg_collation_for(PG_FUNCTION_ARGS)
Datum pg_error_on_null(PG_FUNCTION_ARGS)
Datum pg_num_nonnulls(PG_FUNCTION_ARGS)
TimestampTz GetCurrentTimestamp(void)
Bitmapset * bms_make_singleton(int x)
static Datum values[MAXATTR]
#define CStringGetTextDatum(s)
#define unconstify(underlying_type, expr)
#define IS_HIGHBIT_SET(ch)
#define Assert(condition)
#define OidIsValid(objectId)
const uint8 ScanKeywordCategories[SCANKEYWORDS_NUM_KEYWORDS]
const bool ScanKeywordBareLabel[SCANKEYWORDS_NUM_KEYWORDS]
int errcode_for_file_access(void)
int errcode(int sqlerrcode)
char * unpack_sql_state(int sql_state)
int errhint(const char *fmt,...) pg_attribute_printf(1
int errdetail(const char *fmt,...) pg_attribute_printf(1
#define ereport(elevel,...)
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
HeapTuple BuildTupleFromCStrings(AttInMetadata *attinmeta, char **values)
AttInMetadata * TupleDescGetAttInMetadata(TupleDesc tupdesc)
DIR * AllocateDir(const char *dirname)
struct dirent * ReadDir(DIR *dir, const char *dirname)
FILE * AllocateFile(const char *name, const char *mode)
#define palloc_object(type)
bool get_fn_expr_arg_stable(FmgrInfo *flinfo, int argnum)
void fmgr_info(Oid functionId, FmgrInfo *finfo)
void fmgr_info_cxt(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt)
bool InputFunctionCallSafe(FmgrInfo *flinfo, char *str, Oid typioparam, int32 typmod, Node *escontext, Datum *result)
bool get_fn_expr_variadic(FmgrInfo *flinfo)
Oid get_fn_expr_argtype(FmgrInfo *flinfo, int argnum)
#define PG_GETARG_TEXT_PP(n)
#define PG_GETARG_FLOAT8(n)
#define PG_GETARG_DATUM(n)
#define PG_RETURN_TEXT_P(x)
#define PG_RETURN_INT32(x)
#define PG_RETURN_NAME(x)
#define PG_GETARG_BOOL(n)
#define PG_RETURN_DATUM(x)
#define PG_GET_COLLATION()
#define FunctionCall3(flinfo, arg1, arg2, arg3)
#define PG_RETURN_BOOL(x)
#define PG_GETARG_INT16(n)
char * format_type_be(Oid type_oid)
void InitMaterializedSRF(FunctionCallInfo fcinfo, bits32 flags)
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
#define SRF_IS_FIRSTCALL()
#define SRF_PERCALL_SETUP()
#define SRF_RETURN_NEXT(_funcctx, _result)
#define SRF_FIRSTCALL_INIT()
static Datum HeapTupleGetDatum(const HeapTupleData *tuple)
#define SRF_RETURN_DONE(_funcctx)
#define MAT_SRF_USE_EXPECTED_DESC
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
#define HeapTupleIsValid(tuple)
static void * GETSTRUCT(const HeapTupleData *tuple)
PGDLLIMPORT const ScanKeywordList ScanKeywords
#define UNRESERVED_KEYWORD
#define TYPE_FUNC_NAME_KEYWORD
static const char * GetScanKeyword(int n, const ScanKeywordList *keywords)
void ResetLatch(Latch *latch)
int WaitLatch(Latch *latch, int wakeEvents, long timeout, uint32 wait_event_info)
char * get_database_name(Oid dbid)
void getTypeInputInfo(Oid type, Oid *typInput, Oid *typIOParam)
bool type_is_collatable(Oid typid)
Oid get_base_element_type(Oid typid)
void * MemoryContextAlloc(MemoryContext context, Size size)
void pfree(void *pointer)
MemoryContext CurrentMemoryContext
#define CHECK_FOR_INTERRUPTS()
void namestrcpy(Name name, const char *str)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
bool parseTypeString(const char *str, Oid *typeid_p, int32 *typmod_p, Node *escontext)
char * get_tablespace_location(Oid tablespaceOid)
END_CATALOG_STRUCT typedef FormData_pg_type * Form_pg_type
const char * debug_query_string
static Datum PointerGetDatum(const void *X)
static Datum BoolGetDatum(bool X)
static Datum ObjectIdGetDatum(Oid X)
static Datum CStringGetDatum(const char *X)
static Datum Int32GetDatum(int32 X)
static int fd(const char *x, int i)
char * psprintf(const char *fmt,...)
Oid RelationGetReplicaIndex(Relation relation)
#define TABLESPACE_VERSION_DIRECTORY
int relation_is_updatable(Oid reloid, List *outer_reloids, bool include_triggers, Bitmapset *include_cols)
char * generate_collation_name(Oid collid)
char * downcase_identifier(const char *ident, int len, bool warn, bool truncate)
bool scanner_isspace(char ch)
#define FirstLowInvalidHeapAttributeNumber
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache1(SysCacheIdentifier cacheId, Datum key1)
#define LOG_METAINFO_DATAFILE
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, const Datum *values, const bool *isnull)
text * cstring_to_text_with_len(const char *s, int len)
text * cstring_to_text(const char *s)
char * text_to_cstring(const text *t)
#define WL_EXIT_ON_PM_DEATH