Table containing only valid table names

From: Michael Graham <mgraham(at)bloxx(dot)com>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Table containing only valid table names
Date: 2013-04-26 15:09:44
Message-ID: 517A98B8.4090000@bloxx.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi all,

I'm trying to create a table that contains only valid table names. I'm
currently using reglass for the field type which works fine for when you
are adding to the table (i.e. you can't add invalid tablesnames to the
table). But it is still possible to leave the table in an invalid state
after doing a drop table.

So for example:

=> CREATE TABLE table_list (tablename regclass);
CREATE TABLE
=> INSERT INTO table_list VALUES ('foo');
ERROR: relation "foo" does not exist
LINE 1: INSERT INTO table_list VALUES ('foo');
^
=> CREATE TABLE foo (a int);
CREATE TABLE
=> INSERT INTO table_list VALUES ('foo');
INSERT 0 1
=> DROP TABLE foo;
DROP TABLE
=> SELECT * FROM table_list;
tablename
-----------
122860
(1 row)

Does any one have any ideas that could be used to stop this from
happening? I'm not really in the position to have different users for
the modification of the table_list and the drops so I don't think I can
use different roles.

I'm pretty sure I can't do what I need as postgres doesn't support
triggers on DDL but maybe I'm wrong.

Cheers,
--
Michael Graham

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2013-04-26 15:15:38 Re: Checking for changes in other tables
Previous Message Rowan Collins 2013-04-26 15:06:31 UPDATE using 3 medium-sized tables causes runaway hash table and fills disk