Received: from tolikus.hq.aaanet.ru (tolikus.hq.aaanet.ru [195.151.212.227]) by hub.org (8.9.2/8.9.1) with ESMTP id GAA98870 for ; Sat, 20 Feb 1999 06:15:47 -0500 (EST) (envelope-from tolik@tolikus.hq.aaanet.ru) Received: (from tolik@localhost) by tolikus.hq.aaanet.ru (8.9.1/8.9.1) id OAA06887; Sat, 20 Feb 1999 14:09:43 +0300 (MSK) (envelope-from tolik) To: Eric BASIER Cc: pgsql-sql Subject: Re: [SQL] problem with function in plpgsql References: <36CD7E6A.55E39A5E@ipgp.jussieu.fr> Mime-Version: 1.0 (generated by tm-edit 7.108) Content-Type: text/plain; charset=US-ASCII From: tolik@icomm.ru (Anatoly K. Lasareff) Date: 20 Feb 1999 14:09:41 +0300 In-Reply-To: Eric BASIER's message of "Fri, 19 Feb 1999 16:08:28 +0100" Message-ID: <87ogmp5o22.fsf@tolikus.hq.aaanet.ru> Lines: 63 X-Mailer: Gnus v5.5/XEmacs 20.4 - "Emerald" >>>>> "EB" == Eric BASIER writes: EB> Hello; EB> I have a table pz like this : EB> Table = pz EB> +----------------------------------+----------------------------------+-------+ . . . EB> I have to create a function who take me one row like that EB> create function test_exist_pz (text,int4,int4,float,float) returns text EB> as ' EB> declare EB> pzrec pz%RowType; EB> begin EB> select * into pzrec EB> from pz EB> where typ = $1 EB> and in_unit = $2 EB> and out_unit = $3 EB> and A0 = $4 EB> and AF = $5; EB> if not found then EB> pzrec.cle = -1; EB> end if; EB> return pzrec; EB> end; EB> ' language 'plpgsql'; EB> CREATE EB> When I try to work with the function it doesn't I have this result : EB> seed=> select test_exist_pz('a',1,1,1.1,1.2); EB> ERROR: attribute 'pzrec' not found EB> I am not very familiar with plpgsql and so if there is somebody EB> who can help me or if thre is somebody who can say where can EB> I find documentation about plpgsql it is very well There is at least one error in your text: function test_exist_pz returns 'text' type, but you write 'return pzrec', value of pz%RowType. If you need know - exist or no any row you can retype function: create function test_exist_pz (text,int4,int4,float,float) returns bool as ' declare c int; begin select count(*) into pzrec from pz where typ = $1 and in_unit = $2 and out_unit = $3 and A0 = $4 and AF = $5; return (c > 0); end; ' language 'plpgsql'; But this function you can also code in 'sql' but no 'plpgsql' language. -- Anatoly K. Lasareff Email: tolik@icomm.ru Senior programmer