88 *
99 *
1010 * IDENTIFICATION
11- * $Header: /cvsroot/pgsql/src/backend/parser/parse_type.c,v 1.62 2003/09/25 06:58:01 petere Exp $
11+ * $Header: /cvsroot/pgsql/src/backend/parser/parse_type.c,v 1.63 2003/10/20 17:25:42 tgl Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -430,14 +430,21 @@ typeidTypeRelid(Oid type_id)
430430return result ;
431431}
432432
433+ /*
434+ * error context callback for parse failure during parseTypeString()
435+ */
436+ static void
437+ pts_error_callback (void * arg )
438+ {
439+ const char * str = (const char * )arg ;
440+
441+ errcontext ("invalid type name \"%s\"" ,str );
442+ }
443+
433444/*
434445 * Given a string that is supposed to be a SQL-compatible type declaration,
435446 * such as "int4" or "integer" or "character varying(32)", parse
436447 * the string and convert it to a type OID and type modifier.
437- *
438- * This routine is not currently used by the main backend, but it is
439- * exported for use by add-on modules such as plpgsql, in hopes of
440- * centralizing parsing knowledge about SQL type declarations.
441448 */
442449void
443450parseTypeString (const char * str ,Oid * type_id ,int32 * typmod )
@@ -448,12 +455,27 @@ parseTypeString(const char *str, Oid *type_id, int32 *typmod)
448455ResTarget * restarget ;
449456TypeCast * typecast ;
450457TypeName * typename ;
458+ ErrorContextCallback ptserrcontext ;
459+
460+ /* make sure we give useful error for empty input */
461+ if (strspn (str ," \t\n\r\f" )== strlen (str ))
462+ gotofail ;
451463
452464initStringInfo (& buf );
453- appendStringInfo (& buf ,"SELECT (NULL::%s)" ,str );
465+ appendStringInfo (& buf ,"SELECT NULL::%s" ,str );
466+
467+ /*
468+ * Setup error traceback support in case of ereport() during parse
469+ */
470+ ptserrcontext .callback = pts_error_callback ;
471+ ptserrcontext .arg = (void * )str ;
472+ ptserrcontext .previous = error_context_stack ;
473+ error_context_stack = & ptserrcontext ;
454474
455475raw_parsetree_list = raw_parser (buf .data );
456476
477+ error_context_stack = ptserrcontext .previous ;
478+
457479/*
458480 * Make sure we got back exactly what we expected and no more;
459481 * paranoia is justified since the string might contain anything.