timestamp 'default' question

Started by Charles Hauserabout 23 years ago3 messagesgeneral
Jump to latest
#1Charles Hauser
chauser@duke.edu

All,

I have a TABLE entry for time:

timeaccessioned | timestamp without time zone | not null default
('now'::text)::timestamp(6) with time zone

w/ default set to 'now', I thought postgres would fill in time - not so?

When I attempt to load feature table w/out time entered ->

psql:feature.stdin:1: ERROR: copy: line 1, Missing data for column
"timeaccessioned"

COPY feature (feature_id, dbxref_id, organism_id, name, uniquename,
residues, seqlen, md5checksum, type_id, timeaccessioned,
timelastmodified) FROM stdin;
1 \N 133 scaffold_1 chlre01.1 AAATCCAAGC
376197 53adae6396a767c7e88910c73b9d0b6b 3
\.

Can I get postgres to load current time, or do I need to generate it in
the script creating the SQL?

Charles

#2Jeff Fitzmyers
jeff@cloverpub.com
In reply to: Charles Hauser (#1)
Re: timestamp 'default' question

w/ default set to 'now', I thought postgres would fill in time - not
so?

Try now()

CREATE TABLE users (
creation_date timestamp DEFAULT 'now()' NOT NULL
);

Jeff

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Charles Hauser (#1)
Re: timestamp 'default' question

Charles Hauser <chauser@duke.edu> writes:

When I attempt to load feature table w/out time entered ->
psql:feature.stdin:1: ERROR: copy: line 1, Missing data for column
"timeaccessioned"

Well, yes, because your COPY command is claiming that all eleven columns
will be supplied in the input:

COPY feature (feature_id, dbxref_id, organism_id, name, uniquename,
residues, seqlen, md5checksum, type_id, timeaccessioned,
timelastmodified) FROM stdin;
1 \N 133 scaffold_1 chlre01.1 AAATCCAAGC
376197 53adae6396a767c7e88910c73b9d0b6b 3
\.

I think what you probably intend is

COPY feature (feature_id, dbxref_id, organism_id, name, uniquename,
residues, seqlen, md5checksum, type_id) FROM stdin;

which tells COPY to read those columns from the input and insert
defaults for the remaining columns.

regards, tom lane