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

Definition at line 20 of file parse_type.h.

Function Documentation

◆ GetColumnDefCollation()

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

Definition at line 539 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().

540 {
541  Oid result;
542  Oid typcollation = get_typcollation(typeOid);
543  int location = coldef->location;
544 
545  if (coldef->collClause)
546  {
547  /* We have a raw COLLATE clause, so look up the collation */
548  location = coldef->collClause->location;
549  result = LookupCollation(pstate, coldef->collClause->collname,
550  location);
551  }
552  else if (OidIsValid(coldef->collOid))
553  {
554  /* Precooked collation spec, use that */
555  result = coldef->collOid;
556  }
557  else
558  {
559  /* Use the type's default collation if any */
560  result = typcollation;
561  }
562 
563  /* Complain if COLLATE is applied to an uncollatable type */
564  if (OidIsValid(result) && !OidIsValid(typcollation))
565  ereport(ERROR,
566  (errcode(ERRCODE_DATATYPE_MISMATCH),
567  errmsg("collations are not supported by type %s",
568  format_type_be(typeOid)),
569  parser_errposition(pstate, location)));
570 
571  return result;
572 }
int errcode(int sqlerrcode)
Definition: elog.c:570
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:638
#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:514
Oid get_typcollation(Oid typid)
Definition: lsyscache.c:2823
int parser_errposition(ParseState *pstate, int location)
Definition: parse_node.c:111
CollateClause * collClause
Definition: parsenodes.h:659
List * collname
Definition: parsenodes.h:310
int errmsg(const char *fmt,...)
Definition: elog.c:784

◆ LookupCollation()

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

Definition at line 514 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().

515 {
516  Oid colloid;
517  ParseCallbackState pcbstate;
518 
519  if (pstate)
520  setup_parser_errposition_callback(&pcbstate, pstate, location);
521 
522  colloid = get_collation_oid(collnames, false);
523 
524  if (pstate)
526 
527  return colloid;
528 }
unsigned int Oid
Definition: postgres_ext.h:31
void cancel_parser_errposition_callback(ParseCallbackState *pcbstate)
Definition: parse_node.c:161
void setup_parser_errposition_callback(ParseCallbackState *pcbstate, ParseState *pstate, int location)
Definition: parse_node.c:145
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 39 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().

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

◆ LookupTypeNameExtended()

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

Definition at line 74 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().

