Cannot INSERT: ERROR: array value must start with "{" or dimension information
Cannot INSERT: ERROR: array value must start with "{" or dimension information
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...
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',...
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',...
以上不同的 INSERT
语句在 PostgreSQL 中失败。我做错了什么?
我的架构:
journeypost=# \dt user_data.*
List of relations
Schema | Name | Type | Owner
-----------+-----------+-------+-------
user_data | user_data | table | user
我的table:
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)
您的列 username
似乎是 array 类型,因此文字 'mahman'
无效输入。
应该是'{mahman}'
:
INSERT INTO user_data.user_data (username,randomint)
VALUES ('{mahman}',1);
(或者将其改为普通的 varchar
列或 text
列。)
更新确认:character varying(50)[]
是 character varying(50)
的 数组 。
关于array literal / array constructor:
- Pass array from node-postgres to plpgsql function
- How to pass custom type array to Postgres function
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...
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',...
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',...
以上不同的 INSERT
语句在 PostgreSQL 中失败。我做错了什么?
我的架构:
journeypost=# \dt user_data.*
List of relations
Schema | Name | Type | Owner
-----------+-----------+-------+-------
user_data | user_data | table | user
我的table:
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)
您的列 username
似乎是 array 类型,因此文字 'mahman'
无效输入。
应该是'{mahman}'
:
INSERT INTO user_data.user_data (username,randomint)
VALUES ('{mahman}',1);
(或者将其改为普通的 varchar
列或 text
列。)
更新确认:character varying(50)[]
是 character varying(50)
的 数组 。
关于array literal / array constructor:
- Pass array from node-postgres to plpgsql function
- How to pass custom type array to Postgres function