PostgreSQL Source Code git master
Loading...
Searching...
No Matches
parse_type.c File Reference
#include "postgres.h"
#include "access/htup_details.h"
#include "catalog/namespace.h"
#include "catalog/pg_type.h"
#include "lib/stringinfo.h"
#include "nodes/makefuncs.h"
#include "parser/parse_type.h"
#include "parser/parser.h"
#include "utils/array.h"
#include "utils/builtins.h"
#include "utils/lsyscache.h"
#include "utils/syscache.h"
Include dependency graph for parse_type.c:

Go to the source code of this file.

Functions

static int32 typenameTypeMod (ParseState *pstate, const TypeName *typeName, Type typ)
 
Type LookupTypeName (ParseState *pstate, const TypeName *typeName, int32 *typmod_p, bool missing_ok)
 
Type LookupTypeNameExtended (ParseState *pstate, const TypeName *typeName, int32 *typmod_p, bool temp_ok, bool missing_ok)
 
Oid LookupTypeNameOid (ParseState *pstate, const TypeName *typeName, bool missing_ok)
 
Type typenameType (ParseState *pstate, const TypeName *typeName, int32 *typmod_p)
 
Oid typenameTypeId (ParseState *pstate, const TypeName *typeName)
 
void typenameTypeIdAndMod (ParseState *pstate, const TypeName *typeName, Oid *typeid_p, int32 *typmod_p)
 
static void appendTypeNameToBuffer (const TypeName *typeName, StringInfo string)
 
charTypeNameToString (const TypeName *typeName)
 
charTypeNameListToString (List *typenames)
 
Oid LookupCollation (ParseState *pstate, List *collnames, int location)
 
Oid GetColumnDefCollation (ParseState *pstate, const ColumnDef *coldef, Oid typeOid)
 
Type typeidType (Oid id)
 
Oid typeTypeId (Type tp)
 
int16 typeLen (Type t)
 
bool typeByVal (Type t)
 
chartypeTypeName (Type t)
 
Oid typeTypeRelid (Type typ)
 
Oid typeTypeCollation (Type typ)
 
Datum stringTypeDatum (Type tp, char *string, int32 atttypmod)
 
Oid typeidTypeRelid (Oid type_id)
 
Oid typeOrDomainTypeRelid (Oid type_id)
 
static void pts_error_callback (void *arg)
 
TypeNametypeStringToTypeName (const char *str, Node *escontext)
 
bool parseTypeString (const char *str, Oid *typeid_p, int32 *typmod_p, Node *escontext)
 

Function Documentation

◆ appendTypeNameToBuffer()

static void appendTypeNameToBuffer ( const TypeName typeName,
StringInfo  string 
)
static

Definition at line 439 of file parse_type.c.

440{
441 if (typeName->names != NIL)
442 {
443 /* Emit possibly-qualified name as-is */
444 ListCell *l;
445
446 foreach(l, typeName->names)
447 {
448 if (l != list_head(typeName->names))
449 appendStringInfoChar(string, '.');
451 }
452 }
453 else
454 {
455 /* Look up internally-specified type */
457 }
458
459 /*
460 * Add decoration as needed, but only for fields considered by
461 * LookupTypeName
462 */
463 if (typeName->pct_type)
464 appendStringInfoString(string, "%TYPE");
465
466 if (typeName->arrayBounds != NIL)
467 appendStringInfoString(string, "[]");
468}
char * format_type_be(Oid type_oid)
#define lfirst(lc)
Definition pg_list.h:172
#define NIL
Definition pg_list.h:68
static ListCell * list_head(const List *l)
Definition pg_list.h:128
void appendStringInfoString(StringInfo str, const char *s)
Definition stringinfo.c:230
void appendStringInfoChar(StringInfo str, char ch)
Definition stringinfo.c:242
Oid typeOid
Definition parsenodes.h:286
bool pct_type
Definition parsenodes.h:288
List * names
Definition parsenodes.h:285
List * arrayBounds
Definition parsenodes.h:291
#define strVal(v)
Definition value.h:82

