Обсуждение: Stupid question about default time value

Поиск
Список
Период
Сортировка

Stupid question about default time value

От
"Nikolay Mijaylov"
Дата:
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



Re: [SQL] Stupid question about default time value

От
Tom Lane
Дата:
"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