From: | Lincoln Yeoh <lylyeoh(at)mecomb(dot)com> |
---|---|
To: | pgsql-general(at)postgreSQL(dot)org |
Subject: | Re: [GENERAL] locking/insert into table and transactions |
Date: | 1999-11-26 09:04:09 |
Message-ID: | 3.0.5.32.19991126170409.00841b20@pop.mecomb.po.my |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general pgsql-hackers |
Hi,
I'd like to prevent duplicate ids from being inserted into a table. I can
let the database enforce it by using UNIQUE or PRIMARY KEY. But assuming I
prefer to catch such things with the application, what would be the best
way of doing it?
The only way I figured to do it was to use:
begin;
lock table accounts;
select count(*) from accounts where id=$number;
if count=0, insert into accounts (id,etc) values ($number,$etc)
commit;
Is this a good idea? Or is it much better and faster to let the database
catch things?
Is it faster to use "select count(*) from accounts" or "select id from
accounts"?
Apparently count(*) has some speed optimizations in MySQL. So wondering if
there are similar things in Postgres.
Thanks,
Link.
From | Date | Subject | |
---|---|---|---|
Next Message | Silvio Macedo | 1999-11-26 09:28:59 | Re: [GENERAL] Postgres on Ultrasparc |
Previous Message | Oleg Broytmann | 1999-11-26 08:46:12 | Re: [GENERAL] Postgres on Ultrasparc |
From | Date | Subject | |
---|---|---|---|
Next Message | Zeugswetter Andreas SEV | 1999-11-26 09:38:15 | AW: [HACKERS] Re: [GENERAL] drop/rename table and transactions |
Previous Message | Adriaan Joubert | 1999-11-26 07:12:09 | Re: [HACKERS] Re: [GENERAL] Update of bitmask type |