References appendStringInfoChar(), appendStringInfoString(), TypeName::arrayBounds, format_type_be(), lfirst, list_head(), TypeName::names, NIL, TypeName::pct_type, strVal, and TypeName::typeOid.

Referenced by TypeNameListToString(), and TypeNameToString().

◆ GetColumnDefCollation()

Oid GetColumnDefCollation ( ParseState pstate,
const ColumnDef coldef,
Oid  typeOid 
)

Definition at line 540 of file parse_type.c.

541{
542 Oid result;
543 Oid typcollation = get_typcollation(typeOid);
544 int location = coldef->location;
545
546 if (coldef->collClause)
547 {
548 /* We have a raw COLLATE clause, so look up the collation */
549 location = coldef->collClause->location;
550 result = LookupCollation(pstate, coldef->collClause->collname,
551 location);
552 }
553 else if (OidIsValid(coldef->collOid))
554 {
555 /* Precooked collation spec, use that */
556 result = coldef->collOid;
557 }
558 else
559 {
560 /* Use the type's default collation if any */
561 result = typcollation;
562 }
563
564 /* Complain if COLLATE is applied to an uncollatable type */
565 if (OidIsValid(result) && !OidIsValid(typcollation))
568 errmsg("collations are not supported by type %s",
569 format_type_be(typeOid)),
570 parser_errposition(pstate, location)));
571
572 return result;
573}
#define OidIsValid(objectId)
Definition c.h:788
int errcode(int sqlerrcode)
Definition elog.c:863
int errmsg(const char *fmt,...)
Definition elog.c:1080
#define ERROR
Definition elog.h:39
#define ereport(elevel,...)
Definition elog.h:150
Oid get_typcollation(Oid typid)
Definition lsyscache.c:3206
int parser_errposition(ParseState *pstate, int location)
Definition parse_node.c:106
Oid LookupCollation(ParseState *pstate, List *collnames, int location)
Definition parse_type.c:515
unsigned int Oid
static int fb(int x)

References ereport, errcode(), errmsg(), ERROR, fb(), format_type_be(), get_typcollation(), LookupCollation(), OidIsValid, and parser_errposition().

Referenced by addRangeTableEntryForFunction(), ATExecAddColumn(), ATExecAlterColumnType(), ATPrepAlterColumnType(), BuildDescForRelation(), MergeChildAttribute(), and MergeInheritedAttribute().

◆ LookupCollation()

Oid LookupCollation ( ParseState pstate,
List collnames,
int  location 
)

Definition at line 515 of file parse_type.c.

516{
517 Oid colloid;
519
520 if (pstate)
522
523 colloid = get_collation_oid(collnames, false);
524
525 if (pstate)
527
528 return colloid;
529}
Oid get_collation_oid(List *collname, bool missing_ok)
Definition namespace.c:4041
void cancel_parser_errposition_callback(ParseCallbackState *pcbstate)
Definition parse_node.c:156
void setup_parser_errposition_callback(ParseCallbackState *pcbstate, ParseState *pstate, int location)
Definition parse_node.c:140

References cancel_parser_errposition_callback(), fb(), get_collation_oid(), and setup_parser_errposition_callback().

Referenced by GetColumnDefCollation(), resolve_unique_index_expr(), transformCollateClause(), and transformColumnType().

◆ LookupTypeName()

Type LookupTypeName ( ParseState pstate,
const TypeName typeName,
int32 typmod_p,
bool  missing_ok 
)

Definition at line 38 of file parse_type.c.

40{
41 return LookupTypeNameExtended(pstate,
42 typeName, typmod_p, true, missing_ok);
43}
Type LookupTypeNameExtended(ParseState *pstate, const TypeName *typeName, int32 *typmod_p, bool temp_ok, bool missing_ok)
Definition parse_type.c:73

