Menu

#1337 "Duplicate column name in derived table" for non-derived, top-level tables

current-release
closed
None
1
2014-12-28
2014-02-07
Lukas Eder
No

The following query raises a "duplicate column name in derived table" error:

select table_name, * from information_schema.tables

But there is no derived table, and pretty much every database I know of allows for such a query. For example, PostgreSQL:

http://sqlfiddle.com/#!15/d41d8/1115

This query will produce the same error:

select table_name AS x, * from information_schema.tables

These queries, however, are a workaround for the problem:

select table_name, tables.* from information_schema.tables
select table_name, t.* from information_schema.tables t

Discussion

  • Fred Toussi

    Fred Toussi - 2014-02-07

    Postgres is often wrong in its SQL Standard support.

    You can use the unqualified asterisk in this way:

      select * from ...
    

    Otherwise you have to specify the table name.

     
  • Lukas Eder

    Lukas Eder - 2014-02-07

    You're right, my bad! I misinterpreted the standards document, which says:

    <select list> ::=
    <asterisk>
    | <select sublist> [ { <comma> <select sublist> }... ]
    <select sublist> ::=
    <derived column>
    | <qualified asterisk>
    
     

    Last edit: Lukas Eder 2014-02-07
  • Fred Toussi

    Fred Toussi - 2014-02-19
    • status: open --> closed
    • assigned_to: Fred Toussi
    • Priority: 5 --> 1
     

Log in to post a comment.

MongoDB Logo MongoDB