Dup Goto 📝

Columns Containing Sets Of Values

PT2/db/postgres postgres set 04-02 11:56:30
To Pop
15 lines, 93 words, 520 chars Wednesday 2025-04-02 11:56:30

This is the ARRAY type, not a set. As SQL uses the SET keyword in UPDATE.

CREATE TABLE a ( id SERIAL PRIMARY KEY, name TEXT, s TEXT[] );
INSERT INTO a ( name, s ) VALUES ( 'Hello World', '{ "hello", "world" }' ), ( 'Mr Flibble', '{ "mr", "flibble" }' );
SELECT name, s FROM a WHERE 'hello' = ANY( s );

outputs

    name     |       s       
-------------+---------------
 Hello World | {hello,world}

This does not prevent duplicate elements in a column, e.g. { "hello", "hello" } is possible.