From: Constantin Teodorescu <teo@flex.ro>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: PostgreSQL Interfaces <pgsql-interfaces@postgresql.org>
Subject: Re: What's wrong in this pltcl function ?
Date: Mon, 14 Oct 2002 17:31:18 +0300
Message-ID: <3DAAD536.8030603@flex.ro> (raw)
References: <3DAA8ADB.6060208@flex.ro>
<12147.1034605407@sss.pgh.pa.us>
Tom Lane wrote:
>Constantin Teodorescu <teo@flex.ro> writes:
>
>
>>create function ruldeb(bpchar) returns bpchar as '
>> set cont $1
>> set rulaj 0.0
>> spi_exec -array rec "select valoare from valori where debitor LIKE
>>\'$cont%\'" {
>> set rulaj [expr {$rulaj + $rec(valoare)}]
>> }
>> if {![info exists GD(conturi_lookup)]} {
>> set GD(conturi_lookup) [spi_prepare "select cheie,denumire from
>>conturi where id=\'\\$1\'" [list bpchar]]
>> }
>> spi_execp -count 1 $GD(conturi_lookup) [list $cont]
>> return "{$cheie} {$denumire} $rulaj"
>>' LANGUAGE 'pltcl';
>>
>>
>
>
>
>
>>is giving the following error:
>>
>>
>
>
>
>>ERROR: pltcl: can't read "cheie": no such variable
>>can't read "cheie": no such variable
>>
>>
>
>I think what is happening is that the select is returning zero rows, and
>so none of the output variables get set. You should be checking that
>spi_execp returns a value greater than 0 before trying to use the column
>variables.
>
>As for *why* the select returns zero rows, I think you want the query
>to read like
> ... where id=\\$1"
>As is, it's always looking for the literal id value $1.
>
>
I have replaced:
... where id=\'\\$1\'
with
... where id=\\$1
and the error is now:
ERROR: Unable to identify an operator '=$' for types 'character
varying' and 'integer'
You will have to retype this query using an explicit cast
when I call the function like that:
select ruldeb('4:0:1:1:2:');
-------------
I have to say that that account '4:0:1:1:2:' exists in the "conturi" table!
As I said it previously, the query works fine directly (spi_exec)
without the preparing stuff!
teo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-interfaces@postgresql.org
Cc: teo@flex.ro, tgl@sss.pgh.pa.us
Subject: Re: What's wrong in this pltcl function ?
In-Reply-To: <3DAAD536.8030603@flex.ro>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox