ENUM like data type

From: MRB <nomail(at)example(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: ENUM like data type
Date: 2005-06-21 15:20:19
Message-ID: 11bgc1oblfasq3d@corp.supernews.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-sql

Hi All,

I have something in mind I'm not certain is do-able.

I'm working with a lot of data from MySQL where the MySQL ENUM type is used.

This is not a big problem per se but creating the proper lookup tables
is becoming a bit tedious so I was hoping to make something better of it.

Here is where I get uncertain as to if this is possible. My idea is to
create a pseudo type that triggers the creation of it's lookup tables
the same way the SERIAL type triggers creation of a sequence and returns
an int with the right default value.

Here is what would want to happen:

CREATE TABLE test(
testfield ENUM('Bits', 'of', 'data')
);

-- This would trigger the following events:

CREATE TABLE test_testfield_enum(
id VARCHAR(4) NOT NULL PRIMARY KEY;
);
INSERT INTO test_testfield_enum VALUES('Bits');
INSERT INTO test_testfield_enum VALUES('Of');
INSERT INTO test_testfield_enum VALUES('data');

CREATE TABLE test(
testfield VARCHAR(4) REFERENCES test_testfield_enum(id)
);

Hope that is clear enough. As said I am not quite sure this is possible,
my guess would be no. But any input is appreciated.

Cheers,

Martin

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Karl O. Pinc 2005-06-21 15:25:01 Re: [GENERAL] Escape handling in strings
Previous Message AgentM 2005-06-21 14:58:59 Re: Escape handling in strings

Browse pgsql-sql by date

  From Date Subject
Next Message Stefan Becker 2005-06-21 16:34:39 Re: customising serial type
Previous Message Michael Glaesemann 2005-06-21 10:23:57 Re: customising serial type