pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Suggestion to reduce COPY command output to csv file
4+ messages / 4 participants
[nested] [flat]

* Suggestion to reduce COPY command output to csv file
@ 2020-03-04 18:38  postggen2020 s <postggen2020@gmail.com>
  0 siblings, 3 replies; 4+ messages in thread

From: postggen2020 s @ 2020-03-04 18:38 UTC (permalink / raw)
  To: pgsql-admin@postgresql.org, pgsql-general@postgresql.org, Adrian Klaver <adrian.klaver@aklaver.com>

Hi Team,
Thanks a lot all of you, for providing support peoples like me.
Could you please provide a suggestion on COPY command.

Environment:
DB Version:9.5.15
postgis:
Table contain GIS data.

I have a table with GIS data, its around 300MB and 2Lacks+ records. I want
to export all the records to the CSV file. I can able to export the table
data into a CSV file, but the exported CSV file size around 162MB.
While I am trying to opening the excel it is taking a long time and also
while applying vlookup excel is getting hang.

I am using below command :
\copy cities TO '/var/lib/pgsql/cities.csv' (DELIMITER ',', FORMAT 'csv',
HEADER)

I am trying to achieve the following :
1. The exported CSV file should have within 10MB.
2. The excel file should open quickly and able to perform vlookups without
any problems(like hang).

Could you please provide suggestions on below queries:
1. what I am trying to achieve, is the right assumption?.
2. Can we use this command to use for the above use case?.
3. Is there any tool/extension available for the above use case.?

Your inputs are highly appreciated.

Regards,
Postgadm.

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Suggestion to reduce COPY command output to csv file
@ 2020-03-04 18:46  Adrian Klaver <adrian.klaver@aklaver.com>
  parent: postggen2020 s <postggen2020@gmail.com>
  2 siblings, 0 replies; 4+ messages in thread

From: Adrian Klaver @ 2020-03-04 18:46 UTC (permalink / raw)
  To: postggen2020 s <postggen2020@gmail.com>; pgsql-admin; pgsql-general@postgresql.org

On 3/4/20 10:38 AM, postggen2020 s wrote:
> Hi Team,
> Thanks a lot all of you, for providing support peoples like me.
> Could you please provide a suggestion on COPY command.
> 
> Environment:
> DB Version:9.5.15
> postgis:
> Table contain GIS data.
> I have a table with GIS data, its around 300MB and 2Lacks+ records. I 
> want to export all the records to the CSV file. I can able to export the 
> table data into a CSV file, but the exported CSV file size around 162MB.
> While I am trying to opening the excel it is taking a long time and also 
> while applying vlookup excel is getting hang.
> I am using below command :
> \copy cities TO '/var/lib/pgsql/cities.csv' (DELIMITER ',', FORMAT 
> 'csv', HEADER)
> I am trying to achieve the following :
> 1. The exported CSV file should have within 10MB.

You can select less then the entire table with a query:

https://www.postgresql.org/docs/9.5/sql-copy.html

query

     A SELECT or VALUES command whose results are to be copied. Note 
that parentheses are required around the query.


> 2. The excel file should open quickly and able to perform vlookups 
> without any problems(like hang).

That is something you will need to take up with MS.

> Could you please provide suggestions on below queries:
> 1. what I am trying to achieve, is the right assumption?.
> 2. Can we use this command to use for the above use case?.
> 3. Is there any tool/extension available for the above use case.?

The MS Office data tools for pulling directly from database into 
spreadsheet via ODBC.

Do you use a programming language?
If so use its libraries to pull data out and into CSV or directly into a 
spreadsheet.


> Your inputs are highly appreciated.
> Regards,
> Postgadm.


-- 
Adrian Klaver
adrian.klaver@aklaver.com





^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Suggestion to reduce COPY command output to csv file
@ 2020-03-04 21:40  David G. Johnston <david.g.johnston@gmail.com>
  parent: postggen2020 s <postggen2020@gmail.com>
  2 siblings, 0 replies; 4+ messages in thread

From: David G. Johnston @ 2020-03-04 21:40 UTC (permalink / raw)
  To: postggen2020 s <postggen2020@gmail.com>; +Cc: pgsql-admin; pgsql-general <pgsql-general@postgresql.org>; Adrian Klaver <adrian.klaver@aklaver.com>

On Wed, Mar 4, 2020 at 11:39 AM postggen2020 s <postggen2020@gmail.com>
wrote:

> Hi Team,
> Thanks a lot all of you, for providing support peoples like me.
> Could you please provide a suggestion on COPY command.
>
> Environment:
> DB Version:9.5.15
> postgis:
> Table contain GIS data.
>
> I have a table with GIS data, its around 300MB and 2Lacks+ records. I want
> to export all the records to the CSV file. I can able to export the table
> data into a CSV file, but the exported CSV file size around 162MB.
> While I am trying to opening the excel it is taking a long time and also
> while applying vlookup excel is getting hang.
>
> I am using below command :
> \copy cities TO '/var/lib/pgsql/cities.csv' (DELIMITER ',', FORMAT 'csv',
> HEADER)
>
> I am trying to achieve the following :
> 1. The exported CSV file should have within 10MB.
>

Then you probably need to redefine your problem and solution.


> 2. The excel file should open quickly and able to perform vlookups without
> any problems(like hang).
>

See #1


>
> Could you please provide suggestions on below queries:
> 1. what I am trying to achieve, is the right assumption?.
>

Not really...


> 2. Can we use this command to use for the above use case?.
>

Not without changing your approach to the problem...in which case \copy may
or may not be a useful tool

3. Is there any tool/extension available for the above use case.?
>

Not sure on an additive suggestion but you probably can get considerable
mileage by removing Excel from the equation and bring the external data
into PostgreSQL and use joins (i.e., SQL's version of VLOOKUP).

David J.

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Suggestion to reduce COPY command output to csv file
@ 2020-03-05 07:22  Bo Victor Thomsen <bo.victor.thomsen@gmail.com>
  parent: postggen2020 s <postggen2020@gmail.com>
  2 siblings, 0 replies; 4+ messages in thread

From: Bo Victor Thomsen @ 2020-03-05 07:22 UTC (permalink / raw)
  To: pgsql-admin@lists.postgresql.org

You can use this alternative:

/\copy (SELECT col1, col2, col3... from cities) TO 
'/var/lib/pgsql/cities.csv' (DELIMITER ',', FORMAT 'csv', HEADER)/

The list /col1, col2, col3.../ should only contain names on*necessary* 
columns and not under any circumstances  the geometry column


-- 
Med venlig hilsen / Kind regards

Bo Victor Thomsen



Den 04-03-2020 kl. 19:38 skrev postggen2020 s:
> \copy cities TO '/var/lib/pgsql/cities.csv' (DELIMITER ',', FORMAT 
> 'csv', HEADER)

^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2020-03-05 07:22 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-03-04 18:38 Suggestion to reduce COPY command output to csv file postggen2020 s <postggen2020@gmail.com>
2020-03-04 18:46 ` Adrian Klaver <adrian.klaver@aklaver.com>
2020-03-04 21:40 ` David G. Johnston <david.g.johnston@gmail.com>
2020-03-05 07:22 ` Bo Victor Thomsen <bo.victor.thomsen@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox