关于heroku sql语句的postgres失败

时间:2012-04-05 16:58:07

标签: postgresql heroku

我刚刚将node.js应用程序上传到heroku,我的一个SQL查询失败了。查询是:

INSERT INTO countries (name, user_id, created_timestamp)
SELECT $1, $2, CURRENT_TIMESTAMP
WHERE NOT EXISTS (SELECT 1 FROM countries WHERE name = $1 FOR UPDATE)

失败

  

错误:子查询中不允许SELECT FOR UPDATE / SHARE

有谁知道为什么?如果我无法选择更新,我可以使用吗?

1 个答案:

答案 0 :(得分:1)

这可能对您有用:

BEGIN;

LOCK TABLE countries IN SHARE MODE;

INSERT INTO countries (name, user_id, created_timestamp)
SELECT $1, $2, CURRENT_TIMESTAMP
WHERE NOT EXISTS (SELECT * FROM countries WHERE name = $1);

COMMIT;

Explanation and links in this closely related answer.