pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Holger Jakobs <holger@jakobs.com>
To: pgsql-admin@lists.postgresql.org
Subject: Re: How to use long list of columns with COPY command
Date: Sun, 11 Jun 2023 23:54:15 +0200
Message-ID: <726b10c7-5f27-620a-7fb7-a5ad19cf8bd2@jakobs.com> (raw)
In-Reply-To: <DM4PR19MB597823375C3368B62256F717D357A@DM4PR19MB5978.namprd19.prod.outlook.com>
References: <DM4PR19MB597823375C3368B62256F717D357A@DM4PR19MB5978.namprd19.prod.outlook.com>


Am 11.06.23 um 23:44 schrieb M Sarwar:
> Hello,
> I have some problem while loading the data using COPY command.
>
> *_My environment_*:
> Amazon RDS
> Postgres - Database
> PgAdmin --  with PSQL tool.
> Command -- COPY
>
> I am trying to use COPY command to load the data. Table 
> TEST_GLOBAL_MCM_RAW has 209 columns. In COPY command, I am trying to 
> use around 200 columns to load the data.
> When I try to span COPY command into multiple lines, COPY command is 
> not working. I am forced to use all the command in a single line and 
> which is not legible.
> Do I have any options to make the COPY command legible while using all 
> the columns of any table.
> I have tried \n and this is not working.
>
> It is possible that someone  has faced this situation in the past.
>
> Thank you,
> Sarwar
>
Hi Sarwar,


Page https://www.postgresql.org/docs/15/app-psql.html says:

Another way to obtain the same result as |\copy ... to| is to use the 
SQL |COPY ... TO STDOUT| command and terminate it with |\g /|filename|/| 
or |\g |/|program|/|. Unlike |\copy|, this method allows the command to 
span multiple lines; also, variable interpolation and backquote 
expansion can be used.


So, when loading FROM  a file using \COPY (you were writing about COPY, 
which allows line breaks like all SQL commands), line breaks aren't 
allowed. It's the same for all backslash meta commands of psql.


It seems that you'll have to write the complete \COPY command in one 
line. It's usually quite short, unless you have to name a hell of a lot 
of column names.


Regards,

Holger




-- 
Holger Jakobs, Bergisch Gladbach, Tel. +49-178-9759012



Attachments:

  [application/pgp-signature] OpenPGP_signature (202B, ../726b10c7-5f27-620a-7fb7-a5ad19cf8bd2@jakobs.com/3-OpenPGP_signature)
  download

view thread (9+ messages)  latest in thread

Message-ID: <726b10c7-5f27-620a-7fb7-a5ad19cf8bd2@jakobs.com>
Permalink:  ../726b10c7-5f27-620a-7fb7-a5ad19cf8bd2@jakobs.com/
Also on:    postgresql.org/message-id/726b10c7-5f27-620a-7fb7-a5ad19cf8bd2@jakobs.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-admin@postgresql.org
  Cc: holger@jakobs.com, pgsql-admin@lists.postgresql.org
  Subject: Re: How to use long list of columns with COPY command
  In-Reply-To: <726b10c7-5f27-620a-7fb7-a5ad19cf8bd2@jakobs.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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