Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kiMID-0007gP-29 for pgsql-admin@arkaria.postgresql.org; Thu, 26 Nov 2020 18:46:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kiMI9-0005aQ-W5 for pgsql-admin@arkaria.postgresql.org; Thu, 26 Nov 2020 18:46:53 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kiMI9-0005aJ-Gh for pgsql-admin@lists.postgresql.org; Thu, 26 Nov 2020 18:46:53 +0000 Received: from s65.plako.net ([195.22.20.165] helo=cpanel-web.eurotuxcloud.com) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kiMI1-0002K8-Fl for pgsql-admin@lists.postgresql.org; Thu, 26 Nov 2020 18:46:52 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=diascosta.org; s=default; h=Content-Type:In-Reply-To:MIME-Version:Date: Message-ID:From:References:To:Subject:Sender:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=KivmfU5shysxrvD5b4Vt68gU/uGgORQos6HTPW/xT5I=; b=cvAU3rk3OUElUkp5yCqxGPrTb MdzNDA8tdOCrCx8cwO1TAZbkohSQhinpe5hcNur7XjWJWsU171hUaMEd3SIpcscxOhq2fD3tvYz+V igYmoAsRBzEdwL7ZSsj+Pnm3RgBy9zWvYaNRWaeJW1tNTJqT//zEdlpy68IchN2J2eMjSSuEDigL1 HJ0fgXLAjER3fw7/Sc1Hd2sGRI7AL/OKGsz9gflX72skulgkwqT6CHVGl0GxotCQ5daUSbc053L9J x80ndJF09Ah1bfAw2gjWDmrzQ6VPmpgewZGahWiDG2fPjaR1IEvrgqIEqlFbQ1/gbSr894Go+o0/O mrd92M0Zw==; Received: from a95-92-148-51.cpe.netcabo.pt ([95.92.148.51]:21141 helo=[192.168.0.19]) by cpanel-web.eurotuxcloud.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.91) (envelope-from ) id 1kiMHy-0004fQ-EW for pgsql-admin@lists.postgresql.org; Thu, 26 Nov 2020 18:46:42 +0000 Subject: Re: Conditional query with copy command To: pgsql-admin@lists.postgresql.org References: From: DiasCosta Message-ID: <5155df1c-df47-e11c-4aee-a461171ead65@diascosta.org> Date: Thu, 26 Nov 2020 18:46:42 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------C02779E2804B8158B0C56243" Content-Language: en-GB X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - cpanel-web.eurotuxcloud.com X-AntiAbuse: Original Domain - lists.postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - diascosta.org X-Get-Message-Sender-Via: cpanel-web.eurotuxcloud.com: authenticated_id: diascosta@diascosta.org X-Authenticated-Sender: cpanel-web.eurotuxcloud.com: diascosta@diascosta.org X-Source: X-Source-Args: X-Source-Dir: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------C02779E2804B8158B0C56243 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Hi Sachin Kumar, To resolve a situation similar to yours but with more than 70000000 records in a CSV file for each month in the year (with validation records in public transport), I used the following method: 1 - I created the file_fdw extension and a foreign data wraper 2 - I created a foreign table (FT) with the appropriate structure to support all fields in the CSV file (they can all be of the varchar type). I defined a name for that FT that could be used for all months of the year without needing to change the table definition 3 - I created the import destination table for each month's records with the appropriate column structure. 4 - I created the insertion instruction in the destination table from the selection of the FT, using,  eventually, some restriction clause. I filled in some columns in the target table at the expense of expressions in the select clause of the statement. 5 - Assuming that the structure of the CSV file is the same in each of the following months, I only need to name the source file with the name used in the options of the definition of the destination FT. Dias Costa ------------------------------------------------------------------------------------ On 26-11-2020 10:14, Sachin Kumar wrote: > Thanks Mr. Holger, > > For the Quick reply. We are using Ver 12 and 13 so this query will > work for us. > > One more if you can guide on Archiving old records from PostgreSQL > Table and Retrieving it whenever required. > Any Documentation or example on archiving records. > > On Thu, Nov 26, 2020 at 3:13 PM Holger Jakobs > wrote: > > Hi, > > Use the new syntax as of PostgreSQL 9.0: > > copy hk_card_master_test from > 'C:/inetpub/wwwroot/cards/media/static/gc_card_master2L.csv' > (format csv, header, encoding 'ISO_8859_5') where card_status = 'A' > > This allows a simple WHERE condition as shown. > > > Am 26.11.20 um 09:27 schrieb Sachin Kumar: >> Hi Experts, >> >> I am uploading 10 million data using CSV, but I want to put a >> condition on a column (Card_Status) inside the CSV that only >> where Card_Status = A data should be uploaded rest data are not >> uploaded. >> Please guide me in modifying the query I am using to upload the data >> Query:- >> copy hk_card_master_test from >> 'C:/inetpub/wwwroot/cards/media/static/gc_card_master2L.csv' with >> delimiter ',' csv header encoding 'ISO_8859_5' >> >> -- >> >> Best Regards, >> Sachin Kumar > > -- > Holger Jakobs, Bergisch Gladbach, Tel. +49-178-9759012 > > > > -- > > Best Regards, > Sachin Kumar -- J. M. Dias Costa Telef. 214026948 Se divulgar esta mensagem por terceiros, por favor: 1. Apague o meu endereço de correio electrónico e o meu nome. 2. Apague também os endereços dos seus amigos antes de distribuir. 3. Enderece como cópia oculta (Cc ou Bcc) para os SEUS destinatários. Agindo deste modo, dificultará a disseminação de "vírus", "spams" e "banners" e contribuirá para manter a privacidade de todos e cada um. Obrigado. Nota: Não se deverá ao acaso a ocorrência de palavras na minha escrita que não respeitem o malfadado acordo ortográfico. --------------C02779E2804B8158B0C56243 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit
Hi Sachin Kumar,

To resolve a situation similar to yours but with more than 70000000 records in a CSV file for each month
in the year (with validation records in public transport), I used the following method:
1 - I created the file_fdw extension and a foreign data wraper
2 - I created a foreign table (FT) with the appropriate structure to support all fields in the CSV file (they can all
be of the varchar type). I defined a name for that FT that could be used for all months of the year without
needing to change the table definition
3 - I created the import destination table for each month's records with the appropriate column structure.
4 - I created the insertion instruction in the destination table from the selection of the FT, using,  eventually,
some restriction clause. I filled in some columns in the target table at the expense of expressions in the select
clause of the statement.
5 - Assuming that the structure of the CSV file is the same in each of the following months, I only need to
name the source file with the name used in the options of the definition of the destination FT.

Dias Costa

------------------------------------------------------------------------------------



On 26-11-2020 10:14, Sachin Kumar wrote:
Thanks Mr. Holger,

For the Quick reply. We are using Ver 12 and 13 so this query will work for us.

One more if you can guide on Archiving old records from PostgreSQL Table and Retrieving it whenever required.
Any Documentation or example on archiving records.

On Thu, Nov 26, 2020 at 3:13 PM Holger Jakobs <holger@jakobs.com> wrote:

Hi,

Use the new syntax as of PostgreSQL 9.0:

copy hk_card_master_test from 'C:/inetpub/wwwroot/cards/media/static/gc_card_master2L.csv' (format csv, header, encoding 'ISO_8859_5') where card_status = 'A'

This allows a simple WHERE condition as shown.


Am 26.11.20 um 09:27 schrieb Sachin Kumar:
Hi Experts,

I am uploading 10 million data using CSV, but I want to put a condition on a column (Card_Status) inside the CSV that only where Card_Status = A data should be uploaded rest data are not uploaded.
Please guide me in modifying the query I am using to upload the data
Query:- 
copy hk_card_master_test from 'C:/inetpub/wwwroot/cards/media/static/gc_card_master2L.csv' with delimiter ',' csv header encoding 'ISO_8859_5'

--

Best Regards,
Sachin Kumar
-- 
Holger Jakobs, Bergisch Gladbach, Tel. +49-178-9759012


--

Best Regards,
Sachin Kumar


-- 
J. M. Dias Costa
Telef. 214026948

Se divulgar esta mensagem por terceiros, por favor:
1. Apague o meu endereço de correio electrónico e o meu nome.
2. Apague também os endereços dos seus amigos antes de distribuir.
3. Enderece como cópia oculta (Cc ou Bcc) para os SEUS destinatários.
Agindo deste modo, dificultará a disseminação de "vírus", "spams" e
"banners" e contribuirá para manter a privacidade de todos e cada um.
Obrigado.

Nota: Não se deverá ao acaso a ocorrência de palavras na minha escrita que não respeitem o 
malfadado acordo ortográfico.
--------------C02779E2804B8158B0C56243--