pgsql 7.4b2 bug on column defaults?

Started by Giuseppe Tanzilli - CSFover 22 years ago3 messages
#1Giuseppe Tanzilli - CSF
g.tanzilli@gruppocsf.com

Hi,
just testing beta2 I got strange things on default values with functions:

create table test2 (i integer, t timestamp default 'now()');

test1=# \d test2
Table "public.test2"
Column | Type |
Modifiers
--------+-----------------------------+-------------------------------------------------------------------
i | integer |
t | timestamp without time zone | default '29/08/2003
11:26:23.937421'::timestamp without time zone

test1=# insert into test2 values(1);
INSERT 9841455 1
test1=# insert into test2 values(1);
INSERT 9841456 1
test1=# insert into test2 values(1);
INSERT 9841457 1

test1=# select * from test2;
i | t
---+----------------------------
1 | 29/08/2003 11:26:23.937421
1 | 29/08/2003 11:26:23.937421
1 | 29/08/2003 11:26:23.937421
(3 rows)

Seems that functions are valuated when the table is created,
It is a known change or a bug ?

thanks,
Giuseppe

--
-------------------------------------------------------
Giuseppe Tanzilli g.tanzilli@gruppocsf.com
CSF Sistemi srl phone ++39 0775 7771
Via del Ciavattino
Anagni FR
Italy

#2Giuseppe Tanzilli - CSF Sistemi
g.tanzilli@gruppocsf.com
In reply to: Giuseppe Tanzilli - CSF (#1)
Re: pgsql 7.4b2 bug on column defaults?

Hi,
I see it work without quotes around function,
but I got it from a 7.2 dump with quotes around it.
Maybe it require a note for people dumping from 7.2,
I don't have 7.3 around to try, sorry

bye

Giuseppe Tanzilli - CSF wrote:

Hi,
just testing beta2 I got strange things on default values with functions:

create table test2 (i integer, t timestamp default 'now()');

test1=# \d test2
Table "public.test2"
Column | Type |
Modifiers
--------+-----------------------------+-------------------------------------------------------------------

i | integer |
t | timestamp without time zone | default '29/08/2003
11:26:23.937421'::timestamp without time zone

test1=# insert into test2 values(1);
INSERT 9841455 1
test1=# insert into test2 values(1);
INSERT 9841456 1
test1=# insert into test2 values(1);
INSERT 9841457 1

test1=# select * from test2;
i | t
---+----------------------------
1 | 29/08/2003 11:26:23.937421
1 | 29/08/2003 11:26:23.937421
1 | 29/08/2003 11:26:23.937421
(3 rows)

Seems that functions are valuated when the table is created,
It is a known change or a bug ?

thanks,
Giuseppe

--
-------------------------------------------------------
Giuseppe Tanzilli g.tanzilli@gruppocsf.com
CSF Sistemi srl phone ++39 0775 7771
Via del Ciavattino
Anagni FR
Italy

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Giuseppe Tanzilli - CSF (#1)
Re: pgsql 7.4b2 bug on column defaults?

Giuseppe Tanzilli - CSF <g.tanzilli@gruppocsf.com> writes:

create table test2 (i integer, t timestamp default 'now()');

Use "DEFAULT now()". I'm surprised you didn't get a syntax error from
the above.

It is a known change or a bug ?

It's an intentional change, yes.

regards, tom lane