References fb(), and LookupTypeNameExtended().

Referenced by AlterTypeOwner(), compute_return_type(), get_object_address_type(), interpret_function_parameter_list(), LookupTypeNameOid(), parseTypeString(), and typenameType().

◆ LookupTypeNameExtended()

Type LookupTypeNameExtended ( ParseState pstate,
const TypeName typeName,
int32 typmod_p,
bool  temp_ok,
bool  missing_ok 
)

Definition at line 73 of file parse_type.c.

76{
77 Oid typoid;
79 int32 typmod;
80
81 if (typeName->names == NIL)
82 {
83 /* We have the OID already if it's an internally generated TypeName */
84 typoid = typeName->typeOid;
85 }
86 else if (typeName->pct_type)
87 {
88 /* Handle %TYPE reference to type of an existing field */
89 RangeVar *rel = makeRangeVar(NULL, NULL, typeName->location);
90 char *field = NULL;
91 Oid relid;
93
94 /* deconstruct the name list */
95 switch (list_length(typeName->names))
96 {
97 case 1:
100 errmsg("improper %%TYPE reference (too few dotted names): %s",
101 NameListToString(typeName->names)),
102 parser_errposition(pstate, typeName->location)));
103 break;
104 case 2:
105 rel->relname = strVal(linitial(typeName->names));
106 field = strVal(lsecond(typeName->names));
107 break;
108 case 3:
109 rel->schemaname = strVal(linitial(typeName->names));
110 rel->relname = strVal(lsecond(typeName->names));
111 field = strVal(lthird(typeName->names));
112 break;
113 case 4:
114 rel->catalogname = strVal(linitial(typeName->names));
115 rel->schemaname = strVal(lsecond(typeName->names));
116 rel->relname = strVal(lthird(typeName->names));
117 field = strVal(lfourth(typeName->names));
118 break;
119 default:
122 errmsg("improper %%TYPE reference (too many dotted names): %s",
123 NameListToString(typeName->names)),
124 parser_errposition(pstate, typeName->location)));
125 break;
126 }
127
128 /*
129 * Look up the field.
130 *
131 * XXX: As no lock is taken here, this might fail in the presence of
132 * concurrent DDL. But taking a lock would carry a performance
133 * penalty and would also require a permissions check.
134 */
135 relid = RangeVarGetRelid(rel, NoLock, missing_ok);
136 attnum = get_attnum(relid, field);
138 {
139 if (missing_ok)
140 typoid = InvalidOid;
141 else
144 errmsg("column \"%s\" of relation \"%s\" does not exist",
145 field, rel->relname),
146 parser_errposition(pstate, typeName->location)));
147 }
148 else
149 {
150 typoid = get_atttype(relid, attnum);
151
152 /* this construct should never have an array indicator */
153 Assert(typeName->arrayBounds == NIL);
154
155 /* emit nuisance notice (intentionally not errposition'd) */
157 (errmsg("type reference %s converted to %s",
158 TypeNameToString(typeName),
159 format_type_be(typoid))));
160 }
161 }
162 else
163 {
164 /* Normal reference to a type name */
165 char *schemaname;
166 char *typname;
167
168 /* deconstruct the name list */
169 DeconstructQualifiedName(typeName->names, &schemaname, &typname);
170
171 if (schemaname)
172 {
173 /* Look in specific schema only */
176
178
179 namespaceId = LookupExplicitNamespace(schemaname, missing_ok);
184 else
185 typoid = InvalidOid;
186
188 }
189 else
190 {
191 /* Unqualified type name, so search the search path */
193 }
194
195 /* If an array reference, return the array type instead */
196 if (typeName->arrayBounds != NIL)
197 typoid = get_array_type(typoid);
198 }
199
200 if (!OidIsValid(typoid))
201 {
202 if (typmod_p)
203 *typmod_p = -1;
204 return NULL;
205 }
206
208 if (!HeapTupleIsValid(tup)) /* should not happen */
209 elog(ERROR, "cache lookup failed for type %u", typoid);
210
211 typmod = typenameTypeMod(pstate, typeName, (Type) tup);
212
213 if (typmod_p)
214 *typmod_p = typmod;
215
216 return (Type) tup;
217}
int16 AttrNumber
Definition attnum.h:21
#define InvalidAttrNumber
Definition attnum.h:23
#define Assert(condition)
Definition c.h:873
int32_t int32
Definition c.h:542
#define elog(elevel,...)
Definition elog.h:226
#define NOTICE
Definition elog.h:35
#define HeapTupleIsValid(tuple)
Definition htup.h:78
#define NoLock
Definition lockdefs.h:34
AttrNumber get_attnum(Oid relid, const char *attname)
Definition lsyscache.c:934
Oid get_array_type(Oid typid)
Definition lsyscache.c:2937
Oid get_atttype(Oid relid, AttrNumber attnum)
Definition lsyscache.c:989
RangeVar * makeRangeVar(char *schemaname, char *relname, int location)
Definition makefuncs.c:473
char * NameListToString(const List *names)
Definition namespace.c:3664
Oid LookupExplicitNamespace(const char *nspname, bool missing_ok)
Definition namespace.c:3455
void DeconstructQualifiedName(const List *names, char **nspname_p, char **objname_p)
Definition namespace.c:3371
Oid TypenameGetTypidExtended(const char *typname, bool temp_ok)
Definition namespace.c:1007
#define RangeVarGetRelid(relation, lockmode, missing_ok)
Definition namespace.h:98
char * TypeNameToString(const TypeName *typeName)
Definition parse_type.c:478
static int32 typenameTypeMod(ParseState *pstate, const TypeName *typeName, Type typ)
Definition parse_type.c:332
int16 attnum
static int list_length(const List *l)
Definition pg_list.h:152
#define lthird(l)
Definition pg_list.h:188
#define linitial(l)
Definition pg_list.h:178
#define lsecond(l)
Definition pg_list.h:183
#define lfourth(l)
Definition pg_list.h:193
NameData typname
Definition pg_type.h:41
static Datum PointerGetDatum(const void *X)
Definition postgres.h:352
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:262
#define InvalidOid
char * relname
Definition primnodes.h:83
char * catalogname
Definition primnodes.h:77
char * schemaname
Definition primnodes.h:80
ParseLoc location
Definition parsenodes.h:292
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition syscache.c:220
#define GetSysCacheOid2(cacheId, oidcol, key1, key2)
Definition syscache.h:111

References TypeName::arrayBounds, Assert, attnum, cancel_parser_errposition_callback(), RangeVar::catalogname, DeconstructQualifiedName(), elog, ereport, errcode(), errmsg(), ERROR, fb(), format_type_be(), get_array_type(), get_attnum(), get_atttype(), GetSysCacheOid2, HeapTupleIsValid, InvalidAttrNumber, InvalidOid, lfourth, linitial, list_length(), TypeName::location, LookupExplicitNamespace(), lsecond, lthird, makeRangeVar(), NameListToString(), TypeName::names, NIL, NoLock, NOTICE, ObjectIdGetDatum(), OidIsValid, parser_errposition(), TypeName::pct_type, PointerGetDatum(), RangeVarGetRelid, RangeVar::relname, RangeVar::schemaname, SearchSysCache1(), setup_parser_errposition_callback(), strVal, TypenameGetTypidExtended(), TypeNameToString(), typenameTypeMod(), TypeName::typeOid, and typname.

Referenced by FuncNameAsType(), and LookupTypeName().

◆ LookupTypeNameOid()

Oid LookupTypeNameOid ( ParseState pstate,
const TypeName typeName,
bool  missing_ok 
)

Definition at line 232 of file parse_type.c.

233{
234 Oid typoid;
235 Type tup;
236
237 tup = LookupTypeName(pstate, typeName, NULL, missing_ok);
238 if (tup == NULL)
239 {
240 if (!missing_ok)
243 errmsg("type \"%s\" does not exist",
244 TypeNameToString(typeName)),
245 parser_errposition(pstate, typeName->location)));
246
247 return InvalidOid;
248 }
249
250 typoid = ((Form_pg_type) GETSTRUCT(tup))->oid;
252
253 return typoid;
254}
static void * GETSTRUCT(const HeapTupleData *tuple)
Type LookupTypeName(ParseState *pstate, const TypeName *typeName, int32 *typmod_p, bool missing_ok)
Definition parse_type.c:38
FormData_pg_type * Form_pg_type
Definition pg_type.h:261
void ReleaseSysCache(HeapTuple tuple)
Definition syscache.c:264

