Обсуждение: multiline PL/Python function fails in *.sql

Поиск
Список
Период
Сортировка

multiline PL/Python function fails in *.sql

От
Wolfgang Rohdewald
Дата:
Hi,

as the subject says -

if I do the same interactively in the interpreter, it works.
I tried plsql < x.sql and plsql -f x.sql, both fail with this code:

create function myfunc(text) RETURNS text AS
'
plpy.notice("hallo Notiz")' LANGUAGE 'plpython';

ERROR:  plpython: Unable to compile function myfunc
exceptions.SyntaxError: invalid syntax (line 2)

This works OK in x.sql:
create function myfunc(text) RETURNS text AS
'plpy.notice("hallo Notiz")' LANGUAGE 'plpython';

but multiline only works when using psql interactively.

This seems to be python specific, as this one also works
with plsql -f x.sql:

create function simple(text) returns text as
'
BEGIN
        RETURN $1 || $1 ;
END;
' LANGUAGE 'plpgsql';

BTW I am using PostgreSQL 7.3.4

--
Wolfgang

Re: multiline PL/Python function fails in *.sql

От
Tom Lane
Дата:
Wolfgang Rohdewald <wolfgang@rohdewald.de> writes:
> but multiline only works when using psql interactively.

I'm not much of a Python user, but doesn't Python think that leading
whitespace (particularly tabs) is significant?  You may be losing
tabs if psql tries to take them as completion commands.

            regards, tom lane

Re: multiline PL/Python function fails in *.sql

От
Wolfgang Rohdewald
Дата:
solution:

CRLF line separators are correctly scanned in normal SQL and in PG/SQL
triggers but NOT in Python triggers.

I'd say this is a bug. I will retest with postgresql 7.4 when available
as a debian package.

--
Wolfgang

Re: multiline PL/Python function fails in *.sql

От
rlasjunies@free.fr (Richard LASJUNIES)
Дата:
Hi,

I reproduced the problem, using pgAdmin III.
My postgre 7.4.1 is running on WXP SP1 / cygwin

Could be link with the platform?

regards

richard

Re: multiline PL/Python function fails in *.sql

От
rlasjunies@free.fr (Richard LASJUNIES)
Дата:
Using the pgAccess tools I could add python function / triggers.

regards

richard

Re: multiline PL/Python function fails in *.sql

От
Tom Lane
Дата:
rlasjunies@free.fr (Richard LASJUNIES) writes:
> I reproduced the problem, using pgAdmin III.
> My postgre 7.4.1 is running on WXP SP1 / cygwin

Python is sensitive to leading whitespace --- perhaps whatever you
are using to enter the function is mucking up your indentation?

            regards, tom lane