Search Postgresql Archives

Re: reverse strpos?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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/

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux