Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 470AF4761ED for ; Mon, 14 Oct 2002 10:23:27 -0400 (EDT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id 98CD14761CD for ; Mon, 14 Oct 2002 10:23:26 -0400 (EDT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.5/8.12.5) with ESMTP id g9EENRhR012148; Mon, 14 Oct 2002 10:23:27 -0400 (EDT) To: Constantin Teodorescu Cc: PostgreSQL Interfaces Subject: Re: What's wrong in this pltcl function ? In-reply-to: <3DAA8ADB.6060208@flex.ro> References: <3DAA8ADB.6060208@flex.ro> Comments: In-reply-to Constantin Teodorescu message dated "Mon, 14 Oct 2002 12:14:03 +0300" Date: Mon, 14 Oct 2002 10:23:27 -0400 Message-ID: <12147.1034605407@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200210/34 X-Sequence-Number: 3196 Constantin Teodorescu 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. regards, tom lane