Processing of duplicate data in PostgreSQL database

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.