pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jeff Eckermann <jeff_eckermann@yahoo.com>
To: Cyber Join <cyberjoin@linuxmail.org>
To: pgsql-sql@postgresql.org
Subject: Re: select 3 characters
Date: Thu, 15 May 2003 15:13:06 -0700 (PDT)
Message-ID: <20030515221306.37113.qmail@web20809.mail.yahoo.com> (raw)
In-Reply-To: <200305151358.27937.josh@agliodbs.com>

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



view thread (5+ messages)

Message-ID: <20030515221306.37113.qmail@web20809.mail.yahoo.com>
Permalink:  ../20030515221306.37113.qmail@web20809.mail.yahoo.com/
Also on:    postgresql.org/message-id/20030515221306.37113.qmail@web20809.mail.yahoo.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: jeff_eckermann@yahoo.com, cyberjoin@linuxmail.org
  Subject: Re: select 3 characters
  In-Reply-To: <20030515221306.37113.qmail@web20809.mail.yahoo.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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