Re: 7.0 bug ?? - Mailing list pgsql-bugs

From Tom Lane
Subject Re: 7.0 bug ??
Date
Msg-id 24638.957144664@sss.pgh.pa.us
Whole thread Raw
In response to 7.0 bug ??  (claud yu <claud@tera.cs.tku.edu.tw>)
List pgsql-bugs
claud yu <claud@tera.cs.tku.edu.tw> writes:
> freechange=# insert into accountloginrec values (1,'test','test','test',NOW(),NOW()+30,Max(eshopcode)+1,null);
> ERROR:  Attribute 'eshopcode' not found

> The same syntax at 6.5.3 is OK !!

Not a 7.0 bug, but a 6.5 bug --- it shouldn't have accepted that.
The correct SQL-approved way to do this sort of thing is

insert into accountloginrec
    select 1,'test','test','test',NOW(),NOW()+30,Max(eshopcode)+1,null
    from accountloginrec;

A values() expression is a standalone row-value constructor; it can't
legitimately contain any references to the insert destination table.
In fact the way INSERT is supposed to work is that it's processed as
    INSERT INTO dest_table <something>
where the <something> is a row-value-yielding expression that would
have the same meaning whether it appeared in INSERT or not.  6.5 was
in error to accept free variables in the <something> as references
to the insert's destination table.

The INSERT...SELECT way works in 6.5 too, btw.

            regards, tom lane

pgsql-bugs by date:

Previous
From: claud yu
Date:
Subject: 7.0 bug ??
Next
From: "Rolf C Stadheim"
Date:
Subject: gmake[3]: *** No rule to make target `page/SUBSYS.o'. Stop. ??????????????????