Re: [SQL] Stupid question about default time value

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: [SQL] Stupid question about default time value
Дата
Msg-id 20254.931791968@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Stupid question about default time value  ("Nikolay Mijaylov" <nmmm@nsi.bg>)
Список 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


В списке pgsql-sql по дате отправления:

Предыдущее
От: "Tiberiu Craciun"
Дата:
Сообщение: Re: [SQL] calculating percentages
Следующее
От: Tom Lane
Дата:
Сообщение: Re: [SQL] calculating percentages