77 {
78  Oid typoid;
79  HeapTuple tup;
80  int32 typmod;
81 
82  if (typeName->names == NIL)
83  {
84  /* We have the OID already if it's an internally generated TypeName */
85  typoid = typeName->typeOid;
86  }
87  else if (typeName->pct_type)
88  {
89  /* Handle %TYPE reference to type of an existing field */
90  RangeVar *rel = makeRangeVar(NULL, NULL, typeName->location);
91  char *field = NULL;
92  Oid relid;
94 
95  /* deconstruct the name list */
96  switch (list_length(typeName->names))
97  {
98  case 1:
99  ereport(ERROR,
100  (errcode(ERRCODE_SYNTAX_ERROR),
101  errmsg("improper %%TYPE reference (too few dotted names): %s",
102  NameListToString(typeName->names)),
103  parser_errposition(pstate, typeName->location)));
104  break;
105  case 2:
106  rel->relname = strVal(linitial(typeName->names));
107  field = strVal(lsecond(typeName->names));
108  break;
109  case 3:
110  rel->schemaname = strVal(linitial(typeName->names));
111  rel->relname = strVal(lsecond(typeName->names));
112  field = strVal(lthird(typeName->names));
113  break;
114  case 4:
115  rel->catalogname = strVal(linitial(typeName->names));
116  rel->schemaname = strVal(lsecond(typeName->names));
117  rel->relname = strVal(lthird(typeName->names));
118  field = strVal(lfourth(typeName->names));
119  break;
120  default:
121  ereport(ERROR,
122  (errcode(ERRCODE_SYNTAX_ERROR),
123  errmsg("improper %%TYPE reference (too many dotted names): %s",
124  NameListToString(typeName->names)),
125  parser_errposition(pstate, typeName->location)));
126  break;
127  }
128 
129  /*
130  * Look up the field.
131  *
132  * XXX: As no lock is taken here, this might fail in the presence of
133  * concurrent DDL. But taking a lock would carry a performance
134  * penalty and would also require a permissions check.
135  */
136  relid = RangeVarGetRelid(rel, NoLock, missing_ok);
137  attnum = get_attnum(relid, field);
138  if (attnum == InvalidAttrNumber)
139  {
140  if (missing_ok)
141  typoid = InvalidOid;
142  else
143  ereport(ERROR,
144  (errcode(ERRCODE_UNDEFINED_COLUMN),
145  errmsg("column \"%s\" of relation \"%s\" does not exist",
146  field, rel->relname),
147  parser_errposition(pstate, typeName->location)));
148  }
149  else
150  {
151  typoid = get_atttype(relid, attnum);
152 
153  /* this construct should never have an array indicator */
154  Assert(typeName->arrayBounds == NIL);
155 
156  /* emit nuisance notice (intentionally not errposition'd) */
157  ereport(NOTICE,
158  (errmsg("type reference %s converted to %s",
159  TypeNameToString(typeName),
160  format_type_be(typoid))));
161  }
162  }
163  else
164  {
165  /* Normal reference to a type name */
166  char *schemaname;
167  char *typname;
168 
169  /* deconstruct the name list */
170  DeconstructQualifiedName(typeName->names, &schemaname, &typname);
171 
172  if (schemaname)
173  {
174  /* Look in specific schema only */
175  Oid namespaceId;
176  ParseCallbackState pcbstate;
177 
178  setup_parser_errposition_callback(&pcbstate, pstate, typeName->location);
179 
180  namespaceId = LookupExplicitNamespace(schemaname, missing_ok);
181  if (OidIsValid(namespaceId))
182  typoid = GetSysCacheOid2(TYPENAMENSP, Anum_pg_type_oid,
183  PointerGetDatum(typname),
184  ObjectIdGetDatum(namespaceId));
185  else
186  typoid = InvalidOid;
187 
189  }
190  else
191  {
192  /* Unqualified type name, so search the search path */
193  typoid = TypenameGetTypidExtended(typname, temp_ok);
194  }
195 
196  /* If an array reference, return the array type instead */
197  if (typeName->arrayBounds != NIL)
198  typoid = get_array_type(typoid);
199  }
200 
201  if (!OidIsValid(typoid))
202  {
203  if (typmod_p)
204  *typmod_p = -1;
205  return NULL;
206  }
207 
208  tup = SearchSysCache1(TYPEOID, ObjectIdGetDatum(typoid));
209  if (!HeapTupleIsValid(tup)) /* should not happen */
210  elog(ERROR, "cache lookup failed for type %u", typoid);
211 
212  typmod = typenameTypeMod(pstate, typeName, (Type) tup);
213 
214  if (typmod_p)
215  *typmod_p = typmod;
216 
217  return (Type) tup;
218 }
#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:477
Oid get_array_type(Oid typid)
Definition: lsyscache.c:2554
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:570
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:638
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:346
char * schemaname
Definition: primnodes.h:67
char * relname
Definition: primnodes.h:68
void cancel_parser_errposition_callback(ParseCallbackState *pcbstate)
Definition: parse_node.c:161
#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:145
NameData typname
Definition: pg_type.h:42
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1124
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:732
#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:111
#define InvalidAttrNumber
Definition: attnum.h:23
List * arrayBounds
Definition: parsenodes.h:215
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define elog(elevel,...)
Definition: elog.h:226
#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:333
bool pct_type
Definition: parsenodes.h:212

◆ LookupTypeNameOid()

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

Definition at line 233 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().

