From: Tom Lane <tgl@sss.pgh.pa.us>
To: Ian Cass <ian.cass@mblox.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Help with function optimisation
Date: Wed, 10 Jul 2002 09:34:36 -0400
Message-ID: <16607.1026308076@sss.pgh.pa.us> (raw)
In-Reply-To: <064d01c227f5$a2e06180$6602a8c0@salamander>
References: <064d01c227f5$a2e06180$6602a8c0@salamander>
"Ian Cass" <ian.cass@mblox.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
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: tgl@sss.pgh.pa.us, ian.cass@mblox.com
Subject: Re: Help with function optimisation
In-Reply-To: <16607.1026308076@sss.pgh.pa.us>
* 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