How to deal with SQL column names that look like SQL keywords?

后端 未结 14 1114
温柔的废话
温柔的废话 2020-11-22 13:24

One of my columns is called from. I can\'t change the name because I didn\'t make it. Am I allowed to do something like SELECT from FROM TableName

14条回答
  •  逝去的感伤
    2020-11-22 13:46

    If it had been in PostgreSQL, use double quotes around the name, like:

    select "from" from "table";
    

    Note: Internally PostgreSQL automatically converts all unquoted commands and parameters to lower case. That have the effect that commands and identifiers aren't case sensitive. sEleCt * from tAblE; is interpreted as select * from table;. However, parameters inside double quotes are used as is, and therefore ARE case sensitive: select * from "table"; and select * from "Table"; gets the result from two different tables.

提交回复
热议问题