Pantek Library
Hosting Provided By
CybrHost
High Speed Hosting

Re: [GENERAL] reverse strpos?

From: A. Kretschmer <andreas.kretschmer(at)schollglas.com>
Date: Mon Nov 12 2007 - 12:01:09 EST


am Mon, dem 12.11.2007, um 8:48:29 -0800 mailte David Fetter folgendes:
> > > Is there a function that?ll return the position of the last
> > > occurance of a char in a string?
> > >
> >
> > write a function to revert the string and use strpos().
> >
> > create or replace function rev(varchar) returns varchar as $$
> > declare
> > ...
> > $$ language plpgsql immutable;
> >
> >
> > Andreas
>
> PL/Perl might be easier:
>
> CREATE OR REPLACE FUNCTION rev(TEXT)
> RETURNS TEXT
> IMMUTABLE
> LANGUAGE plperl
> AS $$
> return reverse($_[0]);
> $$;

heh, the PERL-Guru ;-)

>
> CREATE OR REPLACE FUNCTION rev(TEXT)
> RETURNS TEXT
> IMMUTABLE
> LANGUAGE SQL
> AS $$
> SELECT array_to_string(
> ARRAY(
> SELECT substr($1,i,1)
> FROM generate_series(length($1),1,-1) AS i
> ),
> ''
> );
> $$;

Nice.

The generate_series()-function are really great.

Andreas

-- 
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID:   0x3FFF606C, privat 0x7F4584DA   
http://wwwkeys.de.pgp.net

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

               
http://archives.postgresql.org/
Received on Mon Nov 12 12:03:10 2007

This archive was generated by hypermail 2.1.8 : Mon Jun 16 2008 - 19:43:30 EDT


Contact Us  Legal Notices  Order Services Online 
Pantek Home  Privacy Policy  IT news  Site Map  Pantek Library