From: Jan Wieck <janwieck@yahoo.com>
To: guard <guard@ficnet.net>
Cc: pgsql-sql@postgresql.org
Subject: Re: pltcl function -> plpgsql
Date: Thu, 3 Jan 2002 16:01:02 -0500 (EST)
Message-ID: <200201032101.g03L12I16689@saturn.jw.home> (raw)
In-Reply-To: <a0gt6a$1jvr$1@news.tht.net>
guard wrote:
> dear all
>
> I have function >>
> spi_exec "Update $1 set
> adv_amt=adv_amt-$OLD(adv_amt)+$OLD(gadv_amt) where $2=''$OLD($2)'' "
>
> how to change plpgsql code
>
> ps. $1 a variable
It would be nice to see the entire function declaration, or
at least the CREATE FUNCTION part, and not just one single
statement out of it's body.
Second it looks alot like an AFTER UPDATE trigger to me. In
that case, I would suggest changing it into a BEFORE UPDATE
one and do the modification directly in the NEW.adv_amt
field. The way you're doing it now add's one more dead tuple
to the table.
The above is usually achieved in PL/pgSQL with the EXECUTE
syntax. But I would discourage from that and suggest
creating separate functions per table/attribute pair, because
EXECUTE (as well as spi_exec in Tcl) statements are not
cacheable.
Jan
--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck@Yahoo.com #
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
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 using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: janwieck@yahoo.com, guard@ficnet.net
Subject: Re: pltcl function -> plpgsql
In-Reply-To: <200201032101.g03L12I16689@saturn.jw.home>
* 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