@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $ PostgreSQL : pgsql / src / backend / parser / parse_type . c , v 1.103 2009 / 06 / 11 14 : 49 : 00 momjian Exp $
* $ PostgreSQL : pgsql / src / backend / parser / parse_type . c , v 1.104 2009 / 07 / 16 06 : 33 : 43 petere Exp $
*
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*/
@ -27,7 +27,7 @@
# include "utils/syscache.h"
static int32 typenameTypeMod ( ParseState * pstate , const TypeName * typen ame,
static int32 typenameTypeMod ( ParseState * pstate , const TypeName * typeN ame,
Type typ ) ;
@ -54,57 +54,57 @@ static int32 typenameTypeMod(ParseState *pstate, const TypeName *typename,
* pstate is only used for error location info , and may be NULL .
*/
Type
LookupTypeName ( ParseState * pstate , const TypeName * typen ame,
LookupTypeName ( ParseState * pstate , const TypeName * typeN ame,
int32 * typmod_p )
{
Oid typoid ;
HeapTuple tup ;
int32 typmod ;
if ( typen ame- > names = = NIL )
if ( typeN ame- > names = = NIL )
{
/* We have the OID already if it's an internally generated TypeName */
typoid = typen ame- > typeid ;
typoid = typeN ame- > typeO id ;
}
else if ( typen ame- > pct_type )
else if ( typeN ame- > pct_type )
{
/* Handle %TYPE reference to type of an existing field */
RangeVar * rel = makeRangeVar ( NULL , NULL , typen ame- > location ) ;
RangeVar * rel = makeRangeVar ( NULL , NULL , typeN ame- > location ) ;
char * field = NULL ;
Oid relid ;
AttrNumber attnum ;
/* deconstruct the name list */
switch ( list_length ( typen ame- > names ) )
switch ( list_length ( typeN ame- > names ) )
{
case 1 :
ereport ( ERROR ,
( errcode ( ERRCODE_SYNTAX_ERROR ) ,
errmsg ( " improper %%TYPE reference (too few dotted names): %s " ,
NameListToString ( typen ame- > names ) ) ,
parser_errposition ( pstate , typen ame- > location ) ) ) ;
NameListToString ( typeN ame- > names ) ) ,
parser_errposition ( pstate , typeN ame- > location ) ) ) ;
break ;
case 2 :
rel - > relname = strVal ( linitial ( typen ame- > names ) ) ;
field = strVal ( lsecond ( typen ame- > names ) ) ;
rel - > relname = strVal ( linitial ( typeN ame- > names ) ) ;
field = strVal ( lsecond ( typeN ame- > names ) ) ;
break ;
case 3 :
rel - > schemaname = strVal ( linitial ( typen ame- > names ) ) ;
rel - > relname = strVal ( lsecond ( typen ame- > names ) ) ;
field = strVal ( lthird ( typen ame- > names ) ) ;
rel - > schemaname = strVal ( linitial ( typeN ame- > names ) ) ;
rel - > relname = strVal ( lsecond ( typeN ame- > names ) ) ;
field = strVal ( lthird ( typeN ame- > names ) ) ;
break ;
case 4 :
rel - > catalogname = strVal ( linitial ( typen ame- > names ) ) ;
rel - > schemaname = strVal ( lsecond ( typen ame- > names ) ) ;
rel - > relname = strVal ( lthird ( typen ame- > names ) ) ;
field = strVal ( lfourth ( typen ame- > names ) ) ;
rel - > catalogname = strVal ( linitial ( typeN ame- > names ) ) ;
rel - > schemaname = strVal ( lsecond ( typeN ame- > names ) ) ;
rel - > relname = strVal ( lthird ( typeN ame- > names ) ) ;
field = strVal ( lfourth ( typeN ame- > names ) ) ;
break ;
default :
ereport ( ERROR ,
( errcode ( ERRCODE_SYNTAX_ERROR ) ,
errmsg ( " improper %%TYPE reference (too many dotted names): %s " ,
NameListToString ( typen ame- > names ) ) ,
parser_errposition ( pstate , typen ame- > location ) ) ) ;
NameListToString ( typeN ame- > names ) ) ,
parser_errposition ( pstate , typeN ame- > location ) ) ) ;
break ;
}
@ -116,16 +116,16 @@ LookupTypeName(ParseState *pstate, const TypeName *typename,
( errcode ( ERRCODE_UNDEFINED_COLUMN ) ,
errmsg ( " column \" %s \" of relation \" %s \" does not exist " ,
field , rel - > relname ) ,
parser_errposition ( pstate , typen ame- > location ) ) ) ;
parser_errposition ( pstate , typeN ame- > location ) ) ) ;
typoid = get_atttype ( relid , attnum ) ;
/* this construct should never have an array indicator */
Assert ( typen ame- > arrayBounds = = NIL ) ;
Assert ( typeN ame- > arrayBounds = = NIL ) ;
/* emit nuisance notice (intentionally not errposition'd) */
ereport ( NOTICE ,
( errmsg ( " type reference %s converted to %s " ,
TypeNameToString ( typen ame) ,
TypeNameToString ( typeN ame) ,
format_type_be ( typoid ) ) ) ) ;
}
else
@ -135,7 +135,7 @@ LookupTypeName(ParseState *pstate, const TypeName *typename,
char * typname ;
/* deconstruct the name list */
DeconstructQualifiedName ( typen ame- > names , & schemaname , & typname ) ;
DeconstructQualifiedName ( typeN ame- > names , & schemaname , & typname ) ;
if ( schemaname )
{
@ -155,7 +155,7 @@ LookupTypeName(ParseState *pstate, const TypeName *typename,
}
/* If an array reference, return the array type instead */
if ( typen ame- > arrayBounds ! = NIL )
if ( typeN ame- > arrayBounds ! = NIL )
typoid = get_array_type ( typoid ) ;
}
@ -172,7 +172,7 @@ LookupTypeName(ParseState *pstate, const TypeName *typename,
if ( ! HeapTupleIsValid ( tup ) ) /* should not happen */
elog ( ERROR , " cache lookup failed for type %u " , typoid ) ;
typmod = typenameTypeMod ( pstate , typen ame, ( Type ) tup ) ;
typmod = typenameTypeMod ( pstate , typeN ame, ( Type ) tup ) ;
if ( typmod_p )
* typmod_p = typmod ;
@ -188,23 +188,23 @@ LookupTypeName(ParseState *pstate, const TypeName *typename,
* Callers of this can therefore assume the result is a fully valid type .
*/
Type
typenameType ( ParseState * pstate , const TypeName * typen ame, int32 * typmod_p )
typenameType ( ParseState * pstate , const TypeName * typeN ame, int32 * typmod_p )
{
Type tup ;
tup = LookupTypeName ( pstate , typen ame, typmod_p ) ;
tup = LookupTypeName ( pstate , typeN ame, typmod_p ) ;
if ( tup = = NULL )
ereport ( ERROR ,
( errcode ( ERRCODE_UNDEFINED_OBJECT ) ,
errmsg ( " type \" %s \" does not exist " ,
TypeNameToString ( typen ame) ) ,
parser_errposition ( pstate , typen ame- > location ) ) ) ;
TypeNameToString ( typeN ame) ) ,
parser_errposition ( pstate , typeN ame- > location ) ) ) ;
if ( ! ( ( Form_pg_type ) GETSTRUCT ( tup ) ) - > typisdefined )
ereport ( ERROR ,
( errcode ( ERRCODE_UNDEFINED_OBJECT ) ,
errmsg ( " type \" %s \" is only a shell " ,
TypeNameToString ( typen ame) ) ,
parser_errposition ( pstate , typen ame- > location ) ) ) ;
TypeNameToString ( typeN ame) ) ,
parser_errposition ( pstate , typeN ame- > location ) ) ) ;
return tup ;
}
@ -215,12 +215,12 @@ typenameType(ParseState *pstate, const TypeName *typename, int32 *typmod_p)
* not the syscache entry .
*/
Oid
typenameTypeId ( ParseState * pstate , const TypeName * typen ame, int32 * typmod_p )
typenameTypeId ( ParseState * pstate , const TypeName * typeN ame, int32 * typmod_p )
{
Oid typoid ;
Type tup ;
tup = typenameType ( pstate , typen ame, typmod_p ) ;
tup = typenameType ( pstate , typeN ame, typmod_p ) ;
typoid = HeapTupleGetOid ( tup ) ;
ReleaseSysCache ( tup ) ;
@ -239,7 +239,7 @@ typenameTypeId(ParseState *pstate, const TypeName *typename, int32 *typmod_p)
* pstate is only used for error location info , and may be NULL .
*/
static int32
typenameTypeMod ( ParseState * pstate , const TypeName * typen ame, Type typ )
typenameTypeMod ( ParseState * pstate , const TypeName * typeN ame, Type typ )
{
int32 result ;
Oid typmodin ;
@ -250,8 +250,8 @@ typenameTypeMod(ParseState *pstate, const TypeName *typename, Type typ)
ParseCallbackState pcbstate ;
/* Return prespecified typmod if no typmod expressions */
if ( typen ame- > typmods = = NIL )
return typen ame- > typemod ;
if ( typeN ame- > typmods = = NIL )
return typeN ame- > typemod ;
/*
* Else , type had better accept typmods . We give a special error message
@ -262,8 +262,8 @@ typenameTypeMod(ParseState *pstate, const TypeName *typename, Type typ)
ereport ( ERROR ,
( errcode ( ERRCODE_SYNTAX_ERROR ) ,
errmsg ( " type modifier cannot be specified for shell type \" %s \" " ,
TypeNameToString ( typen ame) ) ,
parser_errposition ( pstate , typen ame- > location ) ) ) ;
TypeNameToString ( typeN ame) ) ,
parser_errposition ( pstate , typeN ame- > location ) ) ) ;
typmodin = ( ( Form_pg_type ) GETSTRUCT ( typ ) ) - > typmodin ;
@ -271,17 +271,17 @@ typenameTypeMod(ParseState *pstate, const TypeName *typename, Type typ)
ereport ( ERROR ,
( errcode ( ERRCODE_SYNTAX_ERROR ) ,
errmsg ( " type modifier is not allowed for type \" %s \" " ,
TypeNameToString ( typen ame) ) ,
parser_errposition ( pstate , typen ame- > location ) ) ) ;
TypeNameToString ( typeN ame) ) ,
parser_errposition ( pstate , typeN ame- > location ) ) ) ;
/*
* Convert the list of raw - grammar - output expressions to a cstring array .
* Currently , we allow simple numeric constants , string literals , and
* identifiers ; possibly this list could be extended .
*/
datums = ( Datum * ) palloc ( list_length ( typen ame- > typmods ) * sizeof ( Datum ) ) ;
datums = ( Datum * ) palloc ( list_length ( typeN ame- > typmods ) * sizeof ( Datum ) ) ;
n = 0 ;
foreach ( l , typen ame- > typmods )
foreach ( l , typeN ame- > typmods )
{
Node * tm = ( Node * ) lfirst ( l ) ;
char * cstr = NULL ;
@ -314,7 +314,7 @@ typenameTypeMod(ParseState *pstate, const TypeName *typename, Type typ)
ereport ( ERROR ,
( errcode ( ERRCODE_SYNTAX_ERROR ) ,
errmsg ( " type modifiers must be simple constants or identifiers " ) ,
parser_errposition ( pstate , typen ame- > location ) ) ) ;
parser_errposition ( pstate , typeN ame- > location ) ) ) ;
datums [ n + + ] = CStringGetDatum ( cstr ) ;
}
@ -323,7 +323,7 @@ typenameTypeMod(ParseState *pstate, const TypeName *typename, Type typ)
- 2 , false , ' c ' ) ;
/* arrange to report location if type's typmodin function fails */
setup_parser_errposition_callback ( & pcbstate , pstate , typen ame- > location ) ;
setup_parser_errposition_callback ( & pcbstate , pstate , typeN ame- > location ) ;
result = DatumGetInt32 ( OidFunctionCall1 ( typmodin ,
PointerGetDatum ( arrtypmod ) ) ) ;
@ -345,16 +345,16 @@ typenameTypeMod(ParseState *pstate, const TypeName *typename, Type typ)
* it is mostly used for reporting lookup errors .
*/
static void
appendTypeNameToBuffer ( const TypeName * typen ame, StringInfo string )
appendTypeNameToBuffer ( const TypeName * typeN ame, StringInfo string )
{
if ( typen ame- > names ! = NIL )
if ( typeN ame- > names ! = NIL )
{
/* Emit possibly-qualified name as-is */
ListCell * l ;
foreach ( l , typen ame- > names )
foreach ( l , typeN ame- > names )
{
if ( l ! = list_head ( typen ame- > names ) )
if ( l ! = list_head ( typeN ame- > names ) )
appendStringInfoChar ( string , ' . ' ) ;
appendStringInfoString ( string , strVal ( lfirst ( l ) ) ) ;
}
@ -362,17 +362,17 @@ appendTypeNameToBuffer(const TypeName *typename, StringInfo string)
else
{
/* Look up internally-specified type */
appendStringInfoString ( string , format_type_be ( typen ame- > typeid ) ) ;
appendStringInfoString ( string , format_type_be ( typeN ame- > typeO id ) ) ;
}
/*
* Add decoration as needed , but only for fields considered by
* LookupTypeName
*/
if ( typen ame- > pct_type )
if ( typeN ame- > pct_type )
appendStringInfoString ( string , " %TYPE " ) ;
if ( typen ame- > arrayBounds ! = NIL )
if ( typeN ame- > arrayBounds ! = NIL )
appendStringInfoString ( string , " [] " ) ;
}
@ -384,12 +384,12 @@ appendTypeNameToBuffer(const TypeName *typename, StringInfo string)
* it is mostly used for reporting lookup errors .
*/
char *
TypeNameToString ( const TypeName * typen ame)
TypeNameToString ( const TypeName * typeN ame)
{
StringInfoData string ;
initStringInfo ( & string ) ;
appendTypeNameToBuffer ( typen ame, & string ) ;
appendTypeNameToBuffer ( typeN ame, & string ) ;
return string . data ;
}
@ -406,12 +406,12 @@ TypeNameListToString(List *typenames)
initStringInfo ( & string ) ;
foreach ( l , typenames )
{
TypeName * typen ame = ( TypeName * ) lfirst ( l ) ;
TypeName * typeN ame = ( TypeName * ) lfirst ( l ) ;
Assert ( IsA ( typen ame, TypeName ) ) ;
Assert ( IsA ( typeN ame, TypeName ) ) ;
if ( l ! = list_head ( typenames ) )
appendStringInfoChar ( & string , ' , ' ) ;
appendTypeNameToBuffer ( typen ame, & string ) ;
appendTypeNameToBuffer ( typeN ame, & string ) ;
}
return string . data ;
}
@ -575,7 +575,7 @@ parseTypeString(const char *str, Oid *type_id, int32 *typmod_p)
SelectStmt * stmt ;
ResTarget * restarget ;
TypeCast * typecast ;
TypeName * typen ame;
TypeName * typeN ame;
ErrorContextCallback ptserrcontext ;
/* make sure we give useful error for empty input */
@ -635,14 +635,14 @@ parseTypeString(const char *str, Oid *type_id, int32 *typmod_p)
typecast - > arg = = NULL | |
! IsA ( typecast - > arg , A_Const ) )
goto fail ;
typen ame = typecast - > typen ame;
if ( typen ame = = NULL | |
! IsA ( typen ame, TypeName ) )
typeN ame = typecast - > typeN ame;
if ( typeN ame = = NULL | |
! IsA ( typeN ame, TypeName ) )
goto fail ;
if ( typen ame- > setof )
if ( typeN ame- > setof )
goto fail ;
* type_id = typenameTypeId ( NULL , typen ame, typmod_p ) ;
* type_id = typenameTypeId ( NULL , typeN ame, typmod_p ) ;
pfree ( buf . data ) ;