Re: Add SPI results constants available for PL/*

From: Samuel PHAN <samuel(at)nomao(dot)com>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Christopher Browne <cbbrowne(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Add SPI results constants available for PL/*
Date: 2012-01-04 23:58:19
Message-ID: CAC4O=anySvaFV_Cnxh_REnYuCUDKwscPT45kTykiuHE41pEoCA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I agree with Pavel also. Putting these constants in the pg_catalog isn't
the cleanest solution.

Though one can make its own little lib in python, perl, whatever, to store
these constants, it would be better if through the compilation, these C
constants were copied in a way for PL/*.

I can't really tell for the procedure languages other than PL/python but
for this one, typically, it would be nice to have them in "*plpy*" module.

result = plpy.execute(sql_query)
if result.status() == plpy.SPI_OK_SELECT:
# something...

Since the PG developers are the one who decide these constant values, it's
quite logic that the equivalent constants for each PL are made available by
the PG developers and not each geek to redo the wheel on it's own.

Well, it's not a crucial feature of course, but a nice to have, that was my
point ;-)

Have a nice day, guys,

Samuel

On Wed, Jan 4, 2012 at 3:11 AM, Andrew Dunstan <andrew(at)dunslane(dot)net> wrote:

>
>
> On 01/03/2012 08:40 PM, Robert Haas wrote:
>
>> On Tue, Jan 3, 2012 at 9:33 AM, Pavel Stehule<pavel(dot)stehule(at)gmail(dot)**com<pavel(dot)stehule(at)gmail(dot)com>>
>> wrote:
>>
>>> I'd suppose it interesting to add a table to pg_catalog containing this
>>>> data.
>>>>
>>> - it is useless overhead
>>>
>> I tend to agree.
>>
>> I am expecting so definition some constants in Perl, Python is simple
>>>
>> Presumably one could instead write a script to transform the list of
>> constants into a .pm file that could be loaded into the background, or
>> whatever PL/python's equivalent of that concept is. Not sure if
>> there's a better way to do it.
>>
>
> Yeah, I'm with you and Pavel. Here's my quick perl one-liner to produce a
> set of SPI_* constants for pl/perl. I'm looking at the best way to include
> this in the bootstrap code.
>
> perl -ne 'BEGIN { print "use constant\n{\n"; } END { print "};\n"; }
> print "\t$1 => $2,\n" if /#define (SPI_\S+)\s+\(?(-?\d+)\)?/;'
> src/include/executor/spi.h
>
>
> cheers
>
> andrew
>
>

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2012-01-04 23:59:17 Re: pg_restore direct to database is broken for --insert dumps
Previous Message Tom Lane 2012-01-04 23:37:32 Re: BUG #6379: SQL Function Causes Back-end Crash