Re: Question from a newbie - Mailing list pgsql-general

From Tom Lane
Subject Re: Question from a newbie
Date
Msg-id 27670.1097204103@sss.pgh.pa.us
Whole thread Raw
In response to Question from a newbie  ("Kiarash Bodouhi" <kbodouhi@yahoo.com>)
Responses Re: Question from a newbie
List pgsql-general
"Kiarash Bodouhi" <kbodouhi@yahoo.com> writes:
> I have two questions. First, is it possible to call other functions
> from plpython functions? I used following but didn't work. Any comments?

> CREATE OR REPLACE FUNCTION test4()
>   RETURNS "varchar" AS
> '
> return plpy.execute("select getcountrycode("9821788")",1)
> '
>   LANGUAGE 'plpythonu' VOLATILE;

Didn't work how, exactly?  I don't know much Python but I'd think you
have a quote-nesting mistake there.  And anyway, shouldn't it be single
quotes in the SQL command, ie

    return plpy.execute("select getcountrycode('9821788')",1)

which you actually need to write as

    return plpy.execute("select getcountrycode(\'9821788\')",1)

because you're already inside a single-quoted string.

> Also, do you know any better way (apart from psql) to enter and test
> functions? I used pgAdmin, but it didn't work properly with plpython.

Dunno; it is certainly possible that pgAdmin isn't careful about
preserving leading indentation.  I'd suggest taking that up with the
pgAdmin guys; I'm sure they'll fix it when you point out that python
is picky about this.

            regards, tom lane

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Index problem.... GIST (tsearch2)
Next
From: Dennis Gearon
Date:
Subject: Re: flattened tables with normalized tables