Re: how to make duplicate finding query faster? - Mailing list pgsql-admin

From Scott Ribe
Subject Re: how to make duplicate finding query faster?
Date
Msg-id FEEE2DC4-B506-4B34-80FE-07FCC0ADC61E@elevated-dev.com
Whole thread Raw
In response to how to make duplicate finding query faster?  (Sachin Kumar <sachinkumaras@gmail.com>)
Responses Re: how to make duplicate finding query faster?  (Sachin Kumar <sachinkumaras@gmail.com>)
List pgsql-admin
> On Dec 30, 2020, at 12:36 AM, Sachin Kumar <sachinkumaras@gmail.com> wrote:
>
> Hi All,
>
> I am uploading data into PostgreSQL using the CSV file and checking if there is any duplicates value in DB it should
returna duplicate error.  I am using below mention query. 
>
> if Card_Bank.objects.filter( Q(ACCOUNT_NUMBER=card_number) ).exists():
>         flag=2
>       else:
>         flag=1
> it is taking too much time i am using 600k cards in CSV.
>
> Kindly help me in making the query faster.
>
> I am using Python, Django & PostgreSQL.
> --
>
> Best Regards,
> Sachin Kumar

Are you checking one-by-one because your goal is not to fail the whole upload that contains the duplicates, but rather
toskip only the duplicates? 

If that's the case, I think you'd be better off copying the CSV straight into a temp table, using a join to delete
duplicatesfrom it, then insert the remainder into the target table, and finally drop the temp table. 


pgsql-admin by date:

Previous
From: "Gavan Schneider"
Date:
Subject: Re: how to make duplicate finding query faster?
Next
From: Sachin Kumar
Date:
Subject: Re: how to make duplicate finding query faster?