234 {
235  Oid typoid;
236  Type tup;
237 
238  tup = LookupTypeName(pstate, typeName, NULL, missing_ok);
239  if (tup == NULL)
240  {
241  if (!missing_ok)
242  ereport(ERROR,
243  (errcode(ERRCODE_UNDEFINED_OBJECT),
244  errmsg("type \"%s\" does not exist",
245  TypeNameToString(typeName)),
246  parser_errposition(pstate, typeName->location)));
247 
248  return InvalidOid;
249  }
250 
251  typoid = ((Form_pg_type) GETSTRUCT(tup))->oid;
252  ReleaseSysCache(tup);
253 
254  return typoid;
255 }
Type LookupTypeName(ParseState *pstate, const TypeName *typeName, int32 *typmod_p, bool missing_ok)
Definition: parse_type.c:39
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
char * TypeNameToString(const TypeName *typeName)
Definition: parse_type.c:477
int errcode(int sqlerrcode)
Definition: elog.c:570
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:1172
#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:111
int errmsg(const char *fmt,...)
Definition: elog.c:784

◆ parseTypeString()

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

Definition at line 833 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().

834 {
835  TypeName *typeName;
836  Type tup;
837 
838  typeName = typeStringToTypeName(str);
839 
840  tup = LookupTypeName(NULL, typeName, typmod_p, missing_ok);
841  if (tup == NULL)
842  {
843  if (!missing_ok)
844  ereport(ERROR,
845  (errcode(ERRCODE_UNDEFINED_OBJECT),
846  errmsg("type \"%s\" does not exist",
847  TypeNameToString(typeName)),
848  parser_errposition(NULL, typeName->location)));
849  *typeid_p = InvalidOid;
850  }
851  else
852  {
853  Form_pg_type typ = (Form_pg_type) GETSTRUCT(tup);
854 
855  if (!typ->typisdefined)
856  ereport(ERROR,
857  (errcode(ERRCODE_UNDEFINED_OBJECT),
858  errmsg("type \"%s\" is only a shell",
859  TypeNameToString(typeName)),
860  parser_errposition(NULL, typeName->location)));
861  *typeid_p = typ->oid;
862  ReleaseSysCache(tup);
863  }
864 }
Type LookupTypeName(ParseState *pstate, const TypeName *typeName, int32 *typmod_p, bool missing_ok)
Definition: parse_type.c:39
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
char * TypeNameToString(const TypeName *typeName)
Definition: parse_type.c:477
int errcode(int sqlerrcode)
Definition: elog.c:570
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1172
TypeName * typeStringToTypeName(const char *str)
Definition: parse_type.c:739
#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:111
int errmsg(const char *fmt,...)
Definition: elog.c:784

◆ stringTypeDatum()

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

Definition at line 653 of file parse_type.c.

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

Referenced by coerce_type().

654 {
655  Form_pg_type typform = (Form_pg_type) GETSTRUCT(tp);
656  Oid typinput = typform->typinput;
657  Oid typioparam = getTypeIOParam(tp);
658 
659  return OidInputFunctionCall(typinput, string, typioparam, atttypmod);
660 }
#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 608 of file parse_type.c.

References GETSTRUCT.

Referenced by coerce_type().

609 {
610  Form_pg_type typ;
611 
612  typ = (Form_pg_type) GETSTRUCT(t);
613  return typ->typbyval;
614 }
#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 577 of file parse_type.c.

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

Referenced by coerce_type(), and find_typmod_coercion_function().

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

◆ typeidTypeRelid()

Oid typeidTypeRelid ( Oid  type_id)

Definition at line 667 of file parse_type.c.

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

Referenced by transformAssignmentIndirection(), and typeInheritsFrom().

668 {
669  HeapTuple typeTuple;
671  Oid result;
672 
673  typeTuple = SearchSysCache1(TYPEOID, ObjectIdGetDatum(type_id));
674  if (!HeapTupleIsValid(typeTuple))
675  elog(ERROR, "cache lookup failed for type %u", type_id);
676  type = (Form_pg_type) GETSTRUCT(typeTuple);
677  result = type->typrelid;
678  ReleaseSysCache(typeTuple);
679  return result;
680 }
#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:1124
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1172
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
FormData_pg_type * Form_pg_type
Definition: pg_type.h:251
#define elog(elevel,...)
Definition: elog.h:226

◆ typeLen()

int16 typeLen ( Type  t)

Definition at line 598 of file parse_type.c.

References GETSTRUCT.

Referenced by coerce_type().

599 {
600  Form_pg_type typ;
601 
602  typ = (Form_pg_type) GETSTRUCT(t);
603  return typ->typlen;
604 }
#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 491 of file parse_type.c.

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

