Re: Fix PL/Python metadata when there is no result

Jean-Baptiste Quenot <jbq@caraldi.com>

From: Jean-Baptiste Quenot <jbq@caraldi.com>
To: Peter Eisentraut <peter_e@gmx.net>
Cc: pgsql-hackers@postgresql.org
Date: 2012-02-25T17:03:27Z
Lists: pgsql-hackers
2012/2/24 Peter Eisentraut <peter_e@gmx.net>:
> On fre, 2012-02-10 at 17:44 +0100, Jean-Baptiste Quenot wrote:
>>
>> Please find attached a patch that solves this issue.  Instead of a PG
>> crash, we get the following message:
>>
>> ERROR:  plpy.Error: no result fetched
>
> Hmm, should it be an error or just return None?  Python DB-API
> cursor.description returns None if no result set was returned.

IMO raising an error is much better because:

1) It is not a valid usecase to retrieve result metadata when no rows
are expected to be returned

2) The various metadata methods return a sequence.  Checking for null
value in this case is not a very good programming style.  I expect to
find an empty list when no data is available.

Cheers,
-- 
Jean-Baptiste Quenot