pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jim Ballard <jballard@netezza.com>
To: ANDREW PERRIN <aperrin@email.unc.edu>
To: Mark <mark@zserve.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Case Insensitive Queries
Date: Tue, 29 May 2001 11:54:03 -0700
Message-ID: <200105291154.AA20382230@netezza.com> (raw)

This is a good point - and it means that Postgres is not following the SQL Standard in this regard.  According to the standard, a scalar string function of a single string argument should return the same "type" of string as its input.  So upper(<fixed-char-field>) should return a fixed-char-field.  But it doesn't - it always returns a varchar that includes the trailing spaces from the space-padded fixed char argument.  And those trailing spaces are significant for the varchar comparison with the string literal.

It seems to me there are two ways to correct this behavior.  One is to have overloaded versions of the relevant string function that return the right types.  But, probably better, Postgres could support the notion of PAD SPACE or PAD OFF to control the behavior of string comparisons regardless of the particular types of the character fields involved.

Are ther plans to change this Postgres behavior?

Thanks,
Jim Ballard
Netezza Corp.

---------- Original Message ----------------------------------
From: Mark <mark@zserve.com>
Date: 29 May 2001 10:21:15 -0600

>We tried these but it didn't work.  However, that's because username is
>a bpchar and not a varchar, so its padded with blanks.  so we tried
>where lower(trim(username)) = 'test' and it works.  We'll change that
>column to varchar.  The real problem was in the datatype for username.
>
>Thanks,
>
>On 29 May 2001 12:35:53 -0400, ANDREW PERRIN wrote:
>> Try:
>> 
>> - The ILIKE operator, for example,
>> 
>> SELECT * FROM account WHERE username ILIKE "test";
>> 
>> - upper() or lower(), for example,
>> 
>> SELECT * FROM accont WHERE lower(username) = "test";
>> 
>> ---------------------------------------------------------
>>    Andrew J. Perrin - Assistant Professor of Sociology
>>         University of North Carolina, Chapel Hill
>> 269 Hamilton Hall CB#3210, Chapel Hill, NC 27599-3210 USA
>>    andrew_perrin@unc.edu - http://www.unc.edu/~aperrin
>> 
>> On 29 May 2001, Mark wrote:
>> 
>> > Is it possible to execute a query using a where clause that allows case
>> > insensitive comparison between a field and text.
>> > 
>> > For example:
>> > 
>> > select * from account where username = 'test'
>> > 
>> > where username could be 'Test', which would be a match.  As is, this
>> > compare is case sensitive.
>> > 
>> > grep'd the source, but stricmp is only used for keywords and not actual
>> > column data.
>> > 
>> > Any help would be greatly appreciated.
>> > 
>> > Thanks,
>> > 
>> > Mark
>> > 
>> > 
>> > ---------------------------(end of broadcast)---------------------------
>> > TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
>> > 
>> 
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 4: Don't 'kill -9' the postmaster
>



view thread (19+ messages)  latest in thread

Message-ID: <200105291154.AA20382230@netezza.com>
Permalink:  ../200105291154.AA20382230@netezza.com/
Also on:    postgresql.org/message-id/200105291154.AA20382230@netezza.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: jballard@netezza.com, aperrin@email.unc.edu, mark@zserve.com
  Subject: Re: Case Insensitive Queries
  In-Reply-To: <200105291154.AA20382230@netezza.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox