Search Postgresql Archives

Re: insert into ... select ... and column order

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Tore Halset wrote:
Hello.

One of our users tried a "insert into ... select ..." that gave a strange error message. After digging into the issue, the problem seem to be that the order of the columns in the select statement must match the table definition. Here is a way to reproduce this case.
...

Why does the column order matter when the subselect has all the correct column names?

When I noticed this long ago I just blamed it to SQL standards ;)
I do admit I never checked with the documentation.

And yes the names of the columns do not matter, just use the correct
order - either default or better:

INSERT INTO ... ( a,b,c ) SELECT a,b,c FROM ....

since new columns or reorder would not disturb your insert.

Regards
Tino


---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux