Commit d8528630 authored by Tom Lane's avatar Tom Lane

Error message editing in backend/catalog.

parent da4ed8bf
This diff is collapsed.
This diff is collapsed.
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.247 2003/07/20 21:56:32 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.248 2003/07/21 01:59:08 tgl Exp $
* *
* *
* INTERFACE ROUTINES * INTERFACE ROUTINES
...@@ -147,17 +147,16 @@ static Form_pg_attribute SysAtt[] = {&a1, &a2, &a3, &a4, &a5, &a6, &a7}; ...@@ -147,17 +147,16 @@ static Form_pg_attribute SysAtt[] = {&a1, &a2, &a3, &a4, &a5, &a6, &a7};
/* /*
* This function returns a Form_pg_attribute pointer for a system attribute. * This function returns a Form_pg_attribute pointer for a system attribute.
* Note that we elog if the presented attno is invalid. * Note that we elog if the presented attno is invalid, which would only
* happen if there's a problem upstream.
*/ */
Form_pg_attribute Form_pg_attribute
SystemAttributeDefinition(AttrNumber attno, bool relhasoids) SystemAttributeDefinition(AttrNumber attno, bool relhasoids)
{ {
if (attno >= 0 || attno < -(int) lengthof(SysAtt)) if (attno >= 0 || attno < -(int) lengthof(SysAtt))
elog(ERROR, "SystemAttributeDefinition: invalid attribute number %d", elog(ERROR, "invalid system attribute number %d", attno);
attno);
if (attno == ObjectIdAttributeNumber && !relhasoids) if (attno == ObjectIdAttributeNumber && !relhasoids)
elog(ERROR, "SystemAttributeDefinition: invalid attribute number %d", elog(ERROR, "invalid system attribute number %d", attno);
attno);
return SysAtt[-attno - 1]; return SysAtt[-attno - 1];
} }
...@@ -223,9 +222,11 @@ heap_create(const char *relname, ...@@ -223,9 +222,11 @@ heap_create(const char *relname,
if (!allow_system_table_mods && if (!allow_system_table_mods &&
(IsSystemNamespace(relnamespace) || IsToastNamespace(relnamespace)) && (IsSystemNamespace(relnamespace) || IsToastNamespace(relnamespace)) &&
IsNormalProcessingMode()) IsNormalProcessingMode())
elog(ERROR, "cannot create %s.%s: " ereport(ERROR,
"system catalog modifications are currently disallowed", (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
get_namespace_name(relnamespace), relname); errmsg("permission denied to create \"%s.%s\"",
get_namespace_name(relnamespace), relname),
errdetail("System catalog modifications are currently disallowed.")));
/* /*
* Real ugly stuff to assign the proper relid in the relation * Real ugly stuff to assign the proper relid in the relation
...@@ -338,7 +339,7 @@ heap_storage_create(Relation rel) ...@@ -338,7 +339,7 @@ heap_storage_create(Relation rel)
* *
* this is used to make certain the tuple descriptor contains a * this is used to make certain the tuple descriptor contains a
* valid set of attribute names and datatypes. a problem simply * valid set of attribute names and datatypes. a problem simply
* generates elog(ERROR) which aborts the current transaction. * generates ereport(ERROR) which aborts the current transaction.
* -------------------------------- * --------------------------------
*/ */
void void
...@@ -367,8 +368,10 @@ CheckAttributeNamesTypes(TupleDesc tupdesc, char relkind) ...@@ -367,8 +368,10 @@ CheckAttributeNamesTypes(TupleDesc tupdesc, char relkind)
{ {
if (SystemAttributeByName(NameStr(tupdesc->attrs[i]->attname), if (SystemAttributeByName(NameStr(tupdesc->attrs[i]->attname),
tupdesc->tdhasoid) != NULL) tupdesc->tdhasoid) != NULL)
elog(ERROR, "name of column \"%s\" conflicts with an existing system column", ereport(ERROR,
NameStr(tupdesc->attrs[i]->attname)); (errcode(ERRCODE_DUPLICATE_COLUMN),
errmsg("column name \"%s\" conflicts with a system column name",
NameStr(tupdesc->attrs[i]->attname))));
} }
} }
...@@ -381,8 +384,10 @@ CheckAttributeNamesTypes(TupleDesc tupdesc, char relkind) ...@@ -381,8 +384,10 @@ CheckAttributeNamesTypes(TupleDesc tupdesc, char relkind)
{ {
if (strcmp(NameStr(tupdesc->attrs[j]->attname), if (strcmp(NameStr(tupdesc->attrs[j]->attname),
NameStr(tupdesc->attrs[i]->attname)) == 0) NameStr(tupdesc->attrs[i]->attname)) == 0)
elog(ERROR, "column name \"%s\" is duplicated", ereport(ERROR,
NameStr(tupdesc->attrs[j]->attname)); (errcode(ERRCODE_DUPLICATE_COLUMN),
errmsg("column name \"%s\" is duplicated",
NameStr(tupdesc->attrs[j]->attname))));
} }
} }
...@@ -419,23 +424,28 @@ CheckAttributeType(const char *attname, Oid atttypid) ...@@ -419,23 +424,28 @@ CheckAttributeType(const char *attname, Oid atttypid)
* Berkeley-derived code that thinks it can do this...) * Berkeley-derived code that thinks it can do this...)
*/ */
if (atttypid == UNKNOWNOID) if (atttypid == UNKNOWNOID)
elog(WARNING, "Attribute \"%s\" has an unknown type" ereport(WARNING,
"\n\tProceeding with relation creation anyway", (errcode(ERRCODE_INVALID_TABLE_DEFINITION),
attname); errmsg("attribute \"%s\" has type UNKNOWN", attname),
errdetail("Proceeding with relation creation anyway.")));
else if (att_typtype == 'p') else if (att_typtype == 'p')
{ {
/* Special hack for pg_statistic: allow ANYARRAY during initdb */ /* Special hack for pg_statistic: allow ANYARRAY during initdb */
if (atttypid != ANYARRAYOID || IsUnderPostmaster) if (atttypid != ANYARRAYOID || IsUnderPostmaster)
elog(ERROR, "Attribute \"%s\" has pseudo-type %s", ereport(ERROR,
attname, format_type_be(atttypid)); (errcode(ERRCODE_INVALID_TABLE_DEFINITION),
errmsg("attribute \"%s\" has pseudo-type %s",
attname, format_type_be(atttypid))));
} }
else if (att_typtype == 'c') else if (att_typtype == 'c')
{ {
Oid typrelid = get_typ_typrelid(atttypid); Oid typrelid = get_typ_typrelid(atttypid);
if (get_rel_relkind(typrelid) == RELKIND_COMPOSITE_TYPE) if (get_rel_relkind(typrelid) == RELKIND_COMPOSITE_TYPE)
elog(ERROR, "Attribute \"%s\" has composite type %s", ereport(ERROR,
attname, format_type_be(atttypid)); (errcode(ERRCODE_INVALID_TABLE_DEFINITION),
errmsg("attribute \"%s\" has composite type %s",
attname, format_type_be(atttypid))));
} }
} }
...@@ -719,7 +729,9 @@ heap_create_with_catalog(const char *relname, ...@@ -719,7 +729,9 @@ heap_create_with_catalog(const char *relname,
CheckAttributeNamesTypes(tupdesc, relkind); CheckAttributeNamesTypes(tupdesc, relkind);
if (get_relname_relid(relname, relnamespace)) if (get_relname_relid(relname, relnamespace))
elog(ERROR, "Relation '%s' already exists", relname); ereport(ERROR,
(errcode(ERRCODE_DUPLICATE_TABLE),
errmsg("relation \"%s\" already exists", relname)));
/* /*
* Create the relcache entry (mostly dummy at this point) and the * Create the relcache entry (mostly dummy at this point) and the
...@@ -955,7 +967,7 @@ RemoveAttributeById(Oid relid, AttrNumber attnum) ...@@ -955,7 +967,7 @@ RemoveAttributeById(Oid relid, AttrNumber attnum)
Int16GetDatum(attnum), Int16GetDatum(attnum),
0, 0); 0, 0);
if (!HeapTupleIsValid(tuple)) /* shouldn't happen */ if (!HeapTupleIsValid(tuple)) /* shouldn't happen */
elog(ERROR, "RemoveAttributeById: Failed to find attribute %d in relation %u", elog(ERROR, "cache lookup failed for attribute %d of relation %u",
attnum, relid); attnum, relid);
attStruct = (Form_pg_attribute) GETSTRUCT(tuple); attStruct = (Form_pg_attribute) GETSTRUCT(tuple);
...@@ -1047,7 +1059,7 @@ RemoveAttrDefault(Oid relid, AttrNumber attnum, ...@@ -1047,7 +1059,7 @@ RemoveAttrDefault(Oid relid, AttrNumber attnum,
heap_close(attrdef_rel, RowExclusiveLock); heap_close(attrdef_rel, RowExclusiveLock);
if (complain && !found) if (complain && !found)
elog(ERROR, "RemoveAttrDefault: no default found for rel %u attnum %d", elog(ERROR, "could not find attrdef tuple for relation %u attnum %d",
relid, attnum); relid, attnum);
} }
...@@ -1160,8 +1172,7 @@ heap_drop_with_catalog(Oid rid) ...@@ -1160,8 +1172,7 @@ heap_drop_with_catalog(Oid rid)
*/ */
i = FlushRelationBuffers(rel, (BlockNumber) 0); i = FlushRelationBuffers(rel, (BlockNumber) 0);
if (i < 0) if (i < 0)
elog(ERROR, "heap_drop_with_catalog: FlushRelationBuffers returned %d", elog(ERROR, "FlushRelationBuffers returned %d", i);
i);
/* /*
* remove inheritance information * remove inheritance information
...@@ -1539,8 +1550,10 @@ AddRelationRawConstraints(Relation rel, ...@@ -1539,8 +1550,10 @@ AddRelationRawConstraints(Relation rel,
RelationGetRelid(rel), RelationGetRelid(rel),
RelationGetNamespace(rel), RelationGetNamespace(rel),
ccname)) ccname))
elog(ERROR, "constraint \"%s\" for relation \"%s\" already exists", ereport(ERROR,
ccname, RelationGetRelationName(rel)); (errcode(ERRCODE_DUPLICATE_OBJECT),
errmsg("constraint \"%s\" for relation \"%s\" already exists",
ccname, RelationGetRelationName(rel))));
/* Check against other new constraints */ /* Check against other new constraints */
/* Needed because we don't do CommandCounterIncrement in loop */ /* Needed because we don't do CommandCounterIncrement in loop */
foreach(listptr2, rawConstraints) foreach(listptr2, rawConstraints)
...@@ -1553,8 +1566,10 @@ AddRelationRawConstraints(Relation rel, ...@@ -1553,8 +1566,10 @@ AddRelationRawConstraints(Relation rel,
cdef2->name == NULL) cdef2->name == NULL)
continue; continue;
if (strcmp(cdef2->name, ccname) == 0) if (strcmp(cdef2->name, ccname) == 0)
elog(ERROR, "Duplicate CHECK constraint name: '%s'", ereport(ERROR,
ccname); (errcode(ERRCODE_DUPLICATE_OBJECT),
errmsg("CHECK constraint \"%s\" already exists",
ccname)));
} }
} }
else else
...@@ -1613,16 +1628,22 @@ AddRelationRawConstraints(Relation rel, ...@@ -1613,16 +1628,22 @@ AddRelationRawConstraints(Relation rel,
* Make sure no outside relations are referred to. * Make sure no outside relations are referred to.
*/ */
if (length(pstate->p_rtable) != 1) if (length(pstate->p_rtable) != 1)
elog(ERROR, "Only relation \"%s\" can be referenced in CHECK constraint expression", ereport(ERROR,
relname); (errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
errmsg("only relation \"%s\" can be referenced in CHECK constraint",
relname)));
/* /*
* No subplans or aggregates, either... * No subplans or aggregates, either...
*/ */
if (pstate->p_hasSubLinks) if (pstate->p_hasSubLinks)
elog(ERROR, "cannot use subselect in CHECK constraint expression"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot use sub-select in CHECK constraint")));
if (pstate->p_hasAggs) if (pstate->p_hasAggs)
elog(ERROR, "cannot use aggregate function in CHECK constraint expression"); ereport(ERROR,
(errcode(ERRCODE_GROUPING_ERROR),
errmsg("cannot use aggregate in CHECK constraint")));
/* /*
* Constraints are evaluated with execQual, which expects an * Constraints are evaluated with execQual, which expects an
...@@ -1727,21 +1748,29 @@ cookDefault(ParseState *pstate, ...@@ -1727,21 +1748,29 @@ cookDefault(ParseState *pstate,
* Make sure default expr does not refer to any vars. * Make sure default expr does not refer to any vars.
*/ */
if (contain_var_clause(expr)) if (contain_var_clause(expr))
elog(ERROR, "cannot use column references in DEFAULT clause"); ereport(ERROR,
(errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
errmsg("cannot use column references in DEFAULT clause")));
/* /*
* It can't return a set either. * It can't return a set either.
*/ */
if (expression_returns_set(expr)) if (expression_returns_set(expr))
elog(ERROR, "DEFAULT clause must not return a set"); ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("DEFAULT clause must not return a set")));
/* /*
* No subplans or aggregates, either... * No subplans or aggregates, either...
*/ */
if (pstate->p_hasSubLinks) if (pstate->p_hasSubLinks)
elog(ERROR, "cannot use subselects in DEFAULT clause"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot use sub-select in DEFAULT clause")));
if (pstate->p_hasAggs) if (pstate->p_hasAggs)
elog(ERROR, "cannot use aggregate functions in DEFAULT clause"); ereport(ERROR,
(errcode(ERRCODE_GROUPING_ERROR),
errmsg("cannot use aggregate in DEFAULT clause")));
/* /*
* Check that it will be possible to coerce the expression to the * Check that it will be possible to coerce the expression to the
...@@ -1762,12 +1791,14 @@ cookDefault(ParseState *pstate, ...@@ -1762,12 +1791,14 @@ cookDefault(ParseState *pstate,
atttypid, atttypmod, atttypid, atttypmod,
COERCION_ASSIGNMENT, COERCION_ASSIGNMENT,
COERCE_IMPLICIT_CAST) == NULL) COERCE_IMPLICIT_CAST) == NULL)
elog(ERROR, "Column \"%s\" is of type %s" ereport(ERROR,
" but default expression is of type %s" (errcode(ERRCODE_DATATYPE_MISMATCH),
"\n\tYou will need to rewrite or cast the expression", errmsg("column \"%s\" is of type %s"
" but default expression is of type %s",
attname, attname,
format_type_be(atttypid), format_type_be(atttypid),
format_type_be(type_id)); format_type_be(type_id)),
errhint("You will need to rewrite or cast the expression.")));
} }
return (expr); return (expr);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.211 2003/05/29 00:54:42 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.212 2003/07/21 01:59:08 tgl Exp $
* *
* *
* INTERFACE ROUTINES * INTERFACE ROUTINES
...@@ -156,9 +156,8 @@ ConstructTupleDescriptor(Relation heapRelation, ...@@ -156,9 +156,8 @@ ConstructTupleDescriptor(Relation heapRelation,
/* /*
* here we are indexing on a normal attribute (1...n) * here we are indexing on a normal attribute (1...n)
*/ */
if (atnum > natts) if (atnum > natts) /* safety check */
elog(ERROR, "cannot create index: column %d does not exist", elog(ERROR, "invalid column number %d", atnum);
atnum);
from = heapTupDesc->attrs[AttrNumberGetAttrOffset(atnum)]; from = heapTupDesc->attrs[AttrNumberGetAttrOffset(atnum)];
} }
...@@ -186,7 +185,7 @@ ConstructTupleDescriptor(Relation heapRelation, ...@@ -186,7 +185,7 @@ ConstructTupleDescriptor(Relation heapRelation,
/* Expressional index */ /* Expressional index */
Node *indexkey; Node *indexkey;
if (indexprs == NIL) if (indexprs == NIL) /* shouldn't happen */
elog(ERROR, "too few entries in indexprs list"); elog(ERROR, "too few entries in indexprs list");
indexkey = (Node *) lfirst(indexprs); indexkey = (Node *) lfirst(indexprs);
indexprs = lnext(indexprs); indexprs = lnext(indexprs);
...@@ -205,7 +204,7 @@ ConstructTupleDescriptor(Relation heapRelation, ...@@ -205,7 +204,7 @@ ConstructTupleDescriptor(Relation heapRelation,
ObjectIdGetDatum(keyType), ObjectIdGetDatum(keyType),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(tuple)) if (!HeapTupleIsValid(tuple))
elog(ERROR, "Type %u does not exist", keyType); elog(ERROR, "cache lookup failed for type %u", keyType);
typeTup = (Form_pg_type) GETSTRUCT(tuple); typeTup = (Form_pg_type) GETSTRUCT(tuple);
/* /*
...@@ -239,7 +238,8 @@ ConstructTupleDescriptor(Relation heapRelation, ...@@ -239,7 +238,8 @@ ConstructTupleDescriptor(Relation heapRelation,
ObjectIdGetDatum(classObjectId[i]), ObjectIdGetDatum(classObjectId[i]),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(tuple)) if (!HeapTupleIsValid(tuple))
elog(ERROR, "Opclass %u does not exist", classObjectId[i]); elog(ERROR, "cache lookup failed for opclass %u",
classObjectId[i]);
keyType = ((Form_pg_opclass) GETSTRUCT(tuple))->opckeytype; keyType = ((Form_pg_opclass) GETSTRUCT(tuple))->opckeytype;
ReleaseSysCache(tuple); ReleaseSysCache(tuple);
...@@ -250,7 +250,7 @@ ConstructTupleDescriptor(Relation heapRelation, ...@@ -250,7 +250,7 @@ ConstructTupleDescriptor(Relation heapRelation,
ObjectIdGetDatum(keyType), ObjectIdGetDatum(keyType),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(tuple)) if (!HeapTupleIsValid(tuple))
elog(ERROR, "Type %u does not exist", keyType); elog(ERROR, "cache lookup failed for type %u", keyType);
typeTup = (Form_pg_type) GETSTRUCT(tuple); typeTup = (Form_pg_type) GETSTRUCT(tuple);
to->atttypid = keyType; to->atttypid = keyType;
...@@ -520,7 +520,9 @@ index_create(Oid heapRelationId, ...@@ -520,7 +520,9 @@ index_create(Oid heapRelationId,
if (!allow_system_table_mods && if (!allow_system_table_mods &&
IsSystemRelation(heapRelation) && IsSystemRelation(heapRelation) &&
IsNormalProcessingMode()) IsNormalProcessingMode())
elog(ERROR, "User-defined indexes on system catalogs are not supported"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("user-defined indexes on system catalogs are not supported")));
/* /*
* We cannot allow indexing a shared relation after initdb (because * We cannot allow indexing a shared relation after initdb (because
...@@ -530,11 +532,15 @@ index_create(Oid heapRelationId, ...@@ -530,11 +532,15 @@ index_create(Oid heapRelationId,
* under normal multi-user operation. * under normal multi-user operation.
*/ */
if (shared_relation && IsUnderPostmaster) if (shared_relation && IsUnderPostmaster)
elog(ERROR, "Shared indexes cannot be created after initdb"); ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("shared indexes cannot be created after initdb")));
if (get_relname_relid(indexRelationName, namespaceId)) if (get_relname_relid(indexRelationName, namespaceId))
elog(ERROR, "relation named \"%s\" already exists", ereport(ERROR,
indexRelationName); (errcode(ERRCODE_DUPLICATE_TABLE),
errmsg("relation \"%s\" already exists",
indexRelationName)));
/* /*
* construct tuple descriptor for index tuples * construct tuple descriptor for index tuples
...@@ -639,7 +645,7 @@ index_create(Oid heapRelationId, ...@@ -639,7 +645,7 @@ index_create(Oid heapRelationId,
constraintType = CONSTRAINT_UNIQUE; constraintType = CONSTRAINT_UNIQUE;
else else
{ {
elog(ERROR, "index_create: constraint must be PRIMARY or UNIQUE"); elog(ERROR, "constraint must be PRIMARY or UNIQUE");
constraintType = 0; /* keep compiler quiet */ constraintType = 0; /* keep compiler quiet */
} }
...@@ -807,8 +813,7 @@ index_drop(Oid indexId) ...@@ -807,8 +813,7 @@ index_drop(Oid indexId)
ObjectIdGetDatum(indexId), ObjectIdGetDatum(indexId),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(tuple)) if (!HeapTupleIsValid(tuple))
elog(ERROR, "index_drop: cache lookup failed for index %u", elog(ERROR, "cache lookup failed for index %u", indexId);
indexId);
simple_heap_delete(indexRelation, &tuple->t_self); simple_heap_delete(indexRelation, &tuple->t_self);
...@@ -820,7 +825,7 @@ index_drop(Oid indexId) ...@@ -820,7 +825,7 @@ index_drop(Oid indexId)
*/ */
i = FlushRelationBuffers(userIndexRelation, (BlockNumber) 0); i = FlushRelationBuffers(userIndexRelation, (BlockNumber) 0);
if (i < 0) if (i < 0)
elog(ERROR, "index_drop: FlushRelationBuffers returned %d", i); elog(ERROR, "FlushRelationBuffers returned %d", i);
smgrunlink(DEFAULT_SMGR, userIndexRelation); smgrunlink(DEFAULT_SMGR, userIndexRelation);
...@@ -984,8 +989,10 @@ IndexesAreActive(Relation heaprel) ...@@ -984,8 +989,10 @@ IndexesAreActive(Relation heaprel)
if (heaprel->rd_rel->relkind != RELKIND_RELATION && if (heaprel->rd_rel->relkind != RELKIND_RELATION &&
heaprel->rd_rel->relkind != RELKIND_TOASTVALUE) heaprel->rd_rel->relkind != RELKIND_TOASTVALUE)
elog(ERROR, "relation %s isn't an indexable relation", ereport(ERROR,
RelationGetRelationName(heaprel)); (errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("relation \"%s\" isn't an indexable relation",
RelationGetRelationName(heaprel))));
/* If pg_class.relhasindex is set, indexes are active */ /* If pg_class.relhasindex is set, indexes are active */
isactive = heaprel->rd_rel->relhasindex; isactive = heaprel->rd_rel->relhasindex;
...@@ -1055,8 +1062,7 @@ setRelhasindex(Oid relid, bool hasindex, bool isprimary, Oid reltoastidxid) ...@@ -1055,8 +1062,7 @@ setRelhasindex(Oid relid, bool hasindex, bool isprimary, Oid reltoastidxid)
} }
if (!HeapTupleIsValid(tuple)) if (!HeapTupleIsValid(tuple))
elog(ERROR, "setRelhasindex: cannot find relation %u in pg_class", elog(ERROR, "could not find tuple for relation %u", relid);
relid);
/* /*
* Update fields in the pg_class tuple. * Update fields in the pg_class tuple.
...@@ -1171,7 +1177,7 @@ setNewRelfilenode(Relation relation) ...@@ -1171,7 +1177,7 @@ setNewRelfilenode(Relation relation)
} }
if (!HeapTupleIsValid(tuple)) if (!HeapTupleIsValid(tuple))
elog(ERROR, "setNewRelfilenode: cannot find relation %u in pg_class", elog(ERROR, "could not find tuple for relation %u",
RelationGetRelid(relation)); RelationGetRelid(relation));
rd_rel = (Form_pg_class) GETSTRUCT(tuple); rd_rel = (Form_pg_class) GETSTRUCT(tuple);
...@@ -1283,8 +1289,7 @@ UpdateStats(Oid relid, double reltuples) ...@@ -1283,8 +1289,7 @@ UpdateStats(Oid relid, double reltuples)
} }
if (!HeapTupleIsValid(tuple)) if (!HeapTupleIsValid(tuple))
elog(ERROR, "UpdateStats: cannot find relation %u in pg_class", elog(ERROR, "could not find tuple for relation %u", relid);
relid);
/* /*
* Figure values to insert. * Figure values to insert.
...@@ -1558,7 +1563,7 @@ IndexBuildHeapScan(Relation heapRelation, ...@@ -1558,7 +1563,7 @@ IndexBuildHeapScan(Relation heapRelation,
*/ */
if (!TransactionIdIsCurrentTransactionId( if (!TransactionIdIsCurrentTransactionId(
HeapTupleHeaderGetXmin(heapTuple->t_data))) HeapTupleHeaderGetXmin(heapTuple->t_data)))
elog(ERROR, "IndexBuildHeapScan: concurrent insert in progress"); elog(ERROR, "concurrent insert in progress");
indexIt = true; indexIt = true;
tupleIsAlive = true; tupleIsAlive = true;
break; break;
...@@ -1573,12 +1578,12 @@ IndexBuildHeapScan(Relation heapRelation, ...@@ -1573,12 +1578,12 @@ IndexBuildHeapScan(Relation heapRelation,
*/ */
if (!TransactionIdIsCurrentTransactionId( if (!TransactionIdIsCurrentTransactionId(
HeapTupleHeaderGetXmax(heapTuple->t_data))) HeapTupleHeaderGetXmax(heapTuple->t_data)))
elog(ERROR, "IndexBuildHeapScan: concurrent delete in progress"); elog(ERROR, "concurrent delete in progress");
indexIt = true; indexIt = true;
tupleIsAlive = false; tupleIsAlive = false;
break; break;
default: default:
elog(ERROR, "Unexpected HeapTupleSatisfiesVacuum result"); elog(ERROR, "unexpected HeapTupleSatisfiesVacuum result");
indexIt = tupleIsAlive = false; /* keep compiler quiet */ indexIt = tupleIsAlive = false; /* keep compiler quiet */
break; break;
} }
...@@ -1673,8 +1678,7 @@ IndexGetRelation(Oid indexId) ...@@ -1673,8 +1678,7 @@ IndexGetRelation(Oid indexId)
ObjectIdGetDatum(indexId), ObjectIdGetDatum(indexId),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(tuple)) if (!HeapTupleIsValid(tuple))
elog(ERROR, "IndexGetRelation: can't find index id %u", elog(ERROR, "cache lookup failed for index %u", indexId);
indexId);
index = (Form_pg_index) GETSTRUCT(tuple); index = (Form_pg_index) GETSTRUCT(tuple);
Assert(index->indexrelid == indexId); Assert(index->indexrelid == indexId);
...@@ -1721,8 +1725,6 @@ reindex_index(Oid indexId, bool force, bool inplace) ...@@ -1721,8 +1725,6 @@ reindex_index(Oid indexId, bool force, bool inplace)
* index is locked down. * index is locked down.
*/ */
iRel = index_open(indexId); iRel = index_open(indexId);
if (iRel == NULL)
elog(ERROR, "reindex_index: can't open index relation");
LockRelation(iRel, AccessExclusiveLock); LockRelation(iRel, AccessExclusiveLock);
old = SetReindexProcessing(true); old = SetReindexProcessing(true);
...@@ -1732,8 +1734,6 @@ reindex_index(Oid indexId, bool force, bool inplace) ...@@ -1732,8 +1734,6 @@ reindex_index(Oid indexId, bool force, bool inplace)
/* Open the parent heap relation */ /* Open the parent heap relation */
heapRelation = heap_open(heapId, AccessExclusiveLock); heapRelation = heap_open(heapId, AccessExclusiveLock);
if (heapRelation == NULL)
elog(ERROR, "reindex_index: can't open heap relation");
/* /*
* If it's a shared index, we must do inplace processing (because we * If it's a shared index, we must do inplace processing (because we
...@@ -1747,13 +1747,17 @@ reindex_index(Oid indexId, bool force, bool inplace) ...@@ -1747,13 +1747,17 @@ reindex_index(Oid indexId, bool force, bool inplace)
if (iRel->rd_rel->relisshared) if (iRel->rd_rel->relisshared)
{ {
if (!IsIgnoringSystemIndexes()) if (!IsIgnoringSystemIndexes())
elog(ERROR, "the target relation %u is shared", indexId); ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("the target relation %u is shared", indexId)));
inplace = true; inplace = true;
} }
if (iRel->rd_isnailed) if (iRel->rd_isnailed)
{ {
if (!IsIgnoringSystemIndexes()) if (!IsIgnoringSystemIndexes())
elog(ERROR, "the target relation %u is nailed", indexId); ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("the target relation %u is nailed", indexId)));
inplace = true; inplace = true;
} }
...@@ -1870,7 +1874,9 @@ reindex_relation(Oid relid, bool force) ...@@ -1870,7 +1874,9 @@ reindex_relation(Oid relid, bool force)
deactivate_needed = true; deactivate_needed = true;
} }
else else
elog(ERROR, "the target relation %u is shared", relid); ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("the target relation %u is shared", relid)));
} }
old = SetReindexProcessing(true); old = SetReindexProcessing(true);
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/namespace.c,v 1.53 2003/06/27 17:03:29 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/namespace.c,v 1.54 2003/07/21 01:59:09 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -162,7 +162,9 @@ RangeVarGetRelid(const RangeVar *relation, bool failOK) ...@@ -162,7 +162,9 @@ RangeVarGetRelid(const RangeVar *relation, bool failOK)
if (relation->catalogname) if (relation->catalogname)
{ {
if (strcmp(relation->catalogname, get_database_name(MyDatabaseId)) != 0) if (strcmp(relation->catalogname, get_database_name(MyDatabaseId)) != 0)
elog(ERROR, "Cross-database references are not implemented"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cross-database references are not implemented")));
} }
if (relation->schemaname) if (relation->schemaname)
...@@ -180,11 +182,15 @@ RangeVarGetRelid(const RangeVar *relation, bool failOK) ...@@ -180,11 +182,15 @@ RangeVarGetRelid(const RangeVar *relation, bool failOK)
if (!OidIsValid(relId) && !failOK) if (!OidIsValid(relId) && !failOK)
{ {
if (relation->schemaname) if (relation->schemaname)
elog(ERROR, "Relation \"%s\".\"%s\" does not exist", ereport(ERROR,
relation->schemaname, relation->relname); (errcode(ERRCODE_UNDEFINED_TABLE),
errmsg("relation \"%s.%s\" does not exist",
relation->schemaname, relation->relname)));
else else
elog(ERROR, "Relation \"%s\" does not exist", ereport(ERROR,
relation->relname); (errcode(ERRCODE_UNDEFINED_TABLE),
errmsg("relation \"%s\" does not exist",
relation->relname)));
} }
return relId; return relId;
} }
...@@ -209,14 +215,18 @@ RangeVarGetCreationNamespace(const RangeVar *newRelation) ...@@ -209,14 +215,18 @@ RangeVarGetCreationNamespace(const RangeVar *newRelation)
if (newRelation->catalogname) if (newRelation->catalogname)
{ {
if (strcmp(newRelation->catalogname, get_database_name(MyDatabaseId)) != 0) if (strcmp(newRelation->catalogname, get_database_name(MyDatabaseId)) != 0)
elog(ERROR, "Cross-database references are not implemented"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cross-database references are not implemented")));
} }
if (newRelation->istemp) if (newRelation->istemp)
{ {
/* TEMP tables are created in our backend-local temp namespace */ /* TEMP tables are created in our backend-local temp namespace */
if (newRelation->schemaname) if (newRelation->schemaname)
elog(ERROR, "TEMP tables may not specify a namespace"); ereport(ERROR,
(errcode(ERRCODE_INVALID_TABLE_DEFINITION),
errmsg("TEMP tables may not specify a schema name")));
/* Initialize temp namespace if first time through */ /* Initialize temp namespace if first time through */
if (!OidIsValid(myTempNamespace)) if (!OidIsValid(myTempNamespace))
InitTempTableNamespace(); InitTempTableNamespace();
...@@ -230,8 +240,10 @@ RangeVarGetCreationNamespace(const RangeVar *newRelation) ...@@ -230,8 +240,10 @@ RangeVarGetCreationNamespace(const RangeVar *newRelation)
CStringGetDatum(newRelation->schemaname), CStringGetDatum(newRelation->schemaname),
0, 0, 0); 0, 0, 0);
if (!OidIsValid(namespaceId)) if (!OidIsValid(namespaceId))
elog(ERROR, "Namespace \"%s\" does not exist", ereport(ERROR,
newRelation->schemaname); (errcode(ERRCODE_UNDEFINED_SCHEMA),
errmsg("schema \"%s\" does not exist",
newRelation->schemaname)));
/* we do not check for USAGE rights here! */ /* we do not check for USAGE rights here! */
} }
else else
...@@ -240,7 +252,9 @@ RangeVarGetCreationNamespace(const RangeVar *newRelation) ...@@ -240,7 +252,9 @@ RangeVarGetCreationNamespace(const RangeVar *newRelation)
recomputeNamespacePath(); recomputeNamespacePath();
namespaceId = defaultCreationNamespace; namespaceId = defaultCreationNamespace;
if (!OidIsValid(namespaceId)) if (!OidIsValid(namespaceId))
elog(ERROR, "No namespace has been selected to create in"); ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_SCHEMA),
errmsg("no schema has been selected to create in")));
} }
/* Note: callers will check for CREATE rights when appropriate */ /* Note: callers will check for CREATE rights when appropriate */
...@@ -293,7 +307,7 @@ RelationIsVisible(Oid relid) ...@@ -293,7 +307,7 @@ RelationIsVisible(Oid relid)
ObjectIdGetDatum(relid), ObjectIdGetDatum(relid),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(reltup)) if (!HeapTupleIsValid(reltup))
elog(ERROR, "Cache lookup failed for relation %u", relid); elog(ERROR, "cache lookup failed for relation %u", relid);
relform = (Form_pg_class) GETSTRUCT(reltup); relform = (Form_pg_class) GETSTRUCT(reltup);
recomputeNamespacePath(); recomputeNamespacePath();
...@@ -375,7 +389,7 @@ TypeIsVisible(Oid typid) ...@@ -375,7 +389,7 @@ TypeIsVisible(Oid typid)
ObjectIdGetDatum(typid), ObjectIdGetDatum(typid),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(typtup)) if (!HeapTupleIsValid(typtup))
elog(ERROR, "Cache lookup failed for type %u", typid); elog(ERROR, "cache lookup failed for type %u", typid);
typform = (Form_pg_type) GETSTRUCT(typtup); typform = (Form_pg_type) GETSTRUCT(typtup);
recomputeNamespacePath(); recomputeNamespacePath();
...@@ -576,7 +590,7 @@ FunctionIsVisible(Oid funcid) ...@@ -576,7 +590,7 @@ FunctionIsVisible(Oid funcid)
ObjectIdGetDatum(funcid), ObjectIdGetDatum(funcid),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(proctup)) if (!HeapTupleIsValid(proctup))
elog(ERROR, "Cache lookup failed for procedure %u", funcid); elog(ERROR, "cache lookup failed for function %u", funcid);
procform = (Form_pg_proc) GETSTRUCT(proctup); procform = (Form_pg_proc) GETSTRUCT(proctup);
recomputeNamespacePath(); recomputeNamespacePath();
...@@ -788,7 +802,7 @@ OperatorIsVisible(Oid oprid) ...@@ -788,7 +802,7 @@ OperatorIsVisible(Oid oprid)
ObjectIdGetDatum(oprid), ObjectIdGetDatum(oprid),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(oprtup)) if (!HeapTupleIsValid(oprtup))
elog(ERROR, "Cache lookup failed for operator %u", oprid); elog(ERROR, "cache lookup failed for operator %u", oprid);
oprform = (Form_pg_operator) GETSTRUCT(oprtup); oprform = (Form_pg_operator) GETSTRUCT(oprtup);
recomputeNamespacePath(); recomputeNamespacePath();
...@@ -1001,7 +1015,7 @@ OpclassIsVisible(Oid opcid) ...@@ -1001,7 +1015,7 @@ OpclassIsVisible(Oid opcid)
ObjectIdGetDatum(opcid), ObjectIdGetDatum(opcid),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(opctup)) if (!HeapTupleIsValid(opctup))
elog(ERROR, "Cache lookup failed for opclass %u", opcid); elog(ERROR, "cache lookup failed for opclass %u", opcid);
opcform = (Form_pg_opclass) GETSTRUCT(opctup); opcform = (Form_pg_opclass) GETSTRUCT(opctup);
recomputeNamespacePath(); recomputeNamespacePath();
...@@ -1082,7 +1096,7 @@ ConversionIsVisible(Oid conid) ...@@ -1082,7 +1096,7 @@ ConversionIsVisible(Oid conid)
ObjectIdGetDatum(conid), ObjectIdGetDatum(conid),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(contup)) if (!HeapTupleIsValid(contup))
elog(ERROR, "Cache lookup failed for conversion %u", conid); elog(ERROR, "cache lookup failed for conversion %u", conid);
conform = (Form_pg_conversion) GETSTRUCT(contup); conform = (Form_pg_conversion) GETSTRUCT(contup);
recomputeNamespacePath(); recomputeNamespacePath();
...@@ -1148,11 +1162,15 @@ DeconstructQualifiedName(List *names, ...@@ -1148,11 +1162,15 @@ DeconstructQualifiedName(List *names,
* We check the catalog name and then ignore it. * We check the catalog name and then ignore it.
*/ */
if (strcmp(catalogname, get_database_name(MyDatabaseId)) != 0) if (strcmp(catalogname, get_database_name(MyDatabaseId)) != 0)
elog(ERROR, "Cross-database references are not implemented"); ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cross-database references are not implemented")));
break; break;
default: default:
elog(ERROR, "Improper qualified name (too many dotted names): %s", ereport(ERROR,
NameListToString(names)); (errcode(ERRCODE_SYNTAX_ERROR),
errmsg("improper qualified name (too many dotted names): %s",
NameListToString(names))));
break; break;
} }
...@@ -1165,7 +1183,7 @@ DeconstructQualifiedName(List *names, ...@@ -1165,7 +1183,7 @@ DeconstructQualifiedName(List *names,
* Process an explicitly-specified schema name: look up the schema * Process an explicitly-specified schema name: look up the schema
* and verify we have USAGE (lookup) rights in it. * and verify we have USAGE (lookup) rights in it.
* *
* Returns the namespace OID. Raises elog if any problem. * Returns the namespace OID. Raises ereport if any problem.
*/ */
Oid Oid
LookupExplicitNamespace(const char *nspname) LookupExplicitNamespace(const char *nspname)
...@@ -1177,7 +1195,9 @@ LookupExplicitNamespace(const char *nspname) ...@@ -1177,7 +1195,9 @@ LookupExplicitNamespace(const char *nspname)
CStringGetDatum(nspname), CStringGetDatum(nspname),
0, 0, 0); 0, 0, 0);
if (!OidIsValid(namespaceId)) if (!OidIsValid(namespaceId))
elog(ERROR, "Namespace \"%s\" does not exist", nspname); ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_SCHEMA),
errmsg("schema \"%s\" does not exist", nspname)));
aclresult = pg_namespace_aclcheck(namespaceId, GetUserId(), ACL_USAGE); aclresult = pg_namespace_aclcheck(namespaceId, GetUserId(), ACL_USAGE);
if (aclresult != ACLCHECK_OK) if (aclresult != ACLCHECK_OK)
...@@ -1212,8 +1232,9 @@ QualifiedNameGetCreationNamespace(List *names, char **objname_p) ...@@ -1212,8 +1232,9 @@ QualifiedNameGetCreationNamespace(List *names, char **objname_p)
CStringGetDatum(schemaname), CStringGetDatum(schemaname),
0, 0, 0); 0, 0, 0);
if (!OidIsValid(namespaceId)) if (!OidIsValid(namespaceId))
elog(ERROR, "Namespace \"%s\" does not exist", ereport(ERROR,
schemaname); (errcode(ERRCODE_UNDEFINED_SCHEMA),
errmsg("schema \"%s\" does not exist", schemaname)));
/* we do not check for USAGE rights here! */ /* we do not check for USAGE rights here! */
} }
else else
...@@ -1222,7 +1243,9 @@ QualifiedNameGetCreationNamespace(List *names, char **objname_p) ...@@ -1222,7 +1243,9 @@ QualifiedNameGetCreationNamespace(List *names, char **objname_p)
recomputeNamespacePath(); recomputeNamespacePath();
namespaceId = defaultCreationNamespace; namespaceId = defaultCreationNamespace;
if (!OidIsValid(namespaceId)) if (!OidIsValid(namespaceId))
elog(ERROR, "No namespace has been selected to create in"); ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_SCHEMA),
errmsg("no schema has been selected to create in")));
} }
/* Note: callers will check for CREATE rights when appropriate */ /* Note: callers will check for CREATE rights when appropriate */
...@@ -1255,7 +1278,10 @@ makeRangeVarFromNameList(List *names) ...@@ -1255,7 +1278,10 @@ makeRangeVarFromNameList(List *names)
rel->relname = strVal(lthird(names)); rel->relname = strVal(lthird(names));
break; break;
default: default:
elog(ERROR, "Improper relation name (too many dotted names)"); ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("improper relation name (too many dotted names): %s",
NameListToString(names))));
break; break;
} }
...@@ -1467,7 +1493,7 @@ recomputeNamespacePath(void) ...@@ -1467,7 +1493,7 @@ recomputeNamespacePath(void)
{ {
/* syntax error in name list */ /* syntax error in name list */
/* this should not happen if GUC checked check_search_path */ /* this should not happen if GUC checked check_search_path */
elog(ERROR, "recomputeNamespacePath: invalid list syntax"); elog(ERROR, "invalid list syntax");
} }
/* /*
...@@ -1596,8 +1622,10 @@ InitTempTableNamespace(void) ...@@ -1596,8 +1622,10 @@ InitTempTableNamespace(void)
*/ */
if (pg_database_aclcheck(MyDatabaseId, GetSessionUserId(), if (pg_database_aclcheck(MyDatabaseId, GetSessionUserId(),
ACL_CREATE_TEMP) != ACLCHECK_OK) ACL_CREATE_TEMP) != ACLCHECK_OK)
elog(ERROR, "%s: not authorized to create temp tables", ereport(ERROR,
get_database_name(MyDatabaseId)); (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("not authorized to create temp tables in database \"%s\"",
get_database_name(MyDatabaseId))));
snprintf(namespaceName, sizeof(namespaceName), "pg_temp_%d", MyBackendId); snprintf(namespaceName, sizeof(namespaceName), "pg_temp_%d", MyBackendId);
...@@ -1766,7 +1794,9 @@ assign_search_path(const char *newval, bool doit, bool interactive) ...@@ -1766,7 +1794,9 @@ assign_search_path(const char *newval, bool doit, bool interactive)
if (!SearchSysCacheExists(NAMESPACENAME, if (!SearchSysCacheExists(NAMESPACENAME,
CStringGetDatum(curname), CStringGetDatum(curname),
0, 0, 0)) 0, 0, 0))
elog(ERROR, "Namespace \"%s\" does not exist", curname); ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_SCHEMA),
errmsg("schema \"%s\" does not exist", curname)));
} }
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_aggregate.c,v 1.60 2003/07/04 02:51:33 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/pg_aggregate.c,v 1.61 2003/07/21 01:59:10 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -62,7 +62,7 @@ AggregateCreate(const char *aggName, ...@@ -62,7 +62,7 @@ AggregateCreate(const char *aggName,
ObjectAddress myself, ObjectAddress myself,
referenced; referenced;
/* sanity checks */ /* sanity checks (caller should have caught these) */
if (!aggName) if (!aggName)
elog(ERROR, "no aggregate name supplied"); elog(ERROR, "no aggregate name supplied");
...@@ -75,8 +75,11 @@ AggregateCreate(const char *aggName, ...@@ -75,8 +75,11 @@ AggregateCreate(const char *aggName,
*/ */
if ((aggTransType == ANYARRAYOID || aggTransType == ANYELEMENTOID) && if ((aggTransType == ANYARRAYOID || aggTransType == ANYELEMENTOID) &&
!(aggBaseType == ANYARRAYOID || aggBaseType == ANYELEMENTOID)) !(aggBaseType == ANYARRAYOID || aggBaseType == ANYELEMENTOID))
elog(ERROR, "an aggregate using ANYARRAY or ANYELEMENT as trans type " ereport(ERROR,
"must also have one of them as its base type"); (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
errmsg("cannot determine transition datatype"),
errdetail("An aggregate using ANYARRAY or ANYELEMENT as "
"trans type must have one of them as its base type.")));
/* handle transfn */ /* handle transfn */
MemSet(fnArgs, 0, FUNC_MAX_ARGS * sizeof(Oid)); MemSet(fnArgs, 0, FUNC_MAX_ARGS * sizeof(Oid));
...@@ -102,14 +105,17 @@ AggregateCreate(const char *aggName, ...@@ -102,14 +105,17 @@ AggregateCreate(const char *aggName,
* polymorphic we *must* demand exact equality. * polymorphic we *must* demand exact equality.
*/ */
if (rettype != aggTransType) if (rettype != aggTransType)
elog(ERROR, "return type of transition function %s is not %s", ereport(ERROR,
NameListToString(aggtransfnName), format_type_be(aggTransType)); (errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("return type of transition function %s is not %s",
NameListToString(aggtransfnName),
format_type_be(aggTransType))));
tup = SearchSysCache(PROCOID, tup = SearchSysCache(PROCOID,
ObjectIdGetDatum(transfn), ObjectIdGetDatum(transfn),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(tup)) if (!HeapTupleIsValid(tup))
elog(ERROR, "cache lookup of function %u failed", transfn); elog(ERROR, "cache lookup failed for function %u", transfn);
proc = (Form_pg_proc) GETSTRUCT(tup); proc = (Form_pg_proc) GETSTRUCT(tup);
/* /*
...@@ -121,7 +127,9 @@ AggregateCreate(const char *aggName, ...@@ -121,7 +127,9 @@ AggregateCreate(const char *aggName,
if (proc->proisstrict && agginitval == NULL) if (proc->proisstrict && agginitval == NULL)
{ {
if (!IsBinaryCoercible(aggBaseType, aggTransType)) if (!IsBinaryCoercible(aggBaseType, aggTransType))
elog(ERROR, "must not omit initval when transfn is strict and transtype is not compatible with input type"); ereport(ERROR,
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
errmsg("must not omit initval when transfn is strict and transtype is not compatible with input type")));
} }
ReleaseSysCache(tup); ReleaseSysCache(tup);
...@@ -152,8 +160,11 @@ AggregateCreate(const char *aggName, ...@@ -152,8 +160,11 @@ AggregateCreate(const char *aggName,
*/ */
if ((finaltype == ANYARRAYOID || finaltype == ANYELEMENTOID) && if ((finaltype == ANYARRAYOID || finaltype == ANYELEMENTOID) &&
!(aggBaseType == ANYARRAYOID || aggBaseType == ANYELEMENTOID)) !(aggBaseType == ANYARRAYOID || aggBaseType == ANYELEMENTOID))
elog(ERROR, "an aggregate returning ANYARRAY or ANYELEMENT " ereport(ERROR,
"must also have one of them as its base type"); (errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("cannot determine result datatype"),
errdetail("An aggregate returning ANYARRAY or ANYELEMENT "
"must have one of them as its base type.")));
/* /*
* Everything looks okay. Try to create the pg_proc entry for the * Everything looks okay. Try to create the pg_proc entry for the
...@@ -264,11 +275,15 @@ lookup_agg_function(List *fnName, ...@@ -264,11 +275,15 @@ lookup_agg_function(List *fnName,
/* only valid case is a normal function not returning a set */ /* only valid case is a normal function not returning a set */
if (fdresult != FUNCDETAIL_NORMAL || !OidIsValid(fnOid)) if (fdresult != FUNCDETAIL_NORMAL || !OidIsValid(fnOid))
elog(ERROR, "function %s does not exist", ereport(ERROR,
func_signature_string(fnName, nargs, input_types)); (errcode(ERRCODE_UNDEFINED_FUNCTION),
errmsg("function %s does not exist",
func_signature_string(fnName, nargs, input_types))));
if (retset) if (retset)
elog(ERROR, "function %s returns a set", ereport(ERROR,
func_signature_string(fnName, nargs, input_types)); (errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("function %s returns a set",
func_signature_string(fnName, nargs, input_types))));
/* /*
* If the given type(s) are all polymorphic, there's nothing we * If the given type(s) are all polymorphic, there's nothing we
...@@ -296,15 +311,19 @@ lookup_agg_function(List *fnName, ...@@ -296,15 +311,19 @@ lookup_agg_function(List *fnName,
if (true_oid_array[0] != ANYARRAYOID && if (true_oid_array[0] != ANYARRAYOID &&
true_oid_array[0] != ANYELEMENTOID && true_oid_array[0] != ANYELEMENTOID &&
!IsBinaryCoercible(input_types[0], true_oid_array[0])) !IsBinaryCoercible(input_types[0], true_oid_array[0]))
elog(ERROR, "function %s requires run-time type coercion", ereport(ERROR,
func_signature_string(fnName, nargs, true_oid_array)); (errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("function %s requires run-time type coercion",
func_signature_string(fnName, nargs, true_oid_array))));
if (nargs == 2 && if (nargs == 2 &&
true_oid_array[1] != ANYARRAYOID && true_oid_array[1] != ANYARRAYOID &&
true_oid_array[1] != ANYELEMENTOID && true_oid_array[1] != ANYELEMENTOID &&
!IsBinaryCoercible(input_types[1], true_oid_array[1])) !IsBinaryCoercible(input_types[1], true_oid_array[1]))
elog(ERROR, "function %s requires run-time type coercion", ereport(ERROR,
func_signature_string(fnName, nargs, true_oid_array)); (errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("function %s requires run-time type coercion",
func_signature_string(fnName, nargs, true_oid_array))));
return fnOid; return fnOid;
} }
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_constraint.c,v 1.13 2003/05/28 16:03:56 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/pg_constraint.c,v 1.14 2003/07/21 01:59:10 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -427,8 +427,7 @@ RemoveConstraintById(Oid conId) ...@@ -427,8 +427,7 @@ RemoveConstraintById(Oid conId)
tup = systable_getnext(conscan); tup = systable_getnext(conscan);
if (!HeapTupleIsValid(tup)) if (!HeapTupleIsValid(tup))
elog(ERROR, "RemoveConstraintById: constraint %u not found", elog(ERROR, "could not find tuple for constraint %u", conId);
conId);
con = (Form_pg_constraint) GETSTRUCT(tup); con = (Form_pg_constraint) GETSTRUCT(tup);
/* /*
...@@ -460,12 +459,12 @@ RemoveConstraintById(Oid conId) ...@@ -460,12 +459,12 @@ RemoveConstraintById(Oid conId)
ObjectIdGetDatum(con->conrelid), ObjectIdGetDatum(con->conrelid),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(relTup)) if (!HeapTupleIsValid(relTup))
elog(ERROR, "cache lookup of relation %u failed", elog(ERROR, "cache lookup failed for relation %u",
con->conrelid); con->conrelid);
classForm = (Form_pg_class) GETSTRUCT(relTup); classForm = (Form_pg_class) GETSTRUCT(relTup);
if (classForm->relchecks == 0) if (classForm->relchecks == 0) /* should not happen */
elog(ERROR, "RemoveConstraintById: relation %s has relchecks = 0", elog(ERROR, "relation \"%s\" has relchecks = 0",
RelationGetRelationName(rel)); RelationGetRelationName(rel));
classForm->relchecks--; classForm->relchecks--;
...@@ -492,8 +491,7 @@ RemoveConstraintById(Oid conId) ...@@ -492,8 +491,7 @@ RemoveConstraintById(Oid conId)
} }
else else
{ {
elog(ERROR, "RemoveConstraintById: Constraint %u is not a known type", elog(ERROR, "constraint %u is not of a known type", conId);
conId);
} }
/* Fry the constraint itself */ /* Fry the constraint itself */
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_conversion.c,v 1.10 2003/01/27 00:45:19 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/pg_conversion.c,v 1.11 2003/07/21 01:59:10 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -61,7 +61,9 @@ ConversionCreate(const char *conname, Oid connamespace, ...@@ -61,7 +61,9 @@ ConversionCreate(const char *conname, Oid connamespace,
PointerGetDatum(conname), PointerGetDatum(conname),
ObjectIdGetDatum(connamespace), ObjectIdGetDatum(connamespace),
0, 0)) 0, 0))
elog(ERROR, "conversion name \"%s\" already exists", conname); ereport(ERROR,
(errcode(ERRCODE_DUPLICATE_OBJECT),
errmsg("conversion \"%s\" already exists", conname)));
if (def) if (def)
{ {
...@@ -72,9 +74,11 @@ ConversionCreate(const char *conname, Oid connamespace, ...@@ -72,9 +74,11 @@ ConversionCreate(const char *conname, Oid connamespace,
if (FindDefaultConversion(connamespace, if (FindDefaultConversion(connamespace,
conforencoding, conforencoding,
contoencoding)) contoencoding))
elog(ERROR, "default conversion for %s to %s already exists", ereport(ERROR,
(errcode(ERRCODE_DUPLICATE_OBJECT),
errmsg("default conversion for \"%s\" to \"%s\" already exists",
pg_encoding_to_char(conforencoding), pg_encoding_to_char(conforencoding),
pg_encoding_to_char(contoencoding)); pg_encoding_to_char(contoencoding))));
} }
/* open pg_conversion */ /* open pg_conversion */
...@@ -138,12 +142,13 @@ ConversionDrop(Oid conversionOid, DropBehavior behavior) ...@@ -138,12 +142,13 @@ ConversionDrop(Oid conversionOid, DropBehavior behavior)
ObjectIdGetDatum(conversionOid), ObjectIdGetDatum(conversionOid),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(tuple)) if (!HeapTupleIsValid(tuple))
elog(ERROR, "Conversion %u search from syscache failed", elog(ERROR, "cache lookup failed for conversion %u", conversionOid);
conversionOid);
if (!superuser() && if (!superuser() &&
((Form_pg_conversion) GETSTRUCT(tuple))->conowner != GetUserId()) ((Form_pg_conversion) GETSTRUCT(tuple))->conowner != GetUserId())
elog(ERROR, "DROP CONVERSION: permission denied"); ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("permission denied")));
ReleaseSysCache(tuple); ReleaseSysCache(tuple);
...@@ -189,7 +194,7 @@ RemoveConversionById(Oid conversionOid) ...@@ -189,7 +194,7 @@ RemoveConversionById(Oid conversionOid)
if (HeapTupleIsValid(tuple = heap_getnext(scan, ForwardScanDirection))) if (HeapTupleIsValid(tuple = heap_getnext(scan, ForwardScanDirection)))
simple_heap_delete(rel, &tuple->t_self); simple_heap_delete(rel, &tuple->t_self);
else else
elog(ERROR, "conversion %u does not exist", conversionOid); elog(ERROR, "could not find tuple for conversion %u", conversionOid);
heap_endscan(scan); heap_endscan(scan);
heap_close(rel, RowExclusiveLock); heap_close(rel, RowExclusiveLock);
} }
...@@ -299,13 +304,16 @@ pg_convert_using(PG_FUNCTION_ARGS) ...@@ -299,13 +304,16 @@ pg_convert_using(PG_FUNCTION_ARGS)
parsed_name = textToQualifiedNameList(conv_name, "convert_using"); parsed_name = textToQualifiedNameList(conv_name, "convert_using");
convoid = FindConversionByName(parsed_name); convoid = FindConversionByName(parsed_name);
if (!OidIsValid(convoid)) if (!OidIsValid(convoid))
elog(ERROR, "conversion %s not found", NameListToString(parsed_name)); ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("conversion \"%s\" does not exist",
NameListToString(parsed_name))));
tuple = SearchSysCache(CONOID, tuple = SearchSysCache(CONOID,
ObjectIdGetDatum(convoid), ObjectIdGetDatum(convoid),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(tuple)) if (!HeapTupleIsValid(tuple))
elog(ERROR, "Conversion %u search from syscache failed", convoid); elog(ERROR, "cache lookup failed for conversion %u", convoid);
body = (Form_pg_conversion) GETSTRUCT(tuple); body = (Form_pg_conversion) GETSTRUCT(tuple);
/* Temporary result area should be more than big enough */ /* Temporary result area should be more than big enough */
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_largeobject.c,v 1.14 2002/08/05 03:29:16 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/pg_largeobject.c,v 1.15 2003/07/21 01:59:10 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -105,7 +105,9 @@ LargeObjectDrop(Oid loid) ...@@ -105,7 +105,9 @@ LargeObjectDrop(Oid loid)
heap_close(pg_largeobject, RowShareLock); heap_close(pg_largeobject, RowShareLock);
if (!found) if (!found)
elog(ERROR, "LargeObjectDrop: large object %u not found", loid); ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("large object %u does not exist", loid)));
} }
bool bool
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_namespace.c,v 1.5 2002/08/05 03:29:16 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/pg_namespace.c,v 1.6 2003/07/21 01:59:10 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -46,7 +46,9 @@ NamespaceCreate(const char *nspName, int32 ownerSysId) ...@@ -46,7 +46,9 @@ NamespaceCreate(const char *nspName, int32 ownerSysId)
if (SearchSysCacheExists(NAMESPACENAME, if (SearchSysCacheExists(NAMESPACENAME,
PointerGetDatum(nspName), PointerGetDatum(nspName),
0, 0, 0)) 0, 0, 0))
elog(ERROR, "namespace \"%s\" already exists", nspName); ereport(ERROR,
(errcode(ERRCODE_DUPLICATE_SCHEMA),
errmsg("schema \"%s\" already exists", nspName)));
/* initialize nulls and values */ /* initialize nulls and values */
for (i = 0; i < Natts_pg_namespace; i++) for (i = 0; i < Natts_pg_namespace; i++)
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_operator.c,v 1.79 2003/07/04 02:51:33 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/pg_operator.c,v 1.80 2003/07/21 01:59:11 tgl Exp $
* *
* NOTES * NOTES
* these routines moved here from commands/define.c and somewhat cleaned up. * these routines moved here from commands/define.c and somewhat cleaned up.
...@@ -80,7 +80,7 @@ validOperatorName(const char *name) ...@@ -80,7 +80,7 @@ validOperatorName(const char *name)
/* Can't contain any invalid characters */ /* Can't contain any invalid characters */
/* Test string here should match op_chars in scan.l */ /* Test string here should match op_chars in scan.l */
if (strspn(name, "~!@#^&|`?$+-*/%<>=") != len) if (strspn(name, "~!@#^&|`?+-*/%<>=") != len)
return false; return false;
/* Can't contain slash-star or dash-dash (comment starts) */ /* Can't contain slash-star or dash-dash (comment starts) */
...@@ -102,7 +102,7 @@ validOperatorName(const char *name) ...@@ -102,7 +102,7 @@ validOperatorName(const char *name)
for (ic = len - 2; ic >= 0; ic--) for (ic = len - 2; ic >= 0; ic--)
{ {
if (strchr("~!@#^&|`?$%", name[ic])) if (strchr("~!@#^&|`?%", name[ic]))
break; break;
} }
if (ic < 0) if (ic < 0)
...@@ -212,7 +212,10 @@ OperatorShellMake(const char *operatorName, ...@@ -212,7 +212,10 @@ OperatorShellMake(const char *operatorName,
* validate operator name * validate operator name
*/ */
if (!validOperatorName(operatorName)) if (!validOperatorName(operatorName))
elog(ERROR, "\"%s\" is not a valid operator name", operatorName); ereport(ERROR,
(errcode(ERRCODE_INVALID_NAME),
errmsg("\"%s\" is not a valid operator name",
operatorName)));
/* /*
* initialize our *nulls and *values arrays * initialize our *nulls and *values arrays
...@@ -398,22 +401,35 @@ OperatorCreate(const char *operatorName, ...@@ -398,22 +401,35 @@ OperatorCreate(const char *operatorName,
* Sanity checks * Sanity checks
*/ */
if (!validOperatorName(operatorName)) if (!validOperatorName(operatorName))
elog(ERROR, "\"%s\" is not a valid operator name", operatorName); ereport(ERROR,
(errcode(ERRCODE_INVALID_NAME),
errmsg("\"%s\" is not a valid operator name",
operatorName)));
if (!OidIsValid(leftTypeId) && !OidIsValid(rightTypeId)) if (!OidIsValid(leftTypeId) && !OidIsValid(rightTypeId))
elog(ERROR, "at least one of leftarg or rightarg must be specified"); ereport(ERROR,
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
errmsg("at least one of leftarg or rightarg must be specified")));
if (!(OidIsValid(leftTypeId) && OidIsValid(rightTypeId))) if (!(OidIsValid(leftTypeId) && OidIsValid(rightTypeId)))
{ {
/* If it's not a binary op, these things mustn't be set: */ /* If it's not a binary op, these things mustn't be set: */
if (commutatorName) if (commutatorName)
elog(ERROR, "only binary operators can have commutators"); ereport(ERROR,
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
errmsg("only binary operators can have commutators")));
if (joinName) if (joinName)
elog(ERROR, "only binary operators can have join selectivity"); ereport(ERROR,
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
errmsg("only binary operators can have join selectivity")));
if (canHash) if (canHash)
elog(ERROR, "only binary operators can hash"); ereport(ERROR,
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
errmsg("only binary operators can hash")));
if (leftSortName || rightSortName || ltCompareName || gtCompareName) if (leftSortName || rightSortName || ltCompareName || gtCompareName)
elog(ERROR, "only binary operators can mergejoin"); ereport(ERROR,
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
errmsg("only binary operators can mergejoin")));
} }
operatorObjectId = OperatorGet(operatorName, operatorObjectId = OperatorGet(operatorName,
...@@ -423,8 +439,10 @@ OperatorCreate(const char *operatorName, ...@@ -423,8 +439,10 @@ OperatorCreate(const char *operatorName,
&operatorAlreadyDefined); &operatorAlreadyDefined);
if (operatorAlreadyDefined) if (operatorAlreadyDefined)
elog(ERROR, "OperatorDef: operator \"%s\" already defined", ereport(ERROR,
operatorName); (errcode(ERRCODE_DUPLICATE_FUNCTION),
errmsg("operator %s already exists",
operatorName)));
/* /*
* At this point, if operatorObjectId is not InvalidOid then we are * At this point, if operatorObjectId is not InvalidOid then we are
...@@ -615,7 +633,7 @@ OperatorCreate(const char *operatorName, ...@@ -615,7 +633,7 @@ OperatorCreate(const char *operatorName,
ObjectIdGetDatum(operatorObjectId), ObjectIdGetDatum(operatorObjectId),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(tup)) if (!HeapTupleIsValid(tup))
elog(ERROR, "OperatorDef: operator %u not found", elog(ERROR, "cache lookup failed for operator %u",
operatorObjectId); operatorObjectId);
tup = heap_modifytuple(tup, tup = heap_modifytuple(tup,
...@@ -703,7 +721,9 @@ get_other_operator(List *otherOp, Oid otherLeftTypeId, Oid otherRightTypeId, ...@@ -703,7 +721,9 @@ get_other_operator(List *otherOp, Oid otherLeftTypeId, Oid otherRightTypeId,
* only self-linkage for commutation makes sense. * only self-linkage for commutation makes sense.
*/ */
if (!isCommutator) if (!isCommutator)
elog(ERROR, "operator cannot be its own negator or sort operator"); ereport(ERROR,
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
errmsg("operator cannot be its own negator or sort operator")));
return InvalidOid; return InvalidOid;
} }
...@@ -718,10 +738,6 @@ get_other_operator(List *otherOp, Oid otherLeftTypeId, Oid otherRightTypeId, ...@@ -718,10 +738,6 @@ get_other_operator(List *otherOp, Oid otherLeftTypeId, Oid otherRightTypeId,
otherNamespace, otherNamespace,
otherLeftTypeId, otherLeftTypeId,
otherRightTypeId); otherRightTypeId);
if (!OidIsValid(other_oid))
elog(ERROR,
"OperatorDef: can't create operator shell \"%s\"",
NameListToString(otherOp));
return other_oid; return other_oid;
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_proc.c,v 1.100 2003/07/18 23:20:32 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/pg_proc.c,v 1.101 2003/07/21 01:59:11 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -108,7 +108,8 @@ ProcedureCreate(const char *procedureName, ...@@ -108,7 +108,8 @@ ProcedureCreate(const char *procedureName,
if (!genericParam) if (!genericParam)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION), (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
errmsg("functions returning ANYARRAY or ANYELEMENT must have at least one argument of either type"))); errmsg("cannot determine result datatype"),
errdetail("A function returning ANYARRAY or ANYELEMENT must have at least one argument of either type.")));
} }
/* Make sure we have a zero-padded param type array */ /* Make sure we have a zero-padded param type array */
...@@ -532,7 +533,8 @@ check_sql_fn_retval(Oid rettype, char fn_typtype, List *queryTreeList) ...@@ -532,7 +533,8 @@ check_sql_fn_retval(Oid rettype, char fn_typtype, List *queryTreeList)
/* This should already have been caught ... */ /* This should already have been caught ... */
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION), (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
errmsg("functions returning ANYARRAY or ANYELEMENT must have at least one argument of either type"))); errmsg("cannot determine result datatype"),
errdetail("A function returning ANYARRAY or ANYELEMENT must have at least one argument of either type.")));
} }
else else
ereport(ERROR, ereport(ERROR,
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_type.c,v 1.87 2003/05/08 22:19:56 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/pg_type.c,v 1.88 2003/07/21 01:59:11 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -190,16 +190,22 @@ TypeCreate(const char *typeName, ...@@ -190,16 +190,22 @@ TypeCreate(const char *typeName,
if (!(internalSize > 0 || if (!(internalSize > 0 ||
internalSize == -1 || internalSize == -1 ||
internalSize == -2)) internalSize == -2))
elog(ERROR, "TypeCreate: invalid type internal size %d", ereport(ERROR,
internalSize); (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("invalid type internal size %d",
internalSize)));
if (passedByValue && if (passedByValue &&
(internalSize <= 0 || internalSize > (int16) sizeof(Datum))) (internalSize <= 0 || internalSize > (int16) sizeof(Datum)))
elog(ERROR, "TypeCreate: invalid type internal size %d", ereport(ERROR,
internalSize); (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("invalid type internal size %d",
internalSize)));
/* Only varlena types can be toasted */ /* Only varlena types can be toasted */
if (storage != 'p' && internalSize != -1) if (storage != 'p' && internalSize != -1)
elog(ERROR, "TypeCreate: fixed size types must have storage PLAIN"); ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("fixed-size types must have storage PLAIN")));
/* /*
* initialize arrays needed for heap_formtuple or heap_modifytuple * initialize arrays needed for heap_formtuple or heap_modifytuple
...@@ -278,7 +284,9 @@ TypeCreate(const char *typeName, ...@@ -278,7 +284,9 @@ TypeCreate(const char *typeName,
*/ */
if (((Form_pg_type) GETSTRUCT(tup))->typisdefined || if (((Form_pg_type) GETSTRUCT(tup))->typisdefined ||
assignedTypeOid != InvalidOid) assignedTypeOid != InvalidOid)
elog(ERROR, "type %s already exists", typeName); ereport(ERROR,
(errcode(ERRCODE_DUPLICATE_OBJECT),
errmsg("type \"%s\" already exists", typeName)));
/* /*
* Okay to update existing "shell" type tuple * Okay to update existing "shell" type tuple
...@@ -489,13 +497,17 @@ TypeRename(const char *oldTypeName, Oid typeNamespace, ...@@ -489,13 +497,17 @@ TypeRename(const char *oldTypeName, Oid typeNamespace,
ObjectIdGetDatum(typeNamespace), ObjectIdGetDatum(typeNamespace),
0, 0); 0, 0);
if (!HeapTupleIsValid(tuple)) if (!HeapTupleIsValid(tuple))
elog(ERROR, "type %s does not exist", oldTypeName); ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("type \"%s\" does not exist", oldTypeName)));
if (SearchSysCacheExists(TYPENAMENSP, if (SearchSysCacheExists(TYPENAMENSP,
CStringGetDatum(newTypeName), CStringGetDatum(newTypeName),
ObjectIdGetDatum(typeNamespace), ObjectIdGetDatum(typeNamespace),
0, 0)) 0, 0))
elog(ERROR, "type named %s already exists", newTypeName); ereport(ERROR,
(errcode(ERRCODE_DUPLICATE_OBJECT),
errmsg("type \"%s\" already exists", newTypeName)));
namestrcpy(&(((Form_pg_type) GETSTRUCT(tuple))->typname), newTypeName); namestrcpy(&(((Form_pg_type) GETSTRUCT(tuple))->typname), newTypeName);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: acl.h,v 1.56 2003/06/27 14:45:32 petere Exp $ * $Id: acl.h,v 1.57 2003/07/21 01:59:11 tgl Exp $
* *
* NOTES * NOTES
* For backward-compatibility purposes we have to allow there * For backward-compatibility purposes we have to allow there
...@@ -207,7 +207,7 @@ extern AclResult pg_proc_aclcheck(Oid proc_oid, AclId userid, AclMode mode); ...@@ -207,7 +207,7 @@ extern AclResult pg_proc_aclcheck(Oid proc_oid, AclId userid, AclMode mode);
extern AclResult pg_language_aclcheck(Oid lang_oid, AclId userid, AclMode mode); extern AclResult pg_language_aclcheck(Oid lang_oid, AclId userid, AclMode mode);
extern AclResult pg_namespace_aclcheck(Oid nsp_oid, AclId userid, AclMode mode); extern AclResult pg_namespace_aclcheck(Oid nsp_oid, AclId userid, AclMode mode);
extern void aclcheck_error(AclResult errcode, const char *objectname); extern void aclcheck_error(AclResult aclerr, const char *objectname);
/* ownercheck routines just return true (owner) or false (not) */ /* ownercheck routines just return true (owner) or false (not) */
extern bool pg_class_ownercheck(Oid class_oid, AclId userid); extern bool pg_class_ownercheck(Oid class_oid, AclId userid);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: elog.h,v 1.50 2003/07/20 21:56:35 tgl Exp $ * $Id: elog.h,v 1.51 2003/07/21 01:59:11 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -83,7 +83,8 @@ ...@@ -83,7 +83,8 @@
#define ERRCODE_WARNING_NULL_VALUE_ELIMINATED_IN_SET_FUNCTION MAKE_SQLSTATE('0','1', '0','0','3') #define ERRCODE_WARNING_NULL_VALUE_ELIMINATED_IN_SET_FUNCTION MAKE_SQLSTATE('0','1', '0','0','3')
#define ERRCODE_WARNING_STRING_DATA_RIGHT_TRUNCATION MAKE_SQLSTATE('0','1', '0','0','4') #define ERRCODE_WARNING_STRING_DATA_RIGHT_TRUNCATION MAKE_SQLSTATE('0','1', '0','0','4')
/* Class 02 - No Data */ /* Class 02 - No Data --- this is also a warning class per SQL99 */
/* (do not use this class for failure conditions!) */
#define ERRCODE_NO_DATA MAKE_SQLSTATE('0','2', '0','0','0') #define ERRCODE_NO_DATA MAKE_SQLSTATE('0','2', '0','0','0')
#define ERRCODE_NO_ADDITIONAL_DYNAMIC_RESULT_SETS_RETURNED MAKE_SQLSTATE('0','2', '0','0','1') #define ERRCODE_NO_ADDITIONAL_DYNAMIC_RESULT_SETS_RETURNED MAKE_SQLSTATE('0','2', '0','0','1')
...@@ -111,6 +112,7 @@ ...@@ -111,6 +112,7 @@
/* Class 0L - Invalid Grantor */ /* Class 0L - Invalid Grantor */
#define ERRCODE_INVALID_GRANTOR MAKE_SQLSTATE('0','L', '0','0','0') #define ERRCODE_INVALID_GRANTOR MAKE_SQLSTATE('0','L', '0','0','0')
#define ERRCODE_INVALID_GRANT_OPERATION MAKE_SQLSTATE('0','L', 'P','0','1')
/* Class 0P - Invalid Role Specification */ /* Class 0P - Invalid Role Specification */
#define ERRCODE_INVALID_ROLE_SPECIFICATION MAKE_SQLSTATE('0','P', '0','0','0') #define ERRCODE_INVALID_ROLE_SPECIFICATION MAKE_SQLSTATE('0','P', '0','0','0')
...@@ -186,6 +188,7 @@ ...@@ -186,6 +188,7 @@
/* Class 2B - Dependent Privilege Descriptors Still Exist */ /* Class 2B - Dependent Privilege Descriptors Still Exist */
#define ERRCODE_DEPENDENT_PRIVILEGE_DESCRIPTORS_STILL_EXIST MAKE_SQLSTATE('2','B', '0','0','0') #define ERRCODE_DEPENDENT_PRIVILEGE_DESCRIPTORS_STILL_EXIST MAKE_SQLSTATE('2','B', '0','0','0')
#define ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST MAKE_SQLSTATE('2','B', 'P','0','1')
/* Class 2D - Invalid Transaction Termination */ /* Class 2D - Invalid Transaction Termination */
#define ERRCODE_INVALID_TRANSACTION_TERMINATION MAKE_SQLSTATE('2','D', '0','0','0') #define ERRCODE_INVALID_TRANSACTION_TERMINATION MAKE_SQLSTATE('2','D', '0','0','0')
......
...@@ -358,8 +358,8 @@ NOTICE: ALTER TABLE will create implicit trigger(s) for FOREIGN KEY check(s) ...@@ -358,8 +358,8 @@ NOTICE: ALTER TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
ALTER TABLE FKTABLE ADD FOREIGN KEY(ftest1) references pktable(ptest1); ALTER TABLE FKTABLE ADD FOREIGN KEY(ftest1) references pktable(ptest1);
NOTICE: ALTER TABLE will create implicit trigger(s) for FOREIGN KEY check(s) NOTICE: ALTER TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
DROP TABLE pktable cascade; DROP TABLE pktable cascade;
NOTICE: Drop cascades to constraint $2 on table fktable NOTICE: drop cascades to constraint $2 on table fktable
NOTICE: Drop cascades to constraint $1 on table fktable NOTICE: drop cascades to constraint $1 on table fktable
DROP TABLE fktable; DROP TABLE fktable;
CREATE TEMP TABLE PKTABLE (ptest1 int, ptest2 inet, CREATE TEMP TABLE PKTABLE (ptest1 int, ptest2 inet,
PRIMARY KEY(ptest1, ptest2)); PRIMARY KEY(ptest1, ptest2));
...@@ -619,9 +619,9 @@ alter table pg_class alter relname set not null; ...@@ -619,9 +619,9 @@ alter table pg_class alter relname set not null;
ERROR: "pg_class" is a system catalog ERROR: "pg_class" is a system catalog
-- try altering non-existent table, should fail -- try altering non-existent table, should fail
alter table non_existent alter column bar set not null; alter table non_existent alter column bar set not null;
ERROR: Relation "non_existent" does not exist ERROR: relation "non_existent" does not exist
alter table non_existent alter column bar drop not null; alter table non_existent alter column bar drop not null;
ERROR: Relation "non_existent" does not exist ERROR: relation "non_existent" does not exist
-- test setting columns to null and not null and vice versa -- test setting columns to null and not null and vice versa
-- test checking for null values and primary key -- test checking for null values and primary key
create table atacc1 (test int not null); create table atacc1 (test int not null);
...@@ -744,7 +744,7 @@ alter table pg_class drop column relname; ...@@ -744,7 +744,7 @@ alter table pg_class drop column relname;
ERROR: "pg_class" is a system catalog ERROR: "pg_class" is a system catalog
-- try altering non-existent table, should fail -- try altering non-existent table, should fail
alter table foo drop column bar; alter table foo drop column bar;
ERROR: Relation "foo" does not exist ERROR: relation "foo" does not exist
-- test dropping columns -- test dropping columns
create table atacc1 (a int4 not null, b int4, c int4 not null, d int4); create table atacc1 (a int4 not null, b int4, c int4 not null, d int4);
insert into atacc1 values (1, 2, 3, 4); insert into atacc1 values (1, 2, 3, 4);
...@@ -1074,7 +1074,7 @@ alter table c1 drop column f1; ...@@ -1074,7 +1074,7 @@ alter table c1 drop column f1;
select f1 from c1; select f1 from c1;
ERROR: attribute "f1" not found ERROR: attribute "f1" not found
drop table p1 cascade; drop table p1 cascade;
NOTICE: Drop cascades to table c1 NOTICE: drop cascades to table c1
create table p1 (f1 int, f2 int); create table p1 (f1 int, f2 int);
create table c1 () inherits(p1); create table c1 () inherits(p1);
-- should be rejected since c1.f1 is inherited -- should be rejected since c1.f1 is inherited
...@@ -1085,7 +1085,7 @@ alter table p1 drop column f1; ...@@ -1085,7 +1085,7 @@ alter table p1 drop column f1;
select f1 from c1; select f1 from c1;
ERROR: attribute "f1" not found ERROR: attribute "f1" not found
drop table p1 cascade; drop table p1 cascade;
NOTICE: Drop cascades to table c1 NOTICE: drop cascades to table c1
create table p1 (f1 int, f2 int); create table p1 (f1 int, f2 int);
create table c1 () inherits(p1); create table c1 () inherits(p1);
-- should be rejected since c1.f1 is inherited -- should be rejected since c1.f1 is inherited
...@@ -1095,7 +1095,7 @@ alter table only p1 drop column f1; ...@@ -1095,7 +1095,7 @@ alter table only p1 drop column f1;
-- c1.f1 is NOT dropped, but must now be considered non-inherited -- c1.f1 is NOT dropped, but must now be considered non-inherited
alter table c1 drop column f1; alter table c1 drop column f1;
drop table p1 cascade; drop table p1 cascade;
NOTICE: Drop cascades to table c1 NOTICE: drop cascades to table c1
create table p1 (f1 int, f2 int); create table p1 (f1 int, f2 int);
create table c1 (f1 int not null) inherits(p1); create table c1 (f1 int not null) inherits(p1);
NOTICE: merging attribute "f1" with inherited definition NOTICE: merging attribute "f1" with inherited definition
...@@ -1106,7 +1106,7 @@ alter table only p1 drop column f1; ...@@ -1106,7 +1106,7 @@ alter table only p1 drop column f1;
-- c1.f1 is still there, but no longer inherited -- c1.f1 is still there, but no longer inherited
alter table c1 drop column f1; alter table c1 drop column f1;
drop table p1 cascade; drop table p1 cascade;
NOTICE: Drop cascades to table c1 NOTICE: drop cascades to table c1
create table p1(id int, name text); create table p1(id int, name text);
create table p2(id2 int, name text, height int); create table p2(id2 int, name text, height int);
create table c1(age int) inherits(p1,p2); create table c1(age int) inherits(p1,p2);
...@@ -1166,8 +1166,8 @@ order by relname, attnum; ...@@ -1166,8 +1166,8 @@ order by relname, attnum;
(8 rows) (8 rows)
drop table p1, p2 cascade; drop table p1, p2 cascade;
NOTICE: Drop cascades to table c1 NOTICE: drop cascades to table c1
NOTICE: Drop cascades to table gc1 NOTICE: drop cascades to table gc1
-- --
-- Test the ALTER TABLE WITHOUT OIDS command -- Test the ALTER TABLE WITHOUT OIDS command
-- --
...@@ -1250,8 +1250,8 @@ select * from p1; ...@@ -1250,8 +1250,8 @@ select * from p1;
(2 rows) (2 rows)
drop table p1 cascade; drop table p1 cascade;
NOTICE: Drop cascades to table c1 NOTICE: drop cascades to table c1
NOTICE: Drop cascades to constraint p1_a1 on table c1 NOTICE: drop cascades to constraint p1_a1 on table c1
-- test that operations with a dropped column do not try to reference -- test that operations with a dropped column do not try to reference
-- its datatype -- its datatype
create domain mytype as text; create domain mytype as text;
...@@ -1264,7 +1264,7 @@ select * from foo; ...@@ -1264,7 +1264,7 @@ select * from foo;
(1 row) (1 row)
drop domain mytype cascade; drop domain mytype cascade;
NOTICE: Drop cascades to table foo column f2 NOTICE: drop cascades to table foo column f2
select * from foo; select * from foo;
f1 | f3 f1 | f3
----+---- ----+----
......
...@@ -8,7 +8,7 @@ CREATE CONVERSION myconv FOR 'LATIN1' TO 'UNICODE' FROM iso8859_1_to_utf8; ...@@ -8,7 +8,7 @@ CREATE CONVERSION myconv FOR 'LATIN1' TO 'UNICODE' FROM iso8859_1_to_utf8;
-- cannot make same name conversion in same schema -- cannot make same name conversion in same schema
-- --
CREATE CONVERSION myconv FOR 'LATIN1' TO 'UNICODE' FROM iso8859_1_to_utf8; CREATE CONVERSION myconv FOR 'LATIN1' TO 'UNICODE' FROM iso8859_1_to_utf8;
ERROR: conversion name "myconv" already exists ERROR: conversion "myconv" already exists
-- --
-- create default conversion with qualified name -- create default conversion with qualified name
-- --
...@@ -17,7 +17,7 @@ CREATE DEFAULT CONVERSION public.mydef FOR 'LATIN1' TO 'UNICODE' FROM iso8859_1_ ...@@ -17,7 +17,7 @@ CREATE DEFAULT CONVERSION public.mydef FOR 'LATIN1' TO 'UNICODE' FROM iso8859_1_
-- cannot make default conversion with same shcema/for_encoding/to_encoding -- cannot make default conversion with same shcema/for_encoding/to_encoding
-- --
CREATE DEFAULT CONVERSION public.mydef2 FOR 'LATIN1' TO 'UNICODE' FROM iso8859_1_to_utf8; CREATE DEFAULT CONVERSION public.mydef2 FOR 'LATIN1' TO 'UNICODE' FROM iso8859_1_to_utf8;
ERROR: default conversion for LATIN1 to UNICODE already exists ERROR: default conversion for "LATIN1" to "UNICODE" already exists
-- --
-- drop user defined conversion -- drop user defined conversion
-- --
......
...@@ -72,5 +72,5 @@ SELECT * FROM get_default_test(); ...@@ -72,5 +72,5 @@ SELECT * FROM get_default_test();
(1 row) (1 row)
DROP TYPE default_test_row CASCADE; DROP TYPE default_test_row CASCADE;
NOTICE: Drop cascades to function get_default_test() NOTICE: drop cascades to function get_default_test()
DROP TABLE default_test; DROP TABLE default_test;
...@@ -214,8 +214,8 @@ alter domain dnotnulltest drop not null; -- fails ...@@ -214,8 +214,8 @@ alter domain dnotnulltest drop not null; -- fails
NOTICE: "dnotnulltest" is already set to NULL NOTICE: "dnotnulltest" is already set to NULL
update domnotnull set col1 = null; update domnotnull set col1 = null;
drop domain dnotnulltest cascade; drop domain dnotnulltest cascade;
NOTICE: Drop cascades to table domnotnull column col2 NOTICE: drop cascades to table domnotnull column col2
NOTICE: Drop cascades to table domnotnull column col1 NOTICE: drop cascades to table domnotnull column col1
-- Test ALTER DOMAIN .. DEFAULT .. -- Test ALTER DOMAIN .. DEFAULT ..
create table domdeftest (col1 ddef1); create table domdeftest (col1 ddef1);
insert into domdeftest default values; insert into domdeftest default values;
......
...@@ -25,7 +25,7 @@ select; ...@@ -25,7 +25,7 @@ select;
ERROR: syntax error at or near ";" at character 7 ERROR: syntax error at or near ";" at character 7
-- no such relation -- no such relation
select * from nonesuch; select * from nonesuch;
ERROR: Relation "nonesuch" does not exist ERROR: relation "nonesuch" does not exist
-- missing target list -- missing target list
select from pg_database; select from pg_database;
ERROR: syntax error at or near "from" at character 8 ERROR: syntax error at or near "from" at character 8
...@@ -52,7 +52,7 @@ delete from; ...@@ -52,7 +52,7 @@ delete from;
ERROR: syntax error at or near ";" at character 12 ERROR: syntax error at or near ";" at character 12
-- no such relation -- no such relation
delete from nonesuch; delete from nonesuch;
ERROR: Relation "nonesuch" does not exist ERROR: relation "nonesuch" does not exist
-- --
-- DROP -- DROP
...@@ -71,10 +71,10 @@ alter table rename; ...@@ -71,10 +71,10 @@ alter table rename;
ERROR: syntax error at or near ";" at character 19 ERROR: syntax error at or near ";" at character 19
-- no such relation -- no such relation
alter table nonesuch rename to newnonesuch; alter table nonesuch rename to newnonesuch;
ERROR: Relation "nonesuch" does not exist ERROR: relation "nonesuch" does not exist
-- no such relation -- no such relation
alter table nonesuch rename to stud_emp; alter table nonesuch rename to stud_emp;
ERROR: Relation "nonesuch" does not exist ERROR: relation "nonesuch" does not exist
-- conflict -- conflict
alter table stud_emp rename to aggtest; alter table stud_emp rename to aggtest;
ERROR: relation "aggtest" already exists ERROR: relation "aggtest" already exists
...@@ -84,7 +84,7 @@ ERROR: relation "stud_emp" already exists ...@@ -84,7 +84,7 @@ ERROR: relation "stud_emp" already exists
-- attribute renaming -- attribute renaming
-- no such relation -- no such relation
alter table nonesuchrel rename column nonesuchatt to newnonesuchatt; alter table nonesuchrel rename column nonesuchatt to newnonesuchatt;
ERROR: Relation "nonesuchrel" does not exist ERROR: relation "nonesuchrel" does not exist
-- no such attribute -- no such attribute
alter table emp rename column nonesuchatt to newnonesuchatt; alter table emp rename column nonesuchatt to newnonesuchatt;
ERROR: attribute "nonesuchatt" does not exist ERROR: attribute "nonesuchatt" does not exist
...@@ -227,7 +227,7 @@ drop rule 314159; ...@@ -227,7 +227,7 @@ drop rule 314159;
ERROR: syntax error at or near "314159" at character 11 ERROR: syntax error at or near "314159" at character 11
-- no such rule -- no such rule
drop rule nonesuch on noplace; drop rule nonesuch on noplace;
ERROR: Relation "noplace" does not exist ERROR: relation "noplace" does not exist
-- bad keyword -- bad keyword
drop tuple rule nonesuch; drop tuple rule nonesuch;
ERROR: syntax error at or near "tuple" at character 6 ERROR: syntax error at or near "tuple" at character 6
......
...@@ -138,7 +138,7 @@ SELECT * FROM FKTABLE; ...@@ -138,7 +138,7 @@ SELECT * FROM FKTABLE;
(5 rows) (5 rows)
DROP TABLE PKTABLE CASCADE; DROP TABLE PKTABLE CASCADE;
NOTICE: Drop cascades to constraint constrname on table fktable NOTICE: drop cascades to constraint constrname on table fktable
DROP TABLE FKTABLE; DROP TABLE FKTABLE;
-- --
-- check set default and table constraint on multiple columns -- check set default and table constraint on multiple columns
...@@ -225,10 +225,10 @@ SELECT * FROM FKTABLE; ...@@ -225,10 +225,10 @@ SELECT * FROM FKTABLE;
-- this should fail for lack of CASCADE -- this should fail for lack of CASCADE
DROP TABLE PKTABLE; DROP TABLE PKTABLE;
NOTICE: constraint constrname2 on table fktable depends on table pktable NOTICE: constraint constrname2 on table fktable depends on table pktable
ERROR: Cannot drop table pktable because other objects depend on it ERROR: cannot drop table pktable because other objects depend on it
Use DROP ... CASCADE to drop the dependent objects too HINT: Use DROP ... CASCADE to drop the dependent objects too.
DROP TABLE PKTABLE CASCADE; DROP TABLE PKTABLE CASCADE;
NOTICE: Drop cascades to constraint constrname2 on table fktable NOTICE: drop cascades to constraint constrname2 on table fktable
DROP TABLE FKTABLE; DROP TABLE FKTABLE;
-- --
-- First test, check with no on delete or on update -- First test, check with no on delete or on update
......
...@@ -76,7 +76,8 @@ CREATE AGGREGATE myaggp01a(BASETYPE = "ANY", SFUNC = stfnp, STYPE = int4[], ...@@ -76,7 +76,8 @@ CREATE AGGREGATE myaggp01a(BASETYPE = "ANY", SFUNC = stfnp, STYPE = int4[],
-- should ERROR: stfnp(anyarray) not matched by stfnp(int[]) -- should ERROR: stfnp(anyarray) not matched by stfnp(int[])
CREATE AGGREGATE myaggp02a(BASETYPE = "ANY", SFUNC = stfnp, STYPE = anyarray, CREATE AGGREGATE myaggp02a(BASETYPE = "ANY", SFUNC = stfnp, STYPE = anyarray,
FINALFUNC = ffp, INITCOND = '{}'); FINALFUNC = ffp, INITCOND = '{}');
ERROR: an aggregate using ANYARRAY or ANYELEMENT as trans type must also have one of them as its base type ERROR: cannot determine transition datatype
DETAIL: An aggregate using ANYARRAY or ANYELEMENT as trans type must have one of them as its base type.
-- N P -- N P
-- should CREATE -- should CREATE
CREATE AGGREGATE myaggp03a(BASETYPE = "ANY", SFUNC = stfp, STYPE = int4[], CREATE AGGREGATE myaggp03a(BASETYPE = "ANY", SFUNC = stfp, STYPE = int4[],
...@@ -87,10 +88,12 @@ CREATE AGGREGATE myaggp03b(BASETYPE = "ANY", SFUNC = stfp, STYPE = int4[], ...@@ -87,10 +88,12 @@ CREATE AGGREGATE myaggp03b(BASETYPE = "ANY", SFUNC = stfp, STYPE = int4[],
-- should ERROR: we have no way to resolve S -- should ERROR: we have no way to resolve S
CREATE AGGREGATE myaggp04a(BASETYPE = "ANY", SFUNC = stfp, STYPE = anyarray, CREATE AGGREGATE myaggp04a(BASETYPE = "ANY", SFUNC = stfp, STYPE = anyarray,
FINALFUNC = ffp, INITCOND = '{}'); FINALFUNC = ffp, INITCOND = '{}');
ERROR: an aggregate using ANYARRAY or ANYELEMENT as trans type must also have one of them as its base type ERROR: cannot determine transition datatype
DETAIL: An aggregate using ANYARRAY or ANYELEMENT as trans type must have one of them as its base type.
CREATE AGGREGATE myaggp04b(BASETYPE = "ANY", SFUNC = stfp, STYPE = anyarray, CREATE AGGREGATE myaggp04b(BASETYPE = "ANY", SFUNC = stfp, STYPE = anyarray,
INITCOND = '{}'); INITCOND = '{}');
ERROR: an aggregate using ANYARRAY or ANYELEMENT as trans type must also have one of them as its base type ERROR: cannot determine transition datatype
DETAIL: An aggregate using ANYARRAY or ANYELEMENT as trans type must have one of them as its base type.
-- Case2 (R = P) && ((B = P) || (B = N)) -- Case2 (R = P) && ((B = P) || (B = N))
-- ------------------------------------- -- -------------------------------------
-- S tf1 B tf2 -- S tf1 B tf2
...@@ -144,12 +147,14 @@ ERROR: function tfp(integer[], anyelement) does not exist ...@@ -144,12 +147,14 @@ ERROR: function tfp(integer[], anyelement) does not exist
-- should ERROR: tfnp(anyarray, int) not matched by tfnp(int[],int) -- should ERROR: tfnp(anyarray, int) not matched by tfnp(int[],int)
CREATE AGGREGATE myaggp13a(BASETYPE = int, SFUNC = tfnp, STYPE = anyarray, CREATE AGGREGATE myaggp13a(BASETYPE = int, SFUNC = tfnp, STYPE = anyarray,
FINALFUNC = ffp, INITCOND = '{}'); FINALFUNC = ffp, INITCOND = '{}');
ERROR: an aggregate using ANYARRAY or ANYELEMENT as trans type must also have one of them as its base type ERROR: cannot determine transition datatype
DETAIL: An aggregate using ANYARRAY or ANYELEMENT as trans type must have one of them as its base type.
-- P N N P -- P N N P
-- should ERROR: tf2p(anyarray, int) not matched by tf2p(int[],anyelement) -- should ERROR: tf2p(anyarray, int) not matched by tf2p(int[],anyelement)
CREATE AGGREGATE myaggp14a(BASETYPE = int, SFUNC = tf2p, STYPE = anyarray, CREATE AGGREGATE myaggp14a(BASETYPE = int, SFUNC = tf2p, STYPE = anyarray,
FINALFUNC = ffp, INITCOND = '{}'); FINALFUNC = ffp, INITCOND = '{}');
ERROR: an aggregate using ANYARRAY or ANYELEMENT as trans type must also have one of them as its base type ERROR: cannot determine transition datatype
DETAIL: An aggregate using ANYARRAY or ANYELEMENT as trans type must have one of them as its base type.
-- P N P N -- P N P N
-- should ERROR: tfnp(anyarray, anyelement) not matched by tfnp(int[],int) -- should ERROR: tfnp(anyarray, anyelement) not matched by tfnp(int[],int)
CREATE AGGREGATE myaggp15a(BASETYPE = anyelement, SFUNC = tfnp, CREATE AGGREGATE myaggp15a(BASETYPE = anyelement, SFUNC = tfnp,
...@@ -164,18 +169,22 @@ ERROR: function tf2p(anyarray, anyelement) does not exist ...@@ -164,18 +169,22 @@ ERROR: function tf2p(anyarray, anyelement) does not exist
-- should ERROR: we have no way to resolve S -- should ERROR: we have no way to resolve S
CREATE AGGREGATE myaggp17a(BASETYPE = int, SFUNC = tf1p, STYPE = anyarray, CREATE AGGREGATE myaggp17a(BASETYPE = int, SFUNC = tf1p, STYPE = anyarray,
FINALFUNC = ffp, INITCOND = '{}'); FINALFUNC = ffp, INITCOND = '{}');
ERROR: an aggregate using ANYARRAY or ANYELEMENT as trans type must also have one of them as its base type ERROR: cannot determine transition datatype
DETAIL: An aggregate using ANYARRAY or ANYELEMENT as trans type must have one of them as its base type.
CREATE AGGREGATE myaggp17b(BASETYPE = int, SFUNC = tf1p, STYPE = anyarray, CREATE AGGREGATE myaggp17b(BASETYPE = int, SFUNC = tf1p, STYPE = anyarray,
INITCOND = '{}'); INITCOND = '{}');
ERROR: an aggregate using ANYARRAY or ANYELEMENT as trans type must also have one of them as its base type ERROR: cannot determine transition datatype
DETAIL: An aggregate using ANYARRAY or ANYELEMENT as trans type must have one of them as its base type.
-- P P N P -- P P N P
-- should ERROR: tfp(anyarray, int) not matched by tfp(anyarray, anyelement) -- should ERROR: tfp(anyarray, int) not matched by tfp(anyarray, anyelement)
CREATE AGGREGATE myaggp18a(BASETYPE = int, SFUNC = tfp, STYPE = anyarray, CREATE AGGREGATE myaggp18a(BASETYPE = int, SFUNC = tfp, STYPE = anyarray,
FINALFUNC = ffp, INITCOND = '{}'); FINALFUNC = ffp, INITCOND = '{}');
ERROR: an aggregate using ANYARRAY or ANYELEMENT as trans type must also have one of them as its base type ERROR: cannot determine transition datatype
DETAIL: An aggregate using ANYARRAY or ANYELEMENT as trans type must have one of them as its base type.
CREATE AGGREGATE myaggp18b(BASETYPE = int, SFUNC = tfp, STYPE = anyarray, CREATE AGGREGATE myaggp18b(BASETYPE = int, SFUNC = tfp, STYPE = anyarray,
INITCOND = '{}'); INITCOND = '{}');
ERROR: an aggregate using ANYARRAY or ANYELEMENT as trans type must also have one of them as its base type ERROR: cannot determine transition datatype
DETAIL: An aggregate using ANYARRAY or ANYELEMENT as trans type must have one of them as its base type.
-- P P P N -- P P P N
-- should ERROR: tf1p(anyarray, anyelement) not matched by tf1p(anyarray, int) -- should ERROR: tf1p(anyarray, anyelement) not matched by tf1p(anyarray, int)
CREATE AGGREGATE myaggp19a(BASETYPE = anyelement, SFUNC = tf1p, CREATE AGGREGATE myaggp19a(BASETYPE = anyelement, SFUNC = tf1p,
...@@ -204,10 +213,12 @@ CREATE AGGREGATE myaggn01b(BASETYPE = "ANY", SFUNC = stfnp, STYPE = int4[], ...@@ -204,10 +213,12 @@ CREATE AGGREGATE myaggn01b(BASETYPE = "ANY", SFUNC = stfnp, STYPE = int4[],
-- should ERROR: stfnp(anyarray) not matched by stfnp(int[]) -- should ERROR: stfnp(anyarray) not matched by stfnp(int[])
CREATE AGGREGATE myaggn02a(BASETYPE = "ANY", SFUNC = stfnp, STYPE = anyarray, CREATE AGGREGATE myaggn02a(BASETYPE = "ANY", SFUNC = stfnp, STYPE = anyarray,
FINALFUNC = ffnp, INITCOND = '{}'); FINALFUNC = ffnp, INITCOND = '{}');
ERROR: an aggregate using ANYARRAY or ANYELEMENT as trans type must also have one of them as its base type ERROR: cannot determine transition datatype
DETAIL: An aggregate using ANYARRAY or ANYELEMENT as trans type must have one of them as its base type.
CREATE AGGREGATE myaggn02b(BASETYPE = "ANY", SFUNC = stfnp, STYPE = anyarray, CREATE AGGREGATE myaggn02b(BASETYPE = "ANY", SFUNC = stfnp, STYPE = anyarray,
INITCOND = '{}'); INITCOND = '{}');
ERROR: an aggregate using ANYARRAY or ANYELEMENT as trans type must also have one of them as its base type ERROR: cannot determine transition datatype
DETAIL: An aggregate using ANYARRAY or ANYELEMENT as trans type must have one of them as its base type.
-- N P -- N P
-- should CREATE -- should CREATE
CREATE AGGREGATE myaggn03a(BASETYPE = "ANY", SFUNC = stfp, STYPE = int4[], CREATE AGGREGATE myaggn03a(BASETYPE = "ANY", SFUNC = stfp, STYPE = int4[],
...@@ -216,7 +227,8 @@ CREATE AGGREGATE myaggn03a(BASETYPE = "ANY", SFUNC = stfp, STYPE = int4[], ...@@ -216,7 +227,8 @@ CREATE AGGREGATE myaggn03a(BASETYPE = "ANY", SFUNC = stfp, STYPE = int4[],
-- should ERROR: ffnp(anyarray) not matched by ffnp(int[]) -- should ERROR: ffnp(anyarray) not matched by ffnp(int[])
CREATE AGGREGATE myaggn04a(BASETYPE = "ANY", SFUNC = stfp, STYPE = anyarray, CREATE AGGREGATE myaggn04a(BASETYPE = "ANY", SFUNC = stfp, STYPE = anyarray,
FINALFUNC = ffnp, INITCOND = '{}'); FINALFUNC = ffnp, INITCOND = '{}');
ERROR: an aggregate using ANYARRAY or ANYELEMENT as trans type must also have one of them as its base type ERROR: cannot determine transition datatype
DETAIL: An aggregate using ANYARRAY or ANYELEMENT as trans type must have one of them as its base type.
-- Case4 (R = N) && ((B = P) || (B = N)) -- Case4 (R = N) && ((B = P) || (B = N))
-- ------------------------------------- -- -------------------------------------
-- S tf1 B tf2 -- S tf1 B tf2
...@@ -269,18 +281,22 @@ ERROR: function tfp(integer[], anyelement) does not exist ...@@ -269,18 +281,22 @@ ERROR: function tfp(integer[], anyelement) does not exist
-- should ERROR: tfnp(anyarray, int) not matched by tfnp(int[],int) -- should ERROR: tfnp(anyarray, int) not matched by tfnp(int[],int)
CREATE AGGREGATE myaggn13a(BASETYPE = int, SFUNC = tfnp, STYPE = anyarray, CREATE AGGREGATE myaggn13a(BASETYPE = int, SFUNC = tfnp, STYPE = anyarray,
FINALFUNC = ffnp, INITCOND = '{}'); FINALFUNC = ffnp, INITCOND = '{}');
ERROR: an aggregate using ANYARRAY or ANYELEMENT as trans type must also have one of them as its base type ERROR: cannot determine transition datatype
DETAIL: An aggregate using ANYARRAY or ANYELEMENT as trans type must have one of them as its base type.
CREATE AGGREGATE myaggn13b(BASETYPE = int, SFUNC = tfnp, STYPE = anyarray, CREATE AGGREGATE myaggn13b(BASETYPE = int, SFUNC = tfnp, STYPE = anyarray,
INITCOND = '{}'); INITCOND = '{}');
ERROR: an aggregate using ANYARRAY or ANYELEMENT as trans type must also have one of them as its base type ERROR: cannot determine transition datatype
DETAIL: An aggregate using ANYARRAY or ANYELEMENT as trans type must have one of them as its base type.
-- P N N P -- P N N P
-- should ERROR: tf2p(anyarray, int) not matched by tf2p(int[],anyelement) -- should ERROR: tf2p(anyarray, int) not matched by tf2p(int[],anyelement)
CREATE AGGREGATE myaggn14a(BASETYPE = int, SFUNC = tf2p, STYPE = anyarray, CREATE AGGREGATE myaggn14a(BASETYPE = int, SFUNC = tf2p, STYPE = anyarray,
FINALFUNC = ffnp, INITCOND = '{}'); FINALFUNC = ffnp, INITCOND = '{}');
ERROR: an aggregate using ANYARRAY or ANYELEMENT as trans type must also have one of them as its base type ERROR: cannot determine transition datatype
DETAIL: An aggregate using ANYARRAY or ANYELEMENT as trans type must have one of them as its base type.
CREATE AGGREGATE myaggn14b(BASETYPE = int, SFUNC = tf2p, STYPE = anyarray, CREATE AGGREGATE myaggn14b(BASETYPE = int, SFUNC = tf2p, STYPE = anyarray,
INITCOND = '{}'); INITCOND = '{}');
ERROR: an aggregate using ANYARRAY or ANYELEMENT as trans type must also have one of them as its base type ERROR: cannot determine transition datatype
DETAIL: An aggregate using ANYARRAY or ANYELEMENT as trans type must have one of them as its base type.
-- P N P N -- P N P N
-- should ERROR: tfnp(anyarray, anyelement) not matched by tfnp(int[],int) -- should ERROR: tfnp(anyarray, anyelement) not matched by tfnp(int[],int)
CREATE AGGREGATE myaggn15a(BASETYPE = anyelement, SFUNC = tfnp, CREATE AGGREGATE myaggn15a(BASETYPE = anyelement, SFUNC = tfnp,
...@@ -301,12 +317,14 @@ ERROR: function tf2p(anyarray, anyelement) does not exist ...@@ -301,12 +317,14 @@ ERROR: function tf2p(anyarray, anyelement) does not exist
-- should ERROR: ffnp(anyarray) not matched by ffnp(int[]) -- should ERROR: ffnp(anyarray) not matched by ffnp(int[])
CREATE AGGREGATE myaggn17a(BASETYPE = int, SFUNC = tf1p, STYPE = anyarray, CREATE AGGREGATE myaggn17a(BASETYPE = int, SFUNC = tf1p, STYPE = anyarray,
FINALFUNC = ffnp, INITCOND = '{}'); FINALFUNC = ffnp, INITCOND = '{}');
ERROR: an aggregate using ANYARRAY or ANYELEMENT as trans type must also have one of them as its base type ERROR: cannot determine transition datatype
DETAIL: An aggregate using ANYARRAY or ANYELEMENT as trans type must have one of them as its base type.
-- P P N P -- P P N P
-- should ERROR: tfp(anyarray, int) not matched by tfp(anyarray, anyelement) -- should ERROR: tfp(anyarray, int) not matched by tfp(anyarray, anyelement)
CREATE AGGREGATE myaggn18a(BASETYPE = int, SFUNC = tfp, STYPE = anyarray, CREATE AGGREGATE myaggn18a(BASETYPE = int, SFUNC = tfp, STYPE = anyarray,
FINALFUNC = ffnp, INITCOND = '{}'); FINALFUNC = ffnp, INITCOND = '{}');
ERROR: an aggregate using ANYARRAY or ANYELEMENT as trans type must also have one of them as its base type ERROR: cannot determine transition datatype
DETAIL: An aggregate using ANYARRAY or ANYELEMENT as trans type must have one of them as its base type.
-- P P P N -- P P P N
-- should ERROR: tf1p(anyarray, anyelement) not matched by tf1p(anyarray, int) -- should ERROR: tf1p(anyarray, anyelement) not matched by tf1p(anyarray, int)
CREATE AGGREGATE myaggn19a(BASETYPE = anyelement, SFUNC = tf1p, CREATE AGGREGATE myaggn19a(BASETYPE = anyelement, SFUNC = tf1p,
......
...@@ -69,11 +69,11 @@ SELECT * FROM atest2; -- ok ...@@ -69,11 +69,11 @@ SELECT * FROM atest2; -- ok
INSERT INTO atest1 VALUES (2, 'two'); -- ok INSERT INTO atest1 VALUES (2, 'two'); -- ok
INSERT INTO atest2 VALUES ('foo', true); -- fail INSERT INTO atest2 VALUES ('foo', true); -- fail
ERROR: atest2: permission denied ERROR: permission denied for "atest2"
INSERT INTO atest1 SELECT 1, b FROM atest1; -- ok INSERT INTO atest1 SELECT 1, b FROM atest1; -- ok
UPDATE atest1 SET a = 1 WHERE a = 2; -- ok UPDATE atest1 SET a = 1 WHERE a = 2; -- ok
UPDATE atest2 SET col2 = NOT col2; -- fail UPDATE atest2 SET col2 = NOT col2; -- fail
ERROR: atest2: permission denied ERROR: permission denied for "atest2"
SELECT * FROM atest1 FOR UPDATE; -- ok SELECT * FROM atest1 FOR UPDATE; -- ok
a | b a | b
---+----- ---+-----
...@@ -82,15 +82,15 @@ SELECT * FROM atest1 FOR UPDATE; -- ok ...@@ -82,15 +82,15 @@ SELECT * FROM atest1 FOR UPDATE; -- ok
(2 rows) (2 rows)
SELECT * FROM atest2 FOR UPDATE; -- fail SELECT * FROM atest2 FOR UPDATE; -- fail
ERROR: atest2: permission denied ERROR: permission denied for "atest2"
DELETE FROM atest2; -- fail DELETE FROM atest2; -- fail
ERROR: atest2: permission denied ERROR: permission denied for "atest2"
LOCK atest2 IN ACCESS EXCLUSIVE MODE; -- fail LOCK atest2 IN ACCESS EXCLUSIVE MODE; -- fail
ERROR: atest2: permission denied ERROR: permission denied for "atest2"
COPY atest2 FROM stdin; -- fail COPY atest2 FROM stdin; -- fail
ERROR: atest2: permission denied ERROR: permission denied for "atest2"
GRANT ALL ON atest1 TO PUBLIC; -- fail GRANT ALL ON atest1 TO PUBLIC; -- fail
ERROR: atest1: permission denied ERROR: permission denied for "atest1"
-- checks in subquery, both ok -- checks in subquery, both ok
SELECT * FROM atest1 WHERE ( b IN ( SELECT col1 FROM atest2 ) ); SELECT * FROM atest1 WHERE ( b IN ( SELECT col1 FROM atest2 ) );
a | b a | b
...@@ -117,33 +117,33 @@ SELECT * FROM atest1; -- ok ...@@ -117,33 +117,33 @@ SELECT * FROM atest1; -- ok
(2 rows) (2 rows)
SELECT * FROM atest2; -- fail SELECT * FROM atest2; -- fail
ERROR: atest2: permission denied ERROR: permission denied for "atest2"
INSERT INTO atest1 VALUES (2, 'two'); -- fail INSERT INTO atest1 VALUES (2, 'two'); -- fail
ERROR: atest1: permission denied ERROR: permission denied for "atest1"
INSERT INTO atest2 VALUES ('foo', true); -- fail INSERT INTO atest2 VALUES ('foo', true); -- fail
ERROR: atest2: permission denied ERROR: permission denied for "atest2"
INSERT INTO atest1 SELECT 1, b FROM atest1; -- fail INSERT INTO atest1 SELECT 1, b FROM atest1; -- fail
ERROR: atest1: permission denied ERROR: permission denied for "atest1"
UPDATE atest1 SET a = 1 WHERE a = 2; -- fail UPDATE atest1 SET a = 1 WHERE a = 2; -- fail
ERROR: atest1: permission denied ERROR: permission denied for "atest1"
UPDATE atest2 SET col2 = NULL; -- ok UPDATE atest2 SET col2 = NULL; -- ok
UPDATE atest2 SET col2 = NOT col2; -- fails; requires SELECT on atest2 UPDATE atest2 SET col2 = NOT col2; -- fails; requires SELECT on atest2
ERROR: atest2: permission denied ERROR: permission denied for "atest2"
UPDATE atest2 SET col2 = true WHERE atest1.a = 5; -- ok UPDATE atest2 SET col2 = true WHERE atest1.a = 5; -- ok
SELECT * FROM atest1 FOR UPDATE; -- fail SELECT * FROM atest1 FOR UPDATE; -- fail
ERROR: atest1: permission denied ERROR: permission denied for "atest1"
SELECT * FROM atest2 FOR UPDATE; -- fail SELECT * FROM atest2 FOR UPDATE; -- fail
ERROR: atest2: permission denied ERROR: permission denied for "atest2"
DELETE FROM atest2; -- fail DELETE FROM atest2; -- fail
ERROR: atest2: permission denied ERROR: permission denied for "atest2"
LOCK atest2 IN ACCESS EXCLUSIVE MODE; -- ok LOCK atest2 IN ACCESS EXCLUSIVE MODE; -- ok
COPY atest2 FROM stdin; -- fail COPY atest2 FROM stdin; -- fail
ERROR: atest2: permission denied ERROR: permission denied for "atest2"
-- checks in subquery, both fail -- checks in subquery, both fail
SELECT * FROM atest1 WHERE ( b IN ( SELECT col1 FROM atest2 ) ); SELECT * FROM atest1 WHERE ( b IN ( SELECT col1 FROM atest2 ) );
ERROR: atest2: permission denied ERROR: permission denied for "atest2"
SELECT * FROM atest2 WHERE ( col1 IN ( SELECT b FROM atest1 ) ); SELECT * FROM atest2 WHERE ( col1 IN ( SELECT b FROM atest1 ) );
ERROR: atest2: permission denied ERROR: permission denied for "atest2"
SET SESSION AUTHORIZATION regressuser4; SET SESSION AUTHORIZATION regressuser4;
COPY atest2 FROM stdin; -- ok COPY atest2 FROM stdin; -- ok
SELECT * FROM atest1; -- ok SELECT * FROM atest1; -- ok
...@@ -159,7 +159,7 @@ CREATE TABLE atest3 (one int, two int, three int); ...@@ -159,7 +159,7 @@ CREATE TABLE atest3 (one int, two int, three int);
GRANT DELETE ON atest3 TO GROUP regressgroup2; GRANT DELETE ON atest3 TO GROUP regressgroup2;
SET SESSION AUTHORIZATION regressuser1; SET SESSION AUTHORIZATION regressuser1;
SELECT * FROM atest3; -- fail SELECT * FROM atest3; -- fail
ERROR: atest3: permission denied ERROR: permission denied for "atest3"
DELETE FROM atest3; -- ok DELETE FROM atest3; -- ok
-- views -- views
SET SESSION AUTHORIZATION regressuser3; SET SESSION AUTHORIZATION regressuser3;
...@@ -175,7 +175,7 @@ SELECT * FROM atestv1; -- ok ...@@ -175,7 +175,7 @@ SELECT * FROM atestv1; -- ok
(2 rows) (2 rows)
SELECT * FROM atestv2; -- fail SELECT * FROM atestv2; -- fail
ERROR: atest2: permission denied ERROR: permission denied for "atest2"
GRANT SELECT ON atestv1, atestv3 TO regressuser4; GRANT SELECT ON atestv1, atestv3 TO regressuser4;
GRANT SELECT ON atestv2 TO regressuser2; GRANT SELECT ON atestv2 TO regressuser2;
SET SESSION AUTHORIZATION regressuser4; SET SESSION AUTHORIZATION regressuser4;
...@@ -187,7 +187,7 @@ SELECT * FROM atestv1; -- ok ...@@ -187,7 +187,7 @@ SELECT * FROM atestv1; -- ok
(2 rows) (2 rows)
SELECT * FROM atestv2; -- fail SELECT * FROM atestv2; -- fail
ERROR: atestv2: permission denied ERROR: permission denied for "atestv2"
SELECT * FROM atestv3; -- ok SELECT * FROM atestv3; -- ok
one | two | three one | two | three
-----+-----+------- -----+-----+-------
...@@ -203,7 +203,7 @@ GRANT SELECT ON atestv4 TO regressuser2; ...@@ -203,7 +203,7 @@ GRANT SELECT ON atestv4 TO regressuser2;
SET SESSION AUTHORIZATION regressuser2; SET SESSION AUTHORIZATION regressuser2;
-- Two complex cases: -- Two complex cases:
SELECT * FROM atestv3; -- fail SELECT * FROM atestv3; -- fail
ERROR: atestv3: permission denied ERROR: permission denied for "atestv3"
SELECT * FROM atestv4; -- ok (even though regressuser2 cannot access underlying atestv3) SELECT * FROM atestv4; -- ok (even though regressuser2 cannot access underlying atestv3)
one | two | three one | two | three
-----+-----+------- -----+-----+-------
...@@ -216,7 +216,7 @@ SELECT * FROM atest2; -- ok ...@@ -216,7 +216,7 @@ SELECT * FROM atest2; -- ok
(1 row) (1 row)
SELECT * FROM atestv2; -- fail (even though regressuser2 can access underlying atest2) SELECT * FROM atestv2; -- fail (even though regressuser2 can access underlying atest2)
ERROR: atest2: permission denied ERROR: permission denied for "atest2"
-- privileges on functions, languages -- privileges on functions, languages
-- switch to superuser -- switch to superuser
\c - \c -
...@@ -226,13 +226,13 @@ GRANT USAGE ON LANGUAGE c TO PUBLIC; -- fail ...@@ -226,13 +226,13 @@ GRANT USAGE ON LANGUAGE c TO PUBLIC; -- fail
ERROR: language "c" is not trusted ERROR: language "c" is not trusted
SET SESSION AUTHORIZATION regressuser1; SET SESSION AUTHORIZATION regressuser1;
GRANT USAGE ON LANGUAGE sql TO regressuser2; -- fail GRANT USAGE ON LANGUAGE sql TO regressuser2; -- fail
ERROR: sql: permission denied ERROR: permission denied for "sql"
CREATE FUNCTION testfunc1(int) RETURNS int AS 'select 2 * $1;' LANGUAGE sql; CREATE FUNCTION testfunc1(int) RETURNS int AS 'select 2 * $1;' LANGUAGE sql;
CREATE FUNCTION testfunc2(int) RETURNS int AS 'select 3 * $1;' LANGUAGE sql; CREATE FUNCTION testfunc2(int) RETURNS int AS 'select 3 * $1;' LANGUAGE sql;
REVOKE ALL ON FUNCTION testfunc1(int), testfunc2(int) FROM PUBLIC; REVOKE ALL ON FUNCTION testfunc1(int), testfunc2(int) FROM PUBLIC;
GRANT EXECUTE ON FUNCTION testfunc1(int), testfunc2(int) TO regressuser2; GRANT EXECUTE ON FUNCTION testfunc1(int), testfunc2(int) TO regressuser2;
GRANT USAGE ON FUNCTION testfunc1(int) TO regressuser3; -- semantic error GRANT USAGE ON FUNCTION testfunc1(int) TO regressuser3; -- semantic error
ERROR: invalid privilege type USAGE for function object ERROR: invalid privilege type USAGE for function
GRANT ALL PRIVILEGES ON FUNCTION testfunc1(int) TO regressuser4; GRANT ALL PRIVILEGES ON FUNCTION testfunc1(int) TO regressuser4;
GRANT ALL PRIVILEGES ON FUNCTION testfunc_nosuch(int) TO regressuser4; GRANT ALL PRIVILEGES ON FUNCTION testfunc_nosuch(int) TO regressuser4;
ERROR: function testfunc_nosuch(integer) does not exist ERROR: function testfunc_nosuch(integer) does not exist
...@@ -248,12 +248,12 @@ SELECT testfunc1(5), testfunc2(5); -- ok ...@@ -248,12 +248,12 @@ SELECT testfunc1(5), testfunc2(5); -- ok
(1 row) (1 row)
CREATE FUNCTION testfunc3(int) RETURNS int AS 'select 2 * $1;' LANGUAGE sql; -- fail CREATE FUNCTION testfunc3(int) RETURNS int AS 'select 2 * $1;' LANGUAGE sql; -- fail
ERROR: sql: permission denied ERROR: permission denied for "sql"
SET SESSION AUTHORIZATION regressuser3; SET SESSION AUTHORIZATION regressuser3;
SELECT testfunc1(5); -- fail SELECT testfunc1(5); -- fail
ERROR: testfunc1: permission denied ERROR: permission denied for "testfunc1"
SELECT col1 FROM atest2 WHERE col2 = true; -- fail SELECT col1 FROM atest2 WHERE col2 = true; -- fail
ERROR: atest2: permission denied ERROR: permission denied for "atest2"
SELECT testfunc4(true); -- ok SELECT testfunc4(true); -- ok
testfunc4 testfunc4
----------- -----------
...@@ -268,7 +268,7 @@ SELECT testfunc1(5); -- ok ...@@ -268,7 +268,7 @@ SELECT testfunc1(5); -- ok
(1 row) (1 row)
DROP FUNCTION testfunc1(int); -- fail DROP FUNCTION testfunc1(int); -- fail
ERROR: testfunc1: must be owner ERROR: must be owner of "testfunc1"
\c - \c -
DROP FUNCTION testfunc1(int); -- ok DROP FUNCTION testfunc1(int); -- ok
-- restore to sanity -- restore to sanity
...@@ -282,15 +282,15 @@ select has_table_privilege(NULL,'pg_shadow','select'); ...@@ -282,15 +282,15 @@ select has_table_privilege(NULL,'pg_shadow','select');
(1 row) (1 row)
select has_table_privilege('pg_shad','select'); select has_table_privilege('pg_shad','select');
ERROR: Relation "pg_shad" does not exist ERROR: relation "pg_shad" does not exist
select has_table_privilege('nosuchuser','pg_shadow','select'); select has_table_privilege('nosuchuser','pg_shadow','select');
ERROR: user "nosuchuser" does not exist ERROR: user "nosuchuser" does not exist
select has_table_privilege('pg_shadow','sel'); select has_table_privilege('pg_shadow','sel');
ERROR: has_table_privilege: invalid privilege type sel ERROR: has_table_privilege: invalid privilege type sel
select has_table_privilege(-999999,'pg_shadow','update'); select has_table_privilege(-999999,'pg_shadow','update');
ERROR: pg_class_aclcheck: invalid user id 4293967297 ERROR: user with ID 4293967297 does not exist
select has_table_privilege(1,'rule'); select has_table_privilege(1,'rule');
ERROR: pg_class_aclcheck: relation 1 not found ERROR: relation with OID 1 does not exist
-- superuser -- superuser
\c - \c -
select has_table_privilege(current_user,'pg_shadow','select'); select has_table_privilege(current_user,'pg_shadow','select');
...@@ -551,7 +551,7 @@ ERROR: grant options can only be granted to individual users ...@@ -551,7 +551,7 @@ ERROR: grant options can only be granted to individual users
SET SESSION AUTHORIZATION regressuser2; SET SESSION AUTHORIZATION regressuser2;
GRANT SELECT ON atest4 TO regressuser3; GRANT SELECT ON atest4 TO regressuser3;
GRANT UPDATE ON atest4 TO regressuser3; -- fail GRANT UPDATE ON atest4 TO regressuser3; -- fail
ERROR: atest4: permission denied ERROR: permission denied for "atest4"
SET SESSION AUTHORIZATION regressuser1; SET SESSION AUTHORIZATION regressuser1;
REVOKE SELECT ON atest4 FROM regressuser3; -- does nothing REVOKE SELECT ON atest4 FROM regressuser3; -- does nothing
SELECT has_table_privilege('regressuser3', 'atest4', 'SELECT'); -- true SELECT has_table_privilege('regressuser3', 'atest4', 'SELECT'); -- true
...@@ -589,8 +589,8 @@ DROP VIEW atestv1; ...@@ -589,8 +589,8 @@ DROP VIEW atestv1;
DROP VIEW atestv2; DROP VIEW atestv2;
-- this should cascade to drop atestv4 -- this should cascade to drop atestv4
DROP VIEW atestv3 CASCADE; DROP VIEW atestv3 CASCADE;
NOTICE: Drop cascades to rule _RETURN on view atestv4 NOTICE: drop cascades to rule _RETURN on view atestv4
NOTICE: Drop cascades to view atestv4 NOTICE: drop cascades to view atestv4
-- this should complain "does not exist" -- this should complain "does not exist"
DROP VIEW atestv4; DROP VIEW atestv4;
ERROR: view "atestv4" does not exist ERROR: view "atestv4" does not exist
......
...@@ -44,7 +44,7 @@ DROP TABLE temptest; ...@@ -44,7 +44,7 @@ DROP TABLE temptest;
CREATE TEMP TABLE temptest(col int); CREATE TEMP TABLE temptest(col int);
\c regression \c regression
SELECT * FROM temptest; SELECT * FROM temptest;
ERROR: Relation "temptest" does not exist ERROR: relation "temptest" does not exist
-- Test ON COMMIT DELETE ROWS -- Test ON COMMIT DELETE ROWS
CREATE TEMP TABLE temptest(col int) ON COMMIT DELETE ROWS; CREATE TEMP TABLE temptest(col int) ON COMMIT DELETE ROWS;
BEGIN; BEGIN;
...@@ -78,7 +78,7 @@ SELECT * FROM temptest; ...@@ -78,7 +78,7 @@ SELECT * FROM temptest;
COMMIT; COMMIT;
SELECT * FROM temptest; SELECT * FROM temptest;
ERROR: Relation "temptest" does not exist ERROR: relation "temptest" does not exist
-- ON COMMIT is only allowed for TEMP -- ON COMMIT is only allowed for TEMP
CREATE TABLE temptest(col int) ON COMMIT DELETE ROWS; CREATE TABLE temptest(col int) ON COMMIT DELETE ROWS;
ERROR: ON COMMIT can only be used on TEMP tables ERROR: ON COMMIT can only be used on TEMP tables
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment