当我在PG Admin III中执行以下查询时,运行正常:
WITH new_values (updated_at,talker_id,sentence_id,v0,v1,v2,v3,v4,v5) AS (
VALUES (current_timestamp,'2','3','4','5','6','7','8','9')
),
UPSERT AS (
UPDATE utel u
SET
updated_at=nv.updated_at,
v0=nv.v0,v1=nv.v1,v2=nv.v2,v3=nv.v3,v4=nv.v4,v5=nv.v5
FROM
new_values nv
WHERE
u.talker_id=nv.talker_id AND u.sentence_id=nv.sentence_id RETURNING u.*
)
INSERT into utel (updated_at,talker_id,sentence_id,v0,v1,v2,v3,v4,v5)
SELECT updated_at,talker_id,sentence_id,v0,v1,v2,v3,v4,v5
FROM new_values WHERE NOT EXISTS(
SELECT 1 FROM upsert up
WHERE
up.talker_id=new_values.talker_id
AND up.sentence_id=new_values.sentence_id
)
但是当我尝试通过TFDQuery执行它时,PostgreSQL抱怨道:
字符355处“INSERT”处或附近的语法错误
我打开PostgreSQL日志记录到Windows错误日志并看到以下内容:
DECLARE "10STM" CURSOR WITH HOLD FOR
WITH new_values (updated_at,talker_id,sentence_id,v0,v1,v2,v3,v4,v5) AS (
VALUES (current_timestamp,'2','3','4','5','6','7','8','9')
),
UPSERT AS (
UPDATE utel u
SET
updated_at=nv.updated_at,
v0=nv.v0,v1=nv.v1,v2=nv.v2,v3=nv.v3,v4=nv.v4,v5=nv.v5
FROM
new_values nv
WHERE
u.talker_id=nv.talker_id AND u.sentence_id=nv.sentence_id RETURNING u.*
)
INSERT into utel (updated_at,talker_id,sentence_id,v0,v1,v2,v3,v4,v5)
SELECT updated_at,talker_id,sentence_id,v0,v1,v2,v3,v4,v5
FROM new_values WHERE NOT EXISTS(
SELECT 1 FROM upsert up
WHERE
up.talker_id=new_values.talker_id
AND up.sentence_id=new_values.sentence_id
)
当我在PG Admin III中使用DECLARE "10STM" CURSOR WITH HOLD FOR
执行相同的操作时,我会得到完全相同的错误。
为什么FireDAC会先用光标查询PG查询以及如何避免这种情况?
答案 0 :(得分:0)
维多利亚不想得到她的分数,所以答案是:
获取选项中的游标类型设置为ckAutomatic
。我将其更改为ckDefault
,现在可以正常使用。