journeypost=# INSERT INTO user_data.user_data (username,randomint) VALUES ('mahman',1);
ERROR: array value must start with "{" or dimension information
LINE 1: ... user_data.user_data (username,randomint) VALUES ('mahman...
journeypost=# INSERT INTO user_data.user_data (username,randomint) VALUES {'mahman',1};
ERROR: syntax error at or near "{"
LINE 1: ...O user_data.user_data (username,randomint) VALUES {'mahman',...
journeypost=# INSERT INTO user_data.user_data (username,randomint) VALUES (2,{'mahman',1});
ERROR: syntax error at or near "{"
LINE 1: ...ser_data.user_data (username,randomint) VALUES (2,{'mahman',...
在PostgreSQL中,上述不同的INSERT语句失败了。我做错了什么?
编辑:
我的架构:
journeypost=# \dt user_data.*
List of relations
Schema | Name | Type | Owner
-----------+-----------+-------+-------
user_data | user_data | table | user
(1 row)
我的表:
journeypost=# \d user_data.user_data
Table "user_data.user_data"
Column | Type | Modifiers
-----------+-------------------------+-----------
username | character varying(50)[] | not null
randomint | integer |
Indexes:
"UsernameUnique" PRIMARY KEY, btree (username)
答案 0 :(得分:20)
您的专栏username
似乎是 数组 类型,因此文字'mahman'
不是有效输入。
必须 '{mahman}'
:
INSERT INTO user_data.user_data (username,randomint)
VALUES ('{mahman}',1);
(或者改为使用普通varchar
列或text
列。)
更新确认:character varying(50)[]
是character varying(50)
的数组。