Skip site navigation (1) Skip section navigation (2)

Re: enums

From: Rod Taylor <pg(at)rbt(dot)ca>
To: "Jim C(dot) Nasby" <jnasby(at)pervasive(dot)com>
Cc: Andrew Dunstan <andrew(at)dunslane(dot)net>,PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>,Michael Fuhr <mike(at)fuhr(dot)org>
Subject: Re: enums
Date: 2005-10-28 18:57:03
Message-ID: 1130525823.846.131.camel@home (view raw, whole thread or download thread mbox)
Lists: pgsql-hackers
On Fri, 2005-10-28 at 13:20 -0500, Jim C. Nasby wrote:
> On Thu, Oct 27, 2005 at 11:07:19PM -0400, Rod Taylor wrote:
> > > The other issue is ease of use.
> > > 
> > > We used lookup tables in bugzilla when it was converted to work with 
> > > Postgres. But many users will find having to do that annoying, to say 
> > > the least. I think there's a very good case for providing true enums. 
> > 
> > Then why did you use lookup tables instead of a varchar and a
> > constraint? Probably performance.
> > 
> > A much more general purpose but just as good solution would be the
> > ability to create a hidden surrogate key for a structure.
> > 
> > CREATE TABLE status (code varchar(20) PRIMARY KEY) WITH SURROGATE;
> > CREATE TABLE account (name varchar(60), status varchar(20) references
> > status);
> > 
> > Behind the scenes (transparent to the user) this gets converted to:
> > 
> > CREATE TABLE status (id SERIAL UNIQUE, code varchar(20) PRIMARY KEY)
> > CREATE TABLE account (name varchar(60), status integer references
> > status(id));
> > 
> > 
> > SELECT * FROM account; would be rewritten as
> > SELECT * FROM (SELECT name, code FROM account JOIN status USING (id)) AS
> > account;
> > 
> > Enum might be good for a short list of items but something like the
> > above should be good for any common value that we manually create
> > surrogate keys for today but without the clutter or the application
> > needing to know.
> > 
> > If PostgreSQL had an updatable view implementation it would be pretty
> > simple to implement.
> I'm not quiet following the WITH SURROGATE bit, but what you've
> described certainly looks valuable. Note that I would still want to be
> able to get at the raw numeric values in some fasion.

The basic idea is that most of us break out schemas by creating fake
primary keys for the purpose of obtaining performance because using the
proper primary key (single or multiple columns) is often very slow.

The automatic and transparent creation of a surrogate key by PostgreSQL
would allow us to dramatically clean up the presentation of our schema
to the users using the database without the performance hit we currently

It puts surrogate keys (fake primary keys) back to the level of table
spaces, indexes and other performance enhancements where they belong.


In response to

  • Re: enums at 2005-10-28 18:20:51 from Jim C. Nasby


pgsql-hackers by date

Next:From: Tom LaneDate: 2005-10-28 19:04:02
Subject: Re: TRAP: FailedAssertion("!((itemid)->lp_flags & 0x01)",
Previous:From: Jim C. NasbyDate: 2005-10-28 18:30:51
Subject: Re: pl/pgsql breakage in 8.1b4?

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group