-- TRAP: FailedAssertion("!(!((((const Node*)(node))->type) == T_Query))", File: "var.c", Line: 248)
begin;
CREATE TABLE target (tid integer, balance integer);
INSERT INTO target VALUES (1, 10);
INSERT INTO target VALUES (2, 20);
INSERT INTO target VALUES (3, 30);
ALTER TABLE target ADD PRIMARY KEY (tid);

CREATE TABLE source (sid integer, delta integer);
INSERT INTO source VALUES (4, 40);
INSERT INTO source VALUES (2, 5);
INSERT INTO source VALUES (3, 20);

MERGE INTO public.source as target_0
USING public.source as sample_0
  inner join (select  
        ref_0.tid as c0
      from 
        public.target as ref_0
      where ref_0.tid is NULL
      limit 117) as subq_0
  on (((select sid from public.source limit 1 offset 1)
           is not NULL) 
      or (subq_0.c0 is NULL))
ON target_0.sid = sample_0.sid 
WHEN NOT MATCHED
  AND cast(null as name) ~~ cast(null as text)
   THEN DO NOTHING;

rollback;
