Re: Removing duplicate rows in table

2024-09-12 Thread Rich Shepard
On Thu, 12 Sep 2024, Muhammad Usman Khan wrote: You can try the following CTE which removes all the identical rows and only leave single row Thank you, Muhammed. Rich

Re: Removing duplicate rows in table

2024-09-10 Thread Erik Wienhold
On 2024-09-10 18:38 +0200, Rich Shepard wrote: > P.S. Please reply to the mail list so I receive only one copy of your > message, not two. You can configure your list subscription to not receive an extra copy. That setting is under "Global configuration" on https://lists.postgresql.org/manage/. -

Re: Removing duplicate rows in table

2024-09-10 Thread Rich Shepard
On Tue, 10 Sep 2024, Rich Shepard wrote: to see how big a problem it is. If it is only a few projects it could just a matter of manually deleting the extras. Not knowing how to do that is why I wrote. A web search (which I should have done before posting this thread) shows me how to do this

Re: Removing duplicate rows in table

2024-09-10 Thread Rich Shepard
On Tue, 10 Sep 2024, Adrian Klaver wrote: You might want to do something like: select proj_nbr, count(*) as ct from projects group by proj_nbr; to see how big a problem it is. If it is only a few projects it could just a matter of manually deleting the extras. Adrian, It's a small table, n

Re: Removing duplicate rows in table

2024-09-10 Thread Adrian Klaver
On 9/10/24 08:29, Rich Shepard wrote: On Tue, 10 Sep 2024, Adrian Klaver wrote: Is there a Primary Key or Unique index on this table? Adrian, No. It didn't occur to me to make the project number a PK as this table is not related to others in the database. But, yesterday it occurred to me to

Re: Removing duplicate rows in table

2024-09-10 Thread Rich Shepard
On Tue, 10 Sep 2024, Andreas Kretschmer wrote: you can use the hidden ctid-column: postgres=# create table demo (id int, val text); CREATE TABLE postgres=# insert into demo values (1, 'test1'); INSERT 0 1 postgres=# insert into demo values (1, 'test1'); INSERT 0 1 postgres=# insert into demo va

Re: Removing duplicate rows in table

2024-09-10 Thread Rich Shepard
On Tue, 10 Sep 2024, Christophe Pettus wrote: If you don't mind taking the time to swap tables, you can always do an INSERT ... SELECT DISTINCT into a new table, and then swap it with the existing table. Christophe, I'll make the proj_nbr table the PK then do as you recommend. Thank you, R

Re: Removing duplicate rows in table

2024-09-10 Thread Rich Shepard
On Tue, 10 Sep 2024, Francisco Olarte wrote: Do you have any kid of corruption (i.e, unique index violation) or is it just a duplicate problem? Francisco, Only a duplicate problem because when I created this table I didn't make the proj_nbr column a PK. Also, if you do not have any uniquene

Re: Removing duplicate rows in table

2024-09-10 Thread Rich Shepard
On Tue, 10 Sep 2024, Adrian Klaver wrote: Is there a Primary Key or Unique index on this table? Adrian, No. It didn't occur to me to make the project number a PK as this table is not related to others in the database. But, yesterday it occurred to me to make the proj_nbr a PK to eliminate fu

Re: Removing duplicate rows in table

2024-09-10 Thread Andreas Kretschmer
Am 10.09.24 um 17:07 schrieb Rich Shepard: I've no idea how I entered multiple, identical rows in a table but I want to delete all but one of these rows. Here's an example: bustrac=# select * from projects where proj_nbr = '4242.01';  proj_nbr |   proj_name    | start_date |  end_date  | de

Re: Removing duplicate rows in table

2024-09-10 Thread Adrian Klaver
On 9/10/24 08:07, Rich Shepard wrote: I've no idea how I entered multiple, identical rows in a table but I want to delete all but one of these rows. Is there a Primary Key or Unique index on this table? Here's an example: bustrac=# select * from projects where proj_nbr = '4242.01';  proj_

Removing duplicate rows in table

2024-09-10 Thread Rich Shepard
I've no idea how I entered multiple, identical rows in a table but I want to delete all but one of these rows. Here's an example: bustrac=# select * from projects where proj_nbr = '4242.01'; proj_nbr | proj_name| start_date | end_date | description | notes --+