Re: Dynamic PL/pgSQL select query: value association propblem

From: Thiemo Kellner <thiemo(at)gelassene-pferde(dot)biz>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Dynamic PL/pgSQL select query: value association propblem
Date: 2018-02-16 14:23:59
Message-ID: 20180216152359.20611v7hfggvqb2o@www.gelassene-pferde.biz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Zitat von Daniel Verite <daniel(at)manitou-mail(dot)org>:

> Thiemo Kellner, NHC Barhufpflege wrote:
>
>> > Why you don't create query like
>> >
>> > EXECUTE 'SELECT xxx FROM TAB WHERE A = $1.x AND B = $1.y' USING NEW;
>>
>> I shall try. This would be the direct way, but I doubt the placeholder
>> $1 can be a record.
>
> It could be written without refering to any individual column:
>
> IF EXISTS (select 1 from tablename
> where tablename.* is not distinct from NEW)
> THEN
> -- do something
> END IF;

Wow, I shall see if I can apply this pattern to more.

> But since the select cannot see not-yet-committed changes from other
> sessions, such a trigger cannot reliably detect duplicates, unless
> you make sure that there are no concurrent writes to the table.

This is not trigger specific but always a problem of concurrency. If
you let two processes do SCD2 on the same table at the same time on
the same business keys, you will get a messed-up table.

--
+49 (0)1578-772 37 37
+41 (0)78 947 36 21
Öffentlicher PGP-Schlüssel:
http://pgp.mit.edu/pks/lookup?op=get&search=0x8F70EFD2D972CBEF

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Igor Neyman 2018-02-16 14:34:58 RE: Dynamic PL/pgSQL select query: value association propblem
Previous Message Daniel Verite 2018-02-16 13:56:30 Re: Dynamic PL/pgSQL select query: value association propblem