Re: string functions and operators

From: John R Pierce <pierce(at)hogranch(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: string functions and operators
Date: 2010-03-23 03:49:16
Message-ID: 4BA83A3C.5080602@hogranch.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-novice pgsql-sql

Neil Stlyz wrote:
> Hello,
>
> I have a dilema and I was hoping someone here may offer guidance or
> assistance. I bet this is a very simple question for someone out there
> but I am having problems coming up with a solution. Here it is...
>
> suppose I have a field with the following values:
>
> 77.1
> 77.2
> 134.1
> 134.2
> 134.3
> 5.1
> 5.2
>
> I need two seperate SELECT queries. One would return the following
> values (everything left of the decimal point)
>
> 77
> 77
> 134
> 134
> 5
> 5
>
> The second query would return all of the values to the right of the
> decimal point:
>
> 1
> 2
> 1
> 2
> 3
> 1
> 2

silly me says..

SELECT FLOOR(x), x-FLOOR(x) FROM TABLE;

at least for numeric values.

but, in string space, ummmm...

select split_part(x,'.',1), split_part(x,'.',2) from table;

or
select regexp_replace(x, '\.[0-9]*$',''),
regexp_replace(x,'^[0-9]*\.','') from table;

or god knows how many others.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Petru Ghita 2010-03-23 03:52:46 Re: string functions and operators
Previous Message Petru Ghita 2010-03-23 03:42:34 Re: string functions and operators

Browse pgsql-novice by date

  From Date Subject
Next Message Petru Ghita 2010-03-23 03:52:46 Re: string functions and operators
Previous Message Petru Ghita 2010-03-23 03:42:34 Re: string functions and operators

Browse pgsql-sql by date

  From Date Subject
Next Message Petru Ghita 2010-03-23 03:52:46 Re: string functions and operators
Previous Message Petru Ghita 2010-03-23 03:42:34 Re: string functions and operators