Re: PL/pgSQL examples NOT involving functions

From: "Josh Berkus" <josh(at)agliodbs(dot)com>
To: Roland Roberts <roland(at)astrofoto(dot)org>, pgsql-sql(at)postgresql(dot)org
Subject: Re: PL/pgSQL examples NOT involving functions
Date: 2001-11-16 00:19:23
Message-ID: web-507249@davinci.ethosmedia.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs pgsql-sql

Roland,

> Hmm, there were some complaints recently on the hackers list about
> things being posted on only one list. And a significant chunk of the
> mail I am getting from lists shows it was posted to more than one
> list.

Yeah, and you'll notice me saying "please don't cross-post" a lot.
Basically I'm trying to encourage people to NOT cross-post because we
end up with a lot of questions being answered 2 and 3 times on different
lists. It's really not fair to the people who are trying to be helpful
and answer questions. Hackers is one of the lists I am not subscribed
to (I currently read SQL, NOVICE, PHP and ANNOUNCE).

> So how would I convert an insert to an update when I detect a tuple
> is
> already present in the database? Do I have to write the whole thing
> in Perl/Tcl/whatever and do the conversion there?

Yes. Use the EXECUTE method. Or do it in your middleware. Or
establish a unique index, do both an insert and an update, and ignore
the error messages.

Or ... if you wanna get really tricky ... write some triggers to do the
substitution.

Personally, I find that keeping track, on the client side, of whether
you're adding a new record or editing an old one and acting
appropriately is better than trying to second-guess it on the database
level, but maybe that's just me.

-Josh

______AGLIO DATABASE SOLUTIONS___________________________
Josh Berkus
Complete information technology josh(at)agliodbs(dot)com
and data management solutions (415) 565-7293
for law firms, small businesses fax 621-2533
and non-profit organizations. San Francisco

In response to

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message Tom Lane 2001-11-18 21:29:34 Re: Errors in tutorial
Previous Message Tom Lane 2001-11-15 23:07:28 Cross-posting (was Re: PL/pgSQL examples NOT involving functions)

Browse pgsql-sql by date

  From Date Subject
Next Message Andrew G. Hammond 2001-11-16 06:13:25 Re: Help with INSERT into 2 tables
Previous Message Tom Lane 2001-11-15 23:07:28 Cross-posting (was Re: PL/pgSQL examples NOT involving functions)