Re: left() in postgres

From: Peter Nixon <listuser(at)peternixon(dot)net>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: left() in postgres
Date: 2002-10-25 17:14:24
Message-ID: 20021025201424.59b31a03.listuser@peternixon.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I guess I don't understand how to use it properly. can anyone give me some
more help. When I fire off the following query (at a database of radius
records)

SELECT substring('CalledStationId' from 2 for 3) FROM calls WHERE
h323connecttime BETWEEN DATE'YESTERDAY' AND (DATE'YESTERDAY' + INTERVAL'1
min');

I get:

substring
-----------
all
all
all
all
all
all
all
all
(8 rows)

I if what I want is the behaviour mysql gives with left. ie.

SELECT left(CalledStationId, 3) FROM calls WHERE h323connecttime BETWEEN
DATE'YESTERDAY' AND (DATE'YESTERDAY' + INTERVAL'1 min');

result
-----------
222
222
223
234
444
777
777
778
(8 rows)

ie a list of area codes (which I then want to group on to give a sum per
area code)

Can someone suggest show me a cluestick here please?

-Peter

On Fri, 25 Oct 2002 12:36:24 -0400 (EDT)
Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> wrote:

>
> Try substring().
>
> ------------------------------------------------------------------------
> ---
>
> Peter Nixon wrote:
> > Hi Guys
> >
> > I am trying to do a query similar to the following:
> >
> > select left(field,3) from table;
> >
> > Now this works in Mysql/Access etc etc, but not in postgres
> > (I am running PostgreSQL 7.2)
> >
> > Can anyone suggest how to do this in postgres? I have a database with
> > many millions of records, and this functionality is essential for me.
> >
> > PS. I did do a google search etc before posting.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2002-10-25 17:25:20 Re: left() in postgres
Previous Message Nuno Barros 2002-10-25 17:07:50 Binary Large Objects