pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pltcl function -> plpgsql
2+ messages / 2 participants
[nested] [flat]

* pltcl function -> plpgsql
@ 2001-12-28 04:42 guard <guard@ficnet.net>
  2002-01-03 21:01 ` Re: pltcl function -> plpgsql Jan Wieck <janwieck@yahoo.com>
  0 siblings, 1 reply; 2+ messages in thread

From: guard @ 2001-12-28 04:42 UTC (permalink / raw)
  To: pgsql-sql

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

thanks




--






^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: pltcl function -> plpgsql
  2001-12-28 04:42 pltcl function -> plpgsql guard <guard@ficnet.net>
@ 2002-01-03 21:01 ` Jan Wieck <janwieck@yahoo.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Jan Wieck @ 2002-01-03 21:01 UTC (permalink / raw)
  To: guard <guard@ficnet.net>; +Cc: pgsql-sql

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




^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2002-01-03 21:01 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-12-28 04:42 pltcl function -> plpgsql guard <guard@ficnet.net>
2002-01-03 21:01 ` Jan Wieck <janwieck@yahoo.com>

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