during parse analysis, not only errors detected in the flex/bison stages.
This is per my earlier proposal. This commit includes all the basic
infrastructure, but locations are only tracked and reported for errors
involving column references, function calls, and operators. More could
be done later but this seems like a good set to start with. I've also
moved the ReportSyntaxErrorPosition logic out of psql and into libpq,
which should make it available to more people --- even within psql this
is an improvement because warnings weren't handled by ReportSyntaxErrorPosition.
--
SELECT is_point(ll_to_earth(0,0));
ERROR: function is_point(earth) does not exist
-HINT: No function matches the given name and argument types. You may need to add explicit typecasts.
+LINE 1: SELECT is_point(ll_to_earth(0,0));
+ ^
+HINT: No function matches the given name and argument types. You may need to add explicit type casts.
SELECT cube_dim(ll_to_earth(0,0)) <= 3;
?column?
----------
SELECT is_point(ll_to_earth(30,60));
ERROR: function is_point(earth) does not exist
-HINT: No function matches the given name and argument types. You may need to add explicit typecasts.
+LINE 1: SELECT is_point(ll_to_earth(30,60));
+ ^
+HINT: No function matches the given name and argument types. You may need to add explicit type casts.
SELECT cube_dim(ll_to_earth(30,60)) <= 3;
?column?
----------
SELECT is_point(ll_to_earth(60,90));
ERROR: function is_point(earth) does not exist
-HINT: No function matches the given name and argument types. You may need to add explicit typecasts.
+LINE 1: SELECT is_point(ll_to_earth(60,90));
+ ^
+HINT: No function matches the given name and argument types. You may need to add explicit type casts.
SELECT cube_dim(ll_to_earth(60,90)) <= 3;
?column?
----------
SELECT is_point(ll_to_earth(-30,-90));
ERROR: function is_point(earth) does not exist
-HINT: No function matches the given name and argument types. You may need to add explicit typecasts.
+LINE 1: SELECT is_point(ll_to_earth(-30,-90));
+ ^
+HINT: No function matches the given name and argument types. You may need to add explicit type casts.
SELECT cube_dim(ll_to_earth(-30,-90)) <= 3;
?column?
----------
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/common/tupdesc.c,v 1.114 2006/03/05 15:58:20 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/access/common/tupdesc.c,v 1.115 2006/03/14 22:48:18 tgl Exp $
*
* NOTES
* some of the executor utility code such as "ExecTypeFromTL" should be
attname)));
TupleDescInitEntry(desc, attnum, attname,
- typenameTypeId(entry->typename),
+ typenameTypeId(NULL, entry->typename),
atttypmod, attdim);
/* Fill in additional stuff not handled by TupleDescInitEntry */
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/catalog/pg_aggregate.c,v 1.78 2006/03/05 15:58:23 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/catalog/pg_aggregate.c,v 1.79 2006/03/14 22:48:18 tgl Exp $
*
*-------------------------------------------------------------------------
*/
/* handle sortop, if supplied */
if (aggsortopName)
- sortop = LookupOperName(aggsortopName,
+ sortop = LookupOperName(NULL, aggsortopName,
aggBaseType, aggBaseType,
- false);
+ false, -1);
/*
* Everything looks okay. Try to create the pg_proc entry for the
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/catalog/pg_operator.c,v 1.95 2006/03/05 15:58:23 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/catalog/pg_operator.c,v 1.96 2006/03/14 22:48:18 tgl Exp $
*
* NOTES
* these routines moved here from commands/define.c and somewhat cleaned up.
Oid operatorObjectId;
RegProcedure oprcode;
- operatorObjectId = LookupOperName(operatorName, leftObjectId,
- rightObjectId, true);
+ operatorObjectId = LookupOperName(NULL, operatorName,
+ leftObjectId, rightObjectId,
+ true, -1);
if (!OidIsValid(operatorObjectId))
{
*defined = false;
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/aggregatecmds.c,v 1.32 2006/03/05 15:58:23 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/aggregatecmds.c,v 1.33 2006/03/14 22:48:18 tgl Exp $
*
* DESCRIPTION
* The "DefineFoo" routines take the parse tree and pick out the
if (pg_strcasecmp(TypeNameToString(baseType), "ANY") == 0)
baseTypeId = ANYOID;
else
- baseTypeId = typenameTypeId(baseType);
+ baseTypeId = typenameTypeId(NULL, baseType);
- transTypeId = typenameTypeId(transType);
+ transTypeId = typenameTypeId(NULL, transType);
if (get_typtype(transTypeId) == 'p' &&
transTypeId != ANYARRAYOID &&
transTypeId != ANYELEMENTOID)
* that the aggregate is to apply to all basetypes (eg, COUNT).
*/
if (aggType)
- basetypeID = typenameTypeId(aggType);
+ basetypeID = typenameTypeId(NULL, aggType);
else
basetypeID = ANYOID;
* COUNT).
*/
if (basetype)
- basetypeOid = typenameTypeId(basetype);
+ basetypeOid = typenameTypeId(NULL, basetype);
else
basetypeOid = ANYOID;
* COUNT).
*/
if (basetype)
- basetypeOid = typenameTypeId(basetype);
+ basetypeOid = typenameTypeId(NULL, basetype);
else
basetypeOid = ANYOID;
* Copyright (c) 1996-2006, PostgreSQL Global Development Group
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/comment.c,v 1.87 2006/03/05 15:58:23 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/comment.c,v 1.88 2006/03/14 22:48:18 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "commands/dbcommands.h"
#include "commands/tablespace.h"
#include "miscadmin.h"
+#include "nodes/makefuncs.h"
#include "parser/parse_func.h"
#include "parser/parse_oper.h"
#include "parser/parse_type.h"
Oid oid;
/* XXX a bit of a crock; should accept TypeName in COMMENT syntax */
- tname = makeNode(TypeName);
- tname->names = typename;
- tname->typmod = -1;
+ tname = makeTypeNameFromNameList(typename);
/* Find the type's oid */
- oid = typenameTypeId(tname);
+ oid = typenameTypeId(NULL, tname);
/* Check object security */
/* First, attempt to determine the base aggregate oid */
if (aggtype)
- baseoid = typenameTypeId(aggtype);
+ baseoid = typenameTypeId(NULL, aggtype);
else
baseoid = ANYOID;
Oid oid;
/* Look up the operator */
- oid = LookupOperNameTypeNames(opername, typenode1, typenode2, false);
+ oid = LookupOperNameTypeNames(NULL, opername,
+ typenode1, typenode2,
+ false, -1);
- /* Valid user's ability to comment on this operator */
+ /* Check user's privilege to comment on this operator */
if (!pg_oper_ownercheck(oid, GetUserId()))
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_OPER,
NameListToString(opername));
targettype = (TypeName *) linitial(arguments);
Assert(IsA(targettype, TypeName));
- sourcetypeid = typenameTypeId(sourcetype);
- if (!OidIsValid(sourcetypeid))
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_OBJECT),
- errmsg("source data type %s does not exist",
- TypeNameToString(sourcetype))));
-
- targettypeid = typenameTypeId(targettype);
- if (!OidIsValid(targettypeid))
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_OBJECT),
- errmsg("target data type %s does not exist",
- TypeNameToString(targettype))));
+ sourcetypeid = typenameTypeId(NULL, sourcetype);
+ targettypeid = typenameTypeId(NULL, targettype);
tuple = SearchSysCache(CASTSOURCETARGET,
ObjectIdGetDatum(sourcetypeid),
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/define.c,v 1.94 2006/03/05 15:58:24 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/define.c,v 1.95 2006/03/14 22:48:18 tgl Exp $
*
* DESCRIPTION
* The "DefineFoo" routines take the parse tree and pick out the
#include "catalog/namespace.h"
#include "commands/defrem.h"
+#include "nodes/makefuncs.h"
#include "parser/parse_type.h"
#include "parser/scansup.h"
#include "utils/int8.h"
case T_TypeName:
return (TypeName *) def->arg;
case T_String:
- {
- /* Allow quoted typename for backwards compatibility */
- TypeName *n = makeNode(TypeName);
-
- n->names = list_make1(def->arg);
- n->typmod = -1;
- return n;
- }
+ /* Allow quoted typename for backwards compatibility */
+ return makeTypeNameFromNameList(list_make1(def->arg));
default:
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/functioncmds.c,v 1.72 2006/03/05 15:58:24 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/functioncmds.c,v 1.73 2006/03/14 22:48:18 tgl Exp $
*
* DESCRIPTION
* These routines take the parse tree and pick out the
{
Oid rettype;
- rettype = LookupTypeName(returnType);
+ rettype = LookupTypeName(NULL, returnType);
if (OidIsValid(rettype))
{
TypeName *t = fp->argType;
Oid toid;
- toid = LookupTypeName(t);
+ toid = LookupTypeName(NULL, t);
if (OidIsValid(toid))
{
if (!get_typisdefined(toid))
ObjectAddress myself,
referenced;
- sourcetypeid = LookupTypeName(stmt->sourcetype);
- if (!OidIsValid(sourcetypeid))
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_OBJECT),
- errmsg("source data type %s does not exist",
- TypeNameToString(stmt->sourcetype))));
-
- targettypeid = LookupTypeName(stmt->targettype);
- if (!OidIsValid(targettypeid))
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_OBJECT),
- errmsg("target data type %s does not exist",
- TypeNameToString(stmt->targettype))));
-
- /* No shells, no pseudo-types allowed */
- if (!get_typisdefined(sourcetypeid))
- ereport(ERROR,
- (errcode(ERRCODE_WRONG_OBJECT_TYPE),
- errmsg("source data type %s is only a shell",
- TypeNameToString(stmt->sourcetype))));
-
- if (!get_typisdefined(targettypeid))
- ereport(ERROR,
- (errcode(ERRCODE_WRONG_OBJECT_TYPE),
- errmsg("target data type %s is only a shell",
- TypeNameToString(stmt->targettype))));
+ sourcetypeid = typenameTypeId(NULL, stmt->sourcetype);
+ targettypeid = typenameTypeId(NULL, stmt->targettype);
+ /* No pseudo-types allowed */
if (get_typtype(sourcetypeid) == 'p')
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
HeapTuple tuple;
ObjectAddress object;
- sourcetypeid = LookupTypeName(stmt->sourcetype);
- if (!OidIsValid(sourcetypeid))
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_OBJECT),
- errmsg("source data type %s does not exist",
- TypeNameToString(stmt->sourcetype))));
-
- targettypeid = LookupTypeName(stmt->targettype);
- if (!OidIsValid(targettypeid))
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_OBJECT),
- errmsg("target data type %s does not exist",
- TypeNameToString(stmt->targettype))));
+ sourcetypeid = typenameTypeId(NULL, stmt->sourcetype);
+ targettypeid = typenameTypeId(NULL, stmt->targettype);
tuple = SearchSysCache(CASTSOURCETARGET,
ObjectIdGetDatum(sourcetypeid),
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/opclasscmds.c,v 1.42 2006/03/05 15:58:24 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/opclasscmds.c,v 1.43 2006/03/14 22:48:18 tgl Exp $
*
*-------------------------------------------------------------------------
*/
errmsg("must be superuser to create an operator class")));
/* Look up the datatype */
- typeoid = typenameTypeId(stmt->datatype);
+ typeoid = typenameTypeId(NULL, stmt->datatype);
#ifdef NOT_USED
/* XXX this is unnecessary given the superuser check above */
TypeName *typeName1 = (TypeName *) linitial(item->args);
TypeName *typeName2 = (TypeName *) lsecond(item->args);
- operOid = LookupOperNameTypeNames(item->name,
- typeName1,
- typeName2,
- false);
+ operOid = LookupOperNameTypeNames(NULL, item->name,
+ typeName1, typeName2,
+ false, -1);
}
else
{
/* Default to binary op on input datatype */
- operOid = LookupOperName(item->name, typeoid, typeoid,
- false);
+ operOid = LookupOperName(NULL, item->name,
+ typeoid, typeoid,
+ false, -1);
}
#ifdef NOT_USED
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("storage type specified more than once")));
- storageoid = typenameTypeId(item->storedtype);
+ storageoid = typenameTypeId(NULL, item->storedtype);
#ifdef NOT_USED
/* XXX this is unnecessary given the superuser check above */
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/operatorcmds.c,v 1.28 2006/03/05 15:58:24 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/operatorcmds.c,v 1.29 2006/03/14 22:48:18 tgl Exp $
*
* DESCRIPTION
* The "DefineFoo" routines take the parse tree and pick out the
/* Transform type names to type OIDs */
if (typeName1)
- typeId1 = typenameTypeId(typeName1);
+ typeId1 = typenameTypeId(NULL, typeName1);
if (typeName2)
- typeId2 = typenameTypeId(typeName2);
+ typeId2 = typenameTypeId(NULL, typeName2);
/*
* If any of the mergejoin support operators were given, then canMerge is
HeapTuple tup;
ObjectAddress object;
- operOid = LookupOperNameTypeNames(operatorName, typeName1, typeName2,
- false);
+ operOid = LookupOperNameTypeNames(NULL, operatorName,
+ typeName1, typeName2,
+ false, -1);
tup = SearchSysCache(OPEROID,
ObjectIdGetDatum(operOid),
rel = heap_open(OperatorRelationId, RowExclusiveLock);
- operOid = LookupOperNameTypeNames(name, typeName1, typeName2,
- false);
+ operOid = LookupOperNameTypeNames(NULL, name,
+ typeName1, typeName2,
+ false, -1);
AlterOperatorOwner_internal(rel, operOid, newOwnerId);
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/schemacmds.c,v 1.39 2006/03/05 15:58:24 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/schemacmds.c,v 1.40 2006/03/14 22:48:18 tgl Exp $
*
*-------------------------------------------------------------------------
*/
List *querytree_list;
ListCell *querytree_item;
- querytree_list = parse_analyze(parsetree, NULL, 0);
+ querytree_list = parse_analyze(parsetree, NULL, NULL, 0);
foreach(querytree_item, querytree_list)
{
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/sequence.c,v 1.128 2006/03/05 15:58:24 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/sequence.c,v 1.129 2006/03/14 22:48:18 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "commands/tablecmds.h"
#include "commands/sequence.h"
#include "miscadmin.h"
+#include "nodes/makefuncs.h"
#include "utils/acl.h"
#include "utils/builtins.h"
#include "utils/resowner.h"
stmt->tableElts = NIL;
for (i = SEQ_COL_FIRSTCOL; i <= SEQ_COL_LASTCOL; i++)
{
- ColumnDef *coldef;
- TypeName *typnam;
+ ColumnDef *coldef = makeNode(ColumnDef);
- typnam = makeNode(TypeName);
- typnam->setof = FALSE;
- typnam->arrayBounds = NIL;
- typnam->typmod = -1;
-
- coldef = makeNode(ColumnDef);
- coldef->typename = typnam;
coldef->inhcount = 0;
coldef->is_local = true;
coldef->is_not_null = true;
switch (i)
{
case SEQ_COL_NAME:
- typnam->typeid = NAMEOID;
+ coldef->typename = makeTypeNameFromOid(NAMEOID, -1);
coldef->colname = "sequence_name";
namestrcpy(&name, seq->sequence->relname);
value[i - 1] = NameGetDatum(&name);
break;
case SEQ_COL_LASTVAL:
- typnam->typeid = INT8OID;
+ coldef->typename = makeTypeNameFromOid(INT8OID, -1);
coldef->colname = "last_value";
value[i - 1] = Int64GetDatumFast(new.last_value);
break;
case SEQ_COL_INCBY:
- typnam->typeid = INT8OID;
+ coldef->typename = makeTypeNameFromOid(INT8OID, -1);
coldef->colname = "increment_by";
value[i - 1] = Int64GetDatumFast(new.increment_by);
break;
case SEQ_COL_MAXVALUE:
- typnam->typeid = INT8OID;
+ coldef->typename = makeTypeNameFromOid(INT8OID, -1);
coldef->colname = "max_value";
value[i - 1] = Int64GetDatumFast(new.max_value);
break;
case SEQ_COL_MINVALUE:
- typnam->typeid = INT8OID;
+ coldef->typename = makeTypeNameFromOid(INT8OID, -1);
coldef->colname = "min_value";
value[i - 1] = Int64GetDatumFast(new.min_value);
break;
case SEQ_COL_CACHE:
- typnam->typeid = INT8OID;
+ coldef->typename = makeTypeNameFromOid(INT8OID, -1);
coldef->colname = "cache_value";
value[i - 1] = Int64GetDatumFast(new.cache_value);
break;
case SEQ_COL_LOG:
- typnam->typeid = INT8OID;
+ coldef->typename = makeTypeNameFromOid(INT8OID, -1);
coldef->colname = "log_cnt";
value[i - 1] = Int64GetDatum((int64) 1);
break;
case SEQ_COL_CYCLE:
- typnam->typeid = BOOLOID;
+ coldef->typename = makeTypeNameFromOid(BOOLOID, -1);
coldef->colname = "is_cycled";
value[i - 1] = BoolGetDatum(new.is_cycled);
break;
case SEQ_COL_CALLED:
- typnam->typeid = BOOLOID;
+ coldef->typename = makeTypeNameFromOid(BOOLOID, -1);
coldef->colname = "is_called";
value[i - 1] = BoolGetDatum(false);
break;
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.180 2006/03/05 15:58:24 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.181 2006/03/14 22:48:18 tgl Exp $
*
*-------------------------------------------------------------------------
*/
char *attributeName = NameStr(attribute->attname);
int exist_attno;
ColumnDef *def;
- TypeName *typename;
/*
* Ignore dropped columns in the parent.
(errmsg("merging multiple inherited definitions of column \"%s\"",
attributeName)));
def = (ColumnDef *) list_nth(inhSchema, exist_attno - 1);
- if (typenameTypeId(def->typename) != attribute->atttypid ||
+ if (typenameTypeId(NULL, def->typename) != attribute->atttypid ||
def->typename->typmod != attribute->atttypmod)
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
*/
def = makeNode(ColumnDef);
def->colname = pstrdup(attributeName);
- typename = makeNode(TypeName);
- typename->typeid = attribute->atttypid;
- typename->typmod = attribute->atttypmod;
- def->typename = typename;
+ def->typename = makeTypeNameFromOid(attribute->atttypid,
+ attribute->atttypmod);
def->inhcount = 1;
def->is_local = false;
def->is_not_null = attribute->attnotnull;
(errmsg("merging column \"%s\" with inherited definition",
attributeName)));
def = (ColumnDef *) list_nth(inhSchema, exist_attno - 1);
- if (typenameTypeId(def->typename) != typenameTypeId(newdef->typename) ||
+ if (typenameTypeId(NULL, def->typename) != typenameTypeId(NULL, newdef->typename) ||
def->typename->typmod != newdef->typename->typmod)
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
Form_pg_attribute childatt = (Form_pg_attribute) GETSTRUCT(tuple);
/* Okay if child matches by type */
- if (typenameTypeId(colDef->typename) != childatt->atttypid ||
+ if (typenameTypeId(NULL, colDef->typename) != childatt->atttypid ||
colDef->typename->typmod != childatt->atttypmod)
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
MaxHeapAttributeNumber)));
i = minattnum + 1;
- typeTuple = typenameType(colDef->typename);
+ typeTuple = typenameType(NULL, colDef->typename);
tform = (Form_pg_type) GETSTRUCT(typeTuple);
typeOid = HeapTupleGetOid(typeTuple);
* the right answer from the test below on opclass membership unless
* we select the proper operator.)
*/
- Operator o = oper(list_make1(makeString("=")),
- pktypoid[i], fktypoid[i], true);
+ Operator o = oper(NULL, list_make1(makeString("=")),
+ pktypoid[i], fktypoid[i],
+ true, -1);
if (o == NULL)
ereport(ERROR,
colName)));
/* Look up the target type */
- targettype = LookupTypeName(typename);
- if (!OidIsValid(targettype))
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_OBJECT),
- errmsg("type \"%s\" does not exist",
- TypeNameToString(typename))));
+ targettype = typenameTypeId(NULL, typename);
/* make sure datatype is legal for a column */
CheckAttributeType(colName, targettype);
colName)));
/* Look up the target type (should not fail, since prep found it) */
- typeTuple = typenameType(typename);
+ typeTuple = typenameType(NULL, typename);
tform = (Form_pg_type) GETSTRUCT(typeTuple);
targettype = HeapTupleGetOid(typeTuple);
Node *parsetree = (Node *) lfirst(list_item);
querytree_list = list_concat(querytree_list,
- parse_analyze(parsetree, NULL, 0));
+ parse_analyze(parsetree, cmd, NULL, 0));
}
/*
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/typecmds.c,v 1.88 2006/03/05 15:58:25 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/typecmds.c,v 1.89 2006/03/14 22:48:18 tgl Exp $
*
* DESCRIPTION
* The "DefineFoo" routines take the parse tree and pick out the
#include "executor/executor.h"
#include "miscadmin.h"
#include "nodes/execnodes.h"
-#include "nodes/nodes.h"
+#include "nodes/makefuncs.h"
#include "optimizer/clauses.h"
#include "optimizer/planmain.h"
#include "optimizer/var.h"
static Oid findTypeSendFunction(List *procname, Oid typeOid);
static Oid findTypeAnalyzeFunction(List *procname, Oid typeOid);
static List *get_rels_with_domain(Oid domainOid, LOCKMODE lockmode);
-static void domainOwnerCheck(HeapTuple tup, TypeName *typename);
+static void checkDomainOwner(HeapTuple tup, TypeName *typename);
static char *domainAddConstraint(Oid domainOid, Oid domainNamespace,
Oid baseTypeOid,
int typMod, Constraint *constr,
}
else if (pg_strcasecmp(defel->defname, "element") == 0)
{
- elemType = typenameTypeId(defGetTypeName(defel));
+ elemType = typenameTypeId(NULL, defGetTypeName(defel));
/* disallow arrays of pseudotypes */
if (get_typtype(elemType) == 'p')
ereport(ERROR,
ObjectAddress object;
/* Make a TypeName so we can use standard type lookup machinery */
- typename = makeNode(TypeName);
- typename->names = names;
- typename->typmod = -1;
- typename->arrayBounds = NIL;
+ typename = makeTypeNameFromNameList(names);
/* Use LookupTypeName here so that shell types can be removed. */
- typeoid = LookupTypeName(typename);
+ typeoid = LookupTypeName(NULL, typename);
if (!OidIsValid(typeoid))
{
if (!missing_ok)
/*
* Look up the base type.
*/
- typeTup = typenameType(stmt->typename);
+ typeTup = typenameType(NULL, stmt->typename);
baseType = (Form_pg_type) GETSTRUCT(typeTup);
basetypeoid = HeapTupleGetOid(typeTup);
ObjectAddress object;
/* Make a TypeName so we can use standard type lookup machinery */
- typename = makeNode(TypeName);
- typename->names = names;
- typename->typmod = -1;
- typename->arrayBounds = NIL;
+ typename = makeTypeNameFromNameList(names);
/* Use LookupTypeName here so that shell types can be removed. */
- typeoid = LookupTypeName(typename);
+ typeoid = LookupTypeName(NULL, typename);
if (!OidIsValid(typeoid))
{
if (!missing_ok)
Form_pg_type typTup;
/* Make a TypeName so we can use standard type lookup machinery */
- typename = makeNode(TypeName);
- typename->names = names;
- typename->typmod = -1;
- typename->arrayBounds = NIL;
+ typename = makeTypeNameFromNameList(names);
+ domainoid = typenameTypeId(NULL, typename);
- /* Lock the domain in the type table */
+ /* Look up the domain in the type table */
rel = heap_open(TypeRelationId, RowExclusiveLock);
- /* Use LookupTypeName here so that shell types can be removed. */
- domainoid = LookupTypeName(typename);
- if (!OidIsValid(domainoid))
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_OBJECT),
- errmsg("type \"%s\" does not exist",
- TypeNameToString(typename))));
-
tup = SearchSysCacheCopy(TYPEOID,
ObjectIdGetDatum(domainoid),
0, 0, 0);
if (!HeapTupleIsValid(tup))
elog(ERROR, "cache lookup failed for type %u", domainoid);
+ typTup = (Form_pg_type) GETSTRUCT(tup);
- /* Doesn't return if user isn't allowed to alter the domain */
- domainOwnerCheck(tup, typename);
+ /* Check it's a domain and check user has permission for ALTER DOMAIN */
+ checkDomainOwner(tup, typename);
/* Setup new tuple */
MemSet(new_record, (Datum) 0, sizeof(new_record));
MemSet(new_record_nulls, ' ', sizeof(new_record_nulls));
MemSet(new_record_repl, ' ', sizeof(new_record_repl));
- /* Useful later */
- typTup = (Form_pg_type) GETSTRUCT(tup);
-
/* Store the new default, if null then skip this step */
if (defaultRaw)
{
Form_pg_type typTup;
/* Make a TypeName so we can use standard type lookup machinery */
- typename = makeNode(TypeName);
- typename->names = names;
- typename->typmod = -1;
- typename->arrayBounds = NIL;
+ typename = makeTypeNameFromNameList(names);
+ domainoid = typenameTypeId(NULL, typename);
- /* Lock the type table */
+ /* Look up the domain in the type table */
typrel = heap_open(TypeRelationId, RowExclusiveLock);
- /* Use LookupTypeName here so that shell types can be found (why?). */
- domainoid = LookupTypeName(typename);
- if (!OidIsValid(domainoid))
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_OBJECT),
- errmsg("type \"%s\" does not exist",
- TypeNameToString(typename))));
-
tup = SearchSysCacheCopy(TYPEOID,
ObjectIdGetDatum(domainoid),
0, 0, 0);
elog(ERROR, "cache lookup failed for type %u", domainoid);
typTup = (Form_pg_type) GETSTRUCT(tup);
- /* Doesn't return if user isn't allowed to alter the domain */
- domainOwnerCheck(tup, typename);
+ /* Check it's a domain and check user has permission for ALTER DOMAIN */
+ checkDomainOwner(tup, typename);
/* Is the domain already set to the desired constraint? */
if (typTup->typnotnull == notNull)
* Implements the ALTER DOMAIN DROP CONSTRAINT statement
*/
void
-AlterDomainDropConstraint(List *names, const char *constrName, DropBehavior behavior)
+AlterDomainDropConstraint(List *names, const char *constrName,
+ DropBehavior behavior)
{
TypeName *typename;
Oid domainoid;
HeapTuple contup;
/* Make a TypeName so we can use standard type lookup machinery */
- typename = makeNode(TypeName);
- typename->names = names;
- typename->typmod = -1;
- typename->arrayBounds = NIL;
+ typename = makeTypeNameFromNameList(names);
+ domainoid = typenameTypeId(NULL, typename);
- /* Lock the type table */
+ /* Look up the domain in the type table */
rel = heap_open(TypeRelationId, RowExclusiveLock);
- /* Use LookupTypeName here so that shell types can be removed. */
- domainoid = LookupTypeName(typename);
- if (!OidIsValid(domainoid))
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_OBJECT),
- errmsg("type \"%s\" does not exist",
- TypeNameToString(typename))));
-
tup = SearchSysCacheCopy(TYPEOID,
ObjectIdGetDatum(domainoid),
0, 0, 0);
if (!HeapTupleIsValid(tup))
elog(ERROR, "cache lookup failed for type %u", domainoid);
- /* Doesn't return if user isn't allowed to alter the domain */
- domainOwnerCheck(tup, typename);
+ /* Check it's a domain and check user has permission for ALTER DOMAIN */
+ checkDomainOwner(tup, typename);
/* Grab an appropriate lock on the pg_constraint relation */
conrel = heap_open(ConstraintRelationId, RowExclusiveLock);
Constraint *constr;
/* Make a TypeName so we can use standard type lookup machinery */
- typename = makeNode(TypeName);
- typename->names = names;
- typename->typmod = -1;
- typename->arrayBounds = NIL;
+ typename = makeTypeNameFromNameList(names);
+ domainoid = typenameTypeId(NULL, typename);
- /* Lock the type table */
+ /* Look up the domain in the type table */
typrel = heap_open(TypeRelationId, RowExclusiveLock);
- /* Use LookupTypeName here so that shell types can be found (why?). */
- domainoid = LookupTypeName(typename);
- if (!OidIsValid(domainoid))
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_OBJECT),
- errmsg("type \"%s\" does not exist",
- TypeNameToString(typename))));
-
tup = SearchSysCacheCopy(TYPEOID,
ObjectIdGetDatum(domainoid),
0, 0, 0);
elog(ERROR, "cache lookup failed for type %u", domainoid);
typTup = (Form_pg_type) GETSTRUCT(tup);
- /* Doesn't return if user isn't allowed to alter the domain */
- domainOwnerCheck(tup, typename);
+ /* Check it's a domain and check user has permission for ALTER DOMAIN */
+ checkDomainOwner(tup, typename);
/* Check for unsupported constraint types */
if (IsA(newConstraint, FkConstraint))
}
/*
- * domainOwnerCheck
+ * checkDomainOwner
*
- * Throw an error if the current user doesn't have permission to modify
- * the domain in an ALTER DOMAIN statement, or if the type isn't actually
- * a domain.
+ * Check that the type is actually a domain and that the current user
+ * has permission to do ALTER DOMAIN on it. Throw an error if not.
*/
static void
-domainOwnerCheck(HeapTuple tup, TypeName *typename)
+checkDomainOwner(HeapTuple tup, TypeName *typename)
{
Form_pg_type typTup = (Form_pg_type) GETSTRUCT(tup);
AclResult aclresult;
/* Make a TypeName so we can use standard type lookup machinery */
- typename = makeNode(TypeName);
- typename->names = names;
- typename->typmod = -1;
- typename->arrayBounds = NIL;
-
- /* Lock the type table */
- rel = heap_open(TypeRelationId, RowExclusiveLock);
+ typename = makeTypeNameFromNameList(names);
- /* Use LookupTypeName here so that shell types can be processed (why?) */
- typeOid = LookupTypeName(typename);
+ /* Use LookupTypeName here so that shell types can be processed */
+ typeOid = LookupTypeName(NULL, typename);
if (!OidIsValid(typeOid))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("type \"%s\" does not exist",
TypeNameToString(typename))));
+ /* Look up the type in the type table */
+ rel = heap_open(TypeRelationId, RowExclusiveLock);
+
tup = SearchSysCacheCopy(TYPEOID,
ObjectIdGetDatum(typeOid),
0, 0, 0);
Oid typeOid;
Oid nspOid;
- /* get type OID */
- typename = makeNode(TypeName);
- typename->names = names;
- typename->typmod = -1;
- typename->arrayBounds = NIL;
-
- typeOid = LookupTypeName(typename);
-
- if (!OidIsValid(typeOid))
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_OBJECT),
- errmsg("type \"%s\" does not exist",
- TypeNameToString(typename))));
+ /* Make a TypeName so we can use standard type lookup machinery */
+ typename = makeTypeNameFromNameList(names);
+ typeOid = typenameTypeId(NULL, typename);
/* check permissions on type */
if (!pg_type_ownercheck(typeOid, GetUserId()))
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/view.c,v 1.93 2006/03/05 15:58:25 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/view.c,v 1.94 2006/03/14 22:48:18 tgl Exp $
*
*-------------------------------------------------------------------------
*/
if (!tle->resjunk)
{
ColumnDef *def = makeNode(ColumnDef);
- TypeName *typename = makeNode(TypeName);
def->colname = pstrdup(tle->resname);
-
- typename->typeid = exprType((Node *) tle->expr);
- typename->typmod = exprTypmod((Node *) tle->expr);
- def->typename = typename;
-
+ def->typename = makeTypeNameFromOid(exprType((Node *) tle->expr),
+ exprTypmod((Node *) tle->expr));
def->inhcount = 0;
def->is_local = true;
def->is_not_null = false;
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.148 2006/03/05 15:58:26 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.149 2006/03/14 22:48:19 tgl Exp $
*
*-------------------------------------------------------------------------
*/
Node *parsetree = (Node *) lfirst(list_item);
List *query_list;
- query_list = pg_analyze_and_rewrite(parsetree, argtypes, nargs);
+ query_list = pg_analyze_and_rewrite(parsetree, src, argtypes, nargs);
query_list_list = lappend(query_list_list, query_list);
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.329 2006/03/05 15:58:27 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.330 2006/03/14 22:48:19 tgl Exp $
*
*-------------------------------------------------------------------------
*/
COPY_NODE_FIELD(name);
COPY_NODE_FIELD(lexpr);
COPY_NODE_FIELD(rexpr);
+ COPY_SCALAR_FIELD(location);
return newnode;
}
ColumnRef *newnode = makeNode(ColumnRef);
COPY_NODE_FIELD(fields);
+ COPY_SCALAR_FIELD(location);
return newnode;
}
COPY_NODE_FIELD(args);
COPY_SCALAR_FIELD(agg_star);
COPY_SCALAR_FIELD(agg_distinct);
+ COPY_SCALAR_FIELD(location);
return newnode;
}
COPY_SCALAR_FIELD(pct_type);
COPY_SCALAR_FIELD(typmod);
COPY_NODE_FIELD(arrayBounds);
+ COPY_SCALAR_FIELD(location);
return newnode;
}
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.265 2006/03/05 15:58:27 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.266 2006/03/14 22:48:19 tgl Exp $
*
*-------------------------------------------------------------------------
*/
COMPARE_NODE_FIELD(name);
COMPARE_NODE_FIELD(lexpr);
COMPARE_NODE_FIELD(rexpr);
+ COMPARE_SCALAR_FIELD(location);
return true;
}
_equalColumnRef(ColumnRef *a, ColumnRef *b)
{
COMPARE_NODE_FIELD(fields);
+ COMPARE_SCALAR_FIELD(location);
return true;
}
COMPARE_NODE_FIELD(args);
COMPARE_SCALAR_FIELD(agg_star);
COMPARE_SCALAR_FIELD(agg_distinct);
+ COMPARE_SCALAR_FIELD(location);
return true;
}
COMPARE_SCALAR_FIELD(pct_type);
COMPARE_SCALAR_FIELD(typmod);
COMPARE_NODE_FIELD(arrayBounds);
+ COMPARE_SCALAR_FIELD(location);
return true;
}
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/nodes/makefuncs.c,v 1.49 2006/03/05 15:58:27 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/nodes/makefuncs.c,v 1.50 2006/03/14 22:48:19 tgl Exp $
*
*-------------------------------------------------------------------------
*/
* makes an A_Expr node
*/
A_Expr *
-makeA_Expr(A_Expr_Kind kind, List *name, Node *lexpr, Node *rexpr)
+makeA_Expr(A_Expr_Kind kind, List *name,
+ Node *lexpr, Node *rexpr, int location)
{
A_Expr *a = makeNode(A_Expr);
a->name = name;
a->lexpr = lexpr;
a->rexpr = rexpr;
+ a->location = location;
return a;
}
*/
A_Expr *
makeSimpleA_Expr(A_Expr_Kind kind, const char *name,
- Node *lexpr, Node *rexpr)
+ Node *lexpr, Node *rexpr, int location)
{
A_Expr *a = makeNode(A_Expr);
a->name = list_make1(makeString((char *) name));
a->lexpr = lexpr;
a->rexpr = rexpr;
+ a->location = location;
return a;
}
/*
* makeTypeName -
* build a TypeName node for an unqualified name.
+ *
+ * typmod is defaulted, but can be changed later by caller.
*/
TypeName *
makeTypeName(char *typnam)
n->names = list_make1(makeString(typnam));
n->typmod = -1;
+ n->location = -1;
+ return n;
+}
+
+/*
+ * makeTypeNameFromNameList -
+ * build a TypeName node for a String list representing a qualified name.
+ *
+ * typmod is defaulted, but can be changed later by caller.
+ */
+TypeName *
+makeTypeNameFromNameList(List *names)
+{
+ TypeName *n = makeNode(TypeName);
+
+ n->names = names;
+ n->typmod = -1;
+ n->location = -1;
+ return n;
+}
+
+/*
+ * makeTypeNameFromOid -
+ * build a TypeName node to represent a type already known by OID.
+ */
+TypeName *
+makeTypeNameFromOid(Oid typeid, int32 typmod)
+{
+ TypeName *n = makeNode(TypeName);
+
+ n->typeid = typeid;
+ n->typmod = typmod;
+ n->location = -1;
return n;
}
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.269 2006/03/05 15:58:27 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.270 2006/03/14 22:48:19 tgl Exp $
*
* NOTES
* Every node type that can appear in stored rules' parsetrees *must*
WRITE_NODE_FIELD(args);
WRITE_BOOL_FIELD(agg_star);
WRITE_BOOL_FIELD(agg_distinct);
+ WRITE_INT_FIELD(location);
}
static void
WRITE_BOOL_FIELD(pct_type);
WRITE_INT_FIELD(typmod);
WRITE_NODE_FIELD(arrayBounds);
+ /* location is deliberately not stored */
}
static void
WRITE_NODE_FIELD(lexpr);
WRITE_NODE_FIELD(rexpr);
+ WRITE_INT_FIELD(location);
}
static void
WRITE_NODE_TYPE("COLUMNREF");
WRITE_NODE_FIELD(fields);
+ WRITE_INT_FIELD(location);
}
static void
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/nodes/readfuncs.c,v 1.185 2006/03/05 15:58:28 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/nodes/readfuncs.c,v 1.186 2006/03/14 22:48:19 tgl Exp $
*
* NOTES
* Path and Plan nodes do not have any readfuncs support, because we
READ_BOOL_FIELD(pct_type);
READ_INT_FIELD(typmod);
READ_NODE_FIELD(arrayBounds);
+ /* location is deliberately not stored */
+ local_node->location = -1;
READ_DONE();
}
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/plan/initsplan.c,v 1.116 2006/03/07 01:00:15 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/plan/initsplan.c,v 1.117 2006/03/14 22:48:19 tgl Exp $
*
*-------------------------------------------------------------------------
*/
*/
ltype = exprType(item1);
rtype = exprType(item2);
- eq_operator = compatible_oper(list_make1(makeString("=")),
- ltype, rtype, true);
+ eq_operator = compatible_oper(NULL, list_make1(makeString("=")),
+ ltype, rtype,
+ true, -1);
if (!HeapTupleIsValid(eq_operator))
{
/*
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/util/clauses.c,v 1.209 2006/03/05 15:58:31 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/util/clauses.c,v 1.210 2006/03/14 22:48:19 tgl Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
if (list_length(raw_parsetree_list) != 1)
goto fail;
- querytree_list = parse_analyze(linitial(raw_parsetree_list),
+ querytree_list = parse_analyze(linitial(raw_parsetree_list), src,
argtypes, funcform->pronargs);
if (list_length(querytree_list) != 1)
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.330 2006/03/05 15:58:32 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.331 2006/03/14 22:48:20 tgl Exp $
*
*-------------------------------------------------------------------------
*/
* parse_analyze
* Analyze a raw parse tree and transform it to Query form.
*
+ * If available, pass the source text from which the raw parse tree was
+ * generated; it's OK to pass NULL if this is not available.
+ *
* Optionally, information about $n parameter types can be supplied.
* References to $n indexes not defined by paramTypes[] are disallowed.
*
* a dummy CMD_UTILITY Query node.
*/
List *
-parse_analyze(Node *parseTree, Oid *paramTypes, int numParams)
+parse_analyze(Node *parseTree, const char *sourceText,
+ Oid *paramTypes, int numParams)
{
ParseState *pstate = make_parsestate(NULL);
List *result;
+ pstate->p_sourcetext = sourceText;
pstate->p_paramtypes = paramTypes;
pstate->p_numparams = numParams;
pstate->p_variableparams = false;
* be modified or enlarged (via repalloc).
*/
List *
-parse_analyze_varparams(Node *parseTree, Oid **paramTypes, int *numParams)
+parse_analyze_varparams(Node *parseTree, const char *sourceText,
+ Oid **paramTypes, int *numParams)
{
ParseState *pstate = make_parsestate(NULL);
List *result;
+ pstate->p_sourcetext = sourceText;
pstate->p_paramtypes = *paramTypes;
pstate->p_numparams = *numParams;
pstate->p_variableparams = true;
funccallnode->args = list_make1(snamenode);
funccallnode->agg_star = false;
funccallnode->agg_distinct = false;
+ funccallnode->location = -1;
constraint = makeNode(Constraint);
constraint->contype = CONSTR_DEFAULT;
Form_pg_attribute attribute = tupleDesc->attrs[parent_attno - 1];
char *attributeName = NameStr(attribute->attname);
ColumnDef *def;
- TypeName *typename;
/*
* Ignore dropped columns in the parent.
*/
def = makeNode(ColumnDef);
def->colname = pstrdup(attributeName);
- typename = makeNode(TypeName);
- typename->typeid = attribute->atttypid;
- typename->typmod = attribute->atttypmod;
- def->typename = typename;
+ def->typename = makeTypeNameFromOid(attribute->atttypid,
+ attribute->atttypmod);
def->inhcount = 0;
def->is_local = false;
def->is_not_null = attribute->attnotnull;
foreach(l, stmt->argtypes)
{
TypeName *tn = lfirst(l);
- Oid toid = typenameTypeId(tn);
+ Oid toid = typenameTypeId(pstate, tn);
argtoids[i++] = toid;
}
* from context.
*/
queries = parse_analyze_varparams((Node *) stmt->query,
+ pstate->p_sourcetext,
&argtoids, &nargs);
/*
/*
* All we really need to do here is verify that the type is valid.
*/
- Type ctype = typenameType(column->typename);
+ Type ctype = typenameType(pstate, column->typename);
ReleaseSysCache(ctype);
}
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.534 2006/03/07 01:00:16 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.535 2006/03/14 22:48:20 tgl Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
#include "utils/numeric.h"
+/* Location tracking support --- simpler than bison's default */
+#define YYLLOC_DEFAULT(Current, Rhs, N) \
+ Current = Rhs[1];
+
extern List *parsetree; /* final parse result is delivered here */
static bool QueryIsRule = FALSE;
*/
/*#define __YYSCLASS*/
-static Node *makeColumnRef(char *relname, List *indirection);
+static Node *makeColumnRef(char *relname, List *indirection, int location);
static Node *makeTypeCast(Node *arg, TypeName *typename);
static Node *makeStringConst(char *str, TypeName *typename);
static Node *makeIntConst(int val);
static Node *makeRowNullTest(NullTestType test, RowExpr *row);
static DefElem *makeDefElem(char *name, Node *arg);
static A_Const *makeBoolAConst(bool state);
-static FuncCall *makeOverlaps(List *largs, List *rargs);
+static FuncCall *makeOverlaps(List *largs, List *rargs, int location);
static void check_qualified_name(List *names);
static List *check_func_name(List *names);
static List *extractArgTypes(List *parameters);
List *sortClause, Node *lockingClause,
Node *limitOffset, Node *limitCount);
static Node *makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg);
-static Node *doNegate(Node *n);
+static Node *doNegate(Node *n, int location);
static void doNegateFloat(Value *v);
%}
%name-prefix="base_yy"
+%locations
%union
{
$$->names = lcons(makeString($1), $2);
$$->pct_type = true;
$$->typmod = -1;
+ $$->location = @1;
}
| SETOF type_name attrs '%' TYPE_P
{
$$->pct_type = true;
$$->typmod = -1;
$$->setof = TRUE;
+ $$->location = @2;
}
;
$$ = makeNode(TypeName);
$$->names = lcons(makeString($1), $2);
$$->typmod = -1;
+ $$->location = @1;
}
;
type_name
{
$$ = makeTypeName($1);
+ $$->location = @1;
}
;
n->args = list_make2($5, $1);
n->agg_star = FALSE;
n->agg_distinct = FALSE;
+ n->location = @2;
$$ = (Node *) n;
}
/*
* also to b_expr and to the MathOp list above.
*/
| '+' a_expr %prec UMINUS
- { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2); }
+ { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
| '-' a_expr %prec UMINUS
- { $$ = doNegate($2); }
+ { $$ = doNegate($2, @1); }
| a_expr '+' a_expr
- { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3); }
+ { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
| a_expr '-' a_expr
- { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3); }
+ { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
| a_expr '*' a_expr
- { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3); }
+ { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
| a_expr '/' a_expr
- { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3); }
+ { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
| a_expr '%' a_expr
- { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3); }
+ { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
| a_expr '^' a_expr
- { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3); }
+ { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
| a_expr '<' a_expr
- { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3); }
+ { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
| a_expr '>' a_expr
- { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3); }
+ { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
| a_expr '=' a_expr
- { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3); }
+ { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
| a_expr qual_Op a_expr %prec Op
- { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3); }
+ { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
| qual_Op a_expr %prec Op
- { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2); }
+ { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
| a_expr qual_Op %prec POSTFIXOP
- { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, NULL); }
+ { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, NULL, @2); }
| a_expr AND a_expr
- { $$ = (Node *) makeA_Expr(AEXPR_AND, NIL, $1, $3); }
+ { $$ = (Node *) makeA_Expr(AEXPR_AND, NIL, $1, $3, @2); }
| a_expr OR a_expr
- { $$ = (Node *) makeA_Expr(AEXPR_OR, NIL, $1, $3); }
+ { $$ = (Node *) makeA_Expr(AEXPR_OR, NIL, $1, $3, @2); }
| NOT a_expr
- { $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL, $2); }
+ { $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL, $2, @1); }
| a_expr LIKE a_expr
- { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~", $1, $3); }
+ { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~", $1, $3, @2); }
| a_expr LIKE a_expr ESCAPE a_expr
{
FuncCall *n = makeNode(FuncCall);
n->args = list_make2($3, $5);
n->agg_star = FALSE;
n->agg_distinct = FALSE;
- $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~", $1, (Node *) n);
+ n->location = @4;
+ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~", $1, (Node *) n, @2);
}
| a_expr NOT LIKE a_expr
- { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~", $1, $4); }
+ { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~", $1, $4, @2); }
| a_expr NOT LIKE a_expr ESCAPE a_expr
{
FuncCall *n = makeNode(FuncCall);
n->args = list_make2($4, $6);
n->agg_star = FALSE;
n->agg_distinct = FALSE;
- $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~", $1, (Node *) n);
+ n->location = @5;
+ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~", $1, (Node *) n, @2);
}
| a_expr ILIKE a_expr
- { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~*", $1, $3); }
+ { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~*", $1, $3, @2); }
| a_expr ILIKE a_expr ESCAPE a_expr
{
FuncCall *n = makeNode(FuncCall);
n->args = list_make2($3, $5);
n->agg_star = FALSE;
n->agg_distinct = FALSE;
- $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~*", $1, (Node *) n);
+ n->location = @4;
+ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~~*", $1, (Node *) n, @2);
}
| a_expr NOT ILIKE a_expr
- { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~*", $1, $4); }
+ { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~*", $1, $4, @2); }
| a_expr NOT ILIKE a_expr ESCAPE a_expr
{
FuncCall *n = makeNode(FuncCall);
n->args = list_make2($4, $6);
n->agg_star = FALSE;
n->agg_distinct = FALSE;
- $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~*", $1, (Node *) n);
+ n->location = @5;
+ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~~*", $1, (Node *) n, @2);
}
| a_expr SIMILAR TO a_expr %prec SIMILAR
n->args = list_make2($4, (Node *) c);
n->agg_star = FALSE;
n->agg_distinct = FALSE;
- $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~", $1, (Node *) n);
+ n->location = @2;
+ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~", $1, (Node *) n, @2);
}
| a_expr SIMILAR TO a_expr ESCAPE a_expr
{
n->args = list_make2($4, $6);
n->agg_star = FALSE;
n->agg_distinct = FALSE;
- $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~", $1, (Node *) n);
+ n->location = @5;
+ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "~", $1, (Node *) n, @2);
}
| a_expr NOT SIMILAR TO a_expr %prec SIMILAR
{
n->args = list_make2($5, (Node *) c);
n->agg_star = FALSE;
n->agg_distinct = FALSE;
- $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~", $1, (Node *) n);
+ n->location = @5;
+ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~", $1, (Node *) n, @2);
}
| a_expr NOT SIMILAR TO a_expr ESCAPE a_expr
{
n->args = list_make2($5, $7);
n->agg_star = FALSE;
n->agg_distinct = FALSE;
- $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~", $1, (Node *) n);
+ n->location = @6;
+ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "!~", $1, (Node *) n, @2);
}
/* NullTest clause
}
| row OVERLAPS row
{
- $$ = (Node *)makeOverlaps($1, $3);
+ $$ = (Node *)makeOverlaps($1, $3, @2);
}
| a_expr IS TRUE_P
{
}
| a_expr IS DISTINCT FROM a_expr %prec IS
{
- $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5);
+ $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
}
| a_expr IS NOT DISTINCT FROM a_expr %prec IS
{
$$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
(Node *) makeSimpleA_Expr(AEXPR_DISTINCT,
- "=", $1, $6));
+ "=", $1, $6, @2),
+ @2);
}
| a_expr IS OF '(' type_list ')' %prec IS
{
- $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "=", $1, (Node *) $5);
+ $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "=", $1, (Node *) $5, @2);
}
| a_expr IS NOT OF '(' type_list ')' %prec IS
{
- $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "<>", $1, (Node *) $6);
+ $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "<>", $1, (Node *) $6, @2);
}
| a_expr BETWEEN opt_asymmetric b_expr AND b_expr %prec BETWEEN
{
$$ = (Node *) makeA_Expr(AEXPR_AND, NIL,
- (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $4),
- (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $6));
+ (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $4, @2),
+ (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $6, @2),
+ @2);
}
| a_expr NOT BETWEEN opt_asymmetric b_expr AND b_expr %prec BETWEEN
{
$$ = (Node *) makeA_Expr(AEXPR_OR, NIL,
- (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $5),
- (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $7));
+ (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $5, @2),
+ (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $7, @2),
+ @2);
}
| a_expr BETWEEN SYMMETRIC b_expr AND b_expr %prec BETWEEN
{
$$ = (Node *) makeA_Expr(AEXPR_OR, NIL,
(Node *) makeA_Expr(AEXPR_AND, NIL,
- (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $4),
- (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $6)),
+ (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $4, @2),
+ (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $6, @2),
+ @2),
(Node *) makeA_Expr(AEXPR_AND, NIL,
- (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $6),
- (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $4)));
+ (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $6, @2),
+ (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $4, @2),
+ @2),
+ @2);
}
| a_expr NOT BETWEEN SYMMETRIC b_expr AND b_expr %prec BETWEEN
{
$$ = (Node *) makeA_Expr(AEXPR_AND, NIL,
(Node *) makeA_Expr(AEXPR_OR, NIL,
- (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $5),
- (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $7)),
+ (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $5, @2),
+ (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $7, @2),
+ @2),
(Node *) makeA_Expr(AEXPR_OR, NIL,
- (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $7),
- (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $5)));
+ (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $7, @2),
+ (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $5, @2),
+ @2),
+ @2);
}
| a_expr IN_P in_expr
{
else
{
/* generate scalar IN expression */
- $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "=", $1, $3);
+ $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "=", $1, $3, @2);
}
}
| a_expr NOT IN_P in_expr
n->testexpr = $1;
n->operName = list_make1(makeString("="));
/* Stick a NOT on top */
- $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL, (Node *) n);
+ $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL, (Node *) n, @2);
}
else
{
/* generate scalar NOT IN expression */
- $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "<>", $1, $4);
+ $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "<>", $1, $4, @2);
}
}
| a_expr subquery_Op sub_type select_with_parens %prec Op
| a_expr subquery_Op sub_type '(' a_expr ')' %prec Op
{
if ($3 == ANY_SUBLINK)
- $$ = (Node *) makeA_Expr(AEXPR_OP_ANY, $2, $1, $5);
+ $$ = (Node *) makeA_Expr(AEXPR_OP_ANY, $2, $1, $5, @2);
else
- $$ = (Node *) makeA_Expr(AEXPR_OP_ALL, $2, $1, $5);
+ $$ = (Node *) makeA_Expr(AEXPR_OP_ALL, $2, $1, $5, @2);
}
| UNIQUE select_with_parens
{
| b_expr TYPECAST Typename
{ $$ = makeTypeCast($1, $3); }
| '+' b_expr %prec UMINUS
- { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2); }
+ { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
| '-' b_expr %prec UMINUS
- { $$ = doNegate($2); }
+ { $$ = doNegate($2, @1); }
| b_expr '+' b_expr
- { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3); }
+ { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
| b_expr '-' b_expr
- { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3); }
+ { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
| b_expr '*' b_expr
- { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3); }
+ { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
| b_expr '/' b_expr
- { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3); }
+ { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
| b_expr '%' b_expr
- { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3); }
+ { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
| b_expr '^' b_expr
- { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3); }
+ { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
| b_expr '<' b_expr
- { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3); }
+ { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
| b_expr '>' b_expr
- { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3); }
+ { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
| b_expr '=' b_expr
- { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3); }
+ { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
| b_expr qual_Op b_expr %prec Op
- { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3); }
+ { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
| qual_Op b_expr %prec Op
- { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2); }
+ { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
| b_expr qual_Op %prec POSTFIXOP
- { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, NULL); }
+ { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, NULL, @2); }
| b_expr IS DISTINCT FROM b_expr %prec IS
{
- $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5);
+ $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
}
| b_expr IS NOT DISTINCT FROM b_expr %prec IS
{
$$ = (Node *) makeA_Expr(AEXPR_NOT, NIL,
- NULL, (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $6));
+ NULL, (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $6, @2), @2);
}
| b_expr IS OF '(' type_list ')' %prec IS
{
- $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "=", $1, (Node *) $5);
+ $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "=", $1, (Node *) $5, @2);
}
| b_expr IS NOT OF '(' type_list ')' %prec IS
{
- $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "<>", $1, (Node *) $6);
+ $$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "<>", $1, (Node *) $6, @2);
}
;
n->args = NIL;
n->agg_star = FALSE;
n->agg_distinct = FALSE;
+ n->location = @1;
$$ = (Node *)n;
}
| func_name '(' expr_list ')'
n->args = $3;
n->agg_star = FALSE;
n->agg_distinct = FALSE;
+ n->location = @1;
$$ = (Node *)n;
}
| func_name '(' ALL expr_list ')'
* "must be an aggregate", but there's no provision
* for that in FuncCall at the moment.
*/
+ n->location = @1;
$$ = (Node *)n;
}
| func_name '(' DISTINCT expr_list ')'
n->args = $4;
n->agg_star = FALSE;
n->agg_distinct = TRUE;
+ n->location = @1;
$$ = (Node *)n;
}
| func_name '(' '*' ')'
n->args = list_make1(star);
n->agg_star = TRUE;
n->agg_distinct = FALSE;
+ n->location = @1;
$$ = (Node *)n;
}
| CURRENT_DATE
n->args = NIL;
n->agg_star = FALSE;
n->agg_distinct = FALSE;
+ n->location = @1;
$$ = (Node *)n;
}
| CURRENT_TIMESTAMP '(' Iconst ')'
n->args = NIL;
n->agg_star = FALSE;
n->agg_distinct = FALSE;
+ n->location = @1;
$$ = (Node *)n;
}
| CURRENT_USER
n->args = NIL;
n->agg_star = FALSE;
n->agg_distinct = FALSE;
+ n->location = @1;
$$ = (Node *)n;
}
| SESSION_USER
n->args = NIL;
n->agg_star = FALSE;
n->agg_distinct = FALSE;
+ n->location = @1;
$$ = (Node *)n;
}
| USER
n->args = NIL;
n->agg_star = FALSE;
n->agg_distinct = FALSE;
+ n->location = @1;
$$ = (Node *)n;
}
| CAST '(' a_expr AS Typename ')'
n->args = $3;
n->agg_star = FALSE;
n->agg_distinct = FALSE;
+ n->location = @1;
$$ = (Node *)n;
}
| OVERLAY '(' overlay_list ')'
n->args = $3;
n->agg_star = FALSE;
n->agg_distinct = FALSE;
+ n->location = @1;
$$ = (Node *)n;
}
| POSITION '(' position_list ')'
n->args = $3;
n->agg_star = FALSE;
n->agg_distinct = FALSE;
+ n->location = @1;
$$ = (Node *)n;
}
| SUBSTRING '(' substr_list ')'
n->args = $3;
n->agg_star = FALSE;
n->agg_distinct = FALSE;
+ n->location = @1;
$$ = (Node *)n;
}
| TREAT '(' a_expr AS Typename ')'
* which is defined to be a subtype of the original expression.
* In SQL99, this is intended for use with structured UDTs,
* but let's make this a generally useful form allowing stronger
- * coersions than are handled by implicit casting.
+ * coercions than are handled by implicit casting.
*/
FuncCall *n = makeNode(FuncCall);
/* Convert SystemTypeName() to SystemFuncName() even though
*/
n->funcname = SystemFuncName(((Value *)llast($5->names))->val.str);
n->args = list_make1($3);
+ n->agg_star = FALSE;
+ n->agg_distinct = FALSE;
+ n->location = @1;
$$ = (Node *)n;
}
| TRIM '(' BOTH trim_list ')'
n->args = $4;
n->agg_star = FALSE;
n->agg_distinct = FALSE;
+ n->location = @1;
$$ = (Node *)n;
}
| TRIM '(' LEADING trim_list ')'
n->args = $4;
n->agg_star = FALSE;
n->agg_distinct = FALSE;
+ n->location = @1;
$$ = (Node *)n;
}
| TRIM '(' TRAILING trim_list ')'
n->args = $4;
n->agg_star = FALSE;
n->agg_distinct = FALSE;
+ n->location = @1;
$$ = (Node *)n;
}
| TRIM '(' trim_list ')'
n->args = $3;
n->agg_star = FALSE;
n->agg_distinct = FALSE;
+ n->location = @1;
$$ = (Node *)n;
}
| CONVERT '(' a_expr USING any_name ')'
n->args = list_make2($3, c);
n->agg_star = FALSE;
n->agg_distinct = FALSE;
+ n->location = @1;
$$ = (Node *)n;
}
| CONVERT '(' expr_list ')'
n->args = $3;
n->agg_star = FALSE;
n->agg_distinct = FALSE;
+ n->location = @1;
$$ = (Node *)n;
}
| NULLIF '(' a_expr ',' a_expr ')'
{
- $$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF, "=", $3, $5);
+ $$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF, "=", $3, $5, @1);
}
| COALESCE '(' expr_list ')'
{
*/
columnref: relation_name
{
- $$ = makeColumnRef($1, NIL);
+ $$ = makeColumnRef($1, NIL, @1);
}
| relation_name indirection
{
- $$ = makeColumnRef($1, $2);
+ $$ = makeColumnRef($1, $2, @1);
}
;
{
ColumnRef *n = makeNode(ColumnRef);
n->fields = list_make1(makeString("*"));
+ n->location = @1;
$$ = makeNode(ResTarget);
$$->name = NULL;
%%
static Node *
-makeColumnRef(char *relname, List *indirection)
+makeColumnRef(char *relname, List *indirection, int location)
{
/*
* Generate a ColumnRef node, with an A_Indirection node added if there
int nfields = 0;
ListCell *l;
+ c->location = location;
foreach(l, indirection)
{
if (IsA(lfirst(l), A_Indices))
if (result == NULL)
result = (Node *) n;
else if (test == IS_NOT_NULL)
- result = (Node *) makeA_Expr(AEXPR_OR, NIL, result, (Node *)n);
+ result = (Node *) makeA_Expr(AEXPR_OR, NIL, result, (Node *)n, -1);
else
- result = (Node *) makeA_Expr(AEXPR_AND, NIL, result, (Node *)n);
+ result = (Node *) makeA_Expr(AEXPR_AND, NIL, result, (Node *)n, -1);
}
if (result == NULL)
* Create and populate a FuncCall node to support the OVERLAPS operator.
*/
static FuncCall *
-makeOverlaps(List *largs, List *rargs)
+makeOverlaps(List *largs, List *rargs, int location)
{
FuncCall *n = makeNode(FuncCall);
+
n->funcname = SystemFuncName("overlaps");
if (list_length(largs) == 1)
largs = lappend(largs, largs);
n->args = list_concat(largs, rargs);
n->agg_star = FALSE;
n->agg_distinct = FALSE;
+ n->location = location;
return n;
}
n->names = list_make2(makeString("pg_catalog"), makeString(name));
n->typmod = -1;
+ n->location = -1;
return n;
}
* until we know what the desired type is.
*/
static Node *
-doNegate(Node *n)
+doNegate(Node *n, int location)
{
if (IsA(n, A_Const))
{
}
}
- return (Node *) makeSimpleA_Expr(AEXPR_OP, "-", NULL, n);
+ return (Node *) makeSimpleA_Expr(AEXPR_OP, "-", NULL, n, location);
}
static void
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/parser/parse_clause.c,v 1.147 2006/03/05 21:34:34 neilc Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/parse_clause.c,v 1.148 2006/03/14 22:48:20 tgl Exp $
*
*-------------------------------------------------------------------------
*/
Node *rvar = (Node *) lfirst(rvars);
A_Expr *e;
- e = makeSimpleA_Expr(AEXPR_OP, "=", copyObject(lvar), copyObject(rvar));
+ e = makeSimpleA_Expr(AEXPR_OP, "=",
+ copyObject(lvar), copyObject(rvar),
+ -1);
if (result == NULL)
result = (Node *) e;
{
A_Expr *a;
- a = makeA_Expr(AEXPR_AND, NIL, result, (Node *) e);
+ a = makeA_Expr(AEXPR_AND, NIL, result, (Node *) e, -1);
result = (Node *) a;
}
}
list_length(((ColumnRef *) node)->fields) == 1)
{
char *name = strVal(linitial(((ColumnRef *) node)->fields));
+ int location = ((ColumnRef *) node)->location;
if (clause == GROUP_CLAUSE)
{
* breaks no cases that are legal per spec, and it seems a more
* self-consistent behavior.
*/
- if (colNameToVar(pstate, name, true) != NULL)
+ if (colNameToVar(pstate, name, true, location) != NULL)
name = NULL;
}
* construct, eg ORDER BY
*/
errmsg("%s \"%s\" is ambiguous",
- clauseText[clause], name)));
+ clauseText[clause], name),
+ parser_errposition(pstate, location)));
}
else
target_result = tle;
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/parser/parse_expr.c,v 1.190 2006/03/05 15:58:33 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/parse_expr.c,v 1.191 2006/03/14 22:48:21 tgl Exp $
*
*-------------------------------------------------------------------------
*/
static Node *transformBooleanTest(ParseState *pstate, BooleanTest *b);
static Node *transformColumnRef(ParseState *pstate, ColumnRef *cref);
static Node *transformWholeRowRef(ParseState *pstate, char *schemaname,
- char *relname);
+ char *relname, int location);
static Node *transformBooleanTest(ParseState *pstate, BooleanTest *b);
static Node *transformIndirection(ParseState *pstate, Node *basenode,
List *indirection);
static Node *typecast_expression(ParseState *pstate, Node *expr,
TypeName *typename);
static Node *make_row_comparison_op(ParseState *pstate, List *opname,
- List *largs, List *rargs);
+ List *largs, List *rargs, int location);
static Node *make_row_distinct_op(ParseState *pstate, List *opname,
- RowExpr *lrow, RowExpr *rrow);
+ RowExpr *lrow, RowExpr *rrow, int location);
static Expr *make_distinct_op(ParseState *pstate, List *opname,
- Node *ltree, Node *rtree);
+ Node *ltree, Node *rtree, int location);
/*
result = ParseFuncOrColumn(pstate,
list_make1(n),
list_make1(result),
- false, false, true);
+ false, false, true,
+ -1);
}
}
/* process trailing subscripts, if any */
char *name = strVal(linitial(cref->fields));
/* Try to identify as an unqualified column */
- node = colNameToVar(pstate, name, false);
+ node = colNameToVar(pstate, name, false, cref->location);
if (node == NULL)
{
*/
if (refnameRangeTblEntry(pstate, NULL, name,
&levels_up) != NULL)
- node = transformWholeRowRef(pstate, NULL, name);
+ node = transformWholeRowRef(pstate, NULL, name,
+ cref->location);
else
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_COLUMN),
errmsg("column \"%s\" does not exist",
- name)));
+ name),
+ parser_errposition(pstate, cref->location)));
}
break;
}
/* Whole-row reference? */
if (strcmp(name2, "*") == 0)
{
- node = transformWholeRowRef(pstate, NULL, name1);
+ node = transformWholeRowRef(pstate, NULL, name1,
+ cref->location);
break;
}
/* Try to identify as a once-qualified column */
- node = qualifiedNameToVar(pstate, NULL, name1, name2, true);
+ node = qualifiedNameToVar(pstate, NULL, name1, name2, true,
+ cref->location);
if (node == NULL)
{
/*
* it as a function call. Here, we will create an
* implicit RTE for tables not already entered.
*/
- node = transformWholeRowRef(pstate, NULL, name1);
+ node = transformWholeRowRef(pstate, NULL, name1,
+ cref->location);
node = ParseFuncOrColumn(pstate,
list_make1(makeString(name2)),
list_make1(node),
- false, false, true);
+ false, false, true,
+ cref->location);
}
break;
}
/* Whole-row reference? */
if (strcmp(name3, "*") == 0)
{
- node = transformWholeRowRef(pstate, name1, name2);
+ node = transformWholeRowRef(pstate, name1, name2,
+ cref->location);
break;
}
/* Try to identify as a twice-qualified column */
- node = qualifiedNameToVar(pstate, name1, name2, name3, true);
+ node = qualifiedNameToVar(pstate, name1, name2, name3, true,
+ cref->location);
if (node == NULL)
{
/* Try it as a function call */
- node = transformWholeRowRef(pstate, name1, name2);
+ node = transformWholeRowRef(pstate, name1, name2,
+ cref->location);
node = ParseFuncOrColumn(pstate,
list_make1(makeString(name3)),
list_make1(node),
- false, false, true);
+ false, false, true,
+ cref->location);
}
break;
}
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cross-database references are not implemented: %s",
- NameListToString(cref->fields))));
+ NameListToString(cref->fields)),
+ parser_errposition(pstate, cref->location)));
/* Whole-row reference? */
if (strcmp(name4, "*") == 0)
{
- node = transformWholeRowRef(pstate, name2, name3);
+ node = transformWholeRowRef(pstate, name2, name3,
+ cref->location);
break;
}
/* Try to identify as a twice-qualified column */
- node = qualifiedNameToVar(pstate, name2, name3, name4, true);
+ node = qualifiedNameToVar(pstate, name2, name3, name4, true,
+ cref->location);
if (node == NULL)
{
/* Try it as a function call */
- node = transformWholeRowRef(pstate, name2, name3);
+ node = transformWholeRowRef(pstate, name2, name3,
+ cref->location);
node = ParseFuncOrColumn(pstate,
list_make1(makeString(name4)),
list_make1(node),
- false, false, true);
+ false, false, true,
+ cref->location);
}
break;
}
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("improper qualified name (too many dotted names): %s",
- NameListToString(cref->fields))));
+ NameListToString(cref->fields)),
+ parser_errposition(pstate, cref->location)));
node = NULL; /* keep compiler quiet */
break;
}
result = make_row_comparison_op(pstate,
a->name,
((RowExpr *) lexpr)->args,
- ((RowExpr *) rexpr)->args);
+ ((RowExpr *) rexpr)->args,
+ a->location);
}
else
{
result = (Node *) make_op(pstate,
a->name,
lexpr,
- rexpr);
+ rexpr,
+ a->location);
}
return result;
a->name,
true,
lexpr,
- rexpr);
+ rexpr,
+ a->location);
}
static Node *
a->name,
false,
lexpr,
- rexpr);
+ rexpr,
+ a->location);
}
static Node *
/* "row op row" */
return make_row_distinct_op(pstate, a->name,
(RowExpr *) lexpr,
- (RowExpr *) rexpr);
+ (RowExpr *) rexpr,
+ a->location);
}
else
{
return (Node *) make_distinct_op(pstate,
a->name,
lexpr,
- rexpr);
+ rexpr,
+ a->location);
}
}
result = (Node *) make_op(pstate,
a->name,
lexpr,
- rexpr);
+ rexpr,
+ a->location);
if (((OpExpr *) result)->opresulttype != BOOLOID)
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
- errmsg("NULLIF requires = operator to yield boolean")));
+ errmsg("NULLIF requires = operator to yield boolean"),
+ parser_errposition(pstate, a->location)));
/*
* We rely on NullIfExpr and OpExpr being the same struct
ltype = exprType(lexpr);
foreach(telem, (List *) a->rexpr)
{
- rtype = LookupTypeName(lfirst(telem));
+ rtype = typenameTypeId(pstate, lfirst(telem));
matched = (rtype == ltype);
if (matched)
break;
a->name,
useOr,
lexpr,
- (Node *) newa);
+ (Node *) newa,
+ a->location);
}
}
!IsA(rexpr, RowExpr))
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
- errmsg("arguments of row IN must all be row expressions")));
+ errmsg("arguments of row IN must all be row expressions"),
+ parser_errposition(pstate, a->location)));
cmp = make_row_comparison_op(pstate,
a->name,
(List *) copyObject(((RowExpr *) lexpr)->args),
- ((RowExpr *) rexpr)->args);
+ ((RowExpr *) rexpr)->args,
+ a->location);
}
else
cmp = (Node *) make_op(pstate,
a->name,
copyObject(lexpr),
- rexpr);
+ rexpr,
+ a->location);
cmp = coerce_to_boolean(pstate, cmp, "IN");
if (result == NULL)
targs,
fn->agg_star,
fn->agg_distinct,
- false);
+ false,
+ fn->location);
}
static Node *
/* shorthand form was specified, so expand... */
warg = (Node *) makeSimpleA_Expr(AEXPR_OP, "=",
(Node *) placeholder,
- warg);
+ warg,
+ -1);
}
neww->expr = (Expr *) transformExpr(pstate, warg);
sublink->testexpr = make_row_comparison_op(pstate,
sublink->operName,
left_list,
- right_list);
+ right_list,
+ -1);
}
return result;
* a rowtype; either a named composite type, or RECORD.
*/
static Node *
-transformWholeRowRef(ParseState *pstate, char *schemaname, char *relname)
+transformWholeRowRef(ParseState *pstate, char *schemaname, char *relname,
+ int location)
{
Node *result;
RangeTblEntry *rte;
&sublevels_up);
if (rte == NULL)
- rte = addImplicitRTE(pstate, makeRangeVar(schemaname, relname));
+ rte = addImplicitRTE(pstate, makeRangeVar(schemaname, relname),
+ location);
vnum = RTERangeTablePosn(pstate, rte, &sublevels_up);
Oid inputType = exprType(expr);
Oid targetType;
- targetType = typenameTypeId(typename);
+ targetType = typenameTypeId(pstate, typename);
if (inputType == InvalidOid)
return expr; /* do nothing if NULL input */
(errcode(ERRCODE_CANNOT_COERCE),
errmsg("cannot cast type %s to %s",
format_type_be(inputType),
- format_type_be(targetType))));
+ format_type_be(targetType)),
+ parser_errposition(pstate, typename->location)));
return expr;
}
*/
static Node *
make_row_comparison_op(ParseState *pstate, List *opname,
- List *largs, List *rargs)
+ List *largs, List *rargs, int location)
{
RowCompareExpr *rcexpr;
RowCompareType rctype;
if (nopers != list_length(rargs))
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
- errmsg("unequal number of entries in row expressions")));
+ errmsg("unequal number of entries in row expressions"),
+ parser_errposition(pstate, location)));
/*
* We can't compare zero-length rows because there is no principled
if (nopers == 0)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("cannot compare rows of zero length")));
+ errmsg("cannot compare rows of zero length"),
+ parser_errposition(pstate, location)));
/*
* Identify all the pairwise operators, using make_op so that
Node *rarg = (Node *) lfirst(r);
OpExpr *cmp;
- cmp = (OpExpr *) make_op(pstate, opname, larg, rarg);
+ cmp = (OpExpr *) make_op(pstate, opname, larg, rarg, location);
Assert(IsA(cmp, OpExpr));
/*
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("row comparison operator must yield type boolean, "
"not type %s",
- format_type_be(cmp->opresulttype))));
+ format_type_be(cmp->opresulttype)),
+ parser_errposition(pstate, location)));
if (expression_returns_set((Node *) cmp))
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
- errmsg("row comparison operator must not return a set")));
+ errmsg("row comparison operator must not return a set"),
+ parser_errposition(pstate, location)));
opexprs = lappend(opexprs, cmp);
}
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("could not determine interpretation of row comparison operator %s",
strVal(llast(opname))),
- errhint("Row comparison operators must be associated with btree operator classes.")));
+ errhint("Row comparison operators must be associated with btree operator classes."),
+ parser_errposition(pstate, location)));
rctype = 0; /* keep compiler quiet */
break;
case BMS_SINGLETON:
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("could not determine interpretation of row comparison operator %s",
strVal(llast(opname))),
- errdetail("There are multiple equally-plausible candidates.")));
+ errdetail("There are multiple equally-plausible candidates."),
+ parser_errposition(pstate, location)));
break;
}
}
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("could not determine interpretation of row comparison operator %s",
strVal(llast(opname))),
- errdetail("There are multiple equally-plausible candidates.")));
+ errdetail("There are multiple equally-plausible candidates."),
+ parser_errposition(pstate, location)));
}
/*
*/
static Node *
make_row_distinct_op(ParseState *pstate, List *opname,
- RowExpr *lrow, RowExpr *rrow)
+ RowExpr *lrow, RowExpr *rrow,
+ int location)
{
Node *result = NULL;
List *largs = lrow->args;
if (list_length(largs) != list_length(rargs))
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
- errmsg("unequal number of entries in row expressions")));
+ errmsg("unequal number of entries in row expressions"),
+ parser_errposition(pstate, location)));
forboth(l, largs, r, rargs)
{
Node *rarg = (Node *) lfirst(r);
Node *cmp;
- cmp = (Node *) make_distinct_op(pstate, opname, larg, rarg);
+ cmp = (Node *) make_distinct_op(pstate, opname, larg, rarg, location);
if (result == NULL)
result = cmp;
else
* make the node for an IS DISTINCT FROM operator
*/
static Expr *
-make_distinct_op(ParseState *pstate, List *opname, Node *ltree, Node *rtree)
+make_distinct_op(ParseState *pstate, List *opname, Node *ltree, Node *rtree,
+ int location)
{
Expr *result;
- result = make_op(pstate, opname, ltree, rtree);
+ result = make_op(pstate, opname, ltree, rtree, location);
if (((OpExpr *) result)->opresulttype != BOOLOID)
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
- errmsg("IS DISTINCT FROM requires = operator to yield boolean")));
+ errmsg("IS DISTINCT FROM requires = operator to yield boolean"),
+ parser_errposition(pstate, location)));
/*
* We rely on DistinctExpr and OpExpr being same struct
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/parser/parse_func.c,v 1.184 2006/03/05 15:58:33 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/parse_func.c,v 1.185 2006/03/14 22:48:21 tgl Exp $
*
*-------------------------------------------------------------------------
*/
static Node *ParseComplexProjection(ParseState *pstate, char *funcname,
- Node *first_arg);
-static void unknown_attribute(ParseState *pstate, Node *relref, char *attname);
+ Node *first_arg, int location);
+static void unknown_attribute(ParseState *pstate, Node *relref, char *attname,
+ int location);
/*
*/
Node *
ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs,
- bool agg_star, bool agg_distinct, bool is_column)
+ bool agg_star, bool agg_distinct, bool is_column,
+ int location)
{
Oid rettype;
Oid funcid;
ereport(ERROR,
(errcode(ERRCODE_TOO_MANY_ARGUMENTS),
errmsg("cannot pass more than %d arguments to a function",
- FUNC_MAX_ARGS)));
+ FUNC_MAX_ARGS),
+ parser_errposition(pstate, location)));
/*
* Extract arg type info in preparation for function lookup.
{
retval = ParseComplexProjection(pstate,
strVal(linitial(funcname)),
- first_arg);
+ first_arg,
+ location);
if (retval)
return retval;
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("%s(*) specified, but %s is not an aggregate function",
NameListToString(funcname),
- NameListToString(funcname))));
+ NameListToString(funcname)),
+ parser_errposition(pstate, location)));
if (agg_distinct)
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("DISTINCT specified, but %s is not an aggregate function",
- NameListToString(funcname))));
+ NameListToString(funcname)),
+ parser_errposition(pstate, location)));
}
else if (fdresult != FUNCDETAIL_AGGREGATE)
{
{
Assert(nargs == 1);
Assert(list_length(funcname) == 1);
- unknown_attribute(pstate, first_arg, strVal(linitial(funcname)));
+ unknown_attribute(pstate, first_arg, strVal(linitial(funcname)),
+ location);
}
/*
func_signature_string(funcname, nargs,
actual_arg_types)),
errhint("Could not choose a best candidate function. "
- "You may need to add explicit type casts.")));
+ "You may need to add explicit type casts."),
+ parser_errposition(pstate, location)));
else
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_FUNCTION),
func_signature_string(funcname, nargs,
actual_arg_types)),
errhint("No function matches the given name and argument types. "
- "You may need to add explicit type casts.")));
+ "You may need to add explicit type casts."),
+ parser_errposition(pstate, location)));
}
/*
if (retset)
ereport(ERROR,
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
- errmsg("aggregates may not return sets")));
+ errmsg("aggregates may not return sets"),
+ parser_errposition(pstate, location)));
}
return retval;
if (nargs == 1 && fargs != NIL)
{
Oid targetType;
- TypeName *tn = makeNode(TypeName);
- tn->names = funcname;
- tn->typmod = -1;
- targetType = LookupTypeName(tn);
+ targetType = LookupTypeName(NULL,
+ makeTypeNameFromNameList(funcname));
if (OidIsValid(targetType) &&
!ISCOMPLEX(targetType))
{
* transformed expression tree. If not, return NULL.
*/
static Node *
-ParseComplexProjection(ParseState *pstate, char *funcname, Node *first_arg)
+ParseComplexProjection(ParseState *pstate, char *funcname, Node *first_arg,
+ int location)
{
TupleDesc tupdesc;
int i;
((Var *) first_arg)->varno,
((Var *) first_arg)->varlevelsup);
/* Return a Var if funcname matches a column, else NULL */
- return scanRTEForColumn(pstate, rte, funcname);
+ return scanRTEForColumn(pstate, rte, funcname, location);
}
/*
* helper routine for delivering "column does not exist" error message
*/
static void
-unknown_attribute(ParseState *pstate, Node *relref, char *attname)
+unknown_attribute(ParseState *pstate, Node *relref, char *attname,
+ int location)
{
RangeTblEntry *rte;
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_COLUMN),
errmsg("column %s.%s does not exist",
- rte->eref->aliasname, attname)));
+ rte->eref->aliasname, attname),
+ parser_errposition(pstate, location)));
}
else
{
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_COLUMN),
errmsg("column \"%s\" not found in data type %s",
- attname, format_type_be(relTypeId))));
+ attname, format_type_be(relTypeId)),
+ parser_errposition(pstate, location)));
else if (relTypeId == RECORDOID)
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_COLUMN),
errmsg("could not identify column \"%s\" in record data type",
- attname)));
+ attname),
+ parser_errposition(pstate, location)));
else
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("column notation .%s applied to type %s, "
"which is not a composite type",
- attname, format_type_be(relTypeId))));
+ attname, format_type_be(relTypeId)),
+ parser_errposition(pstate, location)));
}
}
{
TypeName *t = (TypeName *) lfirst(args_item);
- argoids[i] = LookupTypeName(t);
+ argoids[i] = LookupTypeName(NULL, t);
if (!OidIsValid(argoids[i]))
ereport(ERROR,
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/parser/parse_node.c,v 1.91 2006/03/05 15:58:34 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/parse_node.c,v 1.92 2006/03/14 22:48:21 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "catalog/pg_type.h"
+#include "mb/pg_wchar.h"
#include "nodes/makefuncs.h"
#include "parser/parsetree.h"
#include "parser/parse_coerce.h"
pstate->p_next_resno = 1;
if (parentParseState)
+ {
+ pstate->p_sourcetext = parentParseState->p_sourcetext;
pstate->p_variableparams = parentParseState->p_variableparams;
+ }
return pstate;
}
+/*
+ * parser_errposition
+ * Report a parse-analysis-time cursor position, if possible.
+ *
+ * This is expected to be used within an ereport() call. The return value
+ * is a dummy (always 0, in fact).
+ *
+ * The locations stored in raw parsetrees are byte offsets into the source
+ * string. We have to convert them to 1-based character indexes for reporting
+ * to clients. (We do things this way to avoid unnecessary overhead in the
+ * normal non-error case: computing character indexes would be much more
+ * expensive than storing token offsets.)
+ */
+int
+parser_errposition(ParseState *pstate, int location)
+{
+ int pos;
+
+ /* No-op if location was not provided */
+ if (location < 0)
+ return 0;
+ /* Can't do anything if source text is not available */
+ if (pstate == NULL || pstate->p_sourcetext == NULL)
+ return 0;
+ /* Convert offset to character number */
+ pos = pg_mbstrlen_with_len(pstate->p_sourcetext, location) + 1;
+ /* And pass it to the ereport mechanism */
+ return errposition(pos);
+}
+
+
/*
* make_var
* Build a Var node for an attribute identified by RTE and attrno
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/parser/parse_oper.c,v 1.85 2006/03/05 15:58:34 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/parse_oper.c,v 1.86 2006/03/14 22:48:21 tgl Exp $
*
*-------------------------------------------------------------------------
*/
Oid *operOid);
static const char *op_signature_string(List *op, char oprkind,
Oid arg1, Oid arg2);
-static void op_error(List *op, char oprkind, Oid arg1, Oid arg2,
- FuncDetailCode fdresult);
+static void op_error(ParseState *pstate, List *op, char oprkind,
+ Oid arg1, Oid arg2,
+ FuncDetailCode fdresult, int location);
static Expr *make_op_expr(ParseState *pstate, Operator op,
Node *ltree, Node *rtree,
Oid ltypeId, Oid rtypeId);
* namespace search path.
*
* If the operator is not found, we return InvalidOid if noError is true,
- * else raise an error.
+ * else raise an error. pstate and location are used only to report the
+ * error position; pass NULL/-1 if not available.
*/
Oid
-LookupOperName(List *opername, Oid oprleft, Oid oprright, bool noError)
+LookupOperName(ParseState *pstate, List *opername, Oid oprleft, Oid oprright,
+ bool noError, int location)
{
FuncCandidateList clist;
char oprkind;
(errcode(ERRCODE_UNDEFINED_FUNCTION),
errmsg("operator does not exist: %s",
op_signature_string(opername, oprkind,
- oprleft, oprright))));
+ oprleft, oprright)),
+ parser_errposition(pstate, location)));
return InvalidOid;
}
* Pass oprleft = NULL for a prefix op, oprright = NULL for a postfix op.
*/
Oid
-LookupOperNameTypeNames(List *opername, TypeName *oprleft,
- TypeName *oprright, bool noError)
+LookupOperNameTypeNames(ParseState *pstate, List *opername,
+ TypeName *oprleft, TypeName *oprright,
+ bool noError, int location)
{
Oid leftoid,
rightoid;
if (oprleft == NULL)
leftoid = InvalidOid;
else
- {
- leftoid = LookupTypeName(oprleft);
- if (!OidIsValid(leftoid))
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_OBJECT),
- errmsg("type %s does not exist",
- TypeNameToString(oprleft))));
- }
+ leftoid = typenameTypeId(pstate, oprleft);
+
if (oprright == NULL)
rightoid = InvalidOid;
else
- {
- rightoid = LookupTypeName(oprright);
- if (!OidIsValid(rightoid))
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_OBJECT),
- errmsg("type %s does not exist",
- TypeNameToString(oprright))));
- }
+ rightoid = typenameTypeId(pstate, oprright);
- return LookupOperName(opername, leftoid, rightoid, noError);
+ return LookupOperName(pstate, opername, leftoid, rightoid,
+ noError, location);
}
/*
* you need an exact- or binary-compatible match; see compatible_oper.
*
* If no matching operator found, return NULL if noError is true,
- * raise an error if it is false.
+ * raise an error if it is false. pstate and location are used only to report
+ * the error position; pass NULL/-1 if not available.
*
* NOTE: on success, the returned object is a syscache entry. The caller
* must ReleaseSysCache() the entry when done with it.
*/
Operator
-oper(List *opname, Oid ltypeId, Oid rtypeId, bool noError)
+oper(ParseState *pstate, List *opname, Oid ltypeId, Oid rtypeId,
+ bool noError, int location)
{
FuncCandidateList clist;
Oid inputOids[2];
}
if (!HeapTupleIsValid(tup) && !noError)
- op_error(opname, 'b', ltypeId, rtypeId, fdresult);
+ op_error(pstate, opname, 'b', ltypeId, rtypeId, fdresult, location);
return (Operator) tup;
}
* are accepted). Otherwise, the semantics are the same.
*/
Operator
-compatible_oper(List *op, Oid arg1, Oid arg2, bool noError)
+compatible_oper(ParseState *pstate, List *op, Oid arg1, Oid arg2,
+ bool noError, int location)
{
Operator optup;
Form_pg_operator opform;
/* oper() will find the best available match */
- optup = oper(op, arg1, arg2, noError);
+ optup = oper(pstate, op, arg1, arg2, noError, location);
if (optup == (Operator) NULL)
return (Operator) NULL; /* must be noError case */
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_FUNCTION),
errmsg("operator requires run-time type coercion: %s",
- op_signature_string(op, 'b', arg1, arg2))));
+ op_signature_string(op, 'b', arg1, arg2)),
+ parser_errposition(pstate, location)));
return (Operator) NULL;
}
Operator optup;
Oid result;
- optup = compatible_oper(op, arg1, arg2, noError);
+ optup = compatible_oper(NULL, op, arg1, arg2, noError, -1);
if (optup != NULL)
{
result = oprid(optup);
* you need an exact- or binary-compatible match.
*
* If no matching operator found, return NULL if noError is true,
- * raise an error if it is false.
+ * raise an error if it is false. pstate and location are used only to report
+ * the error position; pass NULL/-1 if not available.
*
* NOTE: on success, the returned object is a syscache entry. The caller
* must ReleaseSysCache() the entry when done with it.
*/
Operator
-right_oper(List *op, Oid arg, bool noError)
+right_oper(ParseState *pstate, List *op, Oid arg, bool noError, int location)
{
FuncCandidateList clist;
Oid operOid = InvalidOid;
}
if (!HeapTupleIsValid(tup) && !noError)
- op_error(op, 'r', arg, InvalidOid, fdresult);
+ op_error(pstate, op, 'r', arg, InvalidOid, fdresult, location);
return (Operator) tup;
}
* you need an exact- or binary-compatible match.
*
* If no matching operator found, return NULL if noError is true,
- * raise an error if it is false.
+ * raise an error if it is false. pstate and location are used only to report
+ * the error position; pass NULL/-1 if not available.
*
* NOTE: on success, the returned object is a syscache entry. The caller
* must ReleaseSysCache() the entry when done with it.
*/
Operator
-left_oper(List *op, Oid arg, bool noError)
+left_oper(ParseState *pstate, List *op, Oid arg, bool noError, int location)
{
FuncCandidateList clist;
Oid operOid = InvalidOid;
}
if (!HeapTupleIsValid(tup) && !noError)
- op_error(op, 'l', InvalidOid, arg, fdresult);
+ op_error(pstate, op, 'l', InvalidOid, arg, fdresult, location);
return (Operator) tup;
}
* op_error - utility routine to complain about an unresolvable operator
*/
static void
-op_error(List *op, char oprkind, Oid arg1, Oid arg2, FuncDetailCode fdresult)
+op_error(ParseState *pstate, List *op, char oprkind,
+ Oid arg1, Oid arg2,
+ FuncDetailCode fdresult, int location)
{
if (fdresult == FUNCDETAIL_MULTIPLE)
ereport(ERROR,
errmsg("operator is not unique: %s",
op_signature_string(op, oprkind, arg1, arg2)),
errhint("Could not choose a best candidate operator. "
- "You may need to add explicit type casts.")));
+ "You may need to add explicit type casts."),
+ parser_errposition(pstate, location)));
else
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_FUNCTION),
errmsg("operator does not exist: %s",
op_signature_string(op, oprkind, arg1, arg2)),
errhint("No operator matches the given name and argument type(s). "
- "You may need to add explicit type casts.")));
+ "You may need to add explicit type casts."),
+ parser_errposition(pstate, location)));
}
/*
* processing is wanted.
*/
Expr *
-make_op(ParseState *pstate, List *opname, Node *ltree, Node *rtree)
+make_op(ParseState *pstate, List *opname, Node *ltree, Node *rtree,
+ int location)
{
Oid ltypeId,
rtypeId;
/* right operator */
ltypeId = exprType(ltree);
rtypeId = InvalidOid;
- tup = right_oper(opname, ltypeId, false);
+ tup = right_oper(pstate, opname, ltypeId, false, location);
}
else if (ltree == NULL)
{
/* left operator */
rtypeId = exprType(rtree);
ltypeId = InvalidOid;
- tup = left_oper(opname, rtypeId, false);
+ tup = left_oper(pstate, opname, rtypeId, false, location);
}
else
{
/* otherwise, binary operator */
ltypeId = exprType(ltree);
rtypeId = exprType(rtree);
- tup = oper(opname, ltypeId, rtypeId, false);
+ tup = oper(pstate, opname, ltypeId, rtypeId, false, location);
}
/* Do typecasting and build the expression tree */
Expr *
make_scalar_array_op(ParseState *pstate, List *opname,
bool useOr,
- Node *ltree, Node *rtree)
+ Node *ltree, Node *rtree,
+ int location)
{
Oid ltypeId,
rtypeId,
if (!OidIsValid(rtypeId))
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
- errmsg("op ANY/ALL (array) requires array on right side")));
+ errmsg("op ANY/ALL (array) requires array on right side"),
+ parser_errposition(pstate, location)));
}
/* Now resolve the operator */
- tup = oper(opname, ltypeId, rtypeId, false);
+ tup = oper(pstate, opname, ltypeId, rtypeId, false, location);
opform = (Form_pg_operator) GETSTRUCT(tup);
args = list_make2(ltree, rtree);
if (rettype != BOOLOID)
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
- errmsg("op ANY/ALL (array) requires operator to yield boolean")));
+ errmsg("op ANY/ALL (array) requires operator to yield boolean"),
+ parser_errposition(pstate, location)));
if (get_func_retset(opform->oprcode))
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
- errmsg("op ANY/ALL (array) requires operator not to return a set")));
+ errmsg("op ANY/ALL (array) requires operator not to return a set"),
+ parser_errposition(pstate, location)));
/*
* Now switch back to the array type on the right, arranging for any
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("could not find array type for data type %s",
- format_type_be(declared_arg_types[1]))));
+ format_type_be(declared_arg_types[1])),
+ parser_errposition(pstate, location)));
actual_arg_types[1] = atypeId;
declared_arg_types[1] = res_atypeId;
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/parser/parse_relation.c,v 1.119 2006/03/05 15:58:34 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/parse_relation.c,v 1.120 2006/03/14 22:48:21 tgl Exp $
*
*-------------------------------------------------------------------------
*/
bool include_dropped,
List **colnames, List **colvars);
static int specialAttNum(const char *attname);
-static void warnAutoRange(ParseState *pstate, RangeVar *relation);
+static void warnAutoRange(ParseState *pstate, RangeVar *relation,
+ int location);
/*
* FROM will be marked as requiring read access from the beginning.
*/
Node *
-scanRTEForColumn(ParseState *pstate, RangeTblEntry *rte, char *colname)
+scanRTEForColumn(ParseState *pstate, RangeTblEntry *rte, char *colname,
+ int location)
{
Node *result = NULL;
int attnum = 0;
ereport(ERROR,
(errcode(ERRCODE_AMBIGUOUS_COLUMN),
errmsg("column reference \"%s\" is ambiguous",
- colname)));
+ colname),
+ parser_errposition(pstate, location)));
result = (Node *) make_var(pstate, rte, attnum);
/* Require read access */
rte->requiredPerms |= ACL_SELECT;
* If localonly is true, only names in the innermost query are considered.
*/
Node *
-colNameToVar(ParseState *pstate, char *colname, bool localonly)
+colNameToVar(ParseState *pstate, char *colname, bool localonly,
+ int location)
{
Node *result = NULL;
ParseState *orig_pstate = pstate;
Node *newresult;
/* use orig_pstate here to get the right sublevels_up */
- newresult = scanRTEForColumn(orig_pstate, rte, colname);
+ newresult = scanRTEForColumn(orig_pstate, rte, colname, location);
if (newresult)
{
ereport(ERROR,
(errcode(ERRCODE_AMBIGUOUS_COLUMN),
errmsg("column reference \"%s\" is ambiguous",
- colname)));
+ colname),
+ parser_errposition(orig_pstate, location)));
result = newresult;
}
}
char *schemaname,
char *refname,
char *colname,
- bool implicitRTEOK)
+ bool implicitRTEOK,
+ int location)
{
RangeTblEntry *rte;
int sublevels_up;
{
if (!implicitRTEOK)
return NULL;
- rte = addImplicitRTE(pstate, makeRangeVar(schemaname, refname));
+ rte = addImplicitRTE(pstate, makeRangeVar(schemaname, refname),
+ location);
}
- return scanRTEForColumn(pstate, rte, colname);
+ return scanRTEForColumn(pstate, rte, colname, location);
}
/*
* a conflicting name.
*/
RangeTblEntry *
-addImplicitRTE(ParseState *pstate, RangeVar *relation)
+addImplicitRTE(ParseState *pstate, RangeVar *relation, int location)
{
RangeTblEntry *rte;
/* issue warning or error as needed */
- warnAutoRange(pstate, relation);
+ warnAutoRange(pstate, relation, location);
/*
* Note that we set inFromCl true, so that the RTE will be listed
* explicitly if the parsetree is ever decompiled by ruleutils.c. This
Var *varnode;
Oid atttypid;
- atttypid = typenameTypeId(colDef->typename);
+ atttypid = typenameTypeId(NULL, colDef->typename);
varnode = makeVar(rtindex,
attnum,
{
ColumnDef *colDef = list_nth(rte->coldeflist, attnum - 1);
- *vartype = typenameTypeId(colDef->typename);
+ *vartype = typenameTypeId(NULL, colDef->typename);
*vartypmod = colDef->typename->typmod;
}
else
* a warning.
*/
static void
-warnAutoRange(ParseState *pstate, RangeVar *relation)
+warnAutoRange(ParseState *pstate, RangeVar *relation, int location)
{
RangeTblEntry *rte;
int sublevels_up;
errhint("Perhaps you meant to reference the table alias \"%s\".",
badAlias) :
errhint("There is an entry for table \"%s\", but it cannot be referenced from this part of the query.",
- rte->eref->aliasname))));
+ rte->eref->aliasname)),
+ parser_errposition(pstate, location)));
else
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_TABLE),
errmsg("missing FROM-clause entry in subquery for table \"%s\"",
relation->relname) :
errmsg("missing FROM-clause entry for table \"%s\"",
- relation->relname))));
+ relation->relname)),
+ parser_errposition(pstate, location)));
}
else
{
badAlias) :
(rte ?
errhint("There is an entry for table \"%s\", but it cannot be referenced from this part of the query.",
- rte->eref->aliasname) : 0))));
+ rte->eref->aliasname) : 0)),
+ parser_errposition(pstate, location)));
}
}
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/parser/parse_target.c,v 1.140 2006/03/05 15:58:34 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/parse_target.c,v 1.141 2006/03/14 22:48:21 tgl Exp $
*
*-------------------------------------------------------------------------
*/
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cross-database references are not implemented: %s",
- NameListToString(fields))));
+ NameListToString(fields)),
+ parser_errposition(pstate, cref->location)));
schemaname = strVal(lsecond(fields));
relname = strVal(lthird(fields));
break;
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("improper qualified name (too many dotted names): %s",
- NameListToString(fields))));
+ NameListToString(fields)),
+ parser_errposition(pstate, cref->location)));
schemaname = NULL; /* keep compiler quiet */
relname = NULL;
break;
rte = refnameRangeTblEntry(pstate, schemaname, relname,
&sublevels_up);
if (rte == NULL)
- rte = addImplicitRTE(pstate, makeRangeVar(schemaname,
- relname));
+ rte = addImplicitRTE(pstate, makeRangeVar(schemaname, relname),
+ cref->location);
rtindex = RTERangeTablePosn(pstate, rte, &sublevels_up);
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/parser/parse_type.c,v 1.78 2006/03/05 15:58:34 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/parse_type.c,v 1.79 2006/03/14 22:48:21 tgl Exp $
*
*-------------------------------------------------------------------------
*/
*
* NB: even if the returned OID is not InvalidOid, the type might be
* just a shell. Caller should check typisdefined before using the type.
+ *
+ * pstate is only used for error location info, and may be NULL.
*/
Oid
-LookupTypeName(const TypeName *typename)
+LookupTypeName(ParseState *pstate, const TypeName *typename)
{
Oid restype;
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("improper %%TYPE reference (too few dotted names): %s",
- NameListToString(typename->names))));
+ NameListToString(typename->names)),
+ parser_errposition(pstate, typename->location)));
break;
case 2:
rel->relname = strVal(linitial(typename->names));
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("improper %%TYPE reference (too many dotted names): %s",
- NameListToString(typename->names))));
+ NameListToString(typename->names)),
+ parser_errposition(pstate, typename->location)));
break;
}
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_COLUMN),
errmsg("column \"%s\" of relation \"%s\" does not exist",
- field, rel->relname)));
+ field, rel->relname),
+ parser_errposition(pstate, typename->location)));
restype = get_atttype(relid, attnum);
/* this construct should never have an array indicator */
* a suitable error message if the type cannot be found or is not defined.
*/
Oid
-typenameTypeId(const TypeName *typename)
+typenameTypeId(ParseState *pstate, const TypeName *typename)
{
Oid typoid;
- typoid = LookupTypeName(typename);
+ typoid = LookupTypeName(pstate, typename);
if (!OidIsValid(typoid))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("type \"%s\" does not exist",
- TypeNameToString(typename))));
+ TypeNameToString(typename)),
+ parser_errposition(pstate, typename->location)));
+
if (!get_typisdefined(typoid))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("type \"%s\" is only a shell",
- TypeNameToString(typename))));
+ TypeNameToString(typename)),
+ parser_errposition(pstate, typename->location)));
return typoid;
}
* NB: caller must ReleaseSysCache the type tuple when done with it.
*/
Type
-typenameType(const TypeName *typename)
+typenameType(ParseState *pstate, const TypeName *typename)
{
Oid typoid;
HeapTuple tup;
- typoid = LookupTypeName(typename);
+ typoid = LookupTypeName(pstate, typename);
if (!OidIsValid(typoid))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("type \"%s\" does not exist",
- TypeNameToString(typename))));
+ TypeNameToString(typename)),
+ parser_errposition(pstate, typename->location)));
tup = SearchSysCache(TYPEOID,
ObjectIdGetDatum(typoid),
0, 0, 0);
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("type \"%s\" is only a shell",
- TypeNameToString(typename))));
+ TypeNameToString(typename)),
+ parser_errposition(pstate, typename->location)));
return (Type) tup;
}
if (typename->setof)
goto fail;
- *type_id = typenameTypeId(typename);
+ *type_id = typenameTypeId(NULL, typename);
*typmod = typename->typmod;
pfree(buf.data);
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/parser/scan.l,v 1.132 2006/03/07 01:00:17 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/scan.l,v 1.133 2006/03/14 22:48:21 tgl Exp $
*
*-------------------------------------------------------------------------
*/
static void addlit(char *ytext, int yleng);
static void addlitchar(unsigned char ychar);
static char *litbufdup(void);
-static int pg_err_position(void);
+
+static int lexer_errposition(void);
static void check_escape_warning(void);
static void check_string_escape_warning(unsigned char ychar);
/*
+ * Each call to yylex must set yylloc to the location of the found token
+ * (expressed as a byte offset from the start of the input text).
* When we parse a token that requires multiple lexer rules to process,
- * we set token_start to point at the true start of the token, for use
- * by yyerror(). yytext will point at just the text consumed by the last
- * rule, so it's not very helpful (e.g., it might contain just the last
- * quote mark of a quoted identifier). But to avoid cluttering every rule
- * with setting token_start, we allow token_start = NULL to denote that
- * it's okay to use yytext.
+ * this should be done in the first such rule, else yylloc will point
+ * into the middle of the token.
*/
-static char *token_start;
+#define SET_YYLLOC() (yylloc = yytext - scanbuf)
/* Handles to the buffer that the lexer uses internally */
static YY_BUFFER_STATE scanbufhandle;
%%
-%{
- /* code to execute during start of each call of yylex() */
- token_start = NULL;
-%}
-
{whitespace} {
/* ignore */
}
{xcstart} {
- token_start = yytext;
+ /* Set location in case of syntax error in comment */
+ SET_YYLLOC();
xcdepth = 0;
BEGIN(xc);
/* Put back any characters past slash-star; see above */
<xc>{xcstop} {
if (xcdepth <= 0)
- {
BEGIN(INITIAL);
- /* reset token_start for next token */
- token_start = NULL;
- }
else
xcdepth--;
}
* In the meantime, place a leading "b" on the string
* to mark it for the input routine as a binary string.
*/
- token_start = yytext;
+ SET_YYLLOC();
BEGIN(xb);
startlit();
addlitchar('b');
* In the meantime, place a leading "x" on the string
* to mark it for the input routine as a hex string.
*/
- token_start = yytext;
+ SET_YYLLOC();
BEGIN(xh);
startlit();
addlitchar('x');
*/
const ScanKeyword *keyword;
+ SET_YYLLOC();
yyless(1); /* eat only 'n' this time */
/* nchar had better be a keyword! */
keyword = ScanKeywordLookup("nchar");
{xqstart} {
warn_on_first_escape = true;
- token_start = yytext;
+ SET_YYLLOC();
if (standard_conforming_strings)
BEGIN(xq);
else
}
{xestart} {
warn_on_first_escape = false;
- token_start = yytext;
+ SET_YYLLOC();
BEGIN(xe);
startlit();
}
<xq,xe><<EOF>> { yyerror("unterminated quoted string"); }
{dolqdelim} {
- token_start = yytext;
+ SET_YYLLOC();
dolqstart = pstrdup(yytext);
BEGIN(xdolq);
startlit();
<xdolq><<EOF>> { yyerror("unterminated dollar-quoted string"); }
{xdstart} {
- token_start = yytext;
+ SET_YYLLOC();
BEGIN(xd);
startlit();
}
<xd><<EOF>> { yyerror("unterminated quoted identifier"); }
{typecast} {
+ SET_YYLLOC();
return TYPECAST;
}
{self} {
+ SET_YYLLOC();
return yytext[0];
}
nchars--; /* else remove the +/-, and check again */
}
+ SET_YYLLOC();
+
if (nchars < yyleng)
{
/* Strip the unwanted chars from the token */
}
{param} {
+ SET_YYLLOC();
yylval.ival = atol(yytext + 1);
return PARAM;
}
long val;
char* endptr;
+ SET_YYLLOC();
errno = 0;
val = strtol(yytext, &endptr, 10);
if (*endptr != '\0' || errno == ERANGE
return ICONST;
}
{decimal} {
+ SET_YYLLOC();
yylval.str = pstrdup(yytext);
return FCONST;
}
{real} {
+ SET_YYLLOC();
yylval.str = pstrdup(yytext);
return FCONST;
}
* syntax error anyway, we don't bother to distinguish.
*/
yyless(yyleng-1);
+ SET_YYLLOC();
yylval.str = pstrdup(yytext);
return FCONST;
}
{realfail2} {
/* throw back the [Ee][+-], and proceed as above */
yyless(yyleng-2);
+ SET_YYLLOC();
yylval.str = pstrdup(yytext);
return FCONST;
}
const ScanKeyword *keyword;
char *ident;
+ SET_YYLLOC();
+
/* Is it a keyword? */
keyword = ScanKeywordLookup(yytext);
if (keyword != NULL)
}
{other} {
+ SET_YYLLOC();
return yytext[0];
}
+<<EOF>> {
+ SET_YYLLOC();
+ yyterminate();
+ }
+
%%
+/*
+ * lexer_errposition
+ * Report a lexical-analysis-time cursor position, if possible.
+ *
+ * This is expected to be used within an ereport() call. The return value
+ * is a dummy (always 0, in fact).
+ *
+ * Note that this can only be used for messages from the lexer itself,
+ * since it depends on scanbuf to still be valid.
+ */
static int
-pg_err_position(void)
+lexer_errposition(void)
{
- const char *loc = token_start ? token_start : yytext;
+ int pos;
- /* in multibyte encodings, return index in characters not bytes */
- return pg_mbstrlen_with_len(scanbuf, loc - scanbuf) + 1;
+ /* Convert byte offset to character number */
+ pos = pg_mbstrlen_with_len(scanbuf, yylloc) + 1;
+ /* And pass it to the ereport mechanism */
+ return errposition(pos);
}
+/*
+ * yyerror
+ * Report a lexer or grammar error.
+ *
+ * The message's cursor position identifies the most recently lexed token.
+ * This is OK for syntax error messages from the Bison parser, because Bison
+ * parsers report error as soon as the first unparsable token is reached.
+ * Beware of using yyerror for other purposes, as the cursor position might
+ * be misleading!
+ */
void
yyerror(const char *message)
{
- const char *loc = token_start ? token_start : yytext;
- int cursorpos = pg_err_position();
+ const char *loc = scanbuf + yylloc;
if (*loc == YY_END_OF_BUFFER_CHAR)
{
(errcode(ERRCODE_SYNTAX_ERROR),
/* translator: %s is typically "syntax error" */
errmsg("%s at end of input", _(message)),
- errposition(cursorpos)));
+ lexer_errposition()));
}
else
{
(errcode(ERRCODE_SYNTAX_ERROR),
/* translator: first %s is typically "syntax error" */
errmsg("%s at or near \"%s\"", _(message), loc),
- errposition(cursorpos)));
+ lexer_errposition()));
}
}
(errcode(ERRCODE_NONSTANDARD_USE_OF_ESCAPE_CHARACTER),
errmsg("nonstandard use of \\' in a string literal"),
errhint("Use '' to write quotes in strings, or use the escape string syntax (E'...')."),
- errposition(pg_err_position())));
+ lexer_errposition()));
warn_on_first_escape = false; /* warn only once per string */
}
else if (ychar == '\\')
(errcode(ERRCODE_NONSTANDARD_USE_OF_ESCAPE_CHARACTER),
errmsg("nonstandard use of \\\\ in a string literal"),
errhint("Use the escape string syntax for backslashes, e.g., E'\\\\'."),
- errposition(pg_err_position())));
+ lexer_errposition()));
warn_on_first_escape = false; /* warn only once per string */
}
else
(errcode(ERRCODE_NONSTANDARD_USE_OF_ESCAPE_CHARACTER),
errmsg("nonstandard use of escape in a string literal"),
errhint("Use the escape string syntax for escapes, e.g., E'\\r\\n'."),
- errposition(pg_err_position())));
+ lexer_errposition()));
warn_on_first_escape = false; /* warn only once per string */
}
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.481 2006/03/05 15:58:40 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.482 2006/03/14 22:48:21 tgl Exp $
*
* NOTES
* this is the "main" module of the postgres backend and
querytree_list = list_concat(querytree_list,
pg_analyze_and_rewrite(parsetree,
+ query_string,
paramTypes,
numParams));
}
* NOTE: for reasons mentioned above, this must be separate from raw parsing.
*/
List *
-pg_analyze_and_rewrite(Node *parsetree, Oid *paramTypes, int numParams)
+pg_analyze_and_rewrite(Node *parsetree, const char *query_string,
+ Oid *paramTypes, int numParams)
{
List *querytree_list;
if (log_parser_stats)
ResetUsage();
- querytree_list = parse_analyze(parsetree, paramTypes, numParams);
+ querytree_list = parse_analyze(parsetree, query_string,
+ paramTypes, numParams);
if (log_parser_stats)
ShowUsage("PARSE ANALYSIS STATISTICS");
*/
oldcontext = MemoryContextSwitchTo(MessageContext);
- querytree_list = pg_analyze_and_rewrite(parsetree, NULL, 0);
+ querytree_list = pg_analyze_and_rewrite(parsetree, query_string,
+ NULL, 0);
plantree_list = pg_plan_queries(querytree_list, NULL, true);
ResetUsage();
querytree_list = parse_analyze_varparams(parsetree,
+ query_string,
¶mTypes,
&numParams);
* ruleutils.c - Functions to convert stored expressions/querytrees
* back to source text
*
- * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.215 2006/03/11 16:43:21 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.216 2006/03/14 22:48:22 tgl Exp $
**********************************************************************/
#include "postgres.h"
int32 atttypmod;
attname = n->colname;
- atttypeid = typenameTypeId(n->typename);
+ atttypeid = typenameTypeId(NULL, n->typename);
atttypmod = n->typename->typmod;
if (i > 0)
switch (operform->oprkind)
{
case 'b':
- p_result = oper(list_make1(makeString(oprname)), arg1, arg2, true);
+ p_result = oper(NULL, list_make1(makeString(oprname)), arg1, arg2,
+ true, -1);
break;
case 'l':
- p_result = left_oper(list_make1(makeString(oprname)), arg2, true);
+ p_result = left_oper(NULL, list_make1(makeString(oprname)), arg2,
+ true, -1);
break;
case 'r':
- p_result = right_oper(list_make1(makeString(oprname)), arg1, true);
+ p_result = right_oper(NULL, list_make1(makeString(oprname)), arg1,
+ true, -1);
break;
default:
elog(ERROR, "unrecognized oprkind: %d", operform->oprkind);
*
* Copyright (c) 2000-2006, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.115 2006/03/06 19:49:20 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.116 2006/03/14 22:48:22 tgl Exp $
*/
#include "postgres_fe.h"
#include "common.h"
}
-/*
- * on errors, print syntax error position if available.
- *
- * the query is expected to be in the client encoding.
- */
-static void
-ReportSyntaxErrorPosition(const PGresult *result, const char *query)
-{
-#define DISPLAY_SIZE 60 /* screen width limit, in screen cols */
-#define MIN_RIGHT_CUT 10 /* try to keep this far away from EOL */
-
- int loc = 0;
- const char *sp;
- int clen,
- slen,
- i,
- w,
- *qidx,
- *scridx,
- qoffset,
- scroffset,
- ibeg,
- iend,
- loc_line;
- char *wquery;
- bool beg_trunc,
- end_trunc;
- PQExpBufferData msg;
-
- if (pset.verbosity == PQERRORS_TERSE)
- return;
-
- sp = PQresultErrorField(result, PG_DIAG_STATEMENT_POSITION);
- if (sp == NULL)
- {
- sp = PQresultErrorField(result, PG_DIAG_INTERNAL_POSITION);
- if (sp == NULL)
- return; /* no syntax error */
- query = PQresultErrorField(result, PG_DIAG_INTERNAL_QUERY);
- }
- if (query == NULL)
- return; /* nothing to reference location to */
-
- if (sscanf(sp, "%d", &loc) != 1)
- {
- psql_error("INTERNAL ERROR: unexpected statement position \"%s\"\n",
- sp);
- return;
- }
-
- /* Make a writable copy of the query, and a buffer for messages. */
- wquery = pg_strdup(query);
-
- initPQExpBuffer(&msg);
-
- /*
- * The returned cursor position is measured in logical characters. Each
- * character might occupy multiple physical bytes in the string, and in
- * some Far Eastern character sets it might take more than one screen
- * column as well. We compute the starting byte offset and starting
- * screen column of each logical character, and store these in qidx[] and
- * scridx[] respectively.
- */
-
- /* we need a safe allocation size... */
- slen = strlen(query) + 1;
-
- qidx = (int *) pg_malloc(slen * sizeof(int));
- scridx = (int *) pg_malloc(slen * sizeof(int));
-
- qoffset = 0;
- scroffset = 0;
- for (i = 0; query[qoffset] != '\0'; i++)
- {
- qidx[i] = qoffset;
- scridx[i] = scroffset;
- w = PQdsplen(&query[qoffset], pset.encoding);
- /* treat control chars as width 1; see tab hack below */
- if (w <= 0)
- w = 1;
- scroffset += w;
- qoffset += PQmblen(&query[qoffset], pset.encoding);
- }
- qidx[i] = qoffset;
- scridx[i] = scroffset;
- clen = i;
- psql_assert(clen < slen);
-
- /* convert loc to zero-based offset in qidx/scridx arrays */
- loc--;
-
- /* do we have something to show? */
- if (loc >= 0 && loc <= clen)
- {
- /* input line number of our syntax error. */
- loc_line = 1;
- /* first included char of extract. */
- ibeg = 0;
- /* last-plus-1 included char of extract. */
- iend = clen;
-
- /*
- * Replace tabs with spaces in the writable copy. (Later we might
- * want to think about coping with their variable screen width, but
- * not today.)
- *
- * Extract line number and begin and end indexes of line containing
- * error location. There will not be any newlines or carriage returns
- * in the selected extract.
- */
- for (i = 0; i < clen; i++)
- {
- /* character length must be 1 or it's not ASCII */
- if ((qidx[i + 1] - qidx[i]) == 1)
- {
- if (wquery[qidx[i]] == '\t')
- wquery[qidx[i]] = ' ';
- else if (wquery[qidx[i]] == '\r' || wquery[qidx[i]] == '\n')
- {
- if (i < loc)
- {
- /*
- * count lines before loc. Each \r or \n counts as a
- * line except when \r \n appear together.
- */
- if (wquery[qidx[i]] == '\r' ||
- i == 0 ||
- (qidx[i] - qidx[i - 1]) != 1 ||
- wquery[qidx[i - 1]] != '\r')
- loc_line++;
- /* extract beginning = last line start before loc. */
- ibeg = i + 1;
- }
- else
- {
- /* set extract end. */
- iend = i;
- /* done scanning. */
- break;
- }
- }
- }
- }
-
- /* If the line extracted is too long, we truncate it. */
- beg_trunc = false;
- end_trunc = false;
- if (scridx[iend] - scridx[ibeg] > DISPLAY_SIZE)
- {
- /*
- * We first truncate right if it is enough. This code might be
- * off a space or so on enforcing MIN_RIGHT_CUT if there's a wide
- * character right there, but that should be okay.
- */
- if (scridx[ibeg] + DISPLAY_SIZE >= scridx[loc] + MIN_RIGHT_CUT)
- {
- while (scridx[iend] - scridx[ibeg] > DISPLAY_SIZE)
- iend--;
- end_trunc = true;
- }
- else
- {
- /* Truncate right if not too close to loc. */
- while (scridx[loc] + MIN_RIGHT_CUT < scridx[iend])
- {
- iend--;
- end_trunc = true;
- }
-
- /* Truncate left if still too long. */
- while (scridx[iend] - scridx[ibeg] > DISPLAY_SIZE)
- {
- ibeg++;
- beg_trunc = true;
- }
- }
- }
-
- /* the extract MUST contain the target position! */
- psql_assert(ibeg <= loc && loc <= iend);
-
- /* truncate working copy at desired endpoint */
- wquery[qidx[iend]] = '\0';
-
- /* Begin building the finished message. */
- printfPQExpBuffer(&msg, _("LINE %d: "), loc_line);
- if (beg_trunc)
- appendPQExpBufferStr(&msg, "...");
-
- /*
- * While we have the prefix in the msg buffer, compute its screen
- * width.
- */
- scroffset = 0;
- for (i = 0; i < msg.len; i += PQmblen(&msg.data[i], pset.encoding))
- {
- w = PQdsplen(&msg.data[i], pset.encoding);
- if (w <= 0)
- w = 1;
- scroffset += w;
- }
-
- /* Finish and emit the message. */
- appendPQExpBufferStr(&msg, &wquery[qidx[ibeg]]);
- if (end_trunc)
- appendPQExpBufferStr(&msg, "...");
-
- psql_error("%s\n", msg.data);
-
- /* Now emit the cursor marker line. */
- scroffset += scridx[loc] - scridx[ibeg];
- resetPQExpBuffer(&msg);
- for (i = 0; i < scroffset; i++)
- appendPQExpBufferChar(&msg, ' ');
- appendPQExpBufferChar(&msg, '^');
-
- psql_error("%s\n", msg.data);
- }
-
- /* Clean up. */
- termPQExpBuffer(&msg);
-
- free(wquery);
- free(qidx);
- free(scridx);
-}
-
-
/*
* AcceptResult
*
if (strlen(error))
psql_error("%s", error);
- ReportSyntaxErrorPosition(result, query);
-
CheckConnection();
}
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/nodes/makefuncs.h,v 1.54 2006/03/05 15:58:56 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/nodes/makefuncs.h,v 1.55 2006/03/14 22:48:22 tgl Exp $
*
*-------------------------------------------------------------------------
*/
extern A_Expr *makeA_Expr(A_Expr_Kind kind, List *name,
- Node *lexpr, Node *rexpr);
+ Node *lexpr, Node *rexpr, int location);
extern A_Expr *makeSimpleA_Expr(A_Expr_Kind kind, const char *name,
- Node *lexpr, Node *rexpr);
+ Node *lexpr, Node *rexpr, int location);
extern Var *makeVar(Index varno,
AttrNumber varattno,
extern RangeVar *makeRangeVar(char *schemaname, char *relname);
extern TypeName *makeTypeName(char *typnam);
+extern TypeName *makeTypeNameFromNameList(List *names);
+extern TypeName *makeTypeNameFromOid(Oid typeid, int32 typmod);
extern FuncExpr *makeFuncExpr(Oid funcid, Oid rettype,
List *args, CoercionForm fformat);
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.303 2006/03/05 15:58:56 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.304 2006/03/14 22:48:22 tgl Exp $
*
*-------------------------------------------------------------------------
*/
* Most of these node types appear in raw parsetrees output by the grammar,
* and get transformed to something else by the analyzer. A few of them
* are used as-is in transformed querytrees.
+ *
+ * Many of the node types used in raw parsetrees include a "location" field.
+ * This is a byte (not character) offset in the original source text, to be
+ * used for positioning an error cursor when there is an analysis-time
+ * error related to the node.
****************************************************************************/
/*
bool pct_type; /* %TYPE specified? */
int32 typmod; /* type modifier */
List *arrayBounds; /* array bounds */
+ int location; /* token location, or -1 if unknown */
} TypeName;
/*
{
NodeTag type;
List *fields; /* field names (list of Value strings) */
+ int location; /* token location, or -1 if unknown */
} ColumnRef;
/*
List *name; /* possibly-qualified name of operator */
Node *lexpr; /* left argument, or NULL if none */
Node *rexpr; /* right argument, or NULL if none */
+ int location; /* token location, or -1 if unknown */
} A_Expr;
/*
{
NodeTag type;
Value val; /* the value (with the tag) */
- TypeName *typename; /* typecast */
+ TypeName *typename; /* typecast, or NULL if none */
} A_Const;
/*
* NOTE: for mostly historical reasons, A_Const parsenodes contain
* room for a TypeName; we only generate a separate TypeCast node if the
* argument to be casted is not a constant. In theory either representation
- * would work, but it is convenient to have the target type immediately
- * available while resolving a constant's datatype.
+ * would work, but the combined representation saves a bit of code in many
+ * productions in gram.y.
*/
typedef struct TypeCast
{
List *args; /* the arguments (list of exprs) */
bool agg_star; /* argument was really '*' */
bool agg_distinct; /* arguments were labeled DISTINCT */
+ int location; /* token location, or -1 if unknown */
} FuncCall;
/*
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/parser/analyze.h,v 1.31 2006/03/05 15:58:57 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/parser/analyze.h,v 1.32 2006/03/14 22:48:22 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "parser/parse_node.h"
-extern List *parse_analyze(Node *parseTree, Oid *paramTypes, int numParams);
-extern List *parse_analyze_varparams(Node *parseTree, Oid **paramTypes,
- int *numParams);
+extern List *parse_analyze(Node *parseTree, const char *sourceText,
+ Oid *paramTypes, int numParams);
+extern List *parse_analyze_varparams(Node *parseTree, const char *sourceText,
+ Oid **paramTypes, int *numParams);
extern List *parse_sub_analyze(Node *parseTree, ParseState *parentParseState);
extern List *analyzeCreateSchemaStmt(CreateSchemaStmt *stmt);
extern void CheckSelectLocking(Query *qry, bool forUpdate);
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/parser/gramparse.h,v 1.33 2006/03/07 01:00:18 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/parser/gramparse.h,v 1.34 2006/03/14 22:48:22 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "nodes/parsenodes.h"
+/*
+ * We track token locations in terms of byte offsets from the start of the
+ * source string, not the column number/line number representation that
+ * bison uses by default. Also, to minimize overhead we track only one
+ * location (usually the first token location) for each construct, not
+ * the beginning and ending locations as bison does by default. It's
+ * therefore sufficient to make YYLTYPE an int.
+ */
+#define YYLTYPE int
/* from scan.l */
extern void scanner_init(const char *str);
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/parser/parse_func.h,v 1.54 2006/03/05 15:58:57 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/parser/parse_func.h,v 1.55 2006/03/14 22:48:22 tgl Exp $
*
*-------------------------------------------------------------------------
*/
extern Node *ParseFuncOrColumn(ParseState *pstate,
List *funcname, List *fargs,
- bool agg_star, bool agg_distinct, bool is_column);
+ bool agg_star, bool agg_distinct, bool is_column,
+ int location);
extern FuncDetailCode func_get_detail(List *funcname, List *fargs,
int nargs, Oid *argtypes,
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/parser/parse_node.h,v 1.47 2006/03/05 15:58:57 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/parser/parse_node.h,v 1.48 2006/03/14 22:48:22 tgl Exp $
*
*-------------------------------------------------------------------------
*/
/*
* State information used during parse analysis
*
+ * parentParseState: NULL in a top-level ParseState. When parsing a subquery,
+ * links to current parse state of outer query.
+ *
+ * p_sourcetext: source string that generated the raw parsetree being
+ * analyzed, or NULL if not available. (The string is used only to
+ * generate cursor positions in error messages: we need it to convert
+ * byte-wise locations in parse structures to character-wise cursor
+ * positions.)
+ *
* p_rtable: list of RTEs that will become the rangetable of the query.
* Note that neither relname nor refname of these entries are necessarily
* unique; searching the rtable by name is a bad idea.
typedef struct ParseState
{
struct ParseState *parentParseState; /* stack link */
+ const char *p_sourcetext; /* source text, or NULL if not available */
List *p_rtable; /* range table so far */
List *p_joinlist; /* join items so far (will become FromExpr
* node's fromlist) */
} ParseState;
extern ParseState *make_parsestate(ParseState *parentParseState);
+extern int parser_errposition(ParseState *pstate, int location);
+
extern Var *make_var(ParseState *pstate, RangeTblEntry *rte, int attrno);
extern Oid transformArrayType(Oid arrayType);
extern ArrayRef *transformArraySubscripts(ParseState *pstate,
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/parser/parse_oper.h,v 1.38 2006/03/05 15:58:57 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/parser/parse_oper.h,v 1.39 2006/03/14 22:48:22 tgl Exp $
*
*-------------------------------------------------------------------------
*/
typedef HeapTuple Operator;
/* Routines to look up an operator given name and exact input type(s) */
-extern Oid LookupOperName(List *opername, Oid oprleft, Oid oprright,
- bool noError);
-extern Oid LookupOperNameTypeNames(List *opername, TypeName *oprleft,
- TypeName *oprright, bool noError);
+extern Oid LookupOperName(ParseState *pstate, List *opername,
+ Oid oprleft, Oid oprright,
+ bool noError, int location);
+extern Oid LookupOperNameTypeNames(ParseState *pstate, List *opername,
+ TypeName *oprleft, TypeName *oprright,
+ bool noError, int location);
/* Routines to find operators matching a name and given input types */
/* NB: the selected operator may require coercion of the input types! */
-extern Operator oper(List *op, Oid arg1, Oid arg2, bool noError);
-extern Operator right_oper(List *op, Oid arg, bool noError);
-extern Operator left_oper(List *op, Oid arg, bool noError);
+extern Operator oper(ParseState *pstate, List *op, Oid arg1, Oid arg2,
+ bool noError, int location);
+extern Operator right_oper(ParseState *pstate, List *op, Oid arg,
+ bool noError, int location);
+extern Operator left_oper(ParseState *pstate, List *op, Oid arg,
+ bool noError, int location);
/* Routines to find operators that DO NOT require coercion --- ie, their */
/* input types are either exactly as given, or binary-compatible */
-extern Operator compatible_oper(List *op, Oid arg1, Oid arg2, bool noError);
+extern Operator compatible_oper(ParseState *pstate, List *op,
+ Oid arg1, Oid arg2,
+ bool noError, int location);
/* currently no need for compatible_left_oper/compatible_right_oper */
/* Build expression tree for an operator invocation */
extern Expr *make_op(ParseState *pstate, List *opname,
- Node *ltree, Node *rtree);
+ Node *ltree, Node *rtree, int location);
extern Expr *make_scalar_array_op(ParseState *pstate, List *opname,
bool useOr,
- Node *ltree, Node *rtree);
+ Node *ltree, Node *rtree, int location);
#endif /* PARSE_OPER_H */
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/parser/parse_relation.h,v 1.52 2006/03/05 15:58:57 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/parser/parse_relation.h,v 1.53 2006/03/14 22:48:22 tgl Exp $
*
*-------------------------------------------------------------------------
*/
int varno,
int sublevels_up);
extern Node *scanRTEForColumn(ParseState *pstate, RangeTblEntry *rte,
- char *colname);
-extern Node *colNameToVar(ParseState *pstate, char *colname, bool localonly);
+ char *colname, int location);
+extern Node *colNameToVar(ParseState *pstate, char *colname, bool localonly,
+ int location);
extern Node *qualifiedNameToVar(ParseState *pstate,
char *schemaname,
char *refname,
char *colname,
- bool implicitRTEOK);
+ bool implicitRTEOK,
+ int location);
extern RangeTblEntry *addRangeTableEntry(ParseState *pstate,
RangeVar *relation,
Alias *alias,
extern void addRTEtoQuery(ParseState *pstate, RangeTblEntry *rte,
bool addToJoinList,
bool addToRelNameSpace, bool addToVarNameSpace);
-extern RangeTblEntry *addImplicitRTE(ParseState *pstate, RangeVar *relation);
+extern RangeTblEntry *addImplicitRTE(ParseState *pstate, RangeVar *relation,
+ int location);
extern void expandRTE(RangeTblEntry *rte, int rtindex, int sublevels_up,
bool include_dropped,
List **colnames, List **colvars);
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/parser/parse_type.h,v 1.31 2006/03/05 15:58:57 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/parser/parse_type.h,v 1.32 2006/03/14 22:48:22 tgl Exp $
*
*-------------------------------------------------------------------------
*/
typedef HeapTuple Type;
-extern Oid LookupTypeName(const TypeName *typename);
+extern Oid LookupTypeName(ParseState *pstate, const TypeName *typename);
extern char *TypeNameToString(const TypeName *typename);
-extern Oid typenameTypeId(const TypeName *typename);
-extern Type typenameType(const TypeName *typename);
+extern Oid typenameTypeId(ParseState *pstate, const TypeName *typename);
+extern Type typenameType(ParseState *pstate, const TypeName *typename);
extern Type typeidType(Oid id);
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/tcop/tcopprot.h,v 1.80 2006/03/05 15:59:00 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/tcop/tcopprot.h,v 1.81 2006/03/14 22:48:23 tgl Exp $
*
* OLD COMMENTS
* This file was created so that other c files could get the two
extern List *pg_parse_and_rewrite(const char *query_string,
Oid *paramTypes, int numParams);
extern List *pg_parse_query(const char *query_string);
-extern List *pg_analyze_and_rewrite(Node *parsetree,
+extern List *pg_analyze_and_rewrite(Node *parsetree, const char *query_string,
Oid *paramTypes, int numParams);
extern Plan *pg_plan_query(Query *querytree, ParamListInfo boundParams);
extern List *pg_plan_queries(List *querytrees, ParamListInfo boundParams,
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.327 2006/03/05 15:59:08 momjian Exp $
+ * $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.328 2006/03/14 22:48:23 tgl Exp $
*
*-------------------------------------------------------------------------
*/
free(conn->krbsrvname);
#endif
/* Note that conn->Pfdebug is not ours to close or free */
+ if (conn->last_query)
+ free(conn->last_query);
pg_freeaddrinfo_all(conn->addrlist_family, conn->addrlist);
notify = conn->notifyHead;
while (notify != NULL)
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.181 2006/03/05 15:59:09 momjian Exp $
+ * $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.182 2006/03/14 22:48:23 tgl Exp $
*
*-------------------------------------------------------------------------
*/
/* remember we are using simple query protocol */
conn->queryclass = PGQUERY_SIMPLE;
+ /* and remember the query text too, if possible */
+ /* if insufficient memory, last_query just winds up NULL */
+ if (conn->last_query)
+ free(conn->last_query);
+ conn->last_query = strdup(query);
+
/*
* Give the data a push. In nonblock mode, don't complain if we're unable
* to send it all; PQgetResult() will do any additional flushing needed.
/* remember we are doing just a Parse */
conn->queryclass = PGQUERY_PREPARE;
+ /* and remember the query text too, if possible */
+ /* if insufficient memory, last_query just winds up NULL */
+ if (conn->last_query)
+ free(conn->last_query);
+ conn->last_query = strdup(query);
+
/*
* Give the data a push. In nonblock mode, don't complain if we're unable
* to send it all; PQgetResult() will do any additional flushing needed.
/* remember we are using extended query protocol */
conn->queryclass = PGQUERY_EXTENDED;
+ /* and remember the query text too, if possible */
+ /* if insufficient memory, last_query just winds up NULL */
+ if (conn->last_query)
+ free(conn->last_query);
+ if (command)
+ conn->last_query = strdup(command);
+ else
+ conn->last_query = NULL;
+
/*
* Give the data a push. In nonblock mode, don't complain if we're unable
* to send it all; PQgetResult() will do any additional flushing needed.
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/interfaces/libpq/fe-protocol3.c,v 1.25 2006/03/05 15:59:09 momjian Exp $
+ * $PostgreSQL: pgsql/src/interfaces/libpq/fe-protocol3.c,v 1.26 2006/03/14 22:48:23 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres_fe.h"
-#include <errno.h>
#include <ctype.h>
#include <fcntl.h>
static int getNotify(PGconn *conn);
static int getCopyStart(PGconn *conn, ExecStatusType copytype);
static int getReadyForQuery(PGconn *conn);
+static void reportErrorPosition(PQExpBuffer msg, const char *query,
+ int loc, int encoding);
static int build_startup_packet(const PGconn *conn, char *packet,
const PQEnvironmentOption *options);
PQExpBufferData workBuf;
char id;
const char *val;
+ const char *querytext = NULL;
+ int querypos = 0;
/*
* Since the fields might be pretty long, we create a temporary
val = PQresultErrorField(res, PG_DIAG_STATEMENT_POSITION);
if (val)
{
- /* translator: %s represents a digit string */
- appendPQExpBuffer(&workBuf, libpq_gettext(" at character %s"), val);
+ if (conn->verbosity != PQERRORS_TERSE && conn->last_query != NULL)
+ {
+ /* emit position as a syntax cursor display */
+ querytext = conn->last_query;
+ querypos = atoi(val);
+ }
+ else
+ {
+ /* emit position as text addition to primary message */
+ /* translator: %s represents a digit string */
+ appendPQExpBuffer(&workBuf, libpq_gettext(" at character %s"),
+ val);
+ }
}
else
{
val = PQresultErrorField(res, PG_DIAG_INTERNAL_POSITION);
if (val)
{
- /* translator: %s represents a digit string */
- appendPQExpBuffer(&workBuf, libpq_gettext(" at character %s"),
- val);
+ querytext = PQresultErrorField(res, PG_DIAG_INTERNAL_QUERY);
+ if (conn->verbosity != PQERRORS_TERSE && querytext != NULL)
+ {
+ /* emit position as a syntax cursor display */
+ querypos = atoi(val);
+ }
+ else
+ {
+ /* emit position as text addition to primary message */
+ /* translator: %s represents a digit string */
+ appendPQExpBuffer(&workBuf, libpq_gettext(" at character %s"),
+ val);
+ }
}
}
appendPQExpBufferChar(&workBuf, '\n');
if (conn->verbosity != PQERRORS_TERSE)
{
+ if (querytext && querypos > 0)
+ reportErrorPosition(&workBuf, querytext, querypos,
+ conn->client_encoding);
val = PQresultErrorField(res, PG_DIAG_MESSAGE_DETAIL);
if (val)
appendPQExpBuffer(&workBuf, libpq_gettext("DETAIL: %s\n"), val);
return EOF;
}
+/*
+ * Add an error-location display to the error message under construction.
+ *
+ * The cursor location is measured in logical characters; the query string
+ * is presumed to be in the specified encoding.
+ */
+static void
+reportErrorPosition(PQExpBuffer msg, const char *query, int loc, int encoding)
+{
+#define DISPLAY_SIZE 60 /* screen width limit, in screen cols */
+#define MIN_RIGHT_CUT 10 /* try to keep this far away from EOL */
+
+ char *wquery;
+ int clen,
+ slen,
+ i,
+ w,
+ *qidx,
+ *scridx,
+ qoffset,
+ scroffset,
+ ibeg,
+ iend,
+ loc_line;
+ bool beg_trunc,
+ end_trunc;
+
+ /* Need a writable copy of the query */
+ wquery = strdup(query);
+ if (wquery == NULL)
+ return; /* fail silently if out of memory */
+
+ /*
+ * Each character might occupy multiple physical bytes in the string, and
+ * in some Far Eastern character sets it might take more than one screen
+ * column as well. We compute the starting byte offset and starting
+ * screen column of each logical character, and store these in qidx[] and
+ * scridx[] respectively.
+ */
+
+ /* we need a safe allocation size... */
+ slen = strlen(query) + 1;
+
+ qidx = (int *) malloc(slen * sizeof(int));
+ if (qidx == NULL)
+ {
+ free(wquery);
+ return;
+ }
+ scridx = (int *) malloc(slen * sizeof(int));
+ if (scridx == NULL)
+ {
+ free(qidx);
+ free(wquery);
+ return;
+ }
+
+ qoffset = 0;
+ scroffset = 0;
+ for (i = 0; query[qoffset] != '\0'; i++)
+ {
+ qidx[i] = qoffset;
+ scridx[i] = scroffset;
+ w = pg_encoding_dsplen(encoding, &query[qoffset]);
+ /* treat control chars as width 1; see tab hack below */
+ if (w <= 0)
+ w = 1;
+ scroffset += w;
+ qoffset += pg_encoding_mblen(encoding, &query[qoffset]);
+ }
+ qidx[i] = qoffset;
+ scridx[i] = scroffset;
+ clen = i;
+
+ /* convert loc to zero-based offset in qidx/scridx arrays */
+ loc--;
+
+ /* do we have something to show? */
+ if (loc >= 0 && loc <= clen)
+ {
+ /* input line number of our syntax error. */
+ loc_line = 1;
+ /* first included char of extract. */
+ ibeg = 0;
+ /* last-plus-1 included char of extract. */
+ iend = clen;
+
+ /*
+ * Replace tabs with spaces in the writable copy. (Later we might
+ * want to think about coping with their variable screen width, but
+ * not today.)
+ *
+ * Extract line number and begin and end indexes of line containing
+ * error location. There will not be any newlines or carriage returns
+ * in the selected extract.
+ */
+ for (i = 0; i < clen; i++)
+ {
+ /* character length must be 1 or it's not ASCII */
+ if ((qidx[i + 1] - qidx[i]) == 1)
+ {
+ if (wquery[qidx[i]] == '\t')
+ wquery[qidx[i]] = ' ';
+ else if (wquery[qidx[i]] == '\r' || wquery[qidx[i]] == '\n')
+ {
+ if (i < loc)
+ {
+ /*
+ * count lines before loc. Each \r or \n counts
+ * as a line except when \r \n appear together.
+ */
+ if (wquery[qidx[i]] == '\r' ||
+ i == 0 ||
+ (qidx[i] - qidx[i - 1]) != 1 ||
+ wquery[qidx[i - 1]] != '\r')
+ loc_line++;
+ /* extract beginning = last line start before loc. */
+ ibeg = i + 1;
+ }
+ else
+ {
+ /* set extract end. */
+ iend = i;
+ /* done scanning. */
+ break;
+ }
+ }
+ }
+ }
+
+ /* If the line extracted is too long, we truncate it. */
+ beg_trunc = false;
+ end_trunc = false;
+ if (scridx[iend] - scridx[ibeg] > DISPLAY_SIZE)
+ {
+ /*
+ * We first truncate right if it is enough. This code might be
+ * off a space or so on enforcing MIN_RIGHT_CUT if there's a wide
+ * character right there, but that should be okay.
+ */
+ if (scridx[ibeg] + DISPLAY_SIZE >= scridx[loc] + MIN_RIGHT_CUT)
+ {
+ while (scridx[iend] - scridx[ibeg] > DISPLAY_SIZE)
+ iend--;
+ end_trunc = true;
+ }
+ else
+ {
+ /* Truncate right if not too close to loc. */
+ while (scridx[loc] + MIN_RIGHT_CUT < scridx[iend])
+ {
+ iend--;
+ end_trunc = true;
+ }
+
+ /* Truncate left if still too long. */
+ while (scridx[iend] - scridx[ibeg] > DISPLAY_SIZE)
+ {
+ ibeg++;
+ beg_trunc = true;
+ }
+ }
+ }
+
+ /* truncate working copy at desired endpoint */
+ wquery[qidx[iend]] = '\0';
+
+ /* Begin building the finished message. */
+ i = msg->len;
+ appendPQExpBuffer(msg, libpq_gettext("LINE %d: "), loc_line);
+ if (beg_trunc)
+ appendPQExpBufferStr(msg, "...");
+
+ /*
+ * While we have the prefix in the msg buffer, compute its screen
+ * width.
+ */
+ scroffset = 0;
+ for (; i < msg->len; i += pg_encoding_mblen(encoding, &msg->data[i]))
+ {
+ w = pg_encoding_dsplen(encoding, &msg->data[i]);
+ if (w <= 0)
+ w = 1;
+ scroffset += w;
+ }
+
+ /* Finish up the LINE message line. */
+ appendPQExpBufferStr(msg, &wquery[qidx[ibeg]]);
+ if (end_trunc)
+ appendPQExpBufferStr(msg, "...");
+ appendPQExpBufferChar(msg, '\n');
+
+ /* Now emit the cursor marker line. */
+ scroffset += scridx[loc] - scridx[ibeg];
+ for (i = 0; i < scroffset; i++)
+ appendPQExpBufferChar(msg, ' ');
+ appendPQExpBufferChar(msg, '^');
+ appendPQExpBufferChar(msg, '\n');
+ }
+
+ /* Clean up. */
+ free(scridx);
+ free(qidx);
+ free(wquery);
+}
+
/*
* Attempt to read a ParameterStatus message.
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/interfaces/libpq/libpq-int.h,v 1.111 2006/03/05 15:59:10 momjian Exp $
+ * $PostgreSQL: pgsql/src/interfaces/libpq/libpq-int.h,v 1.112 2006/03/14 22:48:23 tgl Exp $
*
*-------------------------------------------------------------------------
*/
PGAsyncStatusType asyncStatus;
PGTransactionStatusType xactStatus; /* never changes to ACTIVE */
PGQueryClass queryclass;
+ char *last_query; /* last SQL command, or NULL if unknown */
bool options_valid; /* true if OK to attempt connection */
bool nonblocking; /* whether this connection is using nonblock
* sending semantics */
Global symbol "$other_global" requires explicit package name at line 4.
select uses_global();
ERROR: function uses_global() does not exist
+LINE 1: select uses_global();
+ ^
HINT: No function matches the given name and argument types. You may need to add explicit type casts.
SET plperl.use_strict = false;
create or replace function uses_global() returns text language plperl as $$
/**********************************************************************
* plperl.c - perl as a procedural language for PostgreSQL
*
- * $PostgreSQL: pgsql/src/pl/plperl/plperl.c,v 1.105 2006/03/11 16:43:22 momjian Exp $
+ * $PostgreSQL: pgsql/src/pl/plperl/plperl.c,v 1.106 2006/03/14 22:48:23 tgl Exp $
*
**********************************************************************/
#include "commands/trigger.h"
#include "executor/spi.h"
#include "funcapi.h"
+#include "mb/pg_wchar.h"
+#include "miscadmin.h"
+#include "nodes/makefuncs.h"
+#include "parser/parse_type.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
#include "utils/typcache.h"
-#include "miscadmin.h"
-#include "mb/pg_wchar.h"
-#include "parser/parse_type.h"
/* define this before the perl headers get a chance to mangle DLLIMPORT */
extern DLLIMPORT bool check_function_bodies;
plperl_query_desc *qdesc;
void *plan;
int i;
- HeapTuple typeTup;
MemoryContext oldcontext = CurrentMemoryContext;
ResourceOwner oldowner = CurrentResourceOwner;
************************************************************/
for (i = 0; i < argc; i++)
{
- char *argcopy;
- List *names = NIL;
- ListCell *l;
- TypeName *typename;
-
- /************************************************************
- * Use SplitIdentifierString() on a copy of the type name,
- * turn the resulting pointer list into a TypeName node
- * and call typenameType() to get the pg_type tuple.
- ************************************************************/
- argcopy = pstrdup(SvPV(argv[i],PL_na));
- SplitIdentifierString(argcopy, '.', &names);
- typename = makeNode(TypeName);
- foreach(l, names)
- typename->names = lappend(typename->names, makeString(lfirst(l)));
-
- typeTup = typenameType(typename);
+ List *names;
+ HeapTuple typeTup;
+
+ /* Parse possibly-qualified type name and look it up in pg_type */
+ names = stringToQualifiedNameList(SvPV(argv[i], PL_na),
+ "plperl_spi_prepare");
+ typeTup = typenameType(NULL, makeTypeNameFromNameList(names));
qdesc->argtypes[i] = HeapTupleGetOid(typeTup);
perm_fmgr_info(((Form_pg_type) GETSTRUCT(typeTup))->typinput,
&(qdesc->arginfuncs[i]));
qdesc->argtypioparams[i] = getTypeIOParam(typeTup);
ReleaseSysCache(typeTup);
-
- list_free(typename->names);
- pfree(typename);
- list_free(names);
- pfree(argcopy);
}
/************************************************************
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_comp.c,v 1.100 2006/03/09 21:29:36 momjian Exp $
+ * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_comp.c,v 1.101 2006/03/14 22:48:23 tgl Exp $
*
*-------------------------------------------------------------------------
*/
* Word wasn't found on the namestack. Try to find a data type with that
* name, but ignore pg_type entries that are in fact class types.
*/
- typeOid = LookupTypeName(makeTypeName(cp[0]));
+ typeOid = LookupTypeName(NULL, makeTypeName(cp[0]));
if (OidIsValid(typeOid))
{
HeapTuple typeTup;
/**********************************************************************
* plpython.c - python as a procedural language for PostgreSQL
*
- * $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.75 2006/03/11 16:43:22 momjian Exp $
+ * $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.76 2006/03/14 22:48:24 tgl Exp $
*
*********************************************************************
*/
#include "nodes/makefuncs.h"
#include "parser/parse_type.h"
#include "tcop/tcopprot.h"
+#include "utils/builtins.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
#include "utils/syscache.h"
for (i = 0; i < nargs; i++)
{
char *sptr;
+ List *names;
HeapTuple typeTup;
Form_pg_type typeStruct;
sptr = PyString_AsString(optr);
/*
- * XXX should extend this to allow qualified type names
+ * Parse possibly-qualified type name and look it up in
+ * pg_type
*/
- typeTup = typenameType(makeTypeName(sptr));
+ names = stringToQualifiedNameList(sptr,
+ "PLy_spi_prepare");
+ typeTup = typenameType(NULL,
+ makeTypeNameFromNameList(names));
Py_DECREF(optr);
optr = NULL; /* this is important */
* pltcl.c - PostgreSQL support for Tcl as
* procedural language (PL)
*
- * $PostgreSQL: pgsql/src/pl/tcl/pltcl.c,v 1.100 2006/03/11 16:43:22 momjian Exp $
+ * $PostgreSQL: pgsql/src/pl/tcl/pltcl.c,v 1.101 2006/03/14 22:48:24 tgl Exp $
*
**********************************************************************/
pltcl_query_desc *qdesc;
void *plan;
int i;
- HeapTuple typeTup;
Tcl_HashEntry *hashent;
int hashnew;
Tcl_HashTable *query_hash;
************************************************************/
for (i = 0; i < nargs; i++)
{
- char *argcopy;
- List *names = NIL;
- ListCell *l;
- TypeName *typename;
-
- /************************************************************
- * Use SplitIdentifierString() on a copy of the type name,
- * turn the resulting pointer list into a TypeName node
- * and call typenameType() to get the pg_type tuple.
- ************************************************************/
- argcopy = pstrdup(args[i]);
- SplitIdentifierString(argcopy, '.', &names);
- typename = makeNode(TypeName);
- foreach(l, names)
- typename->names = lappend(typename->names, makeString(lfirst(l)));
+ List *names;
+ HeapTuple typeTup;
- typeTup = typenameType(typename);
+ /* Parse possibly-qualified type name and look it up in pg_type */
+ names = stringToQualifiedNameList(args[i],
+ "pltcl_SPI_prepare");
+ typeTup = typenameType(NULL, makeTypeNameFromNameList(names));
qdesc->argtypes[i] = HeapTupleGetOid(typeTup);
perm_fmgr_info(((Form_pg_type) GETSTRUCT(typeTup))->typinput,
&(qdesc->arginfuncs[i]));
qdesc->argtypioparams[i] = getTypeIOParam(typeTup);
ReleaseSysCache(typeTup);
-
- list_free(typename->names);
- pfree(typename);
- list_free(names);
- pfree(argcopy);
}
/************************************************************
select * from atacc1 order by a;
ERROR: column "a" does not exist
+LINE 1: select * from atacc1 order by a;
+ ^
select * from atacc1 order by "........pg.dropped.1........";
ERROR: column "........pg.dropped.1........" does not exist
+LINE 1: select * from atacc1 order by "........pg.dropped.1........"...
+ ^
select * from atacc1 group by a;
ERROR: column "a" does not exist
+LINE 1: select * from atacc1 group by a;
+ ^
select * from atacc1 group by "........pg.dropped.1........";
ERROR: column "........pg.dropped.1........" does not exist
+LINE 1: select * from atacc1 group by "........pg.dropped.1........"...
+ ^
select atacc1.* from atacc1;
b | c | d
---+---+---
select a from atacc1;
ERROR: column "a" does not exist
+LINE 1: select a from atacc1;
+ ^
select atacc1.a from atacc1;
ERROR: column atacc1.a does not exist
+LINE 1: select atacc1.a from atacc1;
+ ^
select b,c,d from atacc1;
b | c | d
---+---+---
select a,b,c,d from atacc1;
ERROR: column "a" does not exist
+LINE 1: select a,b,c,d from atacc1;
+ ^
select * from atacc1 where a = 1;
ERROR: column "a" does not exist
+LINE 1: select * from atacc1 where a = 1;
+ ^
select "........pg.dropped.1........" from atacc1;
ERROR: column "........pg.dropped.1........" does not exist
+LINE 1: select "........pg.dropped.1........" from atacc1;
+ ^
select atacc1."........pg.dropped.1........" from atacc1;
ERROR: column atacc1.........pg.dropped.1........ does not exist
+LINE 1: select atacc1."........pg.dropped.1........" from atacc1;
+ ^
select "........pg.dropped.1........",b,c,d from atacc1;
ERROR: column "........pg.dropped.1........" does not exist
+LINE 1: select "........pg.dropped.1........",b,c,d from atacc1;
+ ^
select * from atacc1 where "........pg.dropped.1........" = 1;
ERROR: column "........pg.dropped.1........" does not exist
+LINE 1: select * from atacc1 where "........pg.dropped.1........" = ...
+ ^
-- UPDATEs
update atacc1 set a = 3;
ERROR: column "a" of relation "atacc1" does not exist
update atacc1 set b = 2 where a = 3;
ERROR: column "a" does not exist
+LINE 1: update atacc1 set b = 2 where a = 3;
+ ^
update atacc1 set "........pg.dropped.1........" = 3;
ERROR: column "........pg.dropped.1........" of relation "atacc1" does not exist
update atacc1 set b = 2 where "........pg.dropped.1........" = 3;
ERROR: column "........pg.dropped.1........" does not exist
+LINE 1: update atacc1 set b = 2 where "........pg.dropped.1........"...
+ ^
-- INSERTs
insert into atacc1 values (10, 11, 12, 13);
ERROR: INSERT has more expressions than target columns
-- DELETEs
delete from atacc1 where a = 3;
ERROR: column "a" does not exist
+LINE 1: delete from atacc1 where a = 3;
+ ^
delete from atacc1 where "........pg.dropped.1........" = 3;
ERROR: column "........pg.dropped.1........" does not exist
+LINE 1: delete from atacc1 where "........pg.dropped.1........" = 3;
+ ^
delete from atacc1;
-- try dropping a non-existent column, should fail
alter table atacc1 drop bar;
alter table c1 drop column f1;
select f1 from c1;
ERROR: column "f1" does not exist
+LINE 1: select f1 from c1;
+ ^
drop table p1 cascade;
NOTICE: drop cascades to table c1
create table p1 (f1 int, f2 int);
-- c1.f1 is dropped now, since there is no local definition for it
select f1 from c1;
ERROR: column "f1" does not exist
+LINE 1: select f1 from c1;
+ ^
drop table p1 cascade;
NOTICE: drop cascades to table c1
create table p1 (f1 int, f2 int);
alter table altstartwith set without oids;
select oid > 0, * from altstartwith; -- fails
ERROR: column "oid" does not exist
+LINE 1: select oid > 0, * from altstartwith;
+ ^
select * from altstartwith;
col
-----
alter table altinhoid set without oids;
select oid > 0, * from altwithoid; -- fails
ERROR: column "oid" does not exist
+LINE 1: select oid > 0, * from altwithoid;
+ ^
select oid > 0, * from altinhoid; -- fails
ERROR: column "oid" does not exist
+LINE 1: select oid > 0, * from altinhoid;
+ ^
select * from altwithoid;
col
-----
-- errors
select 33 * any ('{1,2,3}');
ERROR: op ANY/ALL (array) requires operator to yield boolean
+LINE 1: select 33 * any ('{1,2,3}');
+ ^
select 33 * any (44);
ERROR: op ANY/ALL (array) requires array on right side
+LINE 1: select 33 * any (44);
+ ^
-- nulls
select 33 = any (null::int[]);
?column?
-- missing relation name
select;
-ERROR: syntax error at or near ";" at character 7
+ERROR: syntax error at or near ";"
LINE 1: select;
^
-- no such relation
ERROR: relation "nonesuch" does not exist
-- missing target list
select from pg_database;
-ERROR: syntax error at or near "from" at character 8
+ERROR: syntax error at or near "from"
LINE 1: select from pg_database;
^
-- bad name in target list
select nonesuch from pg_database;
ERROR: column "nonesuch" does not exist
+LINE 1: select nonesuch from pg_database;
+ ^
-- bad attribute name on lhs of operator
select * from pg_database where nonesuch = pg_database.datname;
ERROR: column "nonesuch" does not exist
+LINE 1: select * from pg_database where nonesuch = pg_database.datna...
+ ^
-- bad attribute name on rhs of operator
select * from pg_database where pg_database.datname = nonesuch;
ERROR: column "nonesuch" does not exist
+LINE 1: ...ect * from pg_database where pg_database.datname = nonesuch;
+ ^
-- bad select distinct on syntax, distinct attribute missing
select distinct on (foobar) from pg_database;
-ERROR: syntax error at or near "from" at character 29
+ERROR: syntax error at or near "from"
LINE 1: select distinct on (foobar) from pg_database;
^
-- bad select distinct on syntax, distinct attribute not in target list
select distinct on (foobar) * from pg_database;
ERROR: column "foobar" does not exist
+LINE 1: select distinct on (foobar) * from pg_database;
+ ^
--
-- DELETE
-- missing relation name (this had better not wildcard!)
delete from;
-ERROR: syntax error at or near ";" at character 12
+ERROR: syntax error at or near ";"
LINE 1: delete from;
^
-- no such relation
-- missing relation name (this had better not wildcard!)
drop table;
-ERROR: syntax error at or near ";" at character 11
+ERROR: syntax error at or near ";"
LINE 1: drop table;
^
-- no such relation
-- relation renaming
-- missing relation name
alter table rename;
-ERROR: syntax error at or near ";" at character 19
+ERROR: syntax error at or near ";"
LINE 1: alter table rename;
^
-- no such relation
-- missing index name
drop index;
-ERROR: syntax error at or near ";" at character 11
+ERROR: syntax error at or near ";"
LINE 1: drop index;
^
-- bad index name
drop index 314159;
-ERROR: syntax error at or near "314159" at character 12
+ERROR: syntax error at or near "314159"
LINE 1: drop index 314159;
^
-- no such index
-- missing aggregate name
drop aggregate;
-ERROR: syntax error at or near ";" at character 15
+ERROR: syntax error at or near ";"
LINE 1: drop aggregate;
^
-- missing aggregate type
drop aggregate newcnt1;
-ERROR: syntax error at or near ";" at character 23
+ERROR: syntax error at or near ";"
LINE 1: drop aggregate newcnt1;
^
-- bad aggregate name
drop aggregate 314159 (int);
-ERROR: syntax error at or near "314159" at character 16
+ERROR: syntax error at or near "314159"
LINE 1: drop aggregate 314159 (int);
^
-- bad aggregate type
-- missing function name
drop function ();
-ERROR: syntax error at or near "(" at character 15
+ERROR: syntax error at or near "("
LINE 1: drop function ();
^
-- bad function name
drop function 314159();
-ERROR: syntax error at or near "314159" at character 15
+ERROR: syntax error at or near "314159"
LINE 1: drop function 314159();
^
-- no such function
-- missing type name
drop type;
-ERROR: syntax error at or near ";" at character 10
+ERROR: syntax error at or near ";"
LINE 1: drop type;
^
-- bad type name
drop type 314159;
-ERROR: syntax error at or near "314159" at character 11
+ERROR: syntax error at or near "314159"
LINE 1: drop type 314159;
^
-- no such type
-- missing everything
drop operator;
-ERROR: syntax error at or near ";" at character 14
+ERROR: syntax error at or near ";"
LINE 1: drop operator;
^
-- bad operator name
drop operator equals;
-ERROR: syntax error at or near ";" at character 21
+ERROR: syntax error at or near ";"
LINE 1: drop operator equals;
^
-- missing type list
drop operator ===;
-ERROR: syntax error at or near ";" at character 18
+ERROR: syntax error at or near ";"
LINE 1: drop operator ===;
^
-- missing parentheses
drop operator int4, int4;
-ERROR: syntax error at or near "," at character 19
+ERROR: syntax error at or near ","
LINE 1: drop operator int4, int4;
^
-- missing operator name
drop operator (int4, int4);
-ERROR: syntax error at or near "(" at character 15
+ERROR: syntax error at or near "("
LINE 1: drop operator (int4, int4);
^
-- missing type list contents
drop operator === ();
-ERROR: syntax error at or near ")" at character 20
+ERROR: syntax error at or near ")"
LINE 1: drop operator === ();
^
-- no such operator
HINT: Use NONE to denote the missing argument of a unary operator.
-- no such type1
drop operator = ( , int4);
-ERROR: syntax error at or near "," at character 19
+ERROR: syntax error at or near ","
LINE 1: drop operator = ( , int4);
^
-- no such type1
drop operator = (nonesuch, int4);
-ERROR: type nonesuch does not exist
+ERROR: type "nonesuch" does not exist
-- no such type2
drop operator = (int4, nonesuch);
-ERROR: type nonesuch does not exist
+ERROR: type "nonesuch" does not exist
-- no such type2
drop operator = (int4, );
-ERROR: syntax error at or near ")" at character 24
+ERROR: syntax error at or near ")"
LINE 1: drop operator = (int4, );
^
--
-- missing rule name
drop rule;
-ERROR: syntax error at or near ";" at character 10
+ERROR: syntax error at or near ";"
LINE 1: drop rule;
^
-- bad rule name
drop rule 314159;
-ERROR: syntax error at or near "314159" at character 11
+ERROR: syntax error at or near "314159"
LINE 1: drop rule 314159;
^
-- no such rule
ERROR: relation "noplace" does not exist
-- these postquel variants are no longer supported
drop tuple rule nonesuch;
-ERROR: syntax error at or near "tuple" at character 6
+ERROR: syntax error at or near "tuple"
LINE 1: drop tuple rule nonesuch;
^
drop instance rule nonesuch on noplace;
-ERROR: syntax error at or near "instance" at character 6
+ERROR: syntax error at or near "instance"
LINE 1: drop instance rule nonesuch on noplace;
^
drop rewrite rule nonesuch;
-ERROR: syntax error at or near "rewrite" at character 6
+ERROR: syntax error at or near "rewrite"
LINE 1: drop rewrite rule nonesuch;
^
--
-- Test psql's reporting of syntax error location
--
xxx;
-ERROR: syntax error at or near "xxx" at character 1
+ERROR: syntax error at or near "xxx"
LINE 1: xxx;
^
CREATE foo;
-ERROR: syntax error at or near "foo" at character 8
+ERROR: syntax error at or near "foo"
LINE 1: CREATE foo;
^
CREATE TABLE ;
-ERROR: syntax error at or near ";" at character 14
+ERROR: syntax error at or near ";"
LINE 1: CREATE TABLE ;
^
CREATE TABLE
\g
-ERROR: syntax error at end of input at character 13
+ERROR: syntax error at end of input
LINE 1: CREATE TABLE
^
INSERT INTO foo VALUES(123) foo;
-ERROR: syntax error at or near "foo" at character 29
+ERROR: syntax error at or near "foo"
LINE 1: INSERT INTO foo VALUES(123) foo;
^
INSERT INTO 123
VALUES(123);
-ERROR: syntax error at or near "123" at character 13
+ERROR: syntax error at or near "123"
LINE 1: INSERT INTO 123
^
INSERT INTO foo
VALUES(123) 123
;
-ERROR: syntax error at or near "123" at character 30
+ERROR: syntax error at or near "123"
LINE 2: VALUES(123) 123
^
-- with a tab
(id INT4 UNIQUE NOT NULL, id2 TEXT NOT NULL PRIMARY KEY,
id3 INTEGER NOT NUL,
id4 INT4 UNIQUE NOT NULL, id5 TEXT UNIQUE NOT NULL);
-ERROR: syntax error at or near "NUL" at character 94
+ERROR: syntax error at or near "NUL"
LINE 3: id3 INTEGER NOT NUL,
^
-- long line to be truncated on the left
CREATE TABLE foo(id INT4 UNIQUE NOT NULL, id2 TEXT NOT NULL PRIMARY KEY, id3 INTEGER NOT NUL,
id4 INT4 UNIQUE NOT NULL, id5 TEXT UNIQUE NOT NULL);
-ERROR: syntax error at or near "NUL" at character 90
+ERROR: syntax error at or near "NUL"
LINE 1: ...T NULL, id2 TEXT NOT NULL PRIMARY KEY, id3 INTEGER NOT NUL,
^
-- long line to be truncated on the right
CREATE TABLE foo(
id3 INTEGER NOT NUL, id4 INT4 UNIQUE NOT NULL, id5 TEXT UNIQUE NOT NULL, id INT4 UNIQUE NOT NULL, id2 TEXT NOT NULL PRIMARY KEY);
-ERROR: syntax error at or near "NUL" at character 35
+ERROR: syntax error at or near "NUL"
LINE 2: id3 INTEGER NOT NUL, id4 INT4 UNIQUE NOT NULL, id5 TEXT UNIQ...
^
-- long line to be truncated both ways
CREATE TABLE foo(id INT4 UNIQUE NOT NULL, id2 TEXT NOT NULL PRIMARY KEY, id3 INTEGER NOT NUL, id4 INT4 UNIQUE NOT NULL, id5 TEXT UNIQUE NOT NULL);
-ERROR: syntax error at or near "NUL" at character 90
+ERROR: syntax error at or near "NUL"
LINE 1: ...L, id2 TEXT NOT NULL PRIMARY KEY, id3 INTEGER NOT NUL, id4 I...
^
-- long line to be truncated on the left, many lines
NOT
NULL)
;
-ERROR: syntax error at or near "NUL" at character 101
+ERROR: syntax error at or near "NUL"
LINE 4: ...T NULL, id2 TEXT NOT NULL PRIMARY KEY, id3 INTEGER NOT NUL,
^
-- long line to be truncated on the right, many lines
foo(
id3 INTEGER NOT NUL, id4 INT4 UNIQUE NOT NULL, id5 TEXT UNIQUE NOT NULL, id INT4 UNIQUE NOT NULL, id2 TEXT NOT NULL PRIMARY KEY)
;
-ERROR: syntax error at or near "NUL" at character 47
+ERROR: syntax error at or near "NUL"
LINE 5: id3 INTEGER NOT NUL, id4 INT4 UNIQUE NOT NULL, id5 TEXT UNIQ...
^
-- long line to be truncated both ways, many lines
UNIQUE NOT NULL, idx INT4 UNIQUE NOT NULL, idy INT4 UNIQUE NOT NULL, id2 TEXT NOT NULL PRIMARY KEY, id3 INTEGER NOT NUL, id4 INT4 UNIQUE NOT NULL, id5 TEXT UNIQUE NOT NULL,
idz INT4 UNIQUE NOT NULL,
idv INT4 UNIQUE NOT NULL);
-ERROR: syntax error at or near "NUL" at character 157
+ERROR: syntax error at or near "NUL"
LINE 7: ...L, id2 TEXT NOT NULL PRIMARY KEY, id3 INTEGER NOT NUL, id4 I...
^
-- more than 10 lines...
UNIQUE
NOT
NULL);
-ERROR: syntax error at or near "NUL" at character 190
+ERROR: syntax error at or near "NUL"
LINE 16: ...L, id2 TEXT NOT NULL PRIMARY KEY, id3 INTEGER NOT NUL, id4 I...
^
-- Check that stack depth detection mechanism works and
SELECT '' AS count, p.f1, l.s, l.s # p.f1 AS intersection
FROM LSEG_TBL l, POINT_TBL p;
ERROR: operator does not exist: lseg # point
+LINE 1: SELECT '' AS count, p.f1, l.s, l.s # p.f1 AS intersection
+ ^
HINT: No operator matches the given name and argument type(s). You may need to add explicit type casts.
-- closest point
SELECT '' AS thirty, p.f1, l.s, p.f1 ## l.s AS closest
SELECT '' AS count, p.f1, l.s, l.s # p.f1 AS intersection
FROM LSEG_TBL l, POINT_TBL p;
ERROR: operator does not exist: lseg # point
+LINE 1: SELECT '' AS count, p.f1, l.s, l.s # p.f1 AS intersection
+ ^
HINT: No operator matches the given name and argument type(s). You may need to add explicit type casts.
-- closest point
SELECT '' AS thirty, p.f1, l.s, p.f1 ## l.s AS closest
SELECT '' AS count, p.f1, l.s, l.s # p.f1 AS intersection
FROM LSEG_TBL l, POINT_TBL p;
ERROR: operator does not exist: lseg # point
+LINE 1: SELECT '' AS count, p.f1, l.s, l.s # p.f1 AS intersection
+ ^
HINT: No operator matches the given name and argument type(s). You may need to add explicit type casts.
-- closest point
SELECT '' AS thirty, p.f1, l.s, p.f1 ## l.s AS closest
SELECT date '1991-02-03' - time with time zone '04:05:06 UTC' AS "Subtract Time UTC";
ERROR: operator does not exist: date - time with time zone
+LINE 1: SELECT date '1991-02-03' - time with time zone '04:05:06 UTC...
+ ^
HINT: No operator matches the given name and argument type(s). You may need to add explicit type casts.
--
-- timestamp, interval arithmetic
SELECT '' AS "xxx", i, k, t
FROM J1_TBL CROSS JOIN J2_TBL;
ERROR: column reference "i" is ambiguous
+LINE 1: SELECT '' AS "xxx", i, k, t
+ ^
-- resolve previous ambiguity by specifying the table name
SELECT '' AS "xxx", t1.i, k, t
FROM J1_TBL t1 CROSS JOIN J2_TBL t2;
SELECT '' AS "xxx", i, k, t
FROM J1_TBL CROSS JOIN J2_TBL;
ERROR: column reference "i" is ambiguous
+LINE 1: SELECT '' AS "xxx", i, k, t
+ ^
-- resolve previous ambiguity by specifying the table name
SELECT '' AS "xxx", t1.i, k, t
FROM J1_TBL t1 CROSS JOIN J2_TBL t2;
begin
return i+1;
end$$ language plpgsql;
-ERROR: RETURN cannot have a parameter in function with OUT parameters at or near "i" at character 74
+ERROR: RETURN cannot have a parameter in function with OUT parameters at or near "i"
LINE 3: return i+1;
^
create function f1(in i int, out j int) as $$
a := 10;
return a;
end$$ language plpgsql;
-ERROR: syntax error at or near "Johnny" at character 1
-QUERY: Johnny Yuma
-CONTEXT: SQL statement in PL/PgSQL function "bad_sql1" near line 4
+ERROR: syntax error at or near "Johnny"
LINE 1: Johnny Yuma
^
+QUERY: Johnny Yuma
+CONTEXT: SQL statement in PL/PgSQL function "bad_sql1" near line 4
create function bad_sql2() returns int as $$
declare r record;
begin
end loop;
return 5;
end;$$ language plpgsql;
-ERROR: syntax error at or near "fought" at character 11
-QUERY: select I fought the law, the law won
-CONTEXT: SQL statement in PL/PgSQL function "bad_sql2" near line 3
+ERROR: syntax error at or near "fought"
LINE 1: select I fought the law, the law won
^
+QUERY: select I fought the law, the law won
+CONTEXT: SQL statement in PL/PgSQL function "bad_sql2" near line 3
-- a RETURN expression is mandatory, except for void-returning
-- functions, where it is not allowed
create function missing_return_expr() returns int as $$
begin
return ;
end;$$ language plpgsql;
-ERROR: syntax error at end of input at character 8
-QUERY: SELECT
-CONTEXT: SQL statement in PL/PgSQL function "missing_return_expr" near line 2
+ERROR: syntax error at end of input
LINE 1: SELECT
^
+QUERY: SELECT
+CONTEXT: SQL statement in PL/PgSQL function "missing_return_expr" near line 2
create function void_return_expr() returns void as $$
begin
return 5;
end;$$ language plpgsql;
-ERROR: RETURN cannot have a parameter in function returning void at or near "5" at character 72
+ERROR: RETURN cannot have a parameter in function returning void at or near "5"
LINE 3: return 5;
^
-- VOID functions are allowed to omit RETURN
-- blocks
select excpt_test1();
ERROR: column "sqlstate" does not exist
-CONTEXT: SQL statement "SELECT sqlstate"
-PL/pgSQL function "excpt_test1" line 2 at raise
+LINE 1: SELECT sqlstate
+ ^
+QUERY: SELECT sqlstate
+CONTEXT: PL/pgSQL function "excpt_test1" line 2 at raise
create function excpt_test2() returns void as $$
begin
begin
-- should fail
select excpt_test2();
ERROR: column "sqlstate" does not exist
-CONTEXT: SQL statement "SELECT sqlstate"
-PL/pgSQL function "excpt_test2" line 4 at raise
+LINE 1: SELECT sqlstate
+ ^
+QUERY: SELECT sqlstate
+CONTEXT: PL/pgSQL function "excpt_test2" line 4 at raise
create function excpt_test3() returns void as $$
begin
begin
end loop flbl1;
end;
$$ language plpgsql;
-ERROR: no such label at or near "flbl1" at character 101
+ERROR: no such label at or near "flbl1"
LINE 5: end loop flbl1;
^
-- should fail: end label does not match start label
-- invalid type
PREPARE q4(nonexistenttype) AS SELECT $1;
ERROR: type "nonexistenttype" does not exist
+LINE 1: PREPARE q4(nonexistenttype) AS SELECT $1;
+ ^
-- create table as execute
PREPARE q5(int, text) AS
SELECT * FROM tenk1 WHERE unique1 = $1 OR stringu1 = $2;
set local add_missing_from = false;
select f1, q.c1 from quadtable; -- fails, q is a table reference
ERROR: missing FROM-clause entry for table "q"
+LINE 1: select f1, q.c1 from quadtable;
+ ^
rollback;
select f1, (q).c1, (qq.q).c1.i from quadtable qq;
f1 | c1 | i
select ROW('ABC','DEF') ~~ ROW('DEF','ABC') as fail;
ERROR: could not determine interpretation of row comparison operator ~~
+LINE 1: select ROW('ABC','DEF') ~~ ROW('DEF','ABC') as fail;
+ ^
HINT: Row comparison operators must be associated with btree operator classes.
-- Check row comparison with a subselect
select unique1, unique2 from tenk1
WHERE x.a = y.a
GROUP BY b ORDER BY b;
ERROR: column reference "b" is ambiguous
+LINE 3: GROUP BY b ORDER BY b;
+ ^
-- order w/ target under ambiguous condition
-- failure NOT expected
SELECT a, a FROM test_missing_target
WHERE x.a = y.a
GROUP BY b/2 ORDER BY b/2;
ERROR: column reference "b" is ambiguous
+LINE 3: GROUP BY b/2 ORDER BY b/2;
+ ^
-- group w/ existing GROUP BY target under ambiguous condition
SELECT x.b/2, count(x.b) FROM test_missing_target x, test_missing_target y
WHERE x.a = y.a
WHERE x.a = y.a
GROUP BY x.b/2;
ERROR: column reference "b" is ambiguous
+LINE 1: SELECT count(b) FROM test_missing_target x, test_missing_tar...
+ ^
-- group w/o existing GROUP BY target under ambiguous condition
-- into a table
SELECT count(x.b) INTO TABLE test_missing_target3
WHERE x.a = y.a
GROUP BY b ORDER BY b;
ERROR: column reference "b" is ambiguous
+LINE 3: GROUP BY b ORDER BY b;
+ ^
-- order w/ target under ambiguous condition
-- failure NOT expected
SELECT a, a FROM test_missing_target
WHERE x.a = y.a
GROUP BY b/2 ORDER BY b/2;
ERROR: column reference "b" is ambiguous
+LINE 3: GROUP BY b/2 ORDER BY b/2;
+ ^
-- group w/ existing GROUP BY target under ambiguous condition
SELECT x.b/2, count(x.b) FROM test_missing_target x, test_missing_target y
WHERE x.a = y.a
WHERE x.a = y.a
GROUP BY x.b/2;
ERROR: column reference "b" is ambiguous
+LINE 1: SELECT count(b) FROM test_missing_target x, test_missing_tar...
+ ^
-- group w/o existing GROUP BY target under ambiguous condition
-- into a table
SELECT count(x.b) INTO TABLE test_missing_target3
WHERE x.a = y.a
GROUP BY b ORDER BY b;
ERROR: column reference "b" is ambiguous
+LINE 3: GROUP BY b ORDER BY b;
+ ^
-- order w/ target under ambiguous condition
-- failure NOT expected
SELECT a, a FROM test_missing_target
WHERE x.a = y.a
GROUP BY b/2 ORDER BY b/2;
ERROR: column reference "b" is ambiguous
+LINE 3: GROUP BY b/2 ORDER BY b/2;
+ ^
-- group w/ existing GROUP BY target under ambiguous condition
SELECT x.b/2, count(x.b) FROM test_missing_target x, test_missing_target y
WHERE x.a = y.a
WHERE x.a = y.a
GROUP BY x.b/2;
ERROR: column reference "b" is ambiguous
+LINE 1: SELECT count(b) FROM test_missing_target x, test_missing_tar...
+ ^
-- group w/o existing GROUP BY target under ambiguous condition
-- into a table
SELECT count(x.b) INTO TABLE test_missing_target3
' - next line' /* this comment is not allowed here */
' - third line'
AS "Illegal comment within continuation";
-ERROR: syntax error at or near "' - third line'" at character 75
+ERROR: syntax error at or near "' - third line'"
LINE 3: ' - third line'
^
--
(1 row)
select 'a\bcd' as f1, 'a\b''cd' as f2, 'a\b''''cd' as f3, 'abcd\' as f4, 'ab\''cd' as f5, '\\' as f6;
-WARNING: nonstandard use of escape in a string literal at character 8
+WARNING: nonstandard use of escape in a string literal
+LINE 1: select 'a\bcd' as f1, 'a\b''cd' as f2, 'a\b''''cd' as f3, 'a...
+ ^
HINT: Use the escape string syntax for escapes, e.g., E'\r\n'.
-WARNING: nonstandard use of escape in a string literal at character 23
+WARNING: nonstandard use of escape in a string literal
+LINE 1: select 'a\bcd' as f1, 'a\b''cd' as f2, 'a\b''''cd' as f3, 'a...
+ ^
HINT: Use the escape string syntax for escapes, e.g., E'\r\n'.
-WARNING: nonstandard use of escape in a string literal at character 40
+WARNING: nonstandard use of escape in a string literal
+LINE 1: select 'a\bcd' as f1, 'a\b''cd' as f2, 'a\b''''cd' as f3, 'a...
+ ^
HINT: Use the escape string syntax for escapes, e.g., E'\r\n'.
-WARNING: nonstandard use of escape in a string literal at character 59
+WARNING: nonstandard use of escape in a string literal
+LINE 1: ...a\bcd' as f1, 'a\b''cd' as f2, 'a\b''''cd' as f3, 'abcd\' ...
+ ^
HINT: Use the escape string syntax for escapes, e.g., E'\r\n'.
-WARNING: nonstandard use of escape in a string literal at character 76
+WARNING: nonstandard use of escape in a string literal
+LINE 1: ...b''cd' as f2, 'a\b''''cd' as f3, 'abcd\' as f4, 'ab\''cd' ...
+ ^
HINT: Use the escape string syntax for escapes, e.g., E'\r\n'.
-WARNING: nonstandard use of escape in a string literal at character 93
+WARNING: nonstandard use of escape in a string literal
+LINE 1: ...b''''cd' as f3, 'abcd\' as f4, 'ab\''cd' as f5, '\\' as f6...
+ ^
HINT: Use the escape string syntax for escapes, e.g., E'\r\n'.
f1 | f2 | f3 | f4 | f5 | f6
-------+--------+---------+-------+--------+----
set standard_conforming_strings = off;
select 'a\\bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3, 'abcd\\' as f4, 'ab\\\'cd' as f5, '\\\\' as f6;
-WARNING: nonstandard use of \\ in a string literal at character 8
+WARNING: nonstandard use of \\ in a string literal
+LINE 1: select 'a\\bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3,...
+ ^
HINT: Use the escape string syntax for backslashes, e.g., E'\\'.
-WARNING: nonstandard use of \\ in a string literal at character 24
+WARNING: nonstandard use of \\ in a string literal
+LINE 1: select 'a\\bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3,...
+ ^
HINT: Use the escape string syntax for backslashes, e.g., E'\\'.
-WARNING: nonstandard use of \\ in a string literal at character 42
+WARNING: nonstandard use of \\ in a string literal
+LINE 1: select 'a\\bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3,...
+ ^
HINT: Use the escape string syntax for backslashes, e.g., E'\\'.
-WARNING: nonstandard use of \\ in a string literal at character 62
+WARNING: nonstandard use of \\ in a string literal
+LINE 1: ...bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3, 'abcd\\' ...
+ ^
HINT: Use the escape string syntax for backslashes, e.g., E'\\'.
-WARNING: nonstandard use of \\ in a string literal at character 80
+WARNING: nonstandard use of \\ in a string literal
+LINE 1: ...'cd' as f2, 'a\\b\'''cd' as f3, 'abcd\\' as f4, 'ab\\\'cd'...
+ ^
HINT: Use the escape string syntax for backslashes, e.g., E'\\'.
-WARNING: nonstandard use of \\ in a string literal at character 98
+WARNING: nonstandard use of \\ in a string literal
+LINE 1: ...'''cd' as f3, 'abcd\\' as f4, 'ab\\\'cd' as f5, '\\\\' as ...
+ ^
HINT: Use the escape string syntax for backslashes, e.g., E'\\'.
f1 | f2 | f3 | f4 | f5 | f6
-------+--------+---------+-------+--------+----
-- where we do mixed-type arithmetic. - thomas 2000-12-02
SELECT f1 + time '00:01' AS "Illegal" FROM TIME_TBL;
ERROR: operator is not unique: time without time zone + time without time zone
+LINE 1: SELECT f1 + time '00:01' AS "Illegal" FROM TIME_TBL;
+ ^
HINT: Could not choose a best candidate operator. You may need to add explicit type casts.
-- where we do mixed-type arithmetic. - thomas 2000-12-02
SELECT f1 + time with time zone '00:01' AS "Illegal" FROM TIMETZ_TBL;
ERROR: operator does not exist: time with time zone + time with time zone
+LINE 1: SELECT f1 + time with time zone '00:01' AS "Illegal" FROM TI...
+ ^
HINT: No operator matches the given name and argument type(s). You may need to add explicit type casts.
SAVEPOINT one;
SELECT foo;
ERROR: column "foo" does not exist
+LINE 1: SELECT foo;
+ ^
ROLLBACK TO SAVEPOINT one;
RELEASE SAVEPOINT one;
SAVEPOINT two;
INSERT INTO savepoints VALUES (5);
SELECT foo;
ERROR: column "foo" does not exist
+LINE 1: SELECT foo;
+ ^
COMMIT;
SELECT * FROM savepoints;
a
-- This should fail, because q2 isn't a name of an EXCEPT output column
SELECT q1 FROM int8_tbl EXCEPT SELECT q2 FROM int8_tbl ORDER BY q2 LIMIT 1;
ERROR: column "q2" does not exist
+LINE 1: ... int8_tbl EXCEPT SELECT q2 FROM int8_tbl ORDER BY q2 LIMIT 1...
+ ^
-- But this should work:
SELECT q1 FROM int8_tbl EXCEPT (((SELECT q2 FROM int8_tbl ORDER BY q2 LIMIT 1)));
q1
SET LOCAL add_missing_from = false;
UPDATE update_test AS t SET b = update_test.b + 10 WHERE t.a = 10;
ERROR: invalid reference to FROM-clause entry for table "update_test"
+LINE 1: UPDATE update_test AS t SET b = update_test.b + 10 WHERE t.a...
+ ^
HINT: Perhaps you meant to reference the table alias "t".
ROLLBACK;
DROP TABLE update_test;
-- should fail
SELECT count(oid) FROM wo;
ERROR: column "oid" does not exist
+LINE 1: SELECT count(oid) FROM wo;
+ ^
VACUUM ANALYZE wi;
VACUUM ANALYZE wo;
SELECT min(relpages) < max(relpages), min(reltuples) - max(reltuples)
-- should fail
SELECT count(oid) FROM create_table_test3;
ERROR: column "oid" does not exist
+LINE 1: SELECT count(oid) FROM create_table_test3;
+ ^
PREPARE table_source(int) AS
SELECT a + b AS c1, a - b AS c2, $1 AS c3 FROM create_table_test;
CREATE TABLE execute_with WITH OIDS AS EXECUTE table_source(1);
-- should fail
SELECT count(oid) FROM execute_without;
ERROR: column "oid" does not exist
+LINE 1: SELECT count(oid) FROM execute_without;
+ ^
DROP TABLE create_table_test;
DROP TABLE create_table_test2;
DROP TABLE create_table_test3;
-- syntax errors
-- test for extraneous comma
CREATE TABLE error_tbl (i int DEFAULT (100, ));
-ERROR: syntax error at or near ")" at character 45
+ERROR: syntax error at or near ")"
LINE 1: CREATE TABLE error_tbl (i int DEFAULT (100, ));
^
-- this will fail because gram.y uses b_expr not a_expr for defaults,
-- to avoid a shift/reduce conflict that arises from NOT NULL being
-- part of the column definition syntax:
CREATE TABLE error_tbl (b1 bool DEFAULT 1 IN (1, 2));
-ERROR: syntax error at or near "IN" at character 43
+ERROR: syntax error at or near "IN"
LINE 1: CREATE TABLE error_tbl (b1 bool DEFAULT 1 IN (1, 2));
^
-- this should work, however:
CONTEXT: SQL function "test1"
CREATE FUNCTION test1 (int) RETURNS int LANGUAGE SQL
AS 'not even SQL';
-ERROR: syntax error at or near "not" at character 62
+ERROR: syntax error at or near "not"
LINE 2: AS 'not even SQL';
^
CREATE FUNCTION test1 (int) RETURNS int LANGUAGE SQL