Re: query varchar fields by length - Mailing list pgsql-general

From Holger Klawitter
Subject Re: query varchar fields by length
Date
Msg-id 3ADEF032.80DA7868@klawitter.de
Whole thread Raw
In response to query varchar fields by length  (Ryan Mahoney <ryan@paymentalliance.net>)
List pgsql-general
Ryan Mahoney wrote:
>
> Is it possible to select rows from a field based on the length of the data
> in a varchar field?

length works fine in a select on a varchar field.
    select a from b where length(a)=5;
You didn't ask for this, did you?

Grabbing different columns depending on values of another another column
can be done with "case":

select
    case
        when length(col_var)<5 then col_a
        when length(col_var)>5 then col_b
        else col_5
    end
from
    tbl
;

With kind regards / Mit freundlichem Gruß
    Holger Klawitter
--
Holger Klawitter
holger@klawitter.de                             http://www.klawitter.de


pgsql-general by date:

Previous
From: "Boban Acimovic"
Date:
Subject: Performances using --with-perl
Next
From: swschulz@NOSPAM.astrum.com (S. William Schulz)
Date:
Subject: PHP and pgsql 7.1