Re: Question regarding strings . . . - Mailing list pgsql-general

From Joe Conway
Subject Re: Question regarding strings . . .
Date
Msg-id 3C3A1D3B.1010802@home.com
Whole thread Raw
In response to Question regarding strings . . .  ("Peter E. Chen" <pchen3@jhmi.edu>)
List 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





pgsql-general by date:

Previous
From: "Peter E. Chen"
Date:
Subject: Question regarding strings . . .
Next
From: Martijn van Oosterhout
Date:
Subject: Re: Restart postgres in php as nobody