Search code examples
sqlselectgoogle-cloud-sql

Google Cloud SQL - "SELECT .. AS .." doesn't change the column name


I'm trying to retrieve some columns value from a google cloud sql database, and I want to rename the output column as follows:

select id as tot from mytable

the query result I get is this:

  id
value1
value2
value3
...

as you can see the column name is not changed as I wanted.. I also tried

select id as 'tot' from mytable

and (in fact this works, but obviously every row value is set to 'id' instead of the real row value)

select 'id' as 'tot' from mytable

the table schema I'm testing on is as simple as possible:

create table mytable(id varchar(10))

Has anyone encountered this problem before? Am I missing something or doing something wrong?

Thanks in advance for any help, best regards


Solution

  • This works as expected using the command line tool and looks like a bug in the web ui.

    Here's what I got from the command line tool use (google_sql.sh)

    sql> insert into mytable values('1'), ('2'), ('3');
    3 row(s) affected.
    sql> select * from mytable;                        
    +----+
    | id |
    +----+
    | 1  |
    | 2  |
    | 3  |
    +----+
    3 rows in set (0.10 sec)
    
    sql> select id as 'tot' from mytable
    -> ;
    +-----+
    | tot |
    +-----+
    | 1   |
    | 2   |
    | 3   |
    +-----+
    3 rows in set (0.09 sec)
    
    sql> select 'id' as 'tot' from mytable
    -> ;
    +-----+
    | tot |
    +-----+
    | id  |
    | id  |
    | id  |
    +-----+
    3 rows in set (0.09 sec)
    

    I just logged a bug for this: https://code.google.com/p/googlecloudsql/issues/detail?id=60