When we use the PostgreSQL database, if a table is not constrained, it is likely that there will be several identical pieces of data, that is, duplicate data. As shown in the following:
So what if we were to delete 2 of them? The first is that we can clear the contents of the table, and then insert the content into the table using the insert into statement. This approach works, but it is not recommended for professionals
The second we can combine with the Ctidin the PG database (which is related to physical storage, which refers to which of the data blocks the record is located above) to delete. Here we still use the SELECT statement to query first.
This allows us to delete duplicate data using a uniquely identified Ctid , and can delete 2 of the data in the tb_5201351 table using the following two ways.
DELETE from WHERE inch ('(0,2)','(0,3)');
The principle of the above method is that we manually enter the data to delete the specified Ctid, if there is more data, we can also use the following statement to delete.
DELETE from WHERE not inch (Selectmin from tb_5201351);
The results of the execution are as follows:
Processing of duplicate data in PostgreSQL database