Re: Help with function optimisation

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Ian Cass" <ian(dot)cass(at)mblox(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Help with function optimisation
Date: 2002-07-10 13:34:36
Message-ID: 16607.1026308076@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"Ian Cass" <ian(dot)cass(at)mblox(dot)com> writes:
> I've got a function that I run as a trigger to update a summary table on
> insert to the main table. As you can see below, it does a select & an INSERT
> if not found, or an UPDATE if found. This currently works OK, but I'd like
> to improve performance by removing the SELECT & attempting an UPDATE. If it
> fails, I'd like to INSERT instead. Can this be done?

Sure. Do the UPDATE, check how many rows updated; if none, INSERT.

Finding out how many rows were updated involves a plpgsql command
"GET DIAGNOSTICS varname = ROW_COUNT" (gotta love these Oracle-derived
syntaxes :-()

regards, tom lane

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2002-07-10 14:09:17 Re: Error with DISTINCT and AS keywords
Previous Message Richard Huxton 2002-07-10 13:31:14 Re: Error with DISTINCT and AS keywords