Re: select 3 characters

From: Jeff Eckermann <jeff_eckermann(at)yahoo(dot)com>
To: Cyber Join <cyberjoin(at)linuxmail(dot)org>, pgsql-sql(at)postgresql(dot)org
Subject: Re: select 3 characters
Date: 2003-05-15 22:13:06
Message-ID: 20030515221306.37113.qmail@web20809.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

--- Josh Berkus <josh(at)agliodbs(dot)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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Christoph Haller 2003-05-16 08:41:40 Re: See Temp Table from Trigger
Previous Message Mike Winter 2003-05-15 21:44:29 Efficiency Issue with "SELECT IN (..)" and "SELECT .. OR .."