dbTalk Databases Forums  

[SQL] Help needed in skipping column for copy command

mailing.database.pgsql-sql mailing.database.pgsql-sql


Discuss [SQL] Help needed in skipping column for copy command in the mailing.database.pgsql-sql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Amar Dhole
 
Posts: n/a

Default [SQL] Help needed in skipping column for copy command - 01-17-2011 , 07:59 AM






I have table created as follows





CREATE TABLE D_2147483927_2147484848_TAB(

CP VARCHAR(256) ,

CPR VARCHAR(256) ,

CHOUSENO VARCHAR(256) ,

CSTREET VARCHAR(256) ,

CLOCALITY VARCHAR(256) ,

CCITY VARCHAR(256) ,

CPROVINCE VARCHAR(256) ,

CCOUNTRY VARCHAR(256) ,

CZIP VARCHAR(256) ,

CCO VARCHAR(256) )



I am using copy command to copy the content of file into the table.
(one.txt)



PR,PRO,HOUSENO,STREET,LOCALITY,CITY,PROVINCE,COUNT RY,ZIP,CON

,,A-24 Siddi vihar apt.,Near Krishna Chowk,New
Sanghvi,Pune,MH,India,411027





In the above data, data for last column is missing.





copy D_2147483927_2147484848_TAB from 'D:/work/one.txt' with delimiter
as ',' quote '"' csv HEADER ;





I get the following error as



ERROR: missing data for column "ccontains"

CONTEXT: COPY d_2147483927_2147484848_tab, line 2: "q,q,A-24 Siddi
vihar apt.,

Near Krishna Chowk,New Sanghvi,Pune,MH,India,411027 "



Can any one please tell me how can I make copy command to ignore the
data missing column ? as the data in file is unknown so it column name
is which is missing is not known in advance.



Thanks

Amar

Reply With Quote
  #2  
Old   
Adrian Klaver
 
Posts: n/a

Default Re: [SQL] Help needed in skipping column for copy command - 01-17-2011 , 02:46 PM






On 01/17/2011 05:59 AM, Amar Dhole wrote:
Quote:
I have table created as follows

CREATE TABLE D_2147483927_2147484848_TAB(

CP VARCHAR(256) ,

CPR VARCHAR(256) ,

CHOUSENO VARCHAR(256) ,

CSTREET VARCHAR(256) ,

CLOCALITY VARCHAR(256) ,

CCITY VARCHAR(256) ,

CPROVINCE VARCHAR(256) ,

CCOUNTRY VARCHAR(256) ,

CZIP VARCHAR(256) ,

CCO VARCHAR(256) )

I am using copy command to copy the content of file into the table.
(one.txt)

PR,PRO,HOUSENO,STREET,LOCALITY,CITY,PROVINCE,COUNT RY,ZIP,CON

,,A-24 Siddi vihar apt.,Near Krishna Chowk,New Sanghvi,Pune,MH,India,411027

In the above data, data for last column is missing.
Looks like two columns missing. I see 10 headers and 8 data values
unless that is a cut and paste issue.

Quote:
copy D_2147483927_2147484848_TAB from 'D:/work/one.txt' with delimiter
as ',' quote '"' csv HEADER ;

I get the following error as

ERROR: missing data for column "ccontains"
Where does ccontains from? I am not seeing it in the table or the text file.

Quote:
CONTEXT: COPY d_2147483927_2147484848_tab, line 2: "q,q,A-24 Siddi vihar
apt.,

Near Krishna Chowk,New Sanghvi,Pune,MH,India,411027 "

Can any one please tell me how can I make copy command to ignore the
data missing column ? as the data in file is unknown so it column name
is which is missing is not known in advance.
You can specify a column list to COPY. See here:
http://www.postgresql.org/docs/9.0/i.../sql-copy.html

Quote:
Thanks

Amar


--
Adrian Klaver
adrian.klaver (AT) gmail (DOT) com

--
Sent via pgsql-sql mailing list (pgsql-sql (AT) postgresql (DOT) org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql

Reply With Quote
  #3  
Old   
Russell Galyon
 
Posts: n/a

Default Re: [SQL] Help needed in skipping column for copy command - 01-17-2011 , 03:14 PM



COPY D_2147483927_2147484848_TAB
(
CP
, CPR
, CHOUSENO
, CSTREET
, CLOCALITY
, CCITY
, CPROVINCE
, CCOUNTRY
, CZIP
)
FROM 'one.txt'
WITH DELIMITER ',' QUOTE '"' csv HEADER;



On Mon, Jan 17, 2011 at 7:59 AM, Amar Dhole <adhole (AT) tibco (DOT) com> wrote:

Quote:
I have table created as follows





CREATE TABLE D_2147483927_2147484848_TAB(

CP VARCHAR(256) ,

CPR VARCHAR(256) ,

CHOUSENO VARCHAR(256) ,

CSTREET VARCHAR(256) ,

CLOCALITY VARCHAR(256) ,

CCITY VARCHAR(256) ,

CPROVINCE VARCHAR(256) ,

CCOUNTRY VARCHAR(256) ,

CZIP VARCHAR(256) ,

CCO VARCHAR(256) )



I am using copy command to copy the content of file into the table.
(one.txt)



PR,PRO,HOUSENO,STREET,LOCALITY,CITY,PROVINCE,COUNT RY,ZIP,CON

,,A-24 Siddi vihar apt.,Near Krishna Chowk,New Sanghvi,Pune,MH,India,411027





In the above data, data for last column is missing.





copy D_2147483927_2147484848_TAB from 'D:/work/one.txt' with delimiter as
',' quote '"' csv HEADER ;





I get the following error as



ERROR: missing data for column "ccontains"

CONTEXT: COPY d_2147483927_2147484848_tab, line 2: "q,q,A-24 Siddi vihar
apt.,

Near Krishna Chowk,New Sanghvi,Pune,MH,India,411027 "



Can any one please tell me how can I make copy command to ignore the data
missing column ? as the data in file is unknown so it column name is which
is missing is not known in advance.



Thanks

Amar



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.