References ereport, errcode(), errmsg(), ERROR, fb(), GETSTRUCT(), InvalidOid, TypeName::location, LookupTypeName(), parser_errposition(), ReleaseSysCache(), and TypeNameToString().

Referenced by get_object_address(), LookupFuncWithArgs(), LookupOperWithArgs(), and type_in_list_does_not_exist_skipping().

◆ parseTypeString()

bool parseTypeString ( const char str,
Oid typeid_p,
int32 typmod_p,
Node escontext 
)

Definition at line 785 of file parse_type.c.

787{
788 TypeName *typeName;
789 Type tup;
790
791 typeName = typeStringToTypeName(str, escontext);
792 if (typeName == NULL)
793 return false;
794
795 tup = LookupTypeName(NULL, typeName, typmod_p,
796 (escontext && IsA(escontext, ErrorSaveContext)));
797 if (tup == NULL)
798 {
799 ereturn(escontext, false,
801 errmsg("type \"%s\" does not exist",
802 TypeNameToString(typeName))));
803 }
804 else
805 {
807
808 if (!typ->typisdefined)
809 {
811 ereturn(escontext, false,
813 errmsg("type \"%s\" is only a shell",
814 TypeNameToString(typeName))));
815 }
816 *typeid_p = typ->oid;
818 }
819
820 return true;
821}
#define ereturn(context, dummy_value,...)
Definition elog.h:278
const char * str
#define IsA(nodeptr, _type_)
Definition nodes.h:164
TypeName * typeStringToTypeName(const char *str, Node *escontext)
Definition parse_type.c:738

References ereturn, errcode(), errmsg(), fb(), GETSTRUCT(), IsA, LookupTypeName(), ReleaseSysCache(), str, TypeNameToString(), and typeStringToTypeName().

Referenced by parseNameAndArgTypes(), pg_input_is_valid_common(), plperl_spi_prepare(), pltcl_SPI_prepare(), PLy_spi_prepare(), regtypein(), and to_regtypemod().

◆ pts_error_callback()

static void pts_error_callback ( void arg)
static

Definition at line 719 of file parse_type.c.

720{
721 const char *str = (const char *) arg;
722
723 errcontext("invalid type name \"%s\"", str);
724}
#define errcontext
Definition elog.h:198
void * arg

References arg, errcontext, and str.

Referenced by typeStringToTypeName().

◆ stringTypeDatum()

Datum stringTypeDatum ( Type  tp,
char string,
int32  atttypmod 
)

Definition at line 654 of file parse_type.c.

655{
657 Oid typinput = typform->typinput;
658 Oid typioparam = getTypeIOParam(tp);
659
660 return OidInputFunctionCall(typinput, string, typioparam, atttypmod);
661}
Datum OidInputFunctionCall(Oid functionId, char *str, Oid typioparam, int32 typmod)
Definition fmgr.c:1754
Oid getTypeIOParam(HeapTuple typeTuple)
Definition lsyscache.c:2453

References fb(), GETSTRUCT(), getTypeIOParam(), and OidInputFunctionCall().

Referenced by coerce_type().

◆ typeByVal()

bool typeByVal ( Type  t)

