Re: Inconsistent results from HEX values in predicates

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Gary Cowell <gary(dot)cowell+pgsql(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Inconsistent results from HEX values in predicates
Date: 2014-11-14 14:47:59
Message-ID: 22680.1415976479@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Gary Cowell <gary(dot)cowell+pgsql(at)gmail(dot)com> writes:
> e5iso=# create table t1 (col1 character(3));
> CREATE TABLE
> e5iso=# insert into t1 values('AAA');
> INSERT 0 1
> e5iso=# insert into t1 values('000');
> INSERT 0 1
> e5iso=# insert into t1 values(' ');
> INSERT 0 1
> e5iso=# insert into t1 values(' x ');
> INSERT 0 1
> e5iso=# select col1 from t1 where col1 BETWEEN E'\x01\x01\x01' AND
> E'\xFF\xFF\xFF' ;
> col1
> ------
> AAA
> 000
> x
> (3 rows)

> So where did my ' ' row go?

> Am I missing something, are SPACES special in some way?

In a char(N) column, certainly. Read the manual.

You could dodge that by using varchar or text instead. But you may have
another problem besides trailing blanks not being significant: you're
assuming that the sort order of text is pure bytewise, which would only
be true in C locale. So this coding technique is fragile as can be
and I don't recommend it.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Andy Colson 2014-11-14 14:55:24 Re: service allowing arbitrary relations was Re: hstore, but with fast range comparisons?
Previous Message Adrian Klaver 2014-11-14 14:15:32 Re: NEW in after insert trugger contained incorrect data