X-Original-To: pgsql-sql@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 26703475F34 for ; Thu, 15 May 2003 18:13:07 -0400 (EDT) Received: from postgresql.org ([64.49.215.8]) by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with ESMTP id 27782-02 for ; Thu, 15 May 2003 18:13:05 -0400 (EDT) Received: from web20809.mail.yahoo.com (web20809.mail.yahoo.com [216.136.226.198]) by postgresql.org (Postfix) with SMTP id 31AD0475D0F for ; Thu, 15 May 2003 18:13:05 -0400 (EDT) Message-ID: <20030515221306.37113.qmail@web20809.mail.yahoo.com> Received: from [208.13.35.65] by web20809.mail.yahoo.com via HTTP; Thu, 15 May 2003 15:13:06 PDT Date: Thu, 15 May 2003 15:13:06 -0700 (PDT) From: Jeff Eckermann Subject: Re: select 3 characters To: Cyber Join , pgsql-sql@postgresql.org In-Reply-To: <200305151358.27937.josh@agliodbs.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new X-Archive-Number: 200305/341 X-Sequence-Number: 13506 --- Josh Berkus 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