Why does PostgreSQL default everything to lower case?

前端 未结 1 1752
心在旅途
心在旅途 2021-01-18 09:31

I\'m trying to familiarize myself with Postgres (9.2) after a fair bit of MySQL (5.1) usage, since I\'ve been bitten by a handful of MySQL\'s gotchas. However, in my first f

1条回答
  •  被撕碎了的回忆
    2021-01-18 10:16

    The SQL standard specifies folding unquoted identifiers to upper case. Many other RDBMS's follow the standard in this way. Firebird and Oracle both do. This means that identifier matching is, by default, case insensitive. This behavior is very important when it comes to compatibility in basic queries. In this regard MySQL's behavior is a real outlier.

    However PostgreSQL deviates from the standard by folding to lower case. There are general reasons why this is considered more readable, etc. because you can use case for cuing syntax. Something like:

    SELECT foo FROM bar WHERE baz = 1;
    

    This is more natural when cases are folded to lower. The alternative folding opposite would be:

    select FOO from BAR where BAZ = 1;
    

    In general like the former behavior (folding to lower case) becasue it emphasizes the sql operations better while folding to the other case de-emphasizes the operations and emphasizes the identifiers. Given the complexity of many queries, I think the former works better.

    In general the most discussion I have seen on the postgres mailing lists have been that everyone agrees the standard-mandated behavior is broken. so the above is my understanding of the issues.

    0 讨论(0)
提交回复
热议问题