pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ross J. Reedstrom <reedstrm@rice.edu>
To: John J. Allison <john@joss.ucar.edu>
Cc: pgsql-sql@postgresql.org
Subject: Re: LIKE with no wildcards problem
Date: Thu, 28 Feb 2002 13:46:32 -0600
Message-ID: <20020228194632.GD11120@rice.edu> (raw)
In-Reply-To: <200202281854.LAA13770@virga.joss.ucar.edu>
References: <200202281854.LAA13770@virga.joss.ucar.edu>

On Thu, Feb 28, 2002 at 11:54:02AM -0700, John J. Allison wrote:
> When doing a select with a LIKE in the where clause,
> I always get 0 rows if I do not use a wildcard [_%].
> LIKE should act like = in this case (and the docs say so).
> A select without a from correctly returns 't'.
> I am using PostgreSQL 7.1.3 on Solaris.
> What am I missing?

The whitespace. Your field is of type CHAR(n), which pads all strings
to the defined width. This behavior is required by the standard. Try
using VARCHAR or TEXT instead.

Ross

> 
> Thanks,
> 
> John Allison
> john@joss.ucar.edu
> 
> 
> catalog^> create table foo ( bar char(8) )
> CREATE
> 
> catalog^> insert into foo values ( 'abc' )
> INSERT 38413 1
> 
> catalog^> insert into foo values ( '2.20' )
> INSERT 38414 1
> 
> catalog^> select * from foo
>    bar    
> ----------
>  abc     
>  2.20    
> (2 rows)
> 
> catalog^> select * from foo where bar like 'abc'
>  bar 
> -----
> (0 rows)
> 
> catalog^> select * from foo where bar like 'abc%'
>    bar    
> ----------
>  abc     
> (1 row)
> 
> catalog^> select 'abc' like 'abc'
>  ?column? 
> ----------
>  t
> (1 row)
> 
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster



view thread (4+ messages)

Message-ID: <20020228194632.GD11120@rice.edu>
Permalink:  ../20020228194632.GD11120@rice.edu/
Also on:    postgresql.org/message-id/20020228194632.GD11120@rice.edu

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: reedstrm@rice.edu, john@joss.ucar.edu
  Subject: Re: LIKE with no wildcards problem
  In-Reply-To: <20020228194632.GD11120@rice.edu>

* 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