pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Ron <ronljohnsonjr@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: PG SQL and LIKE clause
Date: Fri, 13 Sep 2019 12:34:01 -0700
Message-ID: <065c0194-cd62-a92e-fdcb-7b439ee67ed9@aklaver.com> (raw)
In-Reply-To: <1f77ce73-c0f0-d994-6f38-dca9e4c4a47f@gmail.com>
References: <20190913052846.GA3070@c720-r342378>
	<ed0438be-ee6c-7e25-e39d-ae56982dc1de@gmail.com>
	<85249ea6-c735-f7fa-955c-b63a363e829e@aklaver.com>
	<1f77ce73-c0f0-d994-6f38-dca9e4c4a47f@gmail.com>

On 9/13/19 7:35 AM, Ron wrote:
> On 9/13/19 9:14 AM, Adrian Klaver wrote:
>> On 9/12/19 11:11 PM, Ron wrote:
>>> On 9/13/19 12:28 AM, Matthias Apitz wrote:
>>>> Hello,
>>>>
>>>> We're porting a huge Library Management System, written using all kind
>>>> of languages one can think of (C, C++, ESQL/C, Perl, Java, ...) on 
>>>> Linux
>>>> from the DBS Sybase to PG, millions of lines of code, which works also
>>>> with DBS Oracle and in the past with INFORMIX-SE and -ONLINE.
>>>>
>>>> We got to know that in CHAR columns with trailing blanks a
>>>>
>>>> SELECT ... FROM ... WHERE name LIKE 'Ali'
>>>>
>>>> does not match in 'name' having 'Ali '.
>>>
>>> Did you forget the "%"?  Because the SQL standard which PostgreSQL 
>>> follows is:
>>>
>>> SELECT ... FROM ... WHERE name LIKE 'Ali%'
>>
>> The above is if you want to find a string starting with 'Ali'. If you 
>> are looking for the complete string 'Ali' then it is appropriate. The 
>> OP is looking for a way to automatically match a complete string 
>> against a right stripped string from a CHAR field.
> 
> This is highly dependent on implementation.  On the RDBMS that I used to 
> work on, trailing whitespace was automatically stripped from CHAR(xx) 
> fields.
> 

That is what is driving the OP's question. On Sybase the trailing 
whitespace is stripped apparently, on Postgres it is not, at least for 
the purposes of LIKE. Though for other comparisons whitespaces are 
ignored. See below for more information:

https://www.postgresql.org/docs/11/datatype-character.html

-- 
Adrian Klaver
adrian.klaver@aklaver.com





view thread (11+ messages)  latest in thread

Message-ID: <065c0194-cd62-a92e-fdcb-7b439ee67ed9@aklaver.com>
Permalink:  ../065c0194-cd62-a92e-fdcb-7b439ee67ed9@aklaver.com/
Also on:    postgresql.org/message-id/065c0194-cd62-a92e-fdcb-7b439ee67ed9@aklaver.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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: adrian.klaver@aklaver.com, ronljohnsonjr@gmail.com
  Subject: Re: PG SQL and LIKE clause
  In-Reply-To: <065c0194-cd62-a92e-fdcb-7b439ee67ed9@aklaver.com>
  References: <20190913052846.GA3070@c720-r342378> <ed0438be-ee6c-7e25-e39d-ae56982dc1de@gmail.com> <85249ea6-c735-f7fa-955c-b63a363e829e@aklaver.com> <1f77ce73-c0f0-d994-6f38-dca9e4c4a47f@gmail.com> <065c0194-cd62-a92e-fdcb-7b439ee67ed9@aklaver.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