我正在尝试为此效果运行一个语句:
IF EXISTS (SELECT * FROM LeadCustomer WHERE FirstName = 'John' AND Surname = 'Smith') THEN
SELECT * FROM LeadCustomer WHERE FirstName = 'John' AND Surname = 'Smith';
ELSE
INSERT INTO LeadCustomer (Firstname, Surname, BillingAddress, email) VALUES ('John', 'Smith', '6 Brewery close, Buxton, Norfolk', 'cmp.testing@example.com');;
END IF;
它抛出错误:
ERROR: syntax error at or near "IF"
我找到了 this question但这些答案中建议的格式似乎也不起作用。想知道是否有人可以告诉我为什么这不起作用?
最佳答案
If
是 plpgsql 语言的一部分。它只能在 plpgsql 函数中工作:
http://www.postgresql.org/docs/current/interactive/plpgsql.html
关于database - 如果 postgres 中的语句抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15709861/