Re: INSERT WHERE NOT EXISTS

From: Karsten Hilbert <Karsten(dot)Hilbert(at)gmx(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: INSERT WHERE NOT EXISTS
Date: 2003-06-25 21:51:26
Message-ID: 20030625235126.A25840@hermes.hilbert.loc
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> // check if entry already exists
> SELECT COUNT(*) FROM tablename WHERE [cond]
You may want to try this instead:

select exists(select * from tablename where [cond])

which should be faster than count(*). You'll get back a
boolean value, though, not an integer.

Karsten
--
GPG key ID E4071346 @ wwwkeys.pgp.net
E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Claudio Lapidus 2003-06-25 22:38:51 Vacuum (table performance)
Previous Message Bruce Momjian 2003-06-25 21:40:47 Re: [GENERAL] capturing and storing query statement with