Referenced by does_not_exist_skipping().

492 {
494  ListCell *l;
495 
496  initStringInfo(&string);
497  foreach(l, typenames)
498  {
499  TypeName *typeName = lfirst_node(TypeName, l);
500 
501  if (l != list_head(typenames))
502  appendStringInfoChar(&string, ',');
503  appendTypeNameToBuffer(typeName, &string);
504  }
505  return string.data;
506 }
#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:438
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:175
void initStringInfo(StringInfo str)
Definition: stringinfo.c:46

◆ TypeNameToString()

◆ typenameType()

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

Definition at line 265 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().

266 {
267  Type tup;
268 
269  tup = LookupTypeName(pstate, typeName, typmod_p, false);
270  if (tup == NULL)
271  ereport(ERROR,
272  (errcode(ERRCODE_UNDEFINED_OBJECT),
273  errmsg("type \"%s\" does not exist",
274  TypeNameToString(typeName)),
275  parser_errposition(pstate, typeName->location)));
276  if (!((Form_pg_type) GETSTRUCT(tup))->typisdefined)
277  ereport(ERROR,
278  (errcode(ERRCODE_UNDEFINED_OBJECT),
279  errmsg("type \"%s\" is only a shell",
280  TypeNameToString(typeName)),
281  parser_errposition(pstate, typeName->location)));
282  return tup;
283 }
Type LookupTypeName(ParseState *pstate, const TypeName *typeName, int32 *typmod_p, bool missing_ok)
Definition: parse_type.c:39
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
char * TypeNameToString(const TypeName *typeName)
Definition: parse_type.c:477
int errcode(int sqlerrcode)
Definition: elog.c:570
#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:111
int errmsg(const char *fmt,...)
Definition: elog.c:784

◆ typenameTypeId()

Oid typenameTypeId ( ParseState pstate,
const TypeName typeName 
)

Definition at line 292 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().

