pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Stupid question about default time value
2+ messages / 2 participants
[nested] [flat]

* Stupid question about default time value
@ 1999-07-12 08:21  Nikolay Mijaylov <nmmm@nsi.bg>
  0 siblings, 1 reply; 2+ messages in thread

From: Nikolay Mijaylov @ 1999-07-12 08:21 UTC (permalink / raw)
  To: pgsql-sql

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....



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()
);

is there better way to do this?????

Niki
w3.nsi.bg/nmmm
www.nsi.bg/nmmm
nmmm.hypermart.net

?????
thanx




^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: [SQL] Stupid question about default time value
@ 1999-07-12 15:06  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Nikolay Mijaylov <nmmm@nsi.bg>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 1999-07-12 15:06 UTC (permalink / raw)
  To: Nikolay Mijaylov <nmmm@nsi.bg>; +Cc: pgsql-sql

"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



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~1999-07-12 15:06 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-07-12 08:21 Stupid question about default time value Nikolay Mijaylov <nmmm@nsi.bg>
1999-07-12 15:06 ` Tom Lane <tgl@sss.pgh.pa.us>

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