very basic SQL question - Mailing list pgsql-general

From Dan Kortschak
Subject very basic SQL question
Date
Msg-id 1290483559.21375.10.camel@zoidberg.mbs.adelaide.edu.au
Whole thread Raw
Responses Re: very basic SQL question  (Sam Mason <sam@samason.me.uk>)
Re: very basic SQL question  (Matthieu Huin <matthieu.huin@wallix.com>)
List pgsql-general
Hi,

I'm using Pg for bioinformatic work and I want to be able to insert,
uniquely, biological sequences into a table returning the sequence id -
this part is fine. However, if the sequence already exists in the table
I want to return to id.

At the moment it seems to me that I should do a

SELECT id FROM table WHERE seq = '<sequence>';

and if that gives NULL then

INSERT .... RETURNING id;

But this seems long winded. Is there a better way to achieve what I
want?

thanks


pgsql-general by date:

Previous
From: David Frankson
Date:
Subject: Extending COALESCE()
Next
From: Jayadevan M
Date:
Subject: Re: gap between error and cure