293 {
294  Oid typoid;
295  Type tup;
296 
297  tup = typenameType(pstate, typeName, NULL);
298  typoid = ((Form_pg_type) GETSTRUCT(tup))->oid;
299  ReleaseSysCache(tup);
300 
301  return typoid;
302 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
Type typenameType(ParseState *pstate, const TypeName *typeName, int32 *typmod_p)
Definition: parse_type.c:265
unsigned int Oid
Definition: postgres_ext.h:31
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1172
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 311 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().

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

◆ typeOrDomainTypeRelid()

Oid typeOrDomainTypeRelid ( Oid  type_id)

Definition at line 688 of file parse_type.c.

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

Referenced by typeInheritsFrom(), and typeIsOfTypedTable().

689 {
690  HeapTuple typeTuple;
692  Oid result;
693 
694  for (;;)
695  {
696  typeTuple = SearchSysCache1(TYPEOID, ObjectIdGetDatum(type_id));
697  if (!HeapTupleIsValid(typeTuple))
698  elog(ERROR, "cache lookup failed for type %u", type_id);
699  type = (Form_pg_type) GETSTRUCT(typeTuple);
700  if (type->typtype != TYPTYPE_DOMAIN)
701  {
702  /* Not a domain, so done looking through domains */
703  break;
704  }
705  /* It is a domain, so examine the base type instead */
706  type_id = type->typbasetype;
707  ReleaseSysCache(typeTuple);
708  }
709  result = type->typrelid;
710  ReleaseSysCache(typeTuple);
711  return result;
712 }
#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:1124
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1172
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
FormData_pg_type * Form_pg_type
Definition: pg_type.h:251
#define elog(elevel,...)
Definition: elog.h:226

◆ typeStringToTypeName()

TypeName* typeStringToTypeName ( const char *  str)

Definition at line 739 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().

740 {
742  List *raw_parsetree_list;
743  SelectStmt *stmt;
744  ResTarget *restarget;
745  TypeCast *typecast;
746  TypeName *typeName;
747  ErrorContextCallback ptserrcontext;
748 
749  /* make sure we give useful error for empty input */
750  if (strspn(str, " \t\n\r\f") == strlen(str))
751  goto fail;
752 
753  initStringInfo(&buf);
754  appendStringInfo(&buf, "SELECT NULL::%s", str);
755 
756  /*
757  * Setup error traceback support in case of ereport() during parse
758  */
759  ptserrcontext.callback = pts_error_callback;
760  ptserrcontext.arg = unconstify(char *, str);
761  ptserrcontext.previous = error_context_stack;
762  error_context_stack = &ptserrcontext;
763 
764  raw_parsetree_list = raw_parser(buf.data);
765 
766  error_context_stack = ptserrcontext.previous;
767 
768  /*
769  * Make sure we got back exactly what we expected and no more; paranoia is
770  * justified since the string might contain anything.
771  */
772  if (list_length(raw_parsetree_list) != 1)
773  goto fail;
774  stmt = (SelectStmt *) linitial_node(RawStmt, raw_parsetree_list)->stmt;
775  if (stmt == NULL ||
776  !IsA(stmt, SelectStmt) ||
777  stmt->distinctClause != NIL ||
778  stmt->intoClause != NULL ||
779  stmt->fromClause != NIL ||
780  stmt->whereClause != NULL ||
781  stmt->groupClause != NIL ||
782  stmt->havingClause != NULL ||
783  stmt->windowClause != NIL ||
784  stmt->valuesLists != NIL ||
785  stmt->sortClause != NIL ||
786  stmt->limitOffset != NULL ||
787  stmt->limitCount != NULL ||
788  stmt->lockingClause != NIL ||
789  stmt->withClause != NULL ||
790  stmt->op != SETOP_NONE)
791  goto fail;
792  if (list_length(stmt->targetList) != 1)
793  goto fail;
794  restarget = (ResTarget *) linitial(stmt->targetList);
795  if (restarget == NULL ||
796  !IsA(restarget, ResTarget) ||
797  restarget->name != NULL ||
798  restarget->indirection != NIL)
799  goto fail;
800  typecast = (TypeCast *) restarget->val;
801  if (typecast == NULL ||
802  !IsA(typecast, TypeCast) ||
803  typecast->arg == NULL ||
804  !IsA(typecast->arg, A_Const))
805  goto fail;
806 
807  typeName = typecast->typeName;
808  if (typeName == NULL ||
809  !IsA(typeName, TypeName))
810  goto fail;
811  if (typeName->setof)
812  goto fail;
813 
814  pfree(buf.data);
815 
816  return typeName;
817 
818 fail:
819  ereport(ERROR,
820  (errcode(ERRCODE_SYNTAX_ERROR),
821  errmsg("invalid type name \"%s\"", str)));
822  return NULL; /* keep compiler quiet */
823 }
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:570
#define linitial_node(type, l)
Definition: pg_list.h:198
void(* callback)(void *arg)
Definition: elog.h:254
struct ErrorContextCallback * previous
Definition: elog.h:253
ErrorContextCallback * error_context_stack
Definition: elog.c:88
List * distinctClause
Definition: parsenodes.h:1571
void pfree(void *pointer)
Definition: mcxt.c:1031
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:78
#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:68
List * sortClause
Definition: parsenodes.h:1595
static void pts_error_callback(void *arg)
Definition: parse_type.c:718
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:46
#define unconstify(underlying_type, expr)
Definition: c.h:1163
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:784
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 639 of file parse_type.c.

References GETSTRUCT.

Referenced by coerce_type().

640 {
641  Form_pg_type typtup;
642 
643  typtup = (Form_pg_type) GETSTRUCT(typ);
644  return typtup->typcollation;
645 }
#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 589 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().

590 {
591  if (tp == NULL) /* probably useless */
592  elog(ERROR, "typeTypeId() called with NULL type struct");
593  return ((Form_pg_type) GETSTRUCT(tp))->oid;
594 }
#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:226

◆ typeTypeName()

char* typeTypeName ( Type  t)

Definition at line 618 of file parse_type.c.

References GETSTRUCT, NameStr, and pstrdup().

Referenced by coerce_type().

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

◆ typeTypeRelid()

Oid typeTypeRelid ( Type  typ)

Definition at line 629 of file parse_type.c.

References GETSTRUCT.

Referenced by FuncNameAsType().

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