Re: Add SPI results constants available for PL/*

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

2012/1/10 Andrew Dunstan <andrew(at)dunslane(dot)net>:
>
>
> On 01/10/2012 12:34 PM, Pavel Stehule wrote:
>>>
>>>
>>> Actually, now I look closer I see that PLPerl passes back a stringified
>>> status from SPI_execute(), so there is no great need for setting up these
>>> constants. It's probably water under the bridge now, but maybe PLPython
>>> should have done this too.
>>>
>> This is not documented well - I see nothing about result value in doc.
>> Does it raise exception when SPI returns some bad result value?
>
>
>
> The docs state:
>
>   You can then access the command status (e.g., SPI_OK_INSERT) like this:
>
>   $res = $rv->{status};
>
>
> And it works like this:
>
>   andrew=# do 'my $rv = spi_exec_query("select 1 as a");
>   elog(NOTICE,$rv->{status});' language plperl;
>   NOTICE:  SPI_OK_SELECT
>   CONTEXT:  PL/Perl anonymous code block
>   DO
>   andrew=#
>
> An error causes the function to end, so it never sees the error status:
>
>   andrew=# do 'my $rv = spi_exec_query("select blurfl");
>   elog(NOTICE,$rv->{status});' language plperl;
>   ERROR:  column "blurfl" does not exist at line 1.
>   CONTEXT:  PL/Perl anonymous code block
>   andrew=#
>
>
> If you think more documentation is needed, submit a patch.

I was blind, I am sorry - I am missing explicit note, so command
status is string, that is all.

Regards

Pavel

>
>
> cheers
>
> andrew
>

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Alex Goncharov 2012-01-10 19:10:21 Re: libpq: PQcmdStatus, PQcmdTuples signatures can be painlessly improved
Previous Message Andrew Dunstan 2012-01-10 17:59:47 Re: Add SPI results constants available for PL/*