Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i8rKl-0005JP-2u for pgsql-general@arkaria.postgresql.org; Fri, 13 Sep 2019 19:34:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i8rKj-0007w2-7w for pgsql-general@arkaria.postgresql.org; Fri, 13 Sep 2019 19:34:17 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i8rKh-0007vj-MR for pgsql-general@lists.postgresql.org; Fri, 13 Sep 2019 19:34:16 +0000 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i8rKY-0006j2-RL for pgsql-general@lists.postgresql.org; Fri, 13 Sep 2019 19:34:15 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id BAF904EE; Fri, 13 Sep 2019 15:34:03 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Fri, 13 Sep 2019 15:34:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm3; bh=i R4lOlG22ezTfGd6ksYdNJDY6A4O216no6mUm9eJDwc=; b=foQZFKw3G9aXEaFvH XVahparfbfr+29Nyr1IBqj54tXZAt+EuSUF/k3ckb40yWmSgoxROQALniq7P35fG +WDodFXKTc3dEFNIRQ00i3BGbJIfPHfAuzhru7gvPbwO3th65H2lonqJRO/XOUWo ZGnToGkqC8afdHpMd9AlXsC+eUlMQpJBIOpZe+ctfH+8VBvbXkRMxJYaVn7/ZfkI MFW0GYLVa6AqIVdNp9hnLpmpzHb8s4iKawOvo3TLhPRzM4Tx0PK6Mxr8Ww2e+Xk8 dKBhHEs1BThqJ3lnK9cACYv+r10e1propVy20UmgBJXlK4L2gY/H0iHS0HDjt6ie pMtcA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=iR4lOlG22ezTfGd6ksYdNJDY6A4O216no6mUm9eJD wc=; b=iGBsugmjU4VnDvJVTgR5kv5acusZFgMfIj20MRG/N6y+WJHxgCAa3mCbU 3a21SAxrL4WF7yin53Ikp13X1iJwvSV8YkJR0kFhhYYfgRyt3gRwjGFHwbvfOryX DI6IKDV9rUCz7bbkMDGEYApikbNMhRZn9XR60MBoYv+OxP9+Qvr4eyx+QWVAaYWw NfeFGU0Bq1pWEl9GMukUQIOjpTpP1le3w3gT14pFk269B8mGQWcq3IdFq2DPPP3Q ivAGNVTAFNqfLBnlcLjQizIpuGTG14uTVn9NBe0vnVHY2TKzgITrrnfLdMU16G1k QujiyqkBPg9eykBZU/6SrNlqC9b/Q== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrtdejgddufeekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefuvfhfhffkffgfgggjtgfgsehtke ertddtfeejnecuhfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhk lhgrvhgvrhesrghklhgrvhgvrhdrtghomheqnecuffhomhgrihhnpehpohhsthhgrhgvsh hqlhdrohhrghenucfkphepudejgedrvddurdduvdelrddujeehnecurfgrrhgrmhepmhgr ihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhmnecuve hluhhsthgvrhfuihiivgeptd X-ME-Proxy: Received: from [192.168.1.3] (174-21-129-175.tukw.qwest.net [174.21.129.175]) by mail.messagingengine.com (Postfix) with ESMTPA id 8A1AA80061; Fri, 13 Sep 2019 15:34:02 -0400 (EDT) Subject: Re: PG SQL and LIKE clause To: Ron , pgsql-general@lists.postgresql.org References: <20190913052846.GA3070@c720-r342378> <85249ea6-c735-f7fa-955c-b63a363e829e@aklaver.com> <1f77ce73-c0f0-d994-6f38-dca9e4c4a47f@gmail.com> From: Adrian Klaver Message-ID: <065c0194-cd62-a92e-fdcb-7b439ee67ed9@aklaver.com> Date: Fri, 13 Sep 2019 12:34:01 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <1f77ce73-c0f0-d994-6f38-dca9e4c4a47f@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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