After RENAME(ing) a Table I'm forced to use quoted identifiers

泪湿孤枕 提交于 2019-12-31 07:07:30

问题


After renaming a table in Postgres I'm experiencing a strange behaviour: if I reference the table without the quotes it doesn't work.

For example: the original name was «devices», after I've altered it to «Devices» the following SELECT breaks:

SELECT * from Devices

but this one

SELECT * from "Devices"

works as expected.

Any idea?


回答1:


Per the manual, identifiers are lower-cased unless quoted.

When you renamed it you did a RENAME TO "Devices", thus making the name mixed-case. You must now refer to it in quoted mixed case everywhere.

To PostgreSQL all these are names for the devices table:

  • devices
  • DEVICES
  • Devices
  • DeViCES

but these are names for separate tables with mixed-case names:

  • "Devices"
  • "DEVICES"

This is according to the SQL standard except that SQL requires implementations to UPPER CASE un-quoted names, where PostgreSQL for historical reasons lower cases them instead.




回答2:


Rename it again to devices (lower case without double quotes). Then you it will be possible to refer to it in any case you want including mixed case:

select * from dEvIceS


来源:https://stackoverflow.com/questions/17746491/after-renameing-a-table-im-forced-to-use-quoted-identifiers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!