无法INSERT:ERROR:数组值必须以" {"或维度信息

时间:2015-07-20 14:25:51

标签: arrays postgresql types sql-insert

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)

1 个答案:

答案 0 :(得分:20)

您的专栏username似乎是 数组 类型,因此文字'mahman'不是有效输入。

必须 '{mahman}'

INSERT INTO user_data.user_data (username,randomint)
VALUES ('{mahman}',1);

(或者改为使用普通varchar列或text列。)

更新确认:character varying(50)[]character varying(50)数组