On Wed, 2009-01-21 at 15:08 -0800, Jeff Davis wrote:
> If we keep the permission check in LockTableCommand(), I can make a
> patch that produces a more useful error message when the table is
> removed right before the pg_class_aclcheck().
Attached.
Regards,
Jeff Davis
diff --git a/src/backend/commands/lockcmds.c b/src/backend/commands/lockcmds.c
index e32b184..a96bdab 100644
--- a/src/backend/commands/lockcmds.c
+++ b/src/backend/commands/lockcmds.c
@@ -59,22 +59,58 @@ LockTableCommand(LockStmt *lockstmt)
Relation rel;
AclResult aclresult;
- /* We don't want to open the relation until we've checked privilege. */
- if (lockstmt->mode == AccessShareLock)
- aclresult = pg_class_aclcheck(childreloid, GetUserId(),
- ACL_SELECT);
- else
- aclresult = pg_class_aclcheck(childreloid, GetUserId(),
- ACL_UPDATE | ACL_DELETE | ACL_TRUNCATE);
+ PG_TRY();
+ {
+ /* We don't want to open the relation until we've checked privilege. */
+ if (lockstmt->mode == AccessShareLock)
+ aclresult = pg_class_aclcheck(childreloid, GetUserId(),
+ ACL_SELECT);
+ else
+ aclresult = pg_class_aclcheck(childreloid, GetUserId(),
+ ACL_UPDATE | ACL_DELETE | ACL_TRUNCATE);
+ }
+ PG_CATCH();
+ {
+ FlushErrorState();
+ if (relation->schemaname)
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_TABLE),
+ errmsg("relation \"%s.%s\" does not exist",
+ relation->schemaname, relation->relname)));
+ else
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_TABLE),
+ errmsg("relation \"%s\" does not exist",
+ relation->relname)));
+ }
+ PG_END_TRY();
if (aclresult != ACLCHECK_OK)
aclcheck_error(aclresult, ACL_KIND_CLASS,
get_rel_name(childreloid));
- if (lockstmt->nowait)
- rel = relation_open_nowait(childreloid, lockstmt->mode);
- else
- rel = relation_open(childreloid, lockstmt->mode);
+ PG_TRY();
+ {
+ if (lockstmt->nowait)
+ rel = relation_open_nowait(childreloid, lockstmt->mode);
+ else
+ rel = relation_open(childreloid, lockstmt->mode);
+ }
+ PG_CATCH();
+ {
+ FlushErrorState();
+ if (relation->schemaname)
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_TABLE),
+ errmsg("relation \"%s.%s\" does not exist",
+ relation->schemaname, relation->relname)));
+ else
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_TABLE),
+ errmsg("relation \"%s\" does not exist",
+ relation->relname)));
+ }
+ PG_END_TRY();
/* Currently, we only allow plain tables to be locked */
if (rel->rd_rel->relkind != RELKIND_RELATION)
--
Sent via pgsql-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers