Received: from verde.onda.com.br (verde.onda.com.br [200.195.192.10]) by mail.postgresql.org (8.11.1/8.11.1) with ESMTP id eA5LfCs68202 for ; Sun, 5 Nov 2000 16:41:13 -0500 (EST) (envelope-from cdallacosta@bigfoot.com) Received: from terrificus (cmcta002p161.onda.com.br [200.195.205.161]) by verde.onda.com.br (8.8.8/8.8.8) with SMTP id TAA20882 for ; Sun, 5 Nov 2000 19:41:00 -0200 (EDT) Message-ID: <003f01c0477a$04717320$02ffa8c0@terrificus> From: "=?iso-8859-1?Q?Crist=F3v=E3o_B._B._Dalla_Costa?=" To: "pgsql-sql" References: Subject: Re: Conditional SQL query Date: Sun, 5 Nov 2000 19:44:53 -0300 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 X-Archive-Number: 200011/37 X-Sequence-Number: 68 > > Now I have one more problem. How do I insert only once if value does not > exist? eg: > You should create a unique index on the appropriate fields. For example: CREATE UNIQUE INDEX indexname ON table (field1, field2) Then the insert will fail if this particular combination of the values of (field1, field2) is already in the table. Be careful if the insert is inside a transaction, tough. If it fails due to non-uniqueness your transaction will be aborted (all further queries ignored untill a COMMIT or ROLLBACK).