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