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

From: Hannu Krosing <hannu(at)skype(dot)net>
To: Guido Goldstein <guido(dot)goldstein(at)a-nugget(dot)org>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org, pgsql-patches(at)postgresql(dot)org
Subject: Re: [HACKERS] pgsql: Fix for plpython functions; return true/false for boolean,
Date: 2007-01-31 09:08:00
Message-ID: 1170234480.3198.17.camel@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers pgsql-hackers pgsql-patches

Ü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

In response to

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Bruce Momjian 2007-01-31 12:57:37 Re: [HACKERS] pgsql: Fix for plpython functions; return true/false for boolean,
Previous Message Peter Eisentraut 2007-01-31 08:33:34 pgsql: Translation updates

Browse pgsql-hackers by date

  From Date Subject
Next Message Magnus Hagander 2007-01-31 09:58:59 Re: [BUGS] Missing error message on missing ssl-key-files
Previous Message Jens-Wolfhard Schicke 2007-01-31 08:28:42 Re: Improving NOT IN

Browse pgsql-patches by date

  From Date Subject
Next Message Bruce Momjian 2007-01-31 12:57:37 Re: [HACKERS] pgsql: Fix for plpython functions; return true/false for boolean,
Previous Message Teodor Sigaev 2007-01-31 07:45:46 Re: Lock compatibility matrix