Re: pl/perl Documentation

Поиск
Список
Период
Сортировка
От Duncan Adams (DNS)
Тема Re: pl/perl Documentation
Дата
Msg-id 7DD34E6DF5CD1B4283DDAB96A855DCED2F3375@vodabemail1.vodacom.co.za
обсуждение исходный текст
Ответ на pl/perl Documentation  ("Duncan Adams (DNS)" <duncan.adams@vcontractor.co.za>)
Список pgsql-novice
thanx to all that helped

here is the solution

CREATE FUNCTION remspace(TEXT) RETURNS TEXT AS '
    my $rem = shift;
    $rem =~ s/\\s+//g;
    return $rem;
' LANGUAGE 'plperl';

URL's that i found useful.

The postgres manual
http://www.linuxgazette.com/issue67/nielsen.html

ta
duncan

-----Original Message-----
From: Joshua b. Jore [mailto:josh@greentechnologist.org]
Sent: Wednesday, May 22, 2002 5:56 PM
To: Tom Lane
Cc: Duncan Adams (DNS); pgsql-novice@postgresql.org
Subject: Re: [NOVICE] pl/perl Documentation


So as a perl monger I'll pitch in. I don't use PL/Perl because I know not
to expect ISPs to support it - I haven't actually used PL/Perl. I do use
PL/SQL and Perl seperately.

Here's a cleaned up version:

CREATE FUNCTION remspace(TEXT) RETURNS TEXT AS '
    return map { s/\s*// } @_;
' LANGUAGE 'plperl' WITH (isstrict);

You may have to prepend that backslash - it might be interpreted as s/s*//
which isn't right. Perform SELECT prosrc FROM pg_proc WHERE pronam =
'remspace' to see the way it came through.

Now for the perl bits:

If you want to apply the regex to an array you have to iterate over it
somehow. In this case the map operation just applies the code block
against each element in the array and returns the result.

The 'return @_' statement may or may not need a semicolon. Perl doesn't
require you use semi-colons where they aren't needed (generally). The
PL/Perl interpreter might require it anyway if it transposes your code
into other bits of code. It's just a good idea to have the semicolon
though it might not be causing you a problem.

Joshua b. Jore
http://www.greentechnologist.org

On Wed, 22 May 2002, Tom Lane wrote:

> "Duncan Adams  (DNS)" <duncan.adams@vcontractor.co.za> writes:
>
> I'm not much of a Perl hacker, but even I can see that this is not good
> Perl.  You need a semicolon to finish the return statement, and I think
> you want to manipulate the first element of the @_ array, not the whole
> array.  So something like
>
> CREATE or REPLACE FUNCTION remspace(TEXT) RETURN TEXT AS '
>     $_[0] =~ s/\s*//;
>     return $_[0];
> ' LANGUAGE 'plperl';
>
> would probably do what you want.
>
> I'd recommend getting hold of a book about Perl.
>
>             regards, tom lane
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org
>

В списке pgsql-novice по дате отправления:

Предыдущее
От: Ron Johnson
Дата:
Сообщение: Re: optimising data load
Следующее
От: John Taylor
Дата:
Сообщение: Re: optimising data load