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

From: "Daniel Verite" <daniel(at)manitou-mail(dot)org>
To: "Thiemo Kellner, NHC Barhufpflege" <thiemo(dot)kellner(at)gelassene-pferde(dot)biz>
Cc: "pgsql-general" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Dynamic PL/pgSQL select query: value association propblem
Date: 2018-02-16 13:56:30
Message-ID: a2e5e1ab-755d-4854-8c5b-5c5c2b24e5b6@manitou-mail.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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;

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.

Best regards,
--
Daniel Vérité
PostgreSQL-powered mailer: http://www.manitou-mail.org
Twitter: @DanielVerite

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Thiemo Kellner 2018-02-16 14:23:59 Re: Dynamic PL/pgSQL select query: value association propblem
Previous Message Adrian Klaver 2018-02-16 13:54:14 Re: postgres started without auto vaccum