PostgreSQL Source Code  git master
parse_type.h File Reference
#include "access/htup.h"
#include "parser/parse_node.h"
Include dependency graph for parse_type.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ISCOMPLEX(typeid)   (typeOrDomainTypeRelid(typeid) != InvalidOid)
 

Typedefs

typedef HeapTuple Type
 

Functions

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)
 
char * TypeNameToString (const TypeName *typeName)
 
char * TypeNameListToString (List *typenames)
 
Oid LookupCollation (ParseState *pstate, List *collnames, int location)
 
Oid GetColumnDefCollation (ParseState *pstate, ColumnDef *coldef, Oid typeOid)
 
Type typeidType (Oid id)
 
Oid typeTypeId (Type tp)
 
int16 typeLen (Type t)
 
bool typeByVal (Type t)
 
char * typeTypeName (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)
 
TypeNametypeStringToTypeName (const char *str)
 
void parseTypeString (const char *str, Oid *typeid_p, int32 *typmod_p, bool missing_ok)
 

Macro Definition Documentation

◆ ISCOMPLEX

#define ISCOMPLEX (   typeid)    (typeOrDomainTypeRelid(typeid) != InvalidOid)

Typedef Documentation

◆ Type

typedef HeapTuple Type

Definition at line 20 of file parse_type.h.

Function Documentation

◆ GetColumnDefCollation()

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

Definition at line 538 of file parse_type.c.

References ColumnDef::collClause, CollateClause::collname, ColumnDef::collOid, ereport, errcode(), errmsg(), ERROR, format_type_be(), get_typcollation(), CollateClause::location, ColumnDef::location, LookupCollation(), OidIsValid, and parser_errposition().

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

539 {
540  Oid result;
541  Oid typcollation = get_typcollation(typeOid);
542  int location = coldef->location;
543 
544  if (coldef->collClause)
545  {
546  /* We have a raw COLLATE clause, so look up the collation */
547  location = coldef->collClause->location;
548  result = LookupCollation(pstate, coldef->collClause->collname,
549  location);
550  }
551  else if (OidIsValid(coldef->collOid))
552  {
553  /* Precooked collation spec, use that */
554  result = coldef->collOid;
555  }
556  else
557  {
558  /* Use the type's default collation if any */
559  result = typcollation;
560  }
561 
562  /* Complain if COLLATE is applied to an uncollatable type */
563  if (OidIsValid(result) && !OidIsValid(typcollation))
564  ereport(ERROR,
565  (errcode(ERRCODE_DATATYPE_MISMATCH),
566  errmsg("collations are not supported by type %s",
567  format_type_be(typeOid)),
568  parser_errposition(pstate, location)));
569 
570  return result;
571 }
int errcode(int sqlerrcode)
Definition: elog.c:608
char * format_type_be(Oid type_oid)
Definition: format_type.c:326
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:639
#define ERROR
Definition: elog.h:43
Oid collOid
Definition: parsenodes.h:660
int location
Definition: parsenodes.h:663
#define ereport(elevel, rest)
Definition: elog.h:141
Oid LookupCollation(ParseState *pstate, List *collnames, int location)
Definition: parse_type.c:513
Oid get_typcollation(Oid typid)
Definition: lsyscache.c:2823
int parser_errposition(ParseState *pstate, int location)
Definition: parse_node.c:110
CollateClause * collClause
Definition: parsenodes.h:659
List * collname
Definition: parsenodes.h:310
int errmsg(const char *fmt,...)
Definition: elog.c:822

◆ LookupCollation()

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

Definition at line 513 of file parse_type.c.

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

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

514 {
515  Oid colloid;
516  ParseCallbackState pcbstate;
517 
518  if (pstate)
519  setup_parser_errposition_callback(&pcbstate, pstate, location);
520 
521  colloid = get_collation_oid(collnames, false);
522 
523  if (pstate)
525 
526  return colloid;
527 }
unsigned int Oid
Definition: postgres_ext.h:31
void cancel_parser_errposition_callback(ParseCallbackState *pcbstate)
Definition: parse_node.c:160
void setup_parser_errposition_callback(ParseCallbackState *pcbstate, ParseState *pstate, int location)
Definition: parse_node.c:144
Oid get_collation_oid(List *name, bool missing_ok)
Definition: namespace.c:3564

◆ LookupTypeName()

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

