very basic SQL question

From: Dan Kortschak <dan(dot)kortschak(at)adelaide(dot)edu(dot)au>
To: pgsql-general(at)postgresql(dot)org
Subject: very basic SQL question
Date: 2010-11-23 03:39:19
Message-ID: 1290483559.21375.10.camel@zoidberg.mbs.adelaide.edu.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jayadevan M 2010-11-23 03:42:15 Re: gap between error and cure
Previous Message David Frankson 2010-11-23 00:40:48 Extending COALESCE()