我正在尝试通过更新或在vote_user_table中插入新记录来更新数据库.该表定义如下:
Column | Type | Modifiers
-----------+---------+--------------------------------------------------------------
id | integer | not null default nextval('vote_user_table_id_seq'::regclass)
review_id | integer | not null
user_id | integer | not null
positive | boolean | default false
negative | boolean | default false
Indexes:
"vote_user_table_pkey" PRIMARY KEY, btree (id)
Run Code Online (Sandbox Code Playgroud)
这是我正在使用的查询.我实际上正在为所有值使用参数,但出于测试目的,我将它们替换为我确定应该工作的值.用户名aaa@aaa.com存在.
WITH updated AS (
UPDATE vote_user_table
SET
positive = 'true',
negative = 'false'
FROM usuario
WHERE
review_id = 6 AND
user_id = usuario.id AND
usuario.username ILIKE 'aaa@aaa.com'
RETURNING vote_user_table.id
) …
Run Code Online (Sandbox Code Playgroud) sql postgresql upsert common-table-expression postgresql-9.2