本文介绍了SQLite 'IF NOT EXISTS' 语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决此错误的其他问题似乎都不适合我.我的查询是:
None of the other questions which address this error seems to work for me. My query is:
IF NOT EXISTS (SELECT 1 FROM Configuration WHERE key = 'CookieCount')
BEGIN
INSERT INTO Configuration (key, value)
VALUES ('CookieCount', '0')
END
我的错误消息是:无法准备语句(IF"附近的 1:语法错误)"
and my error message is: "could not prepare statement (1 near "IF": syntax error)"
我在 Postgres 中有这个工作:http://sqlfiddle.com/#!15/b14ef/2/0但这在 SQLite 中不起作用,我需要它同时使用两者.
I have this working in Postgres: http://sqlfiddle.com/#!15/b14ef/2/0But this does not work in SQLite and I need it to work with both.
推荐答案
尝试用这样的东西代替 IF 语句:
Try to use something like this instead IF statement :
INSERT INTO Configuration (key, value)
SELECT 'CookieCount', '0'
WHERE NOT EXISTS(SELECT 1 FROM Configuration WHERE key = 'CookieCount');
这篇关于SQLite 'IF NOT EXISTS' 语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!