[英]ERROR: syntax error at or near “SELECT”
I am really new to postgres. postgres我真的很新。 The question looks very simple but I just cant see where I got wrong.
这个问题看起来非常简单,但我无法看出我的错误。
I a table created as follows: 我创建的表如下:
CREATE TABLE IF NOT EXISTS t(
tn VARCHAR(30) NOT NULL,
PRIMARY KEY(tn)
);
I want to insert an instance if the instance does not exist. 如果实例不存在,我想插入一个实例。 Here is my code:
这是我的代码:
INSERT INTO t (tn)
VALUES
(SELECT 'q' WHERE NOT EXISTS (SELECT * FROM t WHERE tn = 'q')) ;
And the psql console keeps giving me the error 并且psql控制台一直给我错误
ERROR: syntax error at or near "SELECT"
I have checked every piece of code individually, for instance both 我已经单独检查了每一段代码,例如两者
SELECT 'q' WHERE NOT EXISTS (SELECT * FROM t WHERE tn = 'q');
and 和
INSERT INTO t (tn) VALUES ('p');
run without error. 运行没有错误。 But error occurs when I put them together.
但是当我把它们放在一起时会发生错误。
Does anyone know where I got wrong..? 有谁知道我错在哪里..?
Lose VALUES
and the brackets... 丢失
VALUES
和括号......
INSERT INTO t (tn)
SELECT 'q' WHERE NOT EXISTS (SELECT * FROM t WHERE tn = 'q');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.