create table my_table(
id varchar(255) not null primary key,
text_column varchar(255) not null,
array_column text[] not null
);
My table state is
id|text_column|array_column|
--+-----------+------------+
1 |Abcd |{a,b} |
2 |Abcd |{a} |
3 |Xyz |{a,b} |
I would want this to fail
insert into my_table values ('4', 'Abcd', '{"b", "a"}');
insert into my_table values ('5', 'Abcd', '{"a", "b"}');
I am trying to impose the unique constraint on text_column and array_column.
Array_column is not sorted.
Also is it better way to do?
1条答案
按热度按时间k3bvogb11#
您可以创建一个辅助函数,对数组元素进行排序,并在唯一索引中使用该函数: