pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedPrimary Key Bugs
2+ messages / 2 participants
[nested] [flat]
* Primary Key Bugs
@ 1999-04-25 17:59 Tim Perdue <perdue@raccoon.com>
1999-04-26 12:44 ` Re: [SQL] Primary Key Bugs José Soares <jose@sferacarta.com>
0 siblings, 1 reply; 2+ messages in thread
From: Tim Perdue @ 1999-04-25 17:59 UTC (permalink / raw)
To: pgsql-sql@hub.org
Somehow I have records in my database with duplicate primary keys. Because
of this, I'm not able to update a lot of records, because Postgres then
complains that I'm trying to insert a duplicate primary key.
Can anyone suggest a way to select the duplicate ids out of the table so I
can change them?
I can't really do a SELECT DISTINCT on a 3GB database table or my machine
would likely go down.
Basically, I just want a query like this:
select * into tbl_tmp from tbl_mail where mailid is duplicated
8-)
Any suggestions?
Tim Perdue
PHPBuilder.com / GotoCity.com / Geocrawler.com
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: [SQL] Primary Key Bugs
1999-04-25 17:59 Primary Key Bugs Tim Perdue <perdue@raccoon.com>
@ 1999-04-26 12:44 ` José Soares <jose@sferacarta.com>
0 siblings, 0 replies; 2+ messages in thread
From: José Soares @ 1999-04-26 12:44 UTC (permalink / raw)
To: Tim Perdue <perdue@raccoon.com>; +Cc: pgsql-sql@hub.org
Tim Perdue ha scritto:
> Somehow I have records in my database with duplicate primary keys. Because
> of this, I'm not able to update a lot of records, because Postgres then
> complains that I'm trying to insert a duplicate primary key.
>
> Can anyone suggest a way to select the duplicate ids out of the table so I
> can change them?
>
> I can't really do a SELECT DISTINCT on a 3GB database table or my machine
> would likely go down.
>
> Basically, I just want a query like this:
>
> select * into tbl_tmp from tbl_mail where mailid is duplicated
>
> 8-)
>
> Any suggestions?
>
> Tim Perdue
> PHPBuilder.com / GotoCity.com / Geocrawler.com
The SQL expression to retrieve duplicate rows is:
select * from tbl_mail where mailid in (
select mailid from tbl_mail group by mailid having count(mailid) > 1
);
But currently PostgreSQL have problems with having (see TODO):
* subqueries containing HAVING return incorrect results
Therefore you have to query the tbl_mail in two times.
1) select mailid from tbl_mail group by mailid having count(mailid) > 1
2) select * from tbl_mail where mailid = (replace with values returned at
point 1)
José
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~1999-04-26 12:44 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-04-25 17:59 Primary Key Bugs Tim Perdue <perdue@raccoon.com>
1999-04-26 12:44 ` José Soares <jose@sferacarta.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox