COPY, \copy with defaults

Started by CSNover 21 years ago3 messagesgeneral
Jump to latest
#1CSN
cool_screen_name90001@yahoo.com

I guess this is a feature request since I can't figure
out a way to do it directly in postgresql (plus
COPY/\copy isn't in SQL specs). Often when I import
data I need to assign foreign key id's, timestamps,
etc. How about a syntax something like:

\copy tablename (col1, col2, col3, fkid=8,
ts1='2004-8-8') from 'data.csv'

or maybe add a defaults clause after "with":

\copy tablename (col1, col2, col3) from 'data.csv'
with defaults (fkid=8,ts1='2004-8-8')

Or if anybody knows of a better/existing way please
feel free. :)

CSN

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: CSN (#1)
Re: COPY, \copy with defaults

CSN <cool_screen_name90001@yahoo.com> writes:

I guess this is a feature request since I can't figure
out a way to do it directly in postgresql (plus
COPY/\copy isn't in SQL specs).

You do know that COPY uses the column defaults for all columns not
listed in the input list?

regards, tom lane

#3CSN
cool_screen_name90001@yahoo.com
In reply to: Tom Lane (#2)
Re: COPY, \copy with defaults
--- Tom Lane <tgl@sss.pgh.pa.us> wrote:

CSN <cool_screen_name90001@yahoo.com> writes:

I guess this is a feature request since I can't

figure

out a way to do it directly in postgresql (plus
COPY/\copy isn't in SQL specs).

You do know that COPY uses the column defaults for
all columns not
listed in the input list?

Yep, but that won't work (foreign key id's, timestamps
other than now(), ...)

CSN

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com