Re: Question regarding strings . . .

From: Joe Conway <joseph(dot)conway(at)home(dot)com>
To: "Peter E(dot) Chen" <pchen3(at)jhmi(dot)edu>
Cc: "Postgres (General)" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Question regarding strings . . .
Date: 2002-01-07 22:12:11
Message-ID: 3C3A1D3B.1010802@home.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Peter E. Chen wrote:

> Hey All,
>
> I have a table with one column and one row (of datatype text). I am simply
> trying to retrieve a substring from the column value. I've looked at the
> built-in substring functions and I'd like to know what is the best way to do
> this. What would the SQL statement (or possibly the PL/pgSQL code) look
> like?
>
> Any help is appreciated.
>
> Thanks,
> Peter
>
> Johns Hopkins Institute of Genetic Medicine

test=# create table mystring(f1 text);
CREATE
test=# insert into mystring values('abcdefg');
INSERT 37853285 1
test=# select substr(f1,2,1) from mystring;
substr
--------
b
(1 row)

test=# select substr(f1,2,2) from mystring;
substr
--------
bc
(1 row)

test=# select substr(f1,2) from mystring;
substr
--------
bcdefg
(1 row)

test=# select substring(f1 from 2 for 1) from mystring;
substring
-----------
b
(1 row)

test=# select substring(f1 from 2 for 2) from mystring;
substring
-----------
bc
(1 row)

test=# select substring(f1 from 2) from mystring;
substring
-----------
bcdefg
(1 row)

See http://www.postgresql.org/idocs/index.php?functions-string.html for more information.

HTH,

Joe

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Martijn van Oosterhout 2002-01-07 22:32:26 Re: Restart postgres in php as nobody
Previous Message Peter E. Chen 2002-01-07 21:22:48 Question regarding strings . . .