Re: [HACKERS] create table and default 'now' problem ?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: [HACKERS] create table and default 'now' problem ?
Дата
Msg-id 21268.937921240@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: [HACKERS] create table and default 'now' problem ?  (Oleg Bartunov <oleg@sai.msu.su>)
Ответы Re: [HACKERS] create table and default 'now' problem ?  (Oleg Bartunov <oleg@sai.msu.su>)
Список pgsql-hackers
>>>>>> how I could create table with datetime field default
>>>>>> to 'now'::text in a way Jan did in his shoes rule example ?

A couple of comments on this thread:

1.  Seems to me that the easy, reliable way is just to use the
now() function --- you don't have to make one, it's built in:
create table test ( a datetime default now(), b int);

This avoids all the issues about when constants get coerced, and
probably ought to be what we recommend to newbies.  However,
this is certainly a workaround for an existing bug.

2.  I believe that most of the problem with premature constant coercion
in default values is coming from the bizarre way that default values get
entered into the database.  StoreAttrDefault essentially converts the
parsed default-value tree back to text, constructs a SELECT statement
using the text, parses that, and examines the resulting parsetree.
Yech.  If it were done carefully it might work, but it's not; the
reverse parser does not do quoting carefully, does not do type coercion
carefully, and fails to handle large parts of the expression syntax at
all.  (I've ranted about this before ... check the pghackers archives.)

I have a to-do list item to rip all that code out and do it over again
right.  Might or might not get to it for 6.6 --- does someone else want
to tackle it?

3.  Yes, this is a bug too:

>> create table test ( a datetime default 'now'::text,...)
> Parser complains:
> ERROR:  parser: parse error at or near "'"
> Does this considered as a bug or feature ?

See above --- reverse-parsing of this construct is wrong.  I have
no intention of fixing the reverse parser; I want to get rid of it
entirely.
        regards, tom lane


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

Предыдущее
От: Thomas Lockhart
Дата:
Сообщение: Re: [HACKERS] create table and default 'now' problem ?
Следующее
От: Tom Lane
Дата:
Сообщение: Re: [HACKERS] postmaster disappears