Definition at line 609 of file parse_type.c.

610{
612
614 return typ->typbyval;
615}

References fb(), and GETSTRUCT().

Referenced by coerce_type().

◆ typeidType()

Type typeidType ( Oid  id)

Definition at line 578 of file parse_type.c.

579{
581
583 if (!HeapTupleIsValid(tup))
584 elog(ERROR, "cache lookup failed for type %u", id);
585 return (Type) tup;
586}

References elog, ERROR, fb(), HeapTupleIsValid, ObjectIdGetDatum(), and SearchSysCache1().

Referenced by coerce_type(), and find_typmod_coercion_function().

◆ typeidTypeRelid()

Oid typeidTypeRelid ( Oid  type_id)

Definition at line 668 of file parse_type.c.

669{
672 Oid result;
673
676 elog(ERROR, "cache lookup failed for type %u", type_id);
678 result = type->typrelid;
680 return result;
681}
const char * type

References elog, ERROR, fb(), GETSTRUCT(), HeapTupleIsValid, ObjectIdGetDatum(), ReleaseSysCache(), SearchSysCache1(), and type.

Referenced by transformAssignmentIndirection(), and typeInheritsFrom().

◆ typeLen()

int16 typeLen ( Type  t)

Definition at line 599 of file parse_type.c.

600{
602
604 return typ->typlen;
605}

References fb(), and GETSTRUCT().

Referenced by coerce_type().

◆ TypeNameListToString()

char * TypeNameListToString ( List typenames)

Definition at line 492 of file parse_type.c.

493{
495 ListCell *l;
496
497 initStringInfo(&string);
498 foreach(l, typenames)
499 {
500 TypeName *typeName = lfirst_node(TypeName, l);
501
502 if (l != list_head(typenames))
503 appendStringInfoChar(&string, ',');
504 appendTypeNameToBuffer(typeName, &string);
505 }
506 return string.data;
507}
const char ** typenames
Definition lexi.c:115
static void appendTypeNameToBuffer(const TypeName *typeName, StringInfo string)
Definition parse_type.c:439
#define lfirst_node(type, lc)
Definition pg_list.h:176
char string[11]
void initStringInfo(StringInfo str)
Definition stringinfo.c:97

References appendStringInfoChar(), appendTypeNameToBuffer(), initStringInfo(), lfirst_node, list_head(), and typenames.

Referenced by does_not_exist_skipping().

◆ TypeNameToString()

◆ typenameType()

Type typenameType ( ParseState pstate,
const TypeName typeName,
int32 typmod_p 
)

Definition at line 264 of file parse_type.c.

265{
266 Type tup;
267
268 tup = LookupTypeName(pstate, typeName, typmod_p, false);
269 if (tup == NULL)
272 errmsg("type \"%s\" does not exist",
273 TypeNameToString(typeName)),
274 parser_errposition(pstate, typeName->location)));
278 errmsg("type \"%s\" is only a shell",
279 TypeNameToString(typeName)),
280 parser_errposition(pstate, typeName->location)));
281 return tup;
282}

References ereport, errcode(), errmsg(), ERROR, fb(), GETSTRUCT(), TypeName::location, LookupTypeName(), parser_errposition(), and TypeNameToString().

Referenced by AlterType(), ATExecAddOf(), ATExecAlterColumnType(), DefineDomain(), DefineType(), transformColumnDefinition(), transformColumnType(), transformOfType(), typenameTypeId(), and typenameTypeIdAndMod().

◆ typenameTypeId()

◆ typenameTypeIdAndMod()

◆ typenameTypeMod()

static int32 typenameTypeMod ( ParseState pstate,
const TypeName typeName,
Type  typ 
)
static

Definition at line 332 of file parse_type.c.

