使用带括号的列名创建 table
creating a table with column names having brackets
我尝试使用 postgresql 查询创建 table:
CREATE TABLE customer_account(ID_account integer primary key, customer_name (lastname) text);
但它给出错误信息:
ERROR: syntax error at or near "("
LINE 5: customer_name (lastname) text,
应该是括号的问题,我已经试过了
CREATE TABLE customer_account("ID_account" primary key, "customer_name (lastname)" text);
但是它也给了我一个类似的错误信息。
如何更正查询?我真的需要用括号。
使用 "
将 工作,但您缺少主键的数据类型:
CREATE TABLE customer_account
(
"ID_account" <b>integer</b> primary key,
--^ here
"customer_name (lastname)" text
);
但我强烈建议您不要使用带引号的标识符。
他们会给你带来更多的麻烦 运行 那么他们是值得的。
我建议使用这样的东西:
CREATE TABLE customer_account
(
account_id integer primary key,
customer_lastname text
);
(“ID”作为前缀在英语中听起来很奇怪)
我尝试使用 postgresql 查询创建 table:
CREATE TABLE customer_account(ID_account integer primary key, customer_name (lastname) text);
但它给出错误信息:
ERROR: syntax error at or near "("
LINE 5: customer_name (lastname) text,
应该是括号的问题,我已经试过了
CREATE TABLE customer_account("ID_account" primary key, "customer_name (lastname)" text);
但是它也给了我一个类似的错误信息。
如何更正查询?我真的需要用括号。
使用 "
将 工作,但您缺少主键的数据类型:
CREATE TABLE customer_account
(
"ID_account" <b>integer</b> primary key,
--^ here
"customer_name (lastname)" text
);
但我强烈建议您不要使用带引号的标识符。
他们会给你带来更多的麻烦 运行 那么他们是值得的。
我建议使用这样的东西:
CREATE TABLE customer_account
(
account_id integer primary key,
customer_lastname text
);
(“ID”作为前缀在英语中听起来很奇怪)