Postgres batch update can not work

The offical for ZeosLib 7.3 Report problems, ask for help, post proposals for the new version of Zeoslib 7.3/v8
Quick Info:
-We made two new drivers: odbc(raw and unicode version) and oledb
-GUID domain/field-defined support for FB
-extended error infos of Firebird
-performance ups are still in queue
In future some more feature will arrive, so stay tuned and don't hassitate to help
Post Reply
abk964
Fresh Boarder
Fresh Boarder
Posts: 17
Joined: 24.08.2022, 09:28

Postgres batch update can not work

Post by abk964 »

Batch update can not work with Postgres - function unnest can not be used in WHERE clause.

Generated query:

Code: Select all

UPDATE BATCH_TEST_TABLE SET VAL_FIELD = unnest($1::int4[]) WHERE VAL_FIELD = unnest($2::int4[])
Table DDL:

Code: Select all

CREATE TABLE BATCH_TEST_TABLE (
    VAL_FIELD  INTEGER
);
Project attached.
You do not have the required permissions to view the files attached to this post.
abk964
Fresh Boarder
Fresh Boarder
Posts: 17
Joined: 24.08.2022, 09:28

Re: Postgres batch update can not work

Post by abk964 »

Solved by replacing SQL from

Code: Select all

UPDATE BATCH_TEST_TABLE SET VAL_FIELD = :P0 WHERE VAL_FIELD = :P1
to

Code: Select all

UPDATE batch_test_table SET val_field = "CAST"(r.c0 as integer) FROM (SELECT :p0 as c0, :p1 as c1 ) r
WHERE val_field = "CAST"(r.c1 as integer)
Version with CTE

Code: Select all

WITH r(c0 ,c1 ) AS (SELECT :P0, :P1)
UPDATE public.batch_test_table SET val_field = "CAST"(r.c0 as integer)
FROM r WHERE val_field = "CAST"(r.c1 as integer)
raises access violation in TZBindList.AcquireBuffer.

BTW, can't use CAST operator "::" - one semicolon disappears.
stoffman
Senior Boarder
Senior Boarder
Posts: 50
Joined: 03.12.2020, 06:55

Re: Postgres batch update can not work

Post by stoffman »

You can use the the semicolon operator, you need to double it

so instead var::int
you write var::::int

":" is being used by zeos to parametrize the query, so it kind of conflicts with postgress, but as I said just double its number
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1956
Joined: 17.01.2011, 14:17

Re: Postgres batch update can not work

Post by marsupilami »

Another option is to change the paramchar property. Setting paramchar to # might work:

Code: Select all

UPDATE BATCH_TEST_TABLE SET VAL_FIELD = #P0 WHERE VAL_FIELD = #P1
Post Reply