PostgreSQL forces lowercase names?
Asked Answered
M

1

24

Just started to learn PostgreSQL 9.1 on linux through C and libpq.
For now I check connection, connect, create database, create table and other basic stuff. But I noted that during table creating PQ converts my database name to lowercase. Then I see that table names and field names are also forced to lowercase. Howewer, when I try to connect with uppercase (original) name of database I get warning that asked database don't exist.

Best of all will be that all names stays as written. Is this possible to get with some simple method/setting?

For example:

M_122_KL0001_2011_001_0100001

will be created as m_122_kl0001_2011_001_0100001 what is not wanted for me.
Same happens with table names and field names.

Manager answered 2/3, 2012 at 18:43 Comment(0)
C
33

This is the default behavior of Postgres.

If you want upper- or mixed-case, you can quote the identifier e.g.:

createdb "M_122_KL0001_2011_001_0100001"
Collusion answered 2/3, 2012 at 18:49 Comment(7)
Yes! Thank you wery much. Here would be plenty of 'escaping strings" :)Manager
Would it be smarter to keep "lowercase" rules?Manager
In my opinion, yes, it makes life easier to keep everything lowercase. But if you have some reason to use upper- or mixed-case then at least now you know how it is supported.Collusion
Is anyone aware of the reasoning behind this default behaviour?Lazaretto
@Basic: I'm not 100%, but my guess is that it makes identifiers case insensitive without too much of a performance hit.Flavorsome
@Denis Sorry, I was unclear. The ORM does its job properly. Issuing SQL commands directly for maintenance/updates is where the pain lies. Anyway, I'll delete my comments to avoid clutter on this answerLazaretto
btw you need it also by droping postgres database with uppercase name, otherwise it won't be find. DROP DATABASE "FOLOLO";Moisten

© 2022 - 2024 — McMap. All rights reserved.