Re: Identifying Reason for Column Name Returned by SELECT

From: Darren Duncan <darren(at)darrenduncan(dot)net>
To: Rich Shepard <rshepard(at)appl-ecosys(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Identifying Reason for Column Name Returned by SELECT
Date: 2011-09-14 16:45:15
Message-ID: 4E70DA1B.7050606@darrenduncan.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Your example suggests that the "GW-22" is a substring of the field followed by
trailing spaces so you'll want something that searches substrings, whereas "="
will always just test on matching the entire field.

Try "like" by default, such as "where site_id like 'GW-22 %'". I added the
space between the 22 and the wildcard % so that the field containing just
'GW-22' isn't also matched.

If you need something more specific than simple substring match, you can use a
regular expression, which I think is spelled like "where site_id ~ '...'" but
check the manual to be sure about regexp syntax. But "like" will probably do
you here.

-- Darren Duncan

Rich Shepard wrote:
> I run this SELECT statement on a table:
>
> select distinct(site_id) from chemistry order by site_id;
>
> and in the returned set I see:
>
> GW-21
> GW-22
> GW-22 +
>
> GW-24
>
> I want to find that row returning 'GW-22 +' because I believe it
> should be 'GW-23'. However, my attempts to retrieve that row keep failing.
> I've tried these statements:
>
> select count(*) from chemistry where site_id = 'GW-22 +';
> count -------
> 0
> (1 row)
>
> yet,
>
> select count(*) from chemistry where site_id = 'GW-22';
> count -------
> 803
> (1 row)
>
> Looking for the blank row also fails when I try to specify site_id as is
> null, = ' ', or =''.
>
> Please point me to the proper way of finding this rogue row so I can
> correct the value in the site_id column.
>
> TIA,
>
> Rich
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Robert Treat 2011-09-14 16:46:05 Re: PostgreSQL benchmarked on XFS vs ZFS vs btrfs vs ext4
Previous Message Steve Crawford 2011-09-14 16:42:31 Re: Identifying Reason for Column Name Returned by SELECT