简体   繁体   English

MySQL 5 到 PostgreSQL 8.4,区分大小写的约定,我应该与 PostgreSQL 保持一致

[英]MySQL 5 to PostgreSQL 8.4, case sensitive convention, should I keep it with PostgreSQL

Well now at my company we are switching from MySQL 5 to PostgreSQL 8.4 because the front-end of the project is PHP but the server part is LISP which has problems with MySQL prepared statements. Well now at my company we are switching from MySQL 5 to PostgreSQL 8.4 because the front-end of the project is PHP but the server part is LISP which has problems with MySQL prepared statements.

This was just one of the reasons, and is out of my control so long story short currently we have a db with just about a dozen of tables that have to be migrated.这只是其中一个原因,而且是我无法控制的,所以长话短说,目前我们有一个数据库,其中只有十几个表需要迁移。 The thing is in MySQL we used a case-sensitive sql convention like this:事情是在 MySQL 我们使用了一个区分大小写的 sql 约定,如下所示:

All tables are plural, all the columns are prefixed with the table name (not plural) and words are separated by upper-case like this: Table Posts, columns PostID, UserID, PostTitle, PostContent, PostUpdated, PostCreated etc所有表都是复数,所有列都以表名(不是复数)为前缀,单词用大写分隔,如下所示:Table Posts、列 PostID、UserID、PostTitle、PostContent、PostUpdated、PostCreated 等

While I use PHP PDO in the frontend, there are lots of queries that go like this SELECT * FROM Posts which worked fine in MySQL but in PostgreSQL they have to be eighter SELECT * FROM "Posts" or the tables after the migration should become with low case in PostgreSQL (then it would care for the double-quotes). While I use PHP PDO in the frontend, there are lots of queries that go like this SELECT * FROM Posts which worked fine in MySQL but in PostgreSQL they have to be eighter SELECT * FROM "Posts" or the tables after the migration should become with PostgreSQL 中的小写(然后它会关心双引号)。

Both solutions suck so I would be happy with a third one (like finding a way to be able to keep quering the tables like before and it still work in PostgreSQL) or something else.这两种解决方案都很糟糕,所以我会对第三种解决方案感到满意(比如找到一种能够像以前一样继续查询表的方法,并且它仍然可以在 PostgreSQL 中工作)或其他东西。 But if that is not possible I would appreciate an advice how to do it from here - eg keep creating tables to be case sensitive and the query the db with double quotes around table and column names and change the current queries or change the naming convention to lower case and start using underscore as a separator between words like post_title, post_content and modify all the current queries.但是,如果这不可能,我会很感激如何从这里开始的建议 - 例如,继续创建区分大小写的表,并在表和列名周围使用双引号查询数据库,并更改当前查询或将命名约定更改为小写并开始使用下划线作为 post_title、post_content 等单词之间的分隔符并修改所有当前查询。 Its most important to be the better thing to do in the long run as this will be last such change (the project grows).从长远来看,最重要的是做更好的事情,因为这将是最后一次这样的变化(项目增长)。

In the long run you'll have a lot less frustration if you go to all lower case and underscores.从长远来看,如果您将 go 改为所有小写字母和下划线,您的挫败感就会少很多。 The SQL spec says that if you don't quote an identifier it gets folded to upper case. SQL 规范说,如果你不引用标识符,它会被折叠成大写。 PostgreSQL does this but goes to lower case instead for readability. PostgreSQL 会这样做,但为了便于阅读,改为使用小写字母。 However, once you start quoting mixed case identifiers you have to keep on doing it.但是,一旦您开始引用混合大小写标识符,您就必须继续这样做。

Note that you CAN use unquoted mixed case identifiers in your statements to hit all lowercase identifiers in the db.请注意,您可以在语句中使用不带引号的混合大小写标识符来匹配 db.xml 中的所有小写标识符。 Ie a db with table_name in it can be hit with select * from Table_Name which will fold to all lower case.即一个带有 table_name 的数据库可以用 select * from Table_Name 命中,它将折叠为所有小写。

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

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