Thread: Re: [HACKERS] pgsql: Fix for plpython functions; return true/false for boolean,

Re: [HACKERS] pgsql: Fix for plpython functions; return true/false for boolean,

From
Hannu Krosing
Date:
Ühel kenal päeval, T, 2007-01-30 kell 14:52, kirjutas Guido Goldstein:

> I've checked the patch with postgres 8.1.3 and 8.2.1
> with python 2.4 and 2.5 on intel 32 bit and amd 64 bit
> systems; all systems running linux.
>
> *And* it's not a feature patch but a bug-fixing one!
> Python is a language with strong typing, so silently
> converting a datatype is a bug -- not a feature.

Python is not that strongly typed. More it is a protocol based language,
meaning that you should not relay on "type" of any variable, but rather
see if it does what you want - so any type supporting iteration can be
used if "for" and any thing not None, 0 or empty sequence/dict is
considered to be TRUE

True and False are actually 1 and 0 with different spelling ;)

>>> True+2
3
>>> 1/False
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ZeroDivisionError: integer division or modulo by zero

> Btw, you'll lose the type information of boolean columns in
> trigger functions (NEW and OLD dicts, no explicit parameters),
> which does cause problems.
>
> > That said, we certainly try to support a few more versions of Python
> [...]
>
> If you want to support python 2.3 use the attached patch, which also
> works for the newer python versions.
> The Python 2.3 branch is the oldest _officially_ supported python version.

Officially by who ?

2.3 was the first version to introduce bool as a subtype of int, in
2.2.3 True and False were introduced as two variables pointing to
integers 1 and 0.

So to make your patch ok on all python versions, just make it
conditional on python version being 2.3 or bigger, and return int for
pre-2.3.

> Anyway, to circumvent the above mentiond point a) I herewith anncounce
> that the included patch might break the buildfarm.

:)

> Cheers
>    Guido
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: don't forget to increase your free space map settings
--
----------------
Hannu Krosing
Database Architect
Skype Technologies OÜ
Akadeemia tee 21 F, Tallinn, 12618, Estonia

Skype me:  callto:hkrosing
Get Skype for free:  http://www.skype.com



Re: [HACKERS] pgsql: Fix for plpython functions; return true/false for boolean,

From
Bruce Momjian
Date:
Hannu Krosing wrote:
> Officially by who ?
>
> 2.3 was the first version to introduce bool as a subtype of int, in
> 2.2.3 True and False were introduced as two variables pointing to
> integers 1 and 0.
>
> So to make your patch ok on all python versions, just make it
> conditional on python version being 2.3 or bigger, and return int for
> pre-2.3.

I thought about suggesting that, but do we want plpython to have
different result behavior based on the version of python used?  I didn't
think so.

--
  Bruce Momjian   bruce@momjian.us
  EnterpriseDB    http://www.enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +

Re: [HACKERS] pgsql: Fix for plpython functions; return true/false for boolean,

From
Alvaro Herrera
Date:
Bruce Momjian wrote:
> Hannu Krosing wrote:
> > Officially by who ?
> >
> > 2.3 was the first version to introduce bool as a subtype of int, in
> > 2.2.3 True and False were introduced as two variables pointing to
> > integers 1 and 0.
> >
> > So to make your patch ok on all python versions, just make it
> > conditional on python version being 2.3 or bigger, and return int for
> > pre-2.3.
>
> I thought about suggesting that, but do we want plpython to have
> different result behavior based on the version of python used?  I didn't
> think so.

The alternative would be, what, including the whole python source in our
distribution?  Because the Python guys themselves changed the behavior
depending on the version.

--
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.

Re: [HACKERS] pgsql: Fix for plpython functions; return true/false for boolean,

From
Tino Wildenhain
Date:
Bruce Momjian schrieb:
> Hannu Krosing wrote:
>> Officially by who ?
>>
>> 2.3 was the first version to introduce bool as a subtype of int, in
>> 2.2.3 True and False were introduced as two variables pointing to
>> integers 1 and 0.
>>
>> So to make your patch ok on all python versions, just make it
>> conditional on python version being 2.3 or bigger, and return int for
>> pre-2.3.
>
> I thought about suggesting that, but do we want plpython to have
> different result behavior based on the version of python used?  I didn't
> think so.

Why not? Python2.2 is rarely in use anymore and users of this would get
the same behavior. Users of python2.3 and up would get the additionally
cleaned boolean interface - also users which go the from __future__
import ... way. Thats how python works and develops forth and we should
not work against that from postgres side.

So I'm indeed +1 for conditional approach.

Regards
Tino

Re: [HACKERS] pgsql: Fix for plpython functions; return true/false for boolean,

From
Bruce Momjian
Date:
Tino Wildenhain wrote:
> Bruce Momjian schrieb:
> > Hannu Krosing wrote:
> >> Officially by who ?
> >>
> >> 2.3 was the first version to introduce bool as a subtype of int, in
> >> 2.2.3 True and False were introduced as two variables pointing to
> >> integers 1 and 0.
> >>
> >> So to make your patch ok on all python versions, just make it
> >> conditional on python version being 2.3 or bigger, and return int for
> >> pre-2.3.
> >
> > I thought about suggesting that, but do we want plpython to have
> > different result behavior based on the version of python used?  I didn't
> > think so.
>
> Why not? Python2.2 is rarely in use anymore and users of this would get
> the same behavior. Users of python2.3 and up would get the additionally
> cleaned boolean interface - also users which go the from __future__
> import ... way. Thats how python works and develops forth and we should
> not work against that from postgres side.
>
> So I'm indeed +1 for conditional approach.

Fine if people think that is OK.  Please submit a patch that is
conditional on the python version.

--
  Bruce Momjian   bruce@momjian.us
  EnterpriseDB    http://www.enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +

Tino Wildenhain <tino@wildenhain.de> writes:
> Bruce Momjian schrieb:
>> I thought about suggesting that, but do we want plpython to have
>> different result behavior based on the version of python used?  I didn't
>> think so.

> Why not?

Indeed --- the underlying language changed, so I should think that
python users would *expect* different behavior.  +1 on a conditional
patch (see PY_VERSION_HEX...)

            regards, tom lane