How to release SET() in PgSQL?

Started by Andrey Y. Mosienkoabout 25 years ago4 messagesgeneral
Jump to latest

Hello All!

I used MySQL for a long time. There is SET() conception.
I can define SET('one','two','three') and use that type:

CREATE TABLE "test" (
"a" SET('one','two','three')
};

And then:

SELECT * FROM test WHERE a = 'one';
or
SELECT * FROM test WHERE a like 'one,three';

How can I do it in PgSQL? I need it so much!

--
with respection Andrey Feofilactovich.
e-mail: feo@ttn.ru, feo@feo.org.ru
ICQ: 28073807

#2Peter Eisentraut
peter_e@gmx.net
In reply to: Andrey Y. Mosienko (#1)
Re: How to release SET() in PgSQL?

Andrey Y. Mosienko writes:

CREATE TABLE "test" (
"a" SET('one','two','three')
};

You could split that off into a separate table, e.g.,

CREATE TABLE test1 (
id int,
/* the rest of the columns in your "test" */
);

CREATE TABLE test2 (
id int references test1,
a varchar check a in ('one', 'two', 'three')
);

--
Peter Eisentraut peter_e@gmx.net http://yi.org/peter-e/

#3Dan Lyke
danlyke@flutterby.com
In reply to: Andrey Y. Mosienko (#1)

Andrey Y. Mosienko writes:

SELECT * FROM test WHERE a like 'one,three';

How can I do it in PgSQL? I need it so much!

It isn't quite as clean, but in the long term I think it's a better
solution:

Use a join to another table with your "SET"/"ENUM" list in it.

Dan

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Dan Lyke (#3)
Re: How to release SET() in PgSQL?

How can I do it in PgSQL? I need it so much!

I think the usual advice is to make it a text or varchar column and
use a check constraint to enforce that only one of the allowed strings
can be stored in it.

regards, tom lane