marten icon indicating copy to clipboard operation
marten copied to clipboard

Missing temp CTE table on Patch call

Open barclayadam opened this issue 2 years ago • 3 comments

I am in the process of migrating from v3 to v5 and come across a change to the Patch support. I'm trying to narrow it down some more now, but the issue appears to be if the Patch filter is a little complex:

        this._db.Patch<User>(u => u.ExternalReferences.References.Any(r => r.Reference ==externalReference))
            .Set(u => u.PhotoUrl, photoUrl);

The above fails with:

````42P01: relation "mt_temp_id_list2cte" does not exist```

The generated SQL look like (as 2x:

update public.mt_doc_user as d 
set data = public.mt_transform_patch_doc(data, :p1), mt_last_modified = (now() at time zone 'utc'), mt_version = :p2 
where ctid in (select ctid from mt_temp_id_list2CTE);

update public.mt_doc_user as d set primary_email = data ->> 'PrimaryEmail', member_of = CAST(ARRAY(SELECT jsonb_array_elements_text(CAST(data ->> 'MemberOf' as jsonb))) as varchar[]), secondary_emails = CAST(ARRAY(SELECT jsonb_array_elements_text(CAST(data ->> 'SecondaryEmails' as jsonb))) as varchar[]) 
where ctid in (select ctid from mt_temp_id_list2CTE);

That is the entire statement, where you can see no mt_temp_id_list2CTE is generated

barclayadam avatar Apr 08 '22 08:04 barclayadam

Very, very nasty SQL, but actually not that rough to fix most likely. I'll try to take a look at this today

jeremydmiller avatar Apr 08 '22 10:04 jeremydmiller

@jeremydmiller Many thanks. It's not ideal what I'm doing here, granted (I will look at improving :)), but this did indeed use to work in v3.

barclayadam avatar Apr 08 '22 11:04 barclayadam

This one's a little bigger than I feared. And it impacts several other cases like DeleteWhere(). Sorry to do this, but this might get kicked back yet again.

jeremydmiller avatar May 21 '22 21:05 jeremydmiller

FINALLY.

jeremydmiller avatar May 02 '23 17:05 jeremydmiller

it's done

oskardudycz avatar May 04 '23 13:05 oskardudycz