Re: best way to reference tables

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
Cc: tjo(at)acm(dot)org, dev(at)archonet(dot)com, pgsql-general(at)postgresql(dot)org
Subject: Re: best way to reference tables
Date: 2005-08-09 20:37:56
Message-ID: 18859.1123619876@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> writes:
> On Tue, Aug 09, 2005 at 04:01:33PM -0400, Tom Lane wrote:
>> Yeah, you can store the pg_class OID of the table,

> Maybe it is possible to use a column of type regclass to store it. Not
> sure exactly what advantage that would give, but it's an idea.

Hmm, that's a cute idea.

regression=# create table tablist (tabid regclass);
CREATE TABLE
regression=# create table mytab(f1 int);
CREATE TABLE
regression=# insert into tablist values ('mytab');
INSERT 0 1
regression=# select * from tablist;
tabid
-------
mytab
(1 row)

regression=# alter table mytab rename to histab;
ALTER TABLE
regression=# select * from tablist;
tabid
--------
histab
(1 row)

regression=# create schema s1;
CREATE SCHEMA
regression=# alter table histab set schema s1;
ALTER TABLE
regression=# select * from tablist;
tabid
-----------
s1.histab
(1 row)

regression=# drop table s1.histab;
DROP TABLE
regression=# select * from tablist;
tabid
-------
82301
(1 row)

regression=#

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message SCassidy 2005-08-09 21:32:40 Re: Suppressing Error messages.
Previous Message Guy Rouillier 2005-08-09 20:26:27 Re: How to write jobs in postgresql