Question

I am trying a very simple test query on a forked MPP version of postgreSQL 8.2 and I am trying to figure out if this is expected behavior.

When I do an insert statement for a single row using current_date I get the expected output for the current date:

create table test( t_date timestamp without time zone);

insert into test(  t_date)
VALUES
(
current_date::date
),


 db=> select * from test ;
           t_date        
    ---------------------
     2013-08-19 00:00:00
    (1 row)

But when I add more than one row to the insert statement I get an unexpected result - is this part of the standard?

insert into test(  t_date)
VALUES
(
current_date::date
),
(
current_date::date
);

   db=>  select * from test ;
           t_date        
    ---------------------
     1999-12-31 00:00:00
     1999-12-31 00:00:00
    (2 rows)

My question is : Why does the first insert statement output the correct date when I use current_date::date and the second insert outputs two incorrect dates when I use the same current_date::date cast?

Was it helpful?

Solution

That result is incorrect, unexpected, and bizarre.

PostgreSQL 9.2.4 produces the correct result.

regress=> select * from test;
       t_date        
---------------------
 2013-08-20 00:00:00
 2013-08-20 00:00:00
(2 rows)

as does 8.3, the oldest version I can be bothered testing.

Whatever patched / hacked up version of PostgreSQL you're using has introduced a bug.

OTHER TIPS

Yeah, that's a feature of Postgresql to allow "bulk" loading using the VALUES clause. http://www.postgresql.org/docs/8.2/static/sql-insert.html

See the section under:

To insert multiple rows using the multirow VALUES syntax:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top