This question is raised in Drill's user list [1]. The code logic is
actually in Calcite.

Basically, SQL standard allows couple of reserved identifiers used for
system function call, such as USER, CURRENT_USER, CURRENT_TIME etc.
If someone wants to use those reserved names as column names, he has
to use quoted identifier.

However, looks like Calcite always interprets those simple quoted
identifiers as a system function call, in stead of column name.  Such
behavior is different from Postgres/Oracle, which will interpret a
quoted identifier as column name, instead of system function call).

I would argue that Postgres/Oracle's behavior makes more sense. If
someone quotes an reserved word, the expectation is he can use those
reserved words just like a regular identifier.

If this sounds reasonable, I'll open a JIRA.

-------------------------------------------------------------

Oracle:

create table mytemp("user" int);
insert into mytemp values(100);

SQL> select user from mytemp;

USER
------------------------------
user_id

SQL> select "user" from mytemp;

      user
----------
       100

SQL> select mytemp."user" from mytemp;

      user
----------
       100


Postgres:
select user from (values(100)) as T("user");
 current_user
--------------
 user_id
(1 row)

mydb=# select "user" from (values(100)) as T("user");
 user
------
  100
(1 row)

mydb=# select T."user" from (values(100)) as T("user");
 user
------
  100
(1 row)


Calcite:
select user from (values(100)) as T("user");
-----
user_id

select "user" from (values(100)) as T("user");
-----
user_id

select T."user" from (values(100)) as T("user");
+------------+
|    user    |
+------------+
| 100        |
+------------+

[1] 
http://mail-archives.apache.org/mod_mbox/drill-user/201605.mbox/%3CCAKOFcwrR4m6_EZvKU0ijh5CeSBa-YvZxomBFH6dPmthj7g%2BmWg%40mail.gmail.com%3E

Reply via email to