空数组作为PostgreSQL数组列的默认值 [英] Empty array as PostgreSQL array column default value
本文介绍了空数组作为PostgreSQL数组列的默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在PostgreSQL 9.4数据库中定义了一个数组字段:
I have a defined an array field in postgresql 9.4 database:
character varying(64)[]
我可以有一个空数组吗? {}为该字段的默认值?
设置的语法是什么?
Can I have an empty array e.g. {} for default value of that field? What will be the syntax for setting so?
在仅设置方括号{}的情况下出现以下错误:
I'm getting following error in case of setting just brackets {}:
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
初始化程序并将其转换为正确的类型:
You need to use the explicit array
initializer and cast that to the correct type:
ALTER TABLE public.accounts
ALTER COLUMN pwd_history SET DEFAULT array[]::varchar[];
这篇关于空数组作为PostgreSQL数组列的默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文