333{
334 int32 result;
336 Datum *datums;
337 int n;
338 ListCell *l;
341
342 /* Return prespecified typmod if no typmod expressions */
343 if (typeName->typmods == NIL)
344 return typeName->typemod;
345
346 /*
347 * Else, type had better accept typmods. We give a special error message
348 * for the shell-type case, since a shell couldn't possibly have a
349 * typmodin function.
350 */
354 errmsg("type modifier cannot be specified for shell type \"%s\"",
355 TypeNameToString(typeName)),
356 parser_errposition(pstate, typeName->location)));
357
359
360 if (typmodin == InvalidOid)
363 errmsg("type modifier is not allowed for type \"%s\"",
364 TypeNameToString(typeName)),
365 parser_errposition(pstate, typeName->location)));
366
367 /*
368 * Convert the list of raw-grammar-output expressions to a cstring array.
369 * Currently, we allow simple numeric constants, string literals, and
370 * identifiers; possibly this list could be extended.
371 */
372 datums = palloc_array(Datum, list_length(typeName->typmods));
373 n = 0;
374 foreach(l, typeName->typmods)
375 {
376 Node *tm = (Node *) lfirst(l);
377 char *cstr = NULL;
378
379 if (IsA(tm, A_Const))
380 {
381 A_Const *ac = (A_Const *) tm;
382
383 if (IsA(&ac->val, Integer))
384 {
385 cstr = psprintf("%d", intVal(&ac->val));
386 }
387 else if (IsA(&ac->val, Float))
388 {
389 /* we can just use the string representation directly. */
390 cstr = ac->val.fval.fval;
391 }
392 else if (IsA(&ac->val, String))
393 {
394 /* we can just use the string representation directly. */
395 cstr = strVal(&ac->val);
396 }
397 }
398 else if (IsA(tm, ColumnRef))
399 {
400 ColumnRef *cr = (ColumnRef *) tm;
401
402 if (list_length(cr->fields) == 1 &&
403 IsA(linitial(cr->fields), String))
404 cstr = strVal(linitial(cr->fields));
405 }
406 if (!cstr)
409 errmsg("type modifiers must be simple constants or identifiers"),
410 parser_errposition(pstate, typeName->location)));
411 datums[n++] = CStringGetDatum(cstr);
412 }
413
415
416 /* arrange to report location if type's typmodin function fails */
418
421
423
424 pfree(datums);
426
427 return result;
428}
ArrayType * construct_array_builtin(Datum *elems, int nelems, Oid elmtype)
#define palloc_array(type, count)
Definition fe_memutils.h:76
#define OidFunctionCall1(functionId, arg1)
Definition fmgr.h:722
static struct pg_tm tm
Definition localtime.c:104
void pfree(void *pointer)
Definition mcxt.c:1616
uint64_t Datum
Definition postgres.h:70
static Datum CStringGetDatum(const char *X)
Definition postgres.h:380
static int32 DatumGetInt32(Datum X)
Definition postgres.h:212
char * psprintf(const char *fmt,...)
Definition psprintf.c:43
Definition value.h:48
Definition nodes.h:135
Definition value.h:64
int32 typemod
Definition parsenodes.h:290
List * typmods
Definition parsenodes.h:289
#define intVal(v)
Definition value.h:79

References cancel_parser_errposition_callback(), construct_array_builtin(), CStringGetDatum(), DatumGetInt32(), ereport, errcode(), errmsg(), ERROR, fb(), GETSTRUCT(), intVal, InvalidOid, IsA, lfirst, linitial, list_length(), TypeName::location, NIL, OidFunctionCall1, palloc_array, parser_errposition(), pfree(), PointerGetDatum(), psprintf(), setup_parser_errposition_callback(), strVal, tm, TypeName::typemod, TypeNameToString(), and TypeName::typmods.

Referenced by LookupTypeNameExtended().

◆ typeOrDomainTypeRelid()

Oid typeOrDomainTypeRelid ( Oid  type_id)

Definition at line 689 of file parse_type.c.

