Re: Instead trigger on a view to update base tables ?

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: "Day, David" <dday(at)redcom(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Instead trigger on a view to update base tables ?
Date: 2018-08-07 19:16:49
Message-ID: CAKFQuwZQzWZkGZ0=1kFVPjG=n4JEb5KD4a9chyXsFndFCYA2Dw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Aug 7, 2018 at 12:09 PM, Day, David <dday(at)redcom(dot)com> wrote:

> EXECUTE format(' UPDATE admin.user SET (%I) = ( SELECT %I FROM $1 ) WHERE
> id = $2)', USER_SETTING, USER_SETTING )
> USING NEW, NEW.id;
>
> When this executes my exception handler generates "err syntax error at or
> near \"$1\"
>

The value after FROM must be an identifier and so cannot be parameterized.
You have to use "%I" for that dynamic element as well - only $2 (which
becomes $1) is valid to parameterize (though you could just do "%L" and
drop the USING clause on the EXECUTE...)

David J.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Marcelo Lacerda 2018-08-07 19:17:18 check_function_bodies not doing much
Previous Message Day, David 2018-08-07 19:09:03 Instead trigger on a view to update base tables ?