Pl/Python error when import "from __future__"

Поиск
Список
Период
Сортировка
От Davi Duarte
Тема Pl/Python error when import "from __future__"
Дата
Msg-id BAY136-W28E48255D4B0E68577132B6BF0@phx.gbl
обсуждение исходный текст
Ответы Re: Pl/Python error when import "from __future__"  (Marco Colombo <pgsql@esiway.net>)
Список pgsql-general
Hello,

I'm using PL/Python in PostegreSQL 9.0.3 and Python 2.6.5, I want to use a feature of Python 3, Python have an option to import a module from future version of Python.

In my case, I want to use the Python 3 division module, because it returns a float division of integers by defaut, which in Python 2.x only returns an integer, then I need use division module of the Python 3.

So to import a module from a future version, simply:

from __future__ import modulename

In my case I'm importing the division:

from __future__ import division

Python must requires that the import be in the first line of code, then that is my problem, e.g., when running the function below:

CREATE OR REPLACE FUNCTION test() RETURNS text AS $$
from __future__ import division
a = "8/5"
return eval(a)
$$ LANGUAGE plpython2u;

returns the following error:

SyntaxError: from __future__ imports must occur at the beginning of the file

But "from __future__ ..." is on first line of code.

Has anyone had this error? and what may be this error? a bug in PL/Python? How can I fix this error?

Thanks,

Davi Duarte.

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

Предыдущее
От: "Gauthier, Dave"
Дата:
Сообщение: Re: Access to NEW.column outside of a trigger function.
Следующее
От: Carlo Stonebanks
Дата:
Сообщение: Sequence names have 64 character limit?