BUG #2945: possibly forgotten SPI_push()/SPI_pop()

From: "Sergiy Vyshnevetskiy" <serg(at)vostok(dot)net>
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #2945: possibly forgotten SPI_push()/SPI_pop()
Date: 2007-01-30 13:11:09
Message-ID: 200701301311.l0UDB96M007717@wwwmaster.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs


The following bug has been logged online:

Bug reference: 2945
Logged by: Sergiy Vyshnevetskiy
Email address: serg(at)vostok(dot)net
PostgreSQL version: 8.2.1
Operating system: FreeBSD-6 stable
Description: possibly forgotten SPI_push()/SPI_pop()
Details:

Preparation:

#psql = serg(at)[local]:5432 test
create or replace function "ifLow"() returns int immutable strict language
plpgsql as $F$begin return 0; end$F$;
CREATE FUNCTION
#psql = serg(at)[local]:5432 test
create or replace function "ifHigh"() returns int immutable strict language
plpgsql as $F$begin return 5; end$F$;
CREATE FUNCTION
#psql = serg(at)[local]:5432 test
create domain "D5" as int not null check(value between "ifLow"() and
"ifHigh"());
CREATE DOMAIN
#psql = serg(at)[local]:5432 test

This works:

#psql = serg(at)[local]:5432 test
create or replace function "D5"(int) returns int immutable strict language
plpgsql as $F$begin if($1<"ifLow"())then return "ifLow"();
elsif($1>"ifHigh"())then return "ifHigh"(); end if; return $1; end$F$;
CREATE FUNCTION
#psql = serg(at)[local]:5432 test D5
----
3
(1 )
#psql = serg(at)[local]:5432 test
drop function "D5"(int);
DROP FUNCTION
#psql = serg(at)[local]:5432 test

This doesn't work:

#psql = serg(at)[local]:5432 test
create or replace function "D5"(int) returns "D5" immutable strict language
plpgsql as $F$begin if($1<"ifLow"())then return "ifLow"();
elsif($1>"ifHigh"())then return "ifHigh"(); end if; return $1; end$F$;
CREATE FUNCTION
#psql = serg(at)[local]:5432 test
select "D5"(3);
ERROR: SPI_connect failed: SPI_ERROR_CONNECT
: PL/pgSQL function "D5" while casting return value to
function's return type
#psql = serg(at)[local]:5432 test

Analysis:

The only difference is return type of "D5" function: int works, "D5"
doesn't.

The error is reported during an attempt to call "ifLow"() at "D5" domain
check evaluation.

Casus belli is calling SPI_connect() when _SPI_curid==-1 and
_SPI_connected==0.

Possible reason is forgotten SPI_push()/SPI_pop() wrapper in domain check
evaluation algorithm.

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Sergiy Vyshnevetskiy 2007-01-30 13:18:36 Re: BUG #2945: possibly forgotten SPI_push()/SPI_pop()
Previous Message Tom Lane 2007-01-30 02:56:16 Re: [BUGS] Missing error message on missing ssl-key-files