Definition at line 38 of file parse_type.c.

References LookupTypeNameExtended().

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

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

◆ 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.

References TypeName::arrayBounds, Assert, attnum, cancel_parser_errposition_callback(), RangeVar::catalogname, DeconstructQualifiedName(), elog, ereport, errcode(), errmsg(), ERROR, 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(), TYPENAMENSP, TypeNameToString(), typenameTypeMod(), TYPEOID, TypeName::typeOid, and typname.

Referenced by FuncNameAsType(), and LookupTypeName().

76 {
77  Oid typoid;
78  HeapTuple tup;
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:
98  ereport(ERROR,
99  (errcode(ERRCODE_SYNTAX_ERROR),
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:
120  ereport(ERROR,
121  (errcode(ERRCODE_SYNTAX_ERROR),
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);
137  if (attnum == InvalidAttrNumber)
138  {
139  if (missing_ok)
140  typoid = InvalidOid;
141  else
142  ereport(ERROR,
143  (errcode(ERRCODE_UNDEFINED_COLUMN),
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) */
156  ereport(NOTICE,
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 */
174  Oid namespaceId;
175  ParseCallbackState pcbstate;
176 
177  setup_parser_errposition_callback(&pcbstate, pstate, typeName->location);
178 
179  namespaceId = LookupExplicitNamespace(schemaname, missing_ok);
180  if (OidIsValid(namespaceId))
181  typoid = GetSysCacheOid2(TYPENAMENSP, Anum_pg_type_oid,
182  PointerGetDatum(typname),
183  ObjectIdGetDatum(namespaceId));
184  else
185  typoid = InvalidOid;
186 
188  }
189  else
190  {
191  /* Unqualified type name, so search the search path */
192  typoid = TypenameGetTypidExtended(typname, temp_ok);
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 
207  tup = SearchSysCache1(TYPEOID, ObjectIdGetDatum(typoid));
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 }
#define NIL
Definition: pg_list.h:65
Oid typeOid
Definition: parsenodes.h:210
Oid LookupExplicitNamespace(const char *nspname, bool missing_ok)
Definition: namespace.c:2885
List * names
Definition: parsenodes.h:209
#define PointerGetDatum(X)
Definition: postgres.h:556
#define RangeVarGetRelid(relation, lockmode, missing_ok)
Definition: namespace.h:63
char * TypeNameToString(const TypeName *typeName)
Definition: parse_type.c:476
Oid get_array_type(Oid typid)
Definition: lsyscache.c:2554
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:608
char * format_type_be(Oid type_oid)
Definition: format_type.c:326
void DeconstructQualifiedName(List *names, char **nspname_p, char **objname_p)
Definition: namespace.c:2801
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:639
Oid TypenameGetTypidExtended(const char *typname, bool temp_ok)
Definition: namespace.c:776
#define lsecond(l)
Definition: pg_list.h:200
signed int int32
Definition: c.h:347
char * schemaname
Definition: primnodes.h:67
char * relname
Definition: primnodes.h:68
void cancel_parser_errposition_callback(ParseCallbackState *pcbstate)
Definition: parse_node.c:160
#define linitial(l)
Definition: pg_list.h:195
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
#define NoLock
Definition: lockdefs.h:34
AttrNumber get_attnum(Oid relid, const char *attname)
Definition: lsyscache.c:806
Oid get_atttype(Oid relid, AttrNumber attnum)
Definition: lsyscache.c:861
#define ereport(elevel, rest)
Definition: elog.h:141
void setup_parser_errposition_callback(ParseCallbackState *pcbstate, ParseState *pstate, int location)
Definition: parse_node.c:144
NameData typname
Definition: pg_type.h:42
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
char * NameListToString(List *names)
Definition: namespace.c:3094
#define InvalidOid
Definition: postgres_ext.h:36
int16 attnum
Definition: pg_attribute.h:79
#define NOTICE
Definition: elog.h:37
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define Assert(condition)
Definition: c.h:733
#define GetSysCacheOid2(cacheId, oidcol, key1, key2)
Definition: syscache.h:194
#define lfourth(l)
Definition: pg_list.h:210
int location
Definition: parsenodes.h:216
static int list_length(const List *l)
Definition: pg_list.h:169
int parser_errposition(ParseState *pstate, int location)
Definition: parse_node.c:110
#define InvalidAttrNumber
Definition: attnum.h:23
List * arrayBounds
Definition: parsenodes.h:215
int errmsg(const char *fmt,...)
Definition: elog.c:822
#define elog(elevel,...)
Definition: elog.h:228
#define lthird(l)
Definition: pg_list.h:205
int16 AttrNumber
Definition: attnum.h:21
RangeVar * makeRangeVar(char *schemaname, char *relname, int location)
Definition: makefuncs.c:420
char * catalogname
Definition: primnodes.h:66
static int32 typenameTypeMod(ParseState *pstate, const TypeName *typeName, Type typ)
Definition: parse_type.c:332
bool pct_type
Definition: parsenodes.h:212

◆ LookupTypeNameOid()

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

Definition at line 232 of file parse_type.c.

References ereport, errcode(), errmsg(), ERROR, 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().

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)
241  ereport(ERROR,
242  (errcode(ERRCODE_UNDEFINED_OBJECT),
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;
251  ReleaseSysCache(tup);
252 
253  return typoid;
254 }
Type LookupTypeName(ParseState *pstate, const TypeName *typeName, int32 *typmod_p, bool missing_ok)
Definition: parse_type.c:38
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
char * TypeNameToString(const TypeName *typeName)
Definition: parse_type.c:476
int errcode(int sqlerrcode)
Definition: elog.c:608
unsigned int Oid
Definition: postgres_ext.h:31
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
#define InvalidOid
Definition: postgres_ext.h:36
int location
Definition: parsenodes.h:216
FormData_pg_type * Form_pg_type
Definition: pg_type.h:251
int parser_errposition(ParseState *pstate, int location)
Definition: parse_node.c:110
int errmsg(const char *fmt,...)
Definition: elog.c:822

◆ parseTypeString()

void parseTypeString ( const char *  str,
Oid typeid_p,
int32 typmod_p,
bool  missing_ok 
)

Definition at line 832 of file parse_type.c.

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

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

833 {
834  TypeName *typeName;
835  Type tup;
836 
837  typeName = typeStringToTypeName(str);
838 
839  tup = LookupTypeName(NULL, typeName, typmod_p, missing_ok);
840  if (tup == NULL)
841  {
842  if (!missing_ok)
843  ereport(ERROR,
844  (errcode(ERRCODE_UNDEFINED_OBJECT),
845  errmsg("type \"%s\" does not exist",
846  TypeNameToString(typeName)),
847  parser_errposition(NULL, typeName->location)));
848  *typeid_p = InvalidOid;
849  }
850  else
851  {
852  Form_pg_type typ = (Form_pg_type) GETSTRUCT(tup);
853 
854  if (!typ->typisdefined)
855  ereport(ERROR,
856  (errcode(ERRCODE_UNDEFINED_OBJECT),
857  errmsg("type \"%s\" is only a shell",
858  TypeNameToString(typeName)),
859  parser_errposition(NULL, typeName->location)));
860  *typeid_p = typ->oid;
861  ReleaseSysCache(tup);
862  }
863 }
Type LookupTypeName(ParseState *pstate, const TypeName *typeName, int32 *typmod_p, bool missing_ok)
Definition: parse_type.c:38
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
char * TypeNameToString(const TypeName *typeName)
Definition: parse_type.c:476
int errcode(int sqlerrcode)
Definition: elog.c:608
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
TypeName * typeStringToTypeName(const char *str)
Definition: parse_type.c:738
#define InvalidOid
Definition: postgres_ext.h:36
int location
Definition: parsenodes.h:216
FormData_pg_type * Form_pg_type
Definition: pg_type.h:251
int parser_errposition(ParseState *pstate, int location)
Definition: parse_node.c:110
int errmsg(const char *fmt,...)
Definition: elog.c:822

◆ stringTypeDatum()

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

Definition at line 652 of file parse_type.c.

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

Referenced by coerce_type().

653 {
654  Form_pg_type typform = (Form_pg_type) GETSTRUCT(tp);
655  Oid typinput = typform->typinput;
656  Oid typioparam = getTypeIOParam(tp);
657 
658  return OidInputFunctionCall(typinput, string, typioparam, atttypmod);
659 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
unsigned int Oid
Definition: postgres_ext.h:31
FormData_pg_type * Form_pg_type
Definition: pg_type.h:251
Oid getTypeIOParam(HeapTuple typeTuple)
Definition: lsyscache.c:2081
Datum OidInputFunctionCall(Oid functionId, char *str, Oid typioparam, int32 typmod)
Definition: fmgr.c:1646

◆ typeByVal()

bool typeByVal ( Type  t)

Definition at line 607 of file parse_type.c.

References GETSTRUCT.

Referenced by coerce_type().

608 {
609  Form_pg_type typ;
610 
611  typ = (Form_pg_type) GETSTRUCT(t);
612  return typ->typbyval;
613 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
FormData_pg_type * Form_pg_type
Definition: pg_type.h:251

◆ typeidType()

Type typeidType ( Oid  id)

Definition at line 576 of file parse_type.c.

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

Referenced by coerce_type(), and find_typmod_coercion_function().

577 {
578  HeapTuple tup;
579 
581  if (!HeapTupleIsValid(tup))
582  elog(ERROR, "cache lookup failed for type %u", id);
583  return (Type) tup;
584 }
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define elog(elevel,...)
Definition: elog.h:228

◆ typeidTypeRelid()

Oid typeidTypeRelid ( Oid  type_id)

Definition at line 666 of file parse_type.c.

References elog, ERROR, GETSTRUCT, HeapTupleIsValid, ObjectIdGetDatum, ReleaseSysCache(), SearchSysCache1(), generate_unaccent_rules::type, and TYPEOID.

Referenced by transformAssignmentIndirection(), and typeInheritsFrom().

667 {
668  HeapTuple typeTuple;
670  Oid result;
671 
672  typeTuple = SearchSysCache1(TYPEOID, ObjectIdGetDatum(type_id));
673  if (!HeapTupleIsValid(typeTuple))
674  elog(ERROR, "cache lookup failed for type %u", type_id);
675  type = (Form_pg_type) GETSTRUCT(typeTuple);
676  result = type->typrelid;
677  ReleaseSysCache(typeTuple);
678  return result;
679 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
unsigned int Oid
Definition: postgres_ext.h:31
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
FormData_pg_type * Form_pg_type
Definition: pg_type.h:251
#define elog(elevel,...)
Definition: elog.h:228

◆ typeLen()

int16 typeLen ( Type  t)

Definition at line 597 of file parse_type.c.

References GETSTRUCT.

Referenced by coerce_type().

598 {
599  Form_pg_type typ;
600 
601  typ = (Form_pg_type) GETSTRUCT(t);
602  return typ->typlen;
603 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
FormData_pg_type * Form_pg_type
Definition: pg_type.h:251

◆ TypeNameListToString()

char* TypeNameListToString ( List typenames)

Definition at line 490 of file parse_type.c.

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

Referenced by does_not_exist_skipping().

491 {
493  ListCell *l;
494 
495  initStringInfo(&string);
496  foreach(l, typenames)
497  {
498  TypeName *typeName = lfirst_node(TypeName, l);
499 
500  if (l != list_head(typenames))
501  appendStringInfoChar(&string, ',');
502  appendTypeNameToBuffer(typeName, &string);
503  }
504  return string.data;
505 }
#define lfirst_node(type, lc)
Definition: pg_list.h:193
char string[11]
Definition: preproc-type.c:46
static ListCell * list_head(const List *l)
Definition: pg_list.h:125
static void appendTypeNameToBuffer(const TypeName *typeName, StringInfo string)
Definition: parse_type.c:437
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:188
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59

◆ TypeNameToString()

◆ typenameType()

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

Definition at line 264 of file parse_type.c.

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

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

265 {
266  Type tup;
267 
268  tup = LookupTypeName(pstate, typeName, typmod_p, false);
269  if (tup == NULL)
270  ereport(ERROR,
271  (errcode(ERRCODE_UNDEFINED_OBJECT),
272  errmsg("type \"%s\" does not exist",
273  TypeNameToString(typeName)),
274  parser_errposition(pstate, typeName->location)));
275  if (!((Form_pg_type) GETSTRUCT(tup))->typisdefined)
276  ereport(ERROR,
277  (errcode(ERRCODE_UNDEFINED_OBJECT),
278  errmsg("type \"%s\" is only a shell",
279  TypeNameToString(typeName)),
280  parser_errposition(pstate, typeName->location)));
281  return tup;
282 }
Type LookupTypeName(ParseState *pstate, const TypeName *typeName, int32 *typmod_p, bool missing_ok)
Definition: parse_type.c:38
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
char * TypeNameToString(const TypeName *typeName)
Definition: parse_type.c:476
int errcode(int sqlerrcode)
Definition: elog.c:608
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
int location
Definition: parsenodes.h:216
FormData_pg_type * Form_pg_type
Definition: pg_type.h:251
int parser_errposition(ParseState *pstate, int location)
Definition: parse_node.c:110
int errmsg(const char *fmt,...)
Definition: elog.c:822

◆ typenameTypeId()

Oid typenameTypeId ( ParseState pstate,
const TypeName typeName 
)

Definition at line 291 of file parse_type.c.

References GETSTRUCT, ReleaseSysCache(), and typenameType().

Referenced by AlterDomainAddConstraint(), AlterDomainDefault(), AlterDomainDropConstraint(), AlterDomainNotNull(), AlterDomainValidateConstraint(), AlterEnum(), AlterTypeNamespace(), check_object_ownership(), CreateCast(), CreateFunction(), CreateTransform(), DefineAggregate(), DefineOpClass(), DefineOperator(), DefineRange(), DefineRelation(), DefineType(), init_params(), objectNamesToOids(), PrepareQuery(), processTypesSpec(), RenameConstraint(), RenameType(), transformAExprOf(), and transformAlterTableStmt().

292 {
293  Oid typoid;
294  Type tup;
295 
296  tup = typenameType(pstate, typeName, NULL);
297  typoid = ((Form_pg_type) GETSTRUCT(tup))->oid;
298  ReleaseSysCache(tup);
299 
300  return typoid;
301 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
Type typenameType(ParseState *pstate, const TypeName *typeName, int32 *typmod_p)
Definition: parse_type.c:264
unsigned int Oid
Definition: postgres_ext.h:31
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
FormData_pg_type * Form_pg_type
Definition: pg_type.h:251

◆ typenameTypeIdAndMod()

void typenameTypeIdAndMod ( ParseState pstate,
const TypeName typeName,
Oid typeid_p,
int32 typmod_p 
)

Definition at line 310 of file parse_type.c.

References GETSTRUCT, ReleaseSysCache(), and typenameType().

Referenced by addRangeTableEntryForFunction(), ATExecAddColumn(), ATPrepAlterColumnType(), BuildDescForRelation(), flatten_set_variable_args(), MergeAttributes(), revalidate_rectypeid(), transformRangeTableFunc(), transformTypeCast(), and transformXmlSerialize().

312 {
313  Type tup;
314 
315  tup = typenameType(pstate, typeName, typmod_p);
316  *typeid_p = ((Form_pg_type) GETSTRUCT(tup))->oid;
317  ReleaseSysCache(tup);
318 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
Type typenameType(ParseState *pstate, const TypeName *typeName, int32 *typmod_p)
Definition: parse_type.c:264
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
FormData_pg_type * Form_pg_type
Definition: pg_type.h:251

◆ typeOrDomainTypeRelid()

Oid typeOrDomainTypeRelid ( Oid  type_id)

Definition at line 687 of file parse_type.c.

References elog, ERROR, GETSTRUCT, HeapTupleIsValid, ObjectIdGetDatum, ReleaseSysCache(), SearchSysCache1(), generate_unaccent_rules::type, and TYPEOID.

Referenced by typeInheritsFrom(), and typeIsOfTypedTable().

688 {
689  HeapTuple typeTuple;
691  Oid result;
692 
693  for (;;)
694  {
695  typeTuple = SearchSysCache1(TYPEOID, ObjectIdGetDatum(type_id));
696  if (!HeapTupleIsValid(typeTuple))
697  elog(ERROR, "cache lookup failed for type %u", type_id);
698  type = (Form_pg_type) GETSTRUCT(typeTuple);
699  if (type->typtype != TYPTYPE_DOMAIN)
700  {
701  /* Not a domain, so done looking through domains */
702  break;
703  }
704  /* It is a domain, so examine the base type instead */
705  type_id = type->typbasetype;
706  ReleaseSysCache(typeTuple);
707  }
708  result = type->typrelid;
709  ReleaseSysCache(typeTuple);
710  return result;
711 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
unsigned int Oid
Definition: postgres_ext.h:31
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
FormData_pg_type * Form_pg_type
Definition: pg_type.h:251
#define elog(elevel,...)
Definition: elog.h:228

◆ typeStringToTypeName()

TypeName* typeStringToTypeName ( const char *  str)

Definition at line 738 of file parse_type.c.

References appendStringInfo(), ErrorContextCallback::arg, TypeCast::arg, buf, ErrorContextCallback::callback, StringInfoData::data, SelectStmt::distinctClause, ereport, errcode(), errmsg(), ERROR, error_context_stack, SelectStmt::fromClause, SelectStmt::groupClause, SelectStmt::havingClause, ResTarget::indirection, initStringInfo(), SelectStmt::intoClause, IsA, SelectStmt::limitCount, SelectStmt::limitOffset, linitial, linitial_node, list_length(), SelectStmt::lockingClause, ResTarget::name, NIL, SelectStmt::op, pfree(), ErrorContextCallback::previous, pts_error_callback(), raw_parser(), TypeName::setof, SETOP_NONE, SelectStmt::sortClause, SelectStmt::targetList, TypeCast::typeName, unconstify, ResTarget::val, SelectStmt::valuesLists, SelectStmt::whereClause, SelectStmt::windowClause, and SelectStmt::withClause.

Referenced by parseTypeString(), and pg_get_object_address().

739 {
741  List *raw_parsetree_list;
742  SelectStmt *stmt;
743  ResTarget *restarget;
744  TypeCast *typecast;
745  TypeName *typeName;
746  ErrorContextCallback ptserrcontext;
747 
748  /* make sure we give useful error for empty input */
749  if (strspn(str, " \t\n\r\f") == strlen(str))
750  goto fail;
751 
752  initStringInfo(&buf);
753  appendStringInfo(&buf, "SELECT NULL::%s", str);
754 
755  /*
756  * Setup error traceback support in case of ereport() during parse
757  */
758  ptserrcontext.callback = pts_error_callback;
759  ptserrcontext.arg = unconstify(char *, str);
760  ptserrcontext.previous = error_context_stack;
761  error_context_stack = &ptserrcontext;
762 
763  raw_parsetree_list = raw_parser(buf.data);
764 
765  error_context_stack = ptserrcontext.previous;
766 
767  /*
768  * Make sure we got back exactly what we expected and no more; paranoia is
769  * justified since the string might contain anything.
770  */
771  if (list_length(raw_parsetree_list) != 1)
772  goto fail;
773  stmt = (SelectStmt *) linitial_node(RawStmt, raw_parsetree_list)->stmt;
774  if (stmt == NULL ||
775  !IsA(stmt, SelectStmt) ||
776  stmt->distinctClause != NIL ||
777  stmt->intoClause != NULL ||
778  stmt->fromClause != NIL ||
779  stmt->whereClause != NULL ||
780  stmt->groupClause != NIL ||
781  stmt->havingClause != NULL ||
782  stmt->windowClause != NIL ||
783  stmt->valuesLists != NIL ||
784  stmt->sortClause != NIL ||
785  stmt->limitOffset != NULL ||
786  stmt->limitCount != NULL ||
787  stmt->lockingClause != NIL ||
788  stmt->withClause != NULL ||
789  stmt->op != SETOP_NONE)
790  goto fail;
791  if (list_length(stmt->targetList) != 1)
792  goto fail;
793  restarget = (ResTarget *) linitial(stmt->targetList);
794  if (restarget == NULL ||
795  !IsA(restarget, ResTarget) ||
796  restarget->name != NULL ||
797  restarget->indirection != NIL)
798  goto fail;
799  typecast = (TypeCast *) restarget->val;
800  if (typecast == NULL ||
801  !IsA(typecast, TypeCast) ||
802  typecast->arg == NULL ||
803  !IsA(typecast->arg, A_Const))
804  goto fail;
805 
806  typeName = typecast->typeName;
807  if (typeName == NULL ||
808  !IsA(typeName, TypeName))
809  goto fail;
810  if (typeName->setof)
811  goto fail;
812 
813  pfree(buf.data);
814 
815  return typeName;
816 
817 fail:
818  ereport(ERROR,
819  (errcode(ERRCODE_SYNTAX_ERROR),
820  errmsg("invalid type name \"%s\"", str)));
821  return NULL; /* keep compiler quiet */
822 }
List * indirection
Definition: parsenodes.h:441
#define NIL
Definition: pg_list.h:65
#define IsA(nodeptr, _type_)
Definition: nodes.h:576
Node * val
Definition: parsenodes.h:442
List * raw_parser(const char *str)
Definition: parser.c:36
IntoClause * intoClause
Definition: parsenodes.h:1573
List * fromClause
Definition: parsenodes.h:1575
char * name
Definition: parsenodes.h:440
Node * limitOffset
Definition: parsenodes.h:1596
int errcode(int sqlerrcode)
Definition: elog.c:608
#define linitial_node(type, l)
Definition: pg_list.h:198
void(* callback)(void *arg)
Definition: elog.h:256
struct ErrorContextCallback * previous
Definition: elog.h:255
ErrorContextCallback * error_context_stack
Definition: elog.c:91
List * distinctClause
Definition: parsenodes.h:1571
void pfree(void *pointer)
Definition: mcxt.c:1056
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91
#define linitial(l)
Definition: pg_list.h:195
#define ERROR
Definition: elog.h:43
bool setof
Definition: parsenodes.h:211
static char * buf
Definition: pg_test_fsync.c:67
List * sortClause
Definition: parsenodes.h:1595
static void pts_error_callback(void *arg)
Definition: parse_type.c:717
List * targetList
Definition: parsenodes.h:1574
List * valuesLists
Definition: parsenodes.h:1589
#define ereport(elevel, rest)
Definition: elog.h:141
List * lockingClause
Definition: parsenodes.h:1598
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
#define unconstify(underlying_type, expr)
Definition: c.h:1188
TypeName * typeName
Definition: parsenodes.h:299
List * windowClause
Definition: parsenodes.h:1579
SetOperation op
Definition: parsenodes.h:1604
static int list_length(const List *l)
Definition: pg_list.h:169
List * groupClause
Definition: parsenodes.h:1577
int errmsg(const char *fmt,...)
Definition: elog.c:822
Node * havingClause
Definition: parsenodes.h:1578
WithClause * withClause
Definition: parsenodes.h:1599
Definition: pg_list.h:50
Node * limitCount
Definition: parsenodes.h:1597
Node * whereClause
Definition: parsenodes.h:1576
Node * arg
Definition: parsenodes.h:298

◆ typeTypeCollation()

Oid typeTypeCollation ( Type  typ)

Definition at line 638 of file parse_type.c.

References GETSTRUCT.

Referenced by coerce_type().

639 {
640  Form_pg_type typtup;
641 
642  typtup = (Form_pg_type) GETSTRUCT(typ);
643  return typtup->typcollation;
644 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
FormData_pg_type * Form_pg_type
Definition: pg_type.h:251

◆ typeTypeId()

Oid typeTypeId ( Type  tp)

Definition at line 588 of file parse_type.c.

References elog, ERROR, and GETSTRUCT.

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

589 {
590  if (tp == NULL) /* probably useless */
591  elog(ERROR, "typeTypeId() called with NULL type struct");
592  return ((Form_pg_type) GETSTRUCT(tp))->oid;
593 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
#define ERROR
Definition: elog.h:43
FormData_pg_type * Form_pg_type
Definition: pg_type.h:251
#define elog(elevel,...)
Definition: elog.h:228

◆ typeTypeName()

char* typeTypeName ( Type  t)

Definition at line 617 of file parse_type.c.

References GETSTRUCT, NameStr, and pstrdup().

Referenced by coerce_type().

618 {
619  Form_pg_type typ;
620 
621  typ = (Form_pg_type) GETSTRUCT(t);
622  /* pstrdup here because result may need to outlive the syscache entry */
623  return pstrdup(NameStr(typ->typname));
624 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
char * pstrdup(const char *in)
Definition: mcxt.c:1186
FormData_pg_type * Form_pg_type
Definition: pg_type.h:251
#define NameStr(name)
Definition: c.h:610

◆ typeTypeRelid()

Oid typeTypeRelid ( Type  typ)

Definition at line 628 of file parse_type.c.

References GETSTRUCT.

Referenced by FuncNameAsType().

629 {
630  Form_pg_type typtup;
631 
632  typtup = (Form_pg_type) GETSTRUCT(typ);
633  return typtup->typrelid;
634 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
FormData_pg_type * Form_pg_type
Definition: pg_type.h:251