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 1i8mV8-0002W1-FZ for pgsql-general@arkaria.postgresql.org; Fri, 13 Sep 2019 14:24:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i8mV7-0007vK-90 for pgsql-general@arkaria.postgresql.org; Fri, 13 Sep 2019 14:24:41 +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 1i8mV6-0007vD-Vm for pgsql-general@lists.postgresql.org; Fri, 13 Sep 2019 14:24:41 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i8mV4-0003VR-FY for pgsql-general@lists.postgresql.org; Fri, 13 Sep 2019 14:24:40 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x8DEOZ9I020805; Fri, 13 Sep 2019 10:24:35 -0400 From: Tom Lane To: Matthias Apitz cc: pgsql-general Subject: Re: PG SQL and LIKE clause In-reply-to: <20190913052846.GA3070@c720-r342378> References: <20190913052846.GA3070@c720-r342378> Comments: In-reply-to Matthias Apitz message dated "Fri, 13 Sep 2019 07:28:46 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <20803.1568384675.1@sss.pgh.pa.us> Date: Fri, 13 Sep 2019 10:24:35 -0400 Message-ID: <20804.1568384675@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Matthias Apitz writes: > 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 '. > I glanced through our code with grep pipelines and found some hundred > places which would be affected by this problem. I'm not interested in a > religious discussion if or if not this behaviour of PG is correcter or > better than in Sybase. It's just different to Sybase. > Any hints to address this problem? Don't use char(n) for anything more complicated than cases like it-must-be-a-2-character-state-abbreviation. You can use varchar(n) if you must have an upper limit on the field length. Or text. regards, tom lane