Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VUjnX-0003LL-U6 for pgsql-hackers@arkaria.postgresql.org; Fri, 11 Oct 2013 20:59:00 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VUjnX-0001VX-96 for pgsql-hackers@arkaria.postgresql.org; Fri, 11 Oct 2013 20:58:59 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VUjnV-0001VO-PL for pgsql-hackers@postgresql.org; Fri, 11 Oct 2013 20:58:58 +0000 Received: from nm10-vm0.bullet.mail.bf1.yahoo.com ([98.139.213.147]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VUjnR-0004DW-Ca for pgsql-hackers@postgresql.org; Fri, 11 Oct 2013 20:58:56 +0000 Received: from [98.139.212.145] by nm10.bullet.mail.bf1.yahoo.com with NNFMP; 11 Oct 2013 20:58:51 -0000 Received: from [98.139.212.218] by tm2.bullet.mail.bf1.yahoo.com with NNFMP; 11 Oct 2013 20:58:50 -0000 Received: from [127.0.0.1] by omp1027.mail.bf1.yahoo.com with NNFMP; 11 Oct 2013 20:58:50 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 964956.74937.bm@omp1027.mail.bf1.yahoo.com Received: (qmail 69095 invoked by uid 60001); 11 Oct 2013 20:58:50 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ymail.com; s=s1024; t=1381525130; bh=3hXdX/MQQn5tcUq/kVgiIM2VgxgwJiLPra7gyIambSQ=; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=VIkARr+SmQdNRNDKehsgd/JJWsspCb8QN9a/wu2hDIRHNjaEb9Ilkps93VROmZ0Udk0wLQJJh67ni2cl9qumki7uOV5G26L/a1O78Z+vyOIAEtcBuJB1Un5S2AQ+B9zGx6q+RGwdG1ZNh7a8BQ7u+vOPNKTDEYkyu/5uQmiiQDk= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=ymail.com; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=2zQOtdKLwO1iUCrzKYOmuIKnGu5xZ5EcBCsReurhz9fwe9f12hjxErkYQdK3oM++MoIzdtjP6lGL1ncnLA6szJyepexV/C40RIgOy/J+nEtRb41CgkSwUCbhHfOTlN7KwiK+BJB3NcfPemqGOQoR5P1h87YVDDxpxo6FvOFShDY=; X-YMail-OSG: t.QNqL0VM1n1PPyUtz2IkTaCkCFX4_vU6eF8TdNYi3pRu_h zQEQWXdGsNzkFfP2qg90I9xVdKXwgtV_j_jyE.RLHh4B3e6dPpL2iTVs_lpJ O21u2MyWDSwyZ3NLq.pwSJr9g1cz5BiTSlIY.tRelLSUzfAIVZCcycBcrtsO Oz89pMLsMVVZgVevxWqXcl_Mjg8E.bChEypLWeeLykcB0uQkbUdwBkGBieFW 1Z38SOIyymWS9v.vN8rm4mqqLeT76ZTkfyMkWsy_5_I7PpdqidJS1uYHRVsR hNxDaiP9jHGk4JlFJejMkQ0ttPTGrJowEV.Yz0fDHOnjqrebfkqjYMMcBIv6 j0zO9MTXyRa3JUt.l4zstpLDTy4AyrebQLlgkzvtBYcVRKAqndQbfHjxdmgF Q.J9a7mNo0W685VRDBEUi_HSR8LmXpeEQ6Z.56IWqPscWaa9FtEi3NuhQgrU up8OdX30wt8cpOwxnFa9VrWYyBCgk8KjB79_iTrbH8vP.bYc2Ew_jS68MWUO oBJjGopaktHKIng5Jk_GgjVPSSfzWxAhBbF..C_.N49Tbr3mLBqxVuYndYDq FOWkfnvL8m_OA8dhYnxxUCv0dbT8zzUscVy_83lSCTBKHMp0Xj.4g4jSaiUl FcQ-- Received: from [76.255.18.237] by web162902.mail.bf1.yahoo.com via HTTP; Fri, 11 Oct 2013 13:58:50 PDT X-Rocket-MIMEInfo: 002.001, QnJ1Y2UgTW9tamlhbiA8YnJ1Y2VAbW9tamlhbi51cz4gd3JvdGU6Cj4gVGhvbWFzIEZhbmdoYWVuZWwgd3JvdGU6Cgo.PiBJIHdhcyB3b25kZXJpbmcgYWJvdXQgdGhlIHByb3BlciBzZW1hbnRpY3Mgb2YgQ0hBUiBjb21wYXJpc29ucyBpbiBzb21lIGNvcm5lcgo.PiBjYXNlcyB0aGF0IGludm9sdmUgY29udHJvbCBjaGFyYWN0ZXJzIHdpdGggdmFsdWVzIHRoYXQgYXJlIGxlc3MgdGhhbiAweDIwCj4.IChzcGFjZSkuCgpXaGF0IG1hdHRlcnMgaW4gZ2VuZXJhbCBpc24ndCB3aGVyZSB0aGUgY2hhcmFjdGVycyABMAEBAQE- X-Mailer: YahooMailWebService/0.8.160.587 References: <20131011194437.GA3614@momjian.us> Message-ID: <1381525130.59803.YahooMailNeo@web162902.mail.bf1.yahoo.com> Date: Fri, 11 Oct 2013 13:58:50 -0700 (PDT) From: Kevin Grittner Reply-To: Kevin Grittner Subject: Re: [SQL] Comparison semantics of CHAR data type To: Bruce Momjian , Thomas Fanghaenel Cc: PostgreSQL-development In-Reply-To: <20131011194437.GA3614@momjian.us> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Pg-Spam-Score: -2.0 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org Bruce Momjian wrote: > Thomas Fanghaenel wrote: >> I was wondering about the proper semantics of CHAR comparisons in some c= orner >> cases that involve control characters with values that are less than 0x20 >> (space). What matters in general isn't where the characters fall when comparing individual bytes, but how the strings containing them sort according to the applicable collation.=A0 That said, my recollection of the spec is that when two CHAR(n) values are compared, the shorter should be blank-padded before making the comparison.=A0 *That* said, I think the general advice is to stay away from CHAR(n) in favor or VARCHAR(n) or TEXT, and I think that is good advice. > I am sorry for this long email, but I would be interested to see what > other hackers think about this issue. Since we only have the CHAR(n) type to improve compliance with the SQL specification, and we don't generally encourage its use, I think we should fix any non-compliant behavior.=A0 That seems to mean that if you take two CHAR values and compare them, it should give the same result as comparing the same two values as VARCHAR using the same collation with the shorter value padded with spaces. So this is correct: test=3D# select 'ab'::char(3) collate "en_US" < E'ab\n'::char(3) collate "e= n_US"; =A0?column? ---------- =A0t (1 row) ... because it matches: test=3D# select 'ab '::varchar(3) collate "en_US" < E'ab\n'::varchar(3) col= late "en_US"; =A0?column? ---------- =A0t (1 row) But this is incorrect: test=3D# select 'ab'::char(3) collate "C" < E'ab\n'::char(3) collate "C"; =A0?column? ---------- =A0t (1 row) ... because it doesn't match: test=3D# select 'ab '::varchar(3) collate "C" < E'ab\n'::varchar(3) collate= "C"; =A0?column? ---------- =A0f (1 row) Of course, I have no skin in the game, because it took me about two weeks after my first time converting a database with CHAR columns to PostgreSQL to change them all to VARCHAR, and do that as part of all future conversions. -- Kevin Grittner EDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company --=20 Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers