Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fn7M2-0006V7-FF for pgsql-general@arkaria.postgresql.org; Tue, 07 Aug 2018 19:09:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fn7M0-0005v3-9C for pgsql-general@arkaria.postgresql.org; Tue, 07 Aug 2018 19:09:12 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fn7M0-0005uv-14 for pgsql-general@lists.postgresql.org; Tue, 07 Aug 2018 19:09:12 +0000 Received: from smtp1.redcom.com ([192.86.3.143]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fn7Lw-00073k-RS for pgsql-general@postgresql.org; Tue, 07 Aug 2018 19:09:11 +0000 Received: from localhost (localhost [127.0.0.1]) by smtp1.redcom.com (Postfix) with ESMTP id 18AE9A0DF for ; Tue, 7 Aug 2018 15:09:07 -0400 (EDT) X-Virus-Scanned: amavisd-new at redcom.com Received: from smtp1.redcom.com ([127.0.0.1]) by localhost (smtp1.redcom.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id NANHFUVIAOOE for ; Tue, 7 Aug 2018 15:09:05 -0400 (EDT) Received: from pie.redcom.com (pie [192.168.33.15]) by smtp1.redcom.com (Postfix) with ESMTP id 195379F78 for ; Tue, 7 Aug 2018 15:09:05 -0400 (EDT) Received: from exch-02.redcom.com (exch-02.redcom.com [192.168.32.9]) by pie.redcom.com (8.11.7p1+Sun/8.10.2) with ESMTP id w77J94l12843 for ; Tue, 7 Aug 2018 15:09:04 -0400 (EDT) Received: from exch-02.redcom.com (fd00::ccaa:c259:22f8:6f4b) by exch-02.redcom.com (fd00::ccaa:c259:22f8:6f4b) with Microsoft SMTP Server (TLS) id 15.0.1178.4; Tue, 7 Aug 2018 15:09:04 -0400 Received: from exch-02.redcom.com ([fe80::ccaa:c259:22f8:6f4b]) by exch-02.redcom.com ([fe80::ccaa:c259:22f8:6f4b%12]) with mapi id 15.00.1178.000; Tue, 7 Aug 2018 15:09:04 -0400 From: "Day, David" To: "pgsql-general@postgresql.org" Subject: Instead trigger on a view to update base tables ? Thread-Topic: Instead trigger on a view to update base tables ? Thread-Index: AdQueUWekD4i3uV8Qw6A9Q7E0uLpWw== Date: Tue, 7 Aug 2018 19:09:03 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [192.168.84.42] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk In a view of three joined tables, I install a INSTEAD OF trigger fx on = the view. The fx contains a list of felds/columns variable associated to = each base tables. When an update operation occurs, I am successfully generating the target li= st of colums altered on=20 Each base table. ( comparing OLD v NEW ) and attempting some dynamic sql g= eneration in my trigger fx. =20 I am taking the list of modified fields on the view, and attempting an upda= te on appropriate base tables. In this sample case "language_preference" was modified on the view and sho= uld update the admn.user base table EXECUTE format(' UPDATE admin.user SET (%I) =3D ( SELECT %I FROM $1 ) WHER= E id =3D $2)', USER_SETTING, USER_SETTING ) USING NEW, NEW.id; When this executes my exception handler generates "err syntax error at or n= ear \"$1\" The formatted statement on my base table (admin.user ) that is throwing t= his is executing would be: UPDATE admin.user SET (language_preference) =3D ( SELECT language_preferenc= e FROM $1 ) WHERE id =3D $2)" Feel Like Im close but missing something fundamental. I also an update variant UPDATE [ ONLY ] table_name [ * ] [ [ AS ] alias ] SET=20 ( column_name [, ...] ) =3D [ ROW ] ( { expression | DEFAULT } [,= ...] ) Which I thought might be applicable. but still googling for sample impleme= ntation. Thanks for any guidance in this method or better methods to update the base= tables. Regards Dave Day