Re: plpython function problem workaround

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Ragnar Hafstað <gnari(at)simnet(dot)is>
Cc: David <dbree(at)duo-county(dot)com>, Sim Zacks <sim(at)compulab(dot)co(dot)il>, pgsql-general(at)postgresql(dot)org
Subject: Re: plpython function problem workaround
Date: 2005-03-15 21:50:06
Message-ID: 20050315215006.GA67499@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Mar 15, 2005 at 03:41:37PM +0000, Ragnar Hafstað wrote:

> actually, perl scripts with \r\n line endings will run just fine in
> unix/linux.

Indeed, and PL/Perl doesn't care. I just tested several PLs with
PostgreSQL 8.0.1 on Solaris 9 and here are the results:

PL/pgSQL CRLF ok
PL/Perl CRLF ok
PL/Ruby CRLF ok
PL/Tcl CRLF ok
PL/Python CRLF fails
PL/R CRLF fails

Details:

CREATE FUNCTION test_pgsql() RETURNS integer AS
'DECLARE x integer;\r\nBEGIN\r\nx := 123;\r\nRETURN x;\r\nEND;\r\n'
LANGUAGE plpgsql;

CREATE FUNCTION test_perl() RETURNS integer AS
'$x = 123;\r\nreturn $x;\r\n'
LANGUAGE plperl;

CREATE FUNCTION test_ruby() RETURNS integer AS
'x = 123\r\nreturn x\r\n'
LANGUAGE plruby;

CREATE FUNCTION test_tcl() RETURNS integer AS
'set x 123\r\nreturn $x\r\n'
LANGUAGE pltcl;

CREATE FUNCTION test_python() RETURNS integer AS
'x = 123\r\nreturn x\r\n'
LANGUAGE plpythonu;

CREATE FUNCTION test_r() RETURNS integer AS
'x <- 123\r\nreturn(x)\r\n'
LANGUAGE plr;

SELECT test_pgsql();
test_pgsql
------------
123
(1 row)

SELECT test_perl();
test_perl
-----------
123
(1 row)

SELECT test_ruby();
test_ruby
-----------
123
(1 row)

SELECT test_tcl();
test_tcl
----------
123
(1 row)

SELECT test_python();
ERROR: plpython: could not compile function "test_python"
DETAIL: exceptions.SyntaxError: invalid syntax (line 2)

SELECT test_r();
ERROR: R interpreter parse error
DETAIL: R parse error caught in "PLR36865 <- function() {x <- 123
return(x)
}".
CONTEXT: In PL/R function test_r

If I remove the CRs from the Python and R functions then they work:

CREATE OR REPLACE FUNCTION test_python() RETURNS integer AS
'x = 123\nreturn x\n'
LANGUAGE plpythonu;

CREATE OR REPLACE FUNCTION test_r() RETURNS integer AS
'x <- 123\nreturn(x)\n'
LANGUAGE plr;

SELECT test_python();
test_python
-------------
123
(1 row)

SELECT test_r();
test_r
--------
123
(1 row)

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Joshua D. Drake 2005-03-15 22:13:01 Re: prelimiary performance comparison pgsql vs mysql
Previous Message Jeff Davis 2005-03-15 21:44:36 Re: prelimiary performance comparison pgsql vs mysql