create domain text[]

44 views
Skip to first unread message

Peter Borissow

unread,
Mar 21, 2024, 12:44:35 PMMar 21
to H2 Database
Hello,
    I am using H2 v2.2.224 in PostgreSQL mode. I would like to create a table in H2 with a "text" and "text[]" column. For example, in PostgreSQL I have a table like this:

CREATE TABLE COMPANY (
    ID BIGSERIAL NOT NULL,
    NAME text NOT NULL,
    DESCRIPTION text,
    NAICS text[]
);

I can successfully create a "text" column if I create a custom domain like this:
"CREATE domain IF NOT EXISTS text AS varchar"

However, if I try to create a domain for "text[]" I get an error:
"CREATE domain IF NOT EXISTS text[] AS varchar ARRAY"

org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "CREATE domain IF NOT EXISTS text[*][] AS varchar ARRAY"; expected "., AS, data type";

I think the syntax error lays in the brackets because if I replace "text[]" with "blah" it works:
"CREATE domain IF NOT EXISTS blah AS varchar ARRAY"

Any suggestions for how to get this to work? Maybe a different syntax for the "create domain" statement or a property of some sort?

Thanks in advance,
Peter

Evgenij Ryazanov

unread,
Mar 21, 2024, 8:17:25 PMMar 21
to H2 Database
Hello!

It isn't going to work, text[] is not an identifier and it cannot be used as domain name.

PostgreSQL supports standard arrays for more than 20 years, just use a standard definition in both PostgreSQL and H2.

Peter Borissow

unread,
Mar 22, 2024, 8:51:21 AMMar 22
to H2 Database
Thanks for confirming that there is currently no way to create a "text[]" domain.

Just as an aside, PostgreSQL has supported "text[]" and other arrays using "column_name datatype []" syntax since at least the 7.x release which is also more than 20 years old ;-)

Thanks again for all your help. H2 is awesome!

Best,
Peter

Reply all
Reply to author
Forward
0 new messages