开发者

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.

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:

All tables are plural, all the columns are prefixed with the table n开发者_StackOverflow社区ame (not plural) and words are separated by upper-case like this: Table Posts, columns PostID, UserID, PostTitle, PostContent, PostUpdated, PostCreated etc

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).

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. 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. 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. The SQL spec says that if you don't quote an identifier it gets folded to upper case. PostgreSQL does this but goes to lower case instead for readability. 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. I.e. a db with table_name in it can be hit with select * from Table_Name which will fold to all lower case.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