Re: Case sensitivity?
On Tue, 27 Dec 2005, dfx wrote:
Dear Sirs,
I have a little problem:
- Contest: Server side: Linux Fedora core 4 with PostgreSQL v. 8.0
Client side: both Linux Fedora core 4 with pgAdmin III v.
1.4 and/or Windows 2000 server vith pgAdmin III v. 1.4- I Made a table:
CREATE TABLE "Accoglienza"
(
"IdAccoglienza" int4 NOT NULL DEFAULT
nextval('public."Accoglienza_IdAccoglienza_seq"'::text),
"IdCongresso" int4 NOT NULL DEFAULT 0,
CONSTRAINT "Accoglienza_Pk" PRIMARY KEY ("IdAccoglienza")
)
WITHOUT OIDS;if I try "INSERT INTO Accoglienza (IdCongresso) VALUES (23)"
I get an error "ERROR: la relazione "accoglienza" non esiste" (The relation
"accoglienza does not exist")please note the change of the case of "A" to "a";
if I rename the table to "accoglienza" the error disappear, but arise
another error on "IdAccoglienza" that change in "idaccoglienza". (i.e. all
converted to lower case)The same error arise with window client and linux client.
How I can set case-insensitive the system, or avoid the conversion to lower
case?
Create the table without closing the relation's name with doble quotes:
CREATE TABLE Accoglienza
(
IdAccoglienza int4 NOT NULL DEFAULT
nextval('public.Accoglienza_IdAccoglienza_seq'::text),
IdCongresso int4 NOT NULL DEFAULT 0,
CONSTRAINT Accoglienza_Pk PRIMARY KEY (IdAccoglienza)
)
WITHOUT OIDS;
--
12:00:02 up 4 days, 23:12, 1 user, load average: 0.35, 0.54, 0.70
---------------------------------------------------------
Lic. Martín Marqués | SELECT 'mmarques' ||
Centro de Telemática | '@' || 'unl.edu.ar';
Universidad Nacional | DBA, Programador,
del Litoral | Administrador
---------------------------------------------------------
Import Notes
Reply to msg id not found: 000501c60b40$ea790510$fc00a8c0@dfxReference msg id not found: 000501c60b40$ea790510$fc00a8c0@dfx
On 12/27/05, dfx <dfx@dfx.it> wrote:
Dear Sirs,
I have a little problem:
- Contest: Server side: Linux Fedora core 4 with PostgreSQL v. 8.0
Client side: both Linux Fedora core 4 with pgAdmin III v.
1.4 and/or Windows 2000 server vith pgAdmin III v. 1.4- I Made a table:
CREATE TABLE "Accoglienza"
(
"IdAccoglienza" int4 NOT NULL DEFAULT
nextval('public."Accoglienza_IdAccoglienza_seq"'::text),
"IdCongresso" int4 NOT NULL DEFAULT 0,
CONSTRAINT "Accoglienza_Pk" PRIMARY KEY ("IdAccoglienza")
)
WITHOUT OIDS;if I try "INSERT INTO Accoglienza (IdCongresso) VALUES (23)"
I get an error "ERROR: la relazione "accoglienza" non esiste" (The relation
"accoglienza does not exist")please note the change of the case of "A" to "a";
if I rename the table to "accoglienza" the error disappear, but arise
another error on "IdAccoglienza" that change in "idaccoglienza". (i.e. all
converted to lower case)The same error arise with window client and linux client.
How I can set case-insensitive the system, or avoid the conversion to lower
case?
the server always will transfor the names of the object to lower case
unless you surround them with quotes ("")
so if you say
CREATE TABLE TablE --> it will create a table called table
and if you say
CREATE TABLE "TablE" --> it will create a table called "TablE"
and in this case, if you try to select from table it will give an
error... it will give you an error even if you type TablE you have to
type "TablE" or always live with lower case object names...
It depends on setting of pgAdmin or on setting of the server?
Thank you.
--
Atentamente,
Jaime Casanova
(DBA: DataBase Aniquilator ;)
Import Notes
Reply to msg id not found: 000501c60b40$ea790510$fc00a8c0@dfxReference msg id not found: 000501c60b40$ea790510$fc00a8c0@dfx | Resolved by subject fallback
Due to case weirdness in Postgres, particularly when accessing it from
PHP, I completely abandoned mixed case table and column names. I don't
know if things have changed in the past several years, but when I first
made the leap, mixed case was more trouble than it was worth.
Even after I got over the initial hump and figured out how to make it
work, there was enough weird behavior (i.e. being able to access a
non-existent array element) in PHP that it led to a lot of bugs when
using mixed-case in Postgres. That's my two cents. Your mileage may
vary...
dfx wrote:
Show quoted text
Dear Sirs,
<snip>
please note the change of the case of "A" to "a";if I rename the table to "accoglienza" the error disappear, but arise
another error on "IdAccoglienza" that change in "idaccoglienza". (i.e.
all converted to lower case)
Import Notes
Reply to msg id not found: 000501c60b40$ea790510$fc00a8c0@dfxReference msg id not found: 000501c60b40$ea790510$fc00a8c0@dfx | Resolved by subject fallback
Hi,
On Tue, 2005-12-27 at 15:54 -0800, dfx wrote:
How I can set case-insensitive the system, or avoid the conversion to
lower case?
You need to double-quote the object names that you don't want to be
converted to lower case, like CREATE TABLE "DevrimGunduz".
Regards,
--
The PostgreSQL Company - Command Prompt, Inc. 1.503.667.4564
PostgreSQL Replication, Consulting, Custom Development, 24x7 support
Managed Services, Shared and Dedicated Hosting
Co-Authors: PL/php, plPerlNG - http://www.commandprompt.com/
Import Notes
Reply to msg id not found: 000501c60b40$ea790510$fc00a8c0@dfxReference msg id not found: 000501c60b40$ea790510$fc00a8c0@dfx | Resolved by subject fallback
On Tue, Dec 27, 2005 at 09:14:20AM -0600, John McCawley wrote:
Due to case weirdness in Postgres, particularly when accessing it from
PHP, I completely abandoned mixed case table and column names. I don't
know if things have changed in the past several years, but when I first
made the leap, mixed case was more trouble than it was worth.
Well, the rule is very simple, either always quote your identifiers, or
never quote them. If you always quote them, then you always need to
specify them in the same case. If you never quote them, then you always
get case-insensetivity.
Even after I got over the initial hump and figured out how to make it
work, there was enough weird behavior (i.e. being able to access a
non-existent array element) in PHP that it led to a lot of bugs when
using mixed-case in Postgres. That's my two cents. Your mileage may
vary...
Hmm, you mean how column titles come back as lowercase? By strict SQL
standard they should come back as all upper-case, but you probably
don't want that either...
SQL has always been case-folding, never case-insensetive.
Have a nice day,
--
Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/
Show quoted text
Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
tool for doing 5% of the work and then sitting around waiting for someone
else to do the other 95% so you can sue them.
Well, the rule is very simple, either always quote your identifiers, or
never quote them. If you always quote them, then you always need to
specify them in the same case. If you never quote them, then you always
get case-insensetivity.
My memory is a little hazy, as it's been a few years, but I believe my
ultimate problem was that my code ended up being quite confusing. I was
able to use my mixed case, as you said, when I used quotes in the SQL
query (which had to be escaped in PHP), however, the column names came
in all lowercase, so I ended up having to switch between the two,
leading to me making mistakes. See this example (note my example is
using my DB wrapper class):
<?
$obData = GetSQLHelper();
$sSQL = "SELECT \"FooBar\" FROM \"tbl_Foo\"";
$result = $obData->RunSQLReturnRS($sSQL);
$foobar = $result->fields["foobar"];
?>
I generally give my local variables the same name as their database
counterparts, as shown by foobar in this example. The problem is that
foobar ends up as lowercase when it gets back to me. If I get into the
habit of typing "FooBar" mixed case in my SQL queries, it is only a
matter of time before I do the following:
$Foobar = $result->fields["FooBar"];
PHP won't raise any error here, but rather just create a new "FooBar"
variable in the fields map, which is a pretty insidious behavior.
Rather than open myself up to inevitable bugs, I just abandoned mixed
case. I still end up with a similar problem when I misspell column
names, but there isn't a whole lot I can do to avoid that other than
type more carefully.
I know that this is more of a PHP issue than a Postgres issue, but these
days a lot of people are using higher level languages for web
development etc., and can run into similar issues, so I figured I'd
mention this as an argument for avoiding mixed case in the database.
John