pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: stan <stanb@panix.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Calling a function from a rule?
Date: Wed, 4 Mar 2020 08:15:48 -0500
Message-ID: <20200304131548.GA14715@panix.com> (raw)
In-Reply-To: <20200304130506.GA10957@panix.com>
References: <20200304130506.GA10957@panix.com>

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





view thread (4+ messages)  latest in thread

Message-ID: <20200304131548.GA14715@panix.com>
Permalink:  ../20200304131548.GA14715@panix.com/
Also on:    postgresql.org/message-id/20200304131548.GA14715@panix.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: stanb@panix.com
  Subject: Re: Calling a function from a rule?
  In-Reply-To: <20200304131548.GA14715@panix.com>
  References: <20200304130506.GA10957@panix.com> <20200304131548.GA14715@panix.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox