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.

Wine Too
  • 4,515
  • 22
  • 83
  • 137

1 Answers1

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"
mechanical_meat
  • 163,903
  • 24
  • 228
  • 223
  • 1
    Yes! Thank you wery much. Here would be plenty of 'escaping strings" :) – Wine Too Mar 02 '12 at 19:26
  • Would it be smarter to keep "lowercase" rules? – Wine Too Mar 02 '12 at 19:28
  • 3
    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. – mechanical_meat Mar 02 '12 at 19:29
  • 6
    Is anyone aware of the reasoning behind this default behaviour? – Basic May 09 '13 at 13:49
  • 1
    @Basic: I'm not 100%, but my guess is that it makes identifiers case insensitive without too much of a performance hit. – Denis de Bernardy Dec 16 '13 at 21:20
  • @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 answer – Basic Dec 17 '13 at 18:16
  • btw you need it also by droping postgres database with uppercase name, otherwise it won't be find. `DROP DATABASE "FOLOLO";` – andilabs Nov 07 '14 at 15:11