How can I insert an array of enums
?
Here is my enum
:
CREATE TYPE equipment AS ENUM (\'projector\',\'PAsystem\',\'safe\',\'PC\',\'ph
Additionally to @harm answer, you can skip quotations marks:
INSERT INTO lecture_room (equipment) VALUES ('{projector, safe}');
Old question, but a new answer. In modern versions of Postgres (tested with 9.6) none of this is required. It works as expected:
INSERT INTO lecture_room (equipment) VALUES ('{"projector", "safe"}');
The alternative to an ARRAY constructor like @Mark correctly supplied is to cast a string literal directly:
'{projector,PAsystem,safe}'::equipment[]
This variant is shorter and some clients have problems with the ARRAY constructor, which is a function-like element.
PostgreSQL doesn't know how to automatically cast input of type text
to input of type equipment
. You have to explicitly declare your strings as being of type equipment
:
ARRAY['projector','PAsystem','safe']::equipment[]
I confirmed this with SQL Fiddle.