pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feed"Copy from" omit source columns?
3+ messages / 3 participants
[nested] [flat]
* "Copy from" omit source columns?
@ 2006-11-21 19:13 Steve Midgley <public@misuse.org>
2006-11-21 22:38 ` Re: "Copy from" omit source columns? Richard Broersma Jr <rabroersma@yahoo.com>
2006-11-21 23:42 ` Re: "Copy from" omit source columns? Aaron Bono <postgresql@aranya.com>
0 siblings, 2 replies; 3+ messages in thread
From: Steve Midgley @ 2006-11-21 19:13 UTC (permalink / raw)
To: pgsql-sql
Hello,
(I already fear the answer to my question is "no..") :)
I am using the 'COPY FROM' SQL command (not psql \copy) to move data
into a table from a CSV file. The source data are suitable for import
EXCEPT there are extraneous columns of data in the source file. In
essence, my table schema is:
id, col1, col2, col4
My source file schema is:
col1,col2,col3,col4
I'm curious if there is any way to tell "COPY" to ignore the third
column of data? Basically I'd like to write something along the lines
of:
copy import (col1,col2,\n,col4)
from 'c:/dev/import/source/test.csv'
with CSV HEADER
Note "\n" would indicate there there is a column in the source that
should simply be ignored during the import. Of course, I tried this
syntax and it didn't work. Perhaps there is another way of indicating
that there is a "null column" in the source file that should be skipped
during import?
Any assistance in solving this problem (without having to change the
source file) would be greatly appreciated. If I have to change the
source file, I will, but it would greatly simplify things if I didn't
have to..
Best regards and thanks for any ideas,
Steve
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: "Copy from" omit source columns?
2006-11-21 19:13 "Copy from" omit source columns? Steve Midgley <public@misuse.org>
@ 2006-11-21 22:38 ` Richard Broersma Jr <rabroersma@yahoo.com>
1 sibling, 0 replies; 3+ messages in thread
From: Richard Broersma Jr @ 2006-11-21 22:38 UTC (permalink / raw)
To: Steve Midgley <public@misuse.org>; pgsql-sql
> (I already fear the answer to my question is "no..") :)
> I am using the 'COPY FROM' SQL command (not psql \copy) to move data
> into a table from a CSV file. The source data are suitable for import
> EXCEPT there are extraneous columns of data in the source file. In
> essence, my table schema is:
> id, col1, col2, col4
> My source file schema is:
> col1,col2,col3,col4
> I'm curious if there is any way to tell "COPY" to ignore the third
> column of data? Basically I'd like to write something along the lines
> of:
> copy import (col1,col2,\n,col4)
> from 'c:/dev/import/source/test.csv'
> with CSV HEADER
> Note "\n" would indicate there there is a column in the source that
> should simply be ignored during the import. Of course, I tried this
> syntax and it didn't work. Perhaps there is another way of indicating
> that there is a "null column" in the source file that should be skipped
> during import?
> Any assistance in solving this problem (without having to change the
> source file) would be greatly appreciated. If I have to change the
> source file, I will, but it would greatly simplify things if I didn't
> have to..
I am not to familiar with using copy, so I do not know the eligant solution that you are looking
for. But the brute-force method would be to:
1) push all your data into a temp table
2) validate it
3) push the data of enterest into the destination table.
Regards,
Richard Broersma Jr.
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: "Copy from" omit source columns?
2006-11-21 19:13 "Copy from" omit source columns? Steve Midgley <public@misuse.org>
@ 2006-11-21 23:42 ` Aaron Bono <postgresql@aranya.com>
1 sibling, 0 replies; 3+ messages in thread
From: Aaron Bono @ 2006-11-21 23:42 UTC (permalink / raw)
To: Steve Midgley <public@misuse.org>; +Cc: pgsql-sql
On 11/21/06, Steve Midgley <public@misuse.org> wrote:
>
> Hello,
>
> (I already fear the answer to my question is "no..") :)
>
> I am using the 'COPY FROM' SQL command (not psql \copy) to move data
> into a table from a CSV file. The source data are suitable for import
> EXCEPT there are extraneous columns of data in the source file. In
> essence, my table schema is:
>
> id, col1, col2, col4
>
> My source file schema is:
>
> col1,col2,col3,col4
>
> I'm curious if there is any way to tell "COPY" to ignore the third
> column of data? Basically I'd like to write something along the lines
> of:
>
> copy import (col1,col2,\n,col4)
> from 'c:/dev/import/source/test.csv'
> with CSV HEADER
>
> Note "\n" would indicate there there is a column in the source that
> should simply be ignored during the import. Of course, I tried this
> syntax and it didn't work. Perhaps there is another way of indicating
> that there is a "null column" in the source file that should be skipped
> during import?
>
> Any assistance in solving this problem (without having to change the
> source file) would be greatly appreciated. If I have to change the
> source file, I will, but it would greatly simplify things if I didn't
> have to..
>
> Best regards and thanks for any ideas,
>
If you are using Linux/Unix or a Mac, you could run the file through sed
first and remove the unwanted column:
cat original.csv | sed 's/^\(.*\),\(.*\),\(.*\),\(.*\)$/\1,\2,\4/' > new.csv
Of course if you have commas in the data you will have to play with the sed
command a little but this will get you started.
--
==================================================================
Aaron Bono
Aranya Software Technologies, Inc.
http://www.aranya.com
http://codeelixir.com
==================================================================
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2006-11-21 23:42 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-11-21 19:13 "Copy from" omit source columns? Steve Midgley <public@misuse.org>
2006-11-21 22:38 ` Richard Broersma Jr <rabroersma@yahoo.com>
2006-11-21 23:42 ` Aaron Bono <postgresql@aranya.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