Re: Instead trigger on a view to update base tables ? - Mailing list pgsql-general

From David G. Johnston
Subject Re: Instead trigger on a view to update base tables ?
Date
Msg-id CAKFQuwZQzWZkGZ0=1kFVPjG=n4JEb5KD4a9chyXsFndFCYA2Dw@mail.gmail.com
Whole thread Raw
In response to Instead trigger on a view to update base tables ?  ("Day, David" <dday@redcom.com>)
List pgsql-general
On Tue, Aug 7, 2018 at 12:09 PM, Day, David <dday@redcom.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.

pgsql-general by date:

Previous
From: "Day, David"
Date:
Subject: Instead trigger on a view to update base tables ?
Next
From: Marcelo Lacerda
Date:
Subject: check_function_bodies not doing much