pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Re: select 3 characters
5+ messages / 5 participants
[nested] [flat]

* select 3 characters
@ 2003-05-15 20:05 Cyber Join <cyberjoin@linuxmail.org>
  2003-05-13 05:57 ` Re: select 3 characters A.Bhuvaneswaran <bhuvansql@myrealbox.com>
  2003-05-15 20:58 ` Re: select 3 characters Josh Berkus <josh@agliodbs.com>
  2003-05-15 21:27 ` Re: select 3 characters Richard Huxton <dev@archonet.com>
  0 siblings, 3 replies; 5+ messages in thread

From: Cyber Join @ 2003-05-15 20:05 UTC (permalink / raw)
  To: pgsql-sql

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



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: select 3 characters
  2003-05-15 20:05 select 3 characters Cyber Join <cyberjoin@linuxmail.org>
@ 2003-05-13 05:57 ` A.Bhuvaneswaran <bhuvansql@myrealbox.com>
  2 siblings, 0 replies; 5+ messages in thread

From: A.Bhuvaneswaran @ 2003-05-13 05:57 UTC (permalink / raw)
  To: Cyber Join <cyberjoin@linuxmail.org>; +Cc: pgsql-sql

> 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





^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: select 3 characters
  2003-05-15 20:05 select 3 characters Cyber Join <cyberjoin@linuxmail.org>
@ 2003-05-15 20:58 ` Josh Berkus <josh@agliodbs.com>
  2003-05-15 22:13   ` Re: select 3 characters Jeff Eckermann <jeff_eckermann@yahoo.com>
  2 siblings, 1 reply; 5+ messages in thread

From: Josh Berkus @ 2003-05-15 20:58 UTC (permalink / raw)
  To: Cyber Join <cyberjoin@linuxmail.org>; pgsql-sql

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 Berkus
 Aglio Database Solutions
 San Francisco




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: select 3 characters
  2003-05-15 20:05 select 3 characters Cyber Join <cyberjoin@linuxmail.org>
  2003-05-15 20:58 ` Re: select 3 characters Josh Berkus <josh@agliodbs.com>
@ 2003-05-15 22:13   ` Jeff Eckermann <jeff_eckermann@yahoo.com>
  0 siblings, 0 replies; 5+ messages in thread

From: Jeff Eckermann @ 2003-05-15 22:13 UTC (permalink / raw)
  To: Cyber Join <cyberjoin@linuxmail.org>; pgsql-sql

--- 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



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: select 3 characters
  2003-05-15 20:05 select 3 characters Cyber Join <cyberjoin@linuxmail.org>
@ 2003-05-15 21:27 ` Richard Huxton <dev@archonet.com>
  2 siblings, 0 replies; 5+ messages in thread

From: Richard Huxton @ 2003-05-15 21:27 UTC (permalink / raw)
  To: Cyber Join <cyberjoin@linuxmail.org>; pgsql-sql

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



^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2003-05-15 22:13 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-05-15 20:05 select 3 characters Cyber Join <cyberjoin@linuxmail.org>
2003-05-13 05:57 ` A.Bhuvaneswaran <bhuvansql@myrealbox.com>
2003-05-15 20:58 ` Josh Berkus <josh@agliodbs.com>
2003-05-15 22:13   ` Jeff Eckermann <jeff_eckermann@yahoo.com>
2003-05-15 21:27 ` Richard Huxton <dev@archonet.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox