The following bug has been logged on the website:
Bug reference: 17579
Logged by: Alexey Borzov
Email address: borz_off@cs.msu.su
PostgreSQL version: Unsupported/Unknown
Operating system: Windows
Description:
create table foo (id int);
with cte_failure as (
merge into foo as target
using foo as source
on target.id = source.id
when matched then do nothing
)
select 'fail!';
When executing the above code I get the following error:
> ERROR: DO INSTEAD NOTIFY rules are not supported for data-modifying
statements in WITH
I suspect that MERGE was never intended to work as a CTE, but right now the
grammar allows any PreparableStmt in a common_table_expr and the above error
is triggered a lot later due to implementation details.