简体   繁体   English

为什么PostgreSQL默认一切都是小写的?

[英]Why does PostgreSQL default everything to lower case?

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 . 我试图在使用MySQL(5.1)之后熟悉Postgres(9.2),因为我被一些MySQL的陷阱所困扰 However, in my first five minutes with Postgres I ran into one of its gotchas , which I'm sure hits everyone: 然而,在我与Postgres的前五分钟,我跑进一个它的陷阱 ,我敢肯定,每个人都点击:

  • By default, PostgreSQL converts everything that isn't quoted to lower case. 默认情况下,PostgreSQL会将未引用的所有内容转换为小写。

This isn't too big of a deal to me, since there are a couple of obvious workarounds: 这对我来说并不算太大,因为有几个明显的解决方法:

  • Encapsulate everything in quotes. 用引号封装所有内容。
  • Allow everything to be named in a lower case fashion. 允许以小写方式命名所有内容。

But I'm wondering why. 但我想知道为什么。 Considering how much contention I imagine this design decision causes, I'm surprised that I couldn't find any rationale on the internet. 考虑到我想象这个设计决定导致了多少争用,我很惊讶我在互联网上找不到任何理由。 Does anybody have a thorough explanation, or preferably a link to some developer manifesto, as to why Postgres was designed this way? 有没有人有一个彻底的解释,或者最好是一些开发者宣言的链接,为什么Postgres是这样设计的? I'm interested. 我很感兴趣。

The SQL standard specifies folding unquoted identifiers to upper case. SQL标准指定将不带引号的标识符折叠为大写。 Many other RDBMS's follow the standard in this way. 许多其他RDBMS都以这种方式遵循标准。 Firebird and Oracle both do. Firebird和Oracle都这样做。 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. 在这方面,MySQL的行为是一个真正的异常值。

However PostgreSQL deviates from the standard by folding to lower case. 然而,PostgreSQL通过折叠到小写而偏离标准。 There are general reasons why this is considered more readable, etc. because you can use case for cuing syntax. 一般的原因是为什么这被认为更具可读性等等,因为你可以使用case来提示语法。 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. 通常像前一种行为(折叠到小写)一样,因为它更好地强调了sql操作,而折叠到另一种情况则不再强调操作并强调标识符。 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. 总的来说,我在postgres邮件列表上看到的大多数讨论都是每个人都同意标准规定的行为被打破。 so the above is my understanding of the issues. 所以以上就是我对这些问题的理解。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM