Thread: select 3 characters

select 3 characters

From
"Cyber Join"
Date:
Hi I need select the first 3 characters from a table

I try this but doesn't work

"SELECT left(data,3) AS value FROM table;"

i see the left function doesn't work what is the similar function in postgresql

Thanks

CJ
-- 
______________________________________________
http://www.linuxmail.org/
Now with e-mail forwarding for only US$5.95/yr

Powered by Outblaze


Re: select 3 characters

From
Josh Berkus
Date:
CJ -

You might want to join the NOVICE list and post this kind of question there,
should you have more.

> Hi I need select the first 3 characters from a table
>
> I try this but doesn't work
>
> "SELECT left(data,3) AS value FROM table;"
>
> i see the left function doesn't work what is the similar function in
postgresql

SUBSTR(data, 1, 3)

See "Functions And Operators" in the online docs for more.

--
-Josh BerkusAglio Database SolutionsSan Francisco



Re: select 3 characters

From
Richard Huxton
Date:
On Thursday 15 May 2003 9:05 pm, Cyber Join wrote:
> Hi I need select the first 3 characters from a table
>
> I try this but doesn't work
>
> "SELECT left(data,3) AS value FROM table;"
>
> i see the left function doesn't work what is the similar function in
> postgresql

It's called "substr":

richardh=# select substr('abcde',3);substr
--------cde
(1 row)

richardh=# select substr('abcde',1,3);substr
--------abc
(1 row)

--  Richard Huxton


Re: select 3 characters

From
Jeff Eckermann
Date:
--- Josh Berkus <josh@agliodbs.com> wrote:
> CJ -
> 
> You might want to join the NOVICE list and post this
> kind of question there, 
> should you have more.
> 
> > Hi I need select the first 3 characters from a
> table
> > 
> > I try this but doesn't work
> > 
> > "SELECT left(data,3) AS value FROM table;"
> > 
> > i see the left function doesn't work what is the
> similar function in 
> postgresql
> 
> SUBSTR(data, 1, 3)
> 
> See "Functions And Operators" in the online docs for
> more.

PostgreSQL lets you define your own functions, so you
could do something like:

CREATE OR REPLACE FUNCTION left(text, integer) RETURNS
text AS '
SELECT substr($1, 1, $2);
' LANGUAGE 'SQL';

If you have a lot of code already written using the
"left" function, that will save you from having to
rewrite it.

Look at "CREATE FUNCTION" in the "SQL Commands"
section of the manual; also "Procedural Languages" in
the "Programmers Guide".  Do a search on "function
overloading", so you will be able to define a function
that works regardless of the datatypes fed to it.

__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com


Re: select 3 characters

From
"A.Bhuvaneswaran"
Date:
> I try this but doesn't work
> 
> "SELECT left(data,3) AS value FROM table;"
> 

Left? Substr is the function to extract a substring. substr(data, 1, 3) 
would solve your problem.

regards,
bhuvaneswaran