我在 postgresql 9.4 数据库中定义了一个数组字段:
character varying(64)[]
我可以有一个空数组吗? {} 该字段的默认值? 这样设置的语法是什么?
如果只设置括号 {},我会收到以下错误:
SQL error:
ERROR: syntax error at or near "{"
LINE 1: ...public"."accounts" ALTER COLUMN "pwd_history" SET DEFAULT {}
^
In statement:
ALTER TABLE "public"."accounts" ALTER COLUMN "pwd_history" SET DEFAULT {}
最佳答案
您需要使用显式的array
初始化器并将其转换为正确的类型:
ALTER TABLE public.accounts
ALTER COLUMN pwd_history SET DEFAULT array[]::varchar[];
关于sql - 空数组作为 PostgreSQL 数组列默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30933266/