690{
693 Oid result;
694
695 for (;;)
696 {
699 elog(ERROR, "cache lookup failed for type %u", type_id);
701 if (type->typtype != TYPTYPE_DOMAIN)
702 {
703 /* Not a domain, so done looking through domains */
704 break;
705 }
706 /* It is a domain, so examine the base type instead */
707 type_id = type->typbasetype;
709 }
710 result = type->typrelid;
712 return result;
713}

References elog, ERROR, fb(), GETSTRUCT(), HeapTupleIsValid, ObjectIdGetDatum(), ReleaseSysCache(), SearchSysCache1(), and type.

Referenced by typeInheritsFrom(), and typeIsOfTypedTable().

◆ typeStringToTypeName()

TypeName * typeStringToTypeName ( const char str,
Node escontext 
)

Definition at line 738 of file parse_type.c.

739{
741 TypeName *typeName;
743
744 /* make sure we give useful error for empty input */
745 if (strspn(str, " \t\n\r\f\v") == strlen(str))
746 goto fail;
747
748 /*
749 * Setup error traceback support in case of ereport() during parse
750 */
752 ptserrcontext.arg = unconstify(char *, str);
755
757
759
760 /* We should get back exactly one TypeName node. */
763
764 /* The grammar allows SETOF in TypeName, but we don't want that here. */
765 if (typeName->setof)
766 goto fail;
767
768 return typeName;
769
770fail:
771 ereturn(escontext, NULL,
773 errmsg("invalid type name \"%s\"", str)));
774}
List * raw_parser(const char *str, RawParseMode mode)
Definition parser.c:42
#define unconstify(underlying_type, expr)
Definition c.h:1234
ErrorContextCallback * error_context_stack
Definition elog.c:95
static void pts_error_callback(void *arg)
Definition parse_type.c:719
@ RAW_PARSE_TYPE_NAME
Definition parser.h:40
#define linitial_node(type, l)
Definition pg_list.h:181
struct ErrorContextCallback * previous
Definition elog.h:297
void(* callback)(void *arg)
Definition elog.h:298
Definition pg_list.h:54
bool setof
Definition parsenodes.h:287

References Assert, ErrorContextCallback::callback, ereturn, errcode(), errmsg(), error_context_stack, fb(), linitial_node, list_length(), ErrorContextCallback::previous, pts_error_callback(), RAW_PARSE_TYPE_NAME, raw_parser(), TypeName::setof, str, and unconstify.

Referenced by parseTypeString(), and pg_get_object_address().

◆ typeTypeCollation()

Oid typeTypeCollation ( Type  typ)

Definition at line 640 of file parse_type.c.

641{
643
645 return typtup->typcollation;
646}

References fb(), and GETSTRUCT().

Referenced by coerce_type().

◆ typeTypeId()

Oid typeTypeId ( Type  tp)

Definition at line 590 of file parse_type.c.

591{
592 if (tp == NULL) /* probably useless */
593 elog(ERROR, "typeTypeId() called with NULL type struct");
594 return ((Form_pg_type) GETSTRUCT(tp))->oid;
595}

References elog, ERROR, fb(), and GETSTRUCT().

Referenced by AlterType(), AlterTypeOwner(), compute_return_type(), FuncNameAsType(), get_object_address_type(), and interpret_function_parameter_list().

◆ typeTypeName()

char * typeTypeName ( Type  t)

Definition at line 619 of file parse_type.c.

620{
622
624 /* pstrdup here because result may need to outlive the syscache entry */
625 return pstrdup(NameStr(typ->typname));
626}
#define NameStr(name)
Definition c.h:765
char * pstrdup(const char *in)
Definition mcxt.c:1781

References fb(), GETSTRUCT(), NameStr, and pstrdup().

Referenced by coerce_type().

◆ typeTypeRelid()

Oid typeTypeRelid ( Type  typ)

Definition at line 630 of file parse_type.c.

631{
633
635 return typtup->typrelid;
636}

References fb(), and GETSTRUCT().

Referenced by FuncNameAsType().