Hi Chunling,
Thank you for reporting the issue.
I tried to reproduce the issue on postgres19 and I don't see any crash.
psql (19devel)
Type "help" for help.
postgres=#
postgres=#
postgres=#
postgres=# CREATE TABLE target (col_int INT, col_varchar VARCHAR(2000));
CREATE TABLE
postgres=# CREATE TABLE source (col_int INT, col_varchar VARCHAR(2000));
CREATE TABLE
postgres=# INSERT INTO source VALUES (1, 'test');
INSERT 0 1
postgres=#
postgres=#
postgres=# WITH merge_cte AS (
postgres(# MERGE INTO target t
postgres(# USING source s ON t.col_int = s.col_int
postgres(# WHEN NOT MATCHED THEN INSERT (col_int, col_varchar) VALUES WHEN NOT MATCHED THEN INSERT (col_int, col_varchar) VALUES (s.col_int,
postgres(# s.col_varchar)
postgres(# )
postgres-# SELECT col_int FROM merge_cte;
ERROR: WITH query "merge_cte" does not have a RETURNING clause
LINE 7: SELECT col_int FROM merge_cte;
^
postgres=# WITH merge_cte AS (
postgres(# MERGE INTO target t
postgres(# USING source s ON t.col_int = s.col_int
postgres(# WHEN NOT MATCHED THEN INSERT (col_int, col_varchar) VALUES (s.col_int, s.col_varchar) RETURNING t.col_int
postgres(# )
postgres-# SELECT col_int FROM merge_cte;
col_int
---------
1
(1 row)
I tried to reproduce the issue on postgres15 too, but i see ERROR: MERGE not supported in WITH query.
Regards,
Surya Poondla