Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1j9TsQ-0002H1-2a for pgsql-general@arkaria.postgresql.org; Wed, 04 Mar 2020 13:15:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j9TsO-0003K2-Ph for pgsql-general@arkaria.postgresql.org; Wed, 04 Mar 2020 13:15:52 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1j9TsO-0003Jv-CY for pgsql-general@lists.postgresql.org; Wed, 04 Mar 2020 13:15:52 +0000 Received: from mailbackend.panix.com ([166.84.1.89]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1j9TsM-00035U-1b for pgsql-general@lists.postgresql.org; Wed, 04 Mar 2020 13:15:51 +0000 Received: from panix5.panix.com (panix5.panix.com [166.84.1.5]) by mailbackend.panix.com (Postfix) with ESMTP id 48XZBY183cz1Nt9 for ; Wed, 4 Mar 2020 08:15:49 -0500 (EST) Received: by panix5.panix.com (Postfix, from userid 17622) id 48XZBX6mWJzfYm; Wed, 4 Mar 2020 08:15:48 -0500 (EST) Date: Wed, 4 Mar 2020 08:15:48 -0500 From: stan To: pgsql-general@lists.postgresql.org Subject: Re: Calling a function from a rule? Message-ID: <20200304131548.GA14715@panix.com> References: <20200304130506.GA10957@panix.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200304130506.GA10957@panix.com> X-Editor: gVim List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Wed, Mar 04, 2020 at 08:05:06AM -0500, stan wrote: > I am missing something about how to properly create a rule. > > Thanks to the helpful folks on this list, I am looking a creating some > update able views. So, looks like I need to create a rule and a function > for this. Here is what I am trying as a test. > > > > DROP TRIGGER v_trig_test ON test; > > CREATE OR REPLACE FUNCTION v_trig_test() RETURNS trigger AS $$ > use 5.010; > use strict; > use warnings; > use Data::Dumper qw(Dumper); > > my $new = Dumper $_TD->{new}; > my $old = Dumper $_TD->{old}; > > elog(NOTICE, "old = $old" ); > elog(NOTICE, "new = $new" ); > > return; > > $$ LANGUAGE plperlu; > > > CREATE RULE "_RETURN" AS > ON UPDATE TO purchase_view > DO INSTEAD > SELECT * FROM v_trig_test; > > > But the select line in the create rule seems to be a syntax error. > > Here is my thinking. I have done functions called from triggers, and I am > modeling this after that experience, so I think I need the rule to call the > function, correct? Looks like the issue has to do with defining the return type of the function. I corrected the SELECT in the rule to: SELECT * FROM v_trig_test() Whihc got me as far as a complaint about the return type of the function, so now the parser understands that I am trying to call a function. What should my function return? -- "They that would give up essential liberty for temporary safety deserve neither liberty nor safety." -- Benjamin Franklin