From: Tom Lane <tgl@sss.pgh.pa.us>
To: Nikolay Mijaylov <nmmm@nsi.bg>
Cc: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] Stupid question about default time value
Date: Mon, 12 Jul 1999 11:06:08 -0400
Message-ID: <20254.931791968@sss.pgh.pa.us> (raw)
In-Reply-To: <001001becc3f$7e2962c0$ce2a18c3@skillbrokers.bg>
"Nikolay Mijaylov" <nmmm@nsi.bg> writes:
> I made a table such as:
> create teble x(
> i int2,
> d date default 'today',
> t time default 'now',
> dt datetime default 'now'
> );
> So these default values are not working as i think... they make the default
> values to be equal to time when table was created....
Yes, because the default values will normally be converted to the column
data type at the time the CREATE TABLE is done. What you want is to
leave them as text until an INSERT happens. The trick looks like this:
dt datetime default text 'now'
or
dt datetime default 'now'::text
> i fixed problem in this way:
> create teble x(
> i int2,
> d date default date( now() ), // or now() ::
> date
> t time default datetime_time(datetime (now ()) ),
> dt datetime default now()
> );
That should work too, although it's pretty ugly for all except the
datetime case. (Do you really need to write the conversion functions
explicitly? At least in recent Postgres releases, I think they should
get added for you...)
regards, tom lane
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us, nmmm@nsi.bg
Subject: Re: [SQL] Stupid question about default time value
In-Reply-To: <20254.931791968@sss.pgh.pa.us>
References: <001001becc3f$7e2962c0$ce2a18c3@skillbrokers.bg> <20254.931791968@sss.pgh.pa.us>
* 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