Skip to content

Prefix * with table alias #1003

Closed
Closed

Description

@namarkus

As described in #908 for Oracle and #966 for Teradata, specifying new columns after SELECT * is not possible with Exasol-Database neither. Most likely there are other RDBMS that do not support this.

I like the use of star instead of repeating every columnname, it's very convenient and makes it easier to inspect the generated SQL-query. IMHO adding the alias as a prefix to the star would be a more generic solution to these problems:

Following dplyr-pipe

tbl(db, "my_table") %>%
  mutate(
    new_col = "any_value"
  ) %>% show_query()

sould translate to:

<SQL>
SELECT "t1".*, 'any_value' AS new_col
FROM "my_table" as "t1"

Of course, every derived table e.g. select "sub1".* from (select * from "my_table") "sub1" has to be declared with an alias too.
Would it be possible to prefix every star with an table alias?

Thanks!

Activity

  1. hadley commented on Dec 5, 2022

    @hadley
    Member

    @namarkus are you saying that you can do SELECT table.*, x, y, z in Oracle and Teradata?

  2. changed the title [-]supports_star_without_alias issue for [/-] [+]Prefix `*` with table name[/+] on Dec 5, 2022
  3. changed the title [-]Prefix `*` with table name[/-] [+]Prefix `*` with table alias[/+] on Dec 5, 2022
  4. namarkus commented on Dec 5, 2022

    @namarkus
    Author

    No, that's not what I meant. The wording was a little imprecise, I'm sorry.
    The prefix for the *-notation should be the table alias not the table name. I have adjusted the name of the issue and also the example.

  5. hadley commented on Dec 5, 2022

    @hadley
    Member

    I mean are you implying that adding the prefix fixes the problem with using a bare *?

  6. namarkus commented on Dec 5, 2022

    @namarkus
    Author

    Yes, definitely. I looked this up in the documentation for 3 different RDBMS:
    Oracle
    https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/SELECT.html#GUID-CFA006CA-6FF1-4972-821E-6996142A51C6
    In the section "select_list::=" the following valid possibilities are listed:
    select schema.table.* , ...
    select t_alias.* , ...

    Teradata
    https://docs.teradata.com/r/Teradata-VantageTM-SQL-Data-Manipulation-Language/March-2019/Select-Statements/SELECT
    According to section "B
    SELECT table_name.* , ...
    is a valid expression. Unfortunately, it is not quite clear whether table_name means the actual name of the table or an alias.

    Exasol
    https://docs.exasol.com/db/latest/sql/select.htm
    Section "select_list::=" names the following valid expressions:
    SELECT table.* , ...
    SELECT view.* , ....
    (however in my Exasol system only SELECT table_alias.* works...)

    In my experience (and contrary to the documentation)
    SELECT table_alias.* ,...
    actually works in most systems.
    What is clear in all 3 syntax definitions, however, is that
    SELECT *, ...
    is not a valid statement.

  7. hadley commented on Dec 5, 2022

    @hadley
    Member

    @mgirlich do you think we could make this an option or maybe even the default?

  8. hadley commented on Dec 5, 2022

    @hadley
    Member

    I think this implies it's valid SQL 92?

    1. The ".*" for some Q is equivalent to a sequence in which each is a CR that references a column of T that is not a common column of a . Each col- umn of T that is not a common column of a shall be referenced exactly once. The columns shall be referenced in the ascending sequence of their ordinal positions within T.
  9. namarkus commented on Dec 6, 2022

    @namarkus
    Author

    I agree, it could be interpreted that way. But the diagram for it states otherwise:

    < query specification > ::=
    SELECT [ < set quantifier > ] < select list > < table expression >

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

    A < select list > is either a single asterisk only or a comma-separated sequence of < select sublist >. A < select sublist > in turn can be < qualifier > < period > < asterisk >.

    Consequently, if multiple < select sublist > occur in a < query specification >, the asterisk must have < qualifier >-prefix.

  10. hadley commented on Dec 6, 2022

    @hadley
    Member

    I think that does imply that < qualifier > < period > < asterisk > is ok?

  11. namarkus commented on Dec 6, 2022

    @namarkus
    Author

    Yes, I agree with that.

  12. But2ene commented on Jan 30, 2023

    @But2ene

    I mean are you implying that adding the prefix fixes the problem with using a bare *?

    In Teradata, yes it does.

    I think that does imply that < qualifier > < period > < asterisk > is ok?

    Yes it works in Teradata, both table name and alias work. Qualifier/alias would be the best default for Teradata

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions