Received: from akirason.se.verio.net (akirason.se.verio.net [204.27.64.122]) by postgresql.org (8.11.3/8.11.4) with ESMTP id f8JJsme48990 for ; Wed, 19 Sep 2001 15:54:48 -0400 (EDT) (envelope-from jeckermann@verio.net) Received: from beancounter (no-wkstns.gs.verio.net [204.27.67.225]) (authenticated) by akirason.se.verio.net (8.11.4/8.11.4) with ESMTP id f8JJxWI32441; Wed, 19 Sep 2001 14:59:33 -0500 (CDT) (envelope-from jeckermann@verio.net) Message-ID: <01a001c14144$ebd04100$279c10ac@INTERNAL> From: "Jeff Eckermann" To: =?iso-8859-1?Q?Miguel_Gonz=E1lez?= Cc: "PostgreSQL SQL" References: <000901c1413c$b29fe0f0$1301a8c0@uimagen> Subject: Re: Creating a boolean function Date: Wed, 19 Sep 2001 14:54:38 -0500 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-Archive-Number: 200109/157 X-Sequence-Number: 4835 Maybe the reason is that you defined the function to return bool, but are attempting to return text? You need conditional logic, which suggests pl/pgsql is the way to go. Something simple should do it, like: create function check_loan (text,int,int) returns bool as ' begin select * from loans where typetable=$1 and code_user=$2 and code_loan=$3; if found then return true; else return false; end if; return true; end; ' language 'plpgsql'; Since this is your project, I will take the luxury of not testing that code :-) ----- Original Message ----- From: "Miguel González" To: "Haller Christoph" Cc: "PostgreSQL SQL" Sent: Wednesday, September 19, 2001 1:55 PM Subject: Creating a boolean function > by the way you know how to create the following sql function? > > I need to return a boolean saying if an object is onloan. > > the loan table is as follows: > > loans > ----- > code_loan > code_user > typetable > > > i want to check these three fields, the first two fields (the code ones) are > integer and the last a string. > > I tried > > create function check_loan (text,int,int) > returns bool > as > 'select CAST(typetable AS text) from loans where typetable=$1 and > code_user=$2 and code_loan=$3;' > language 'sql'; > > > But I got that the parser cannot identify the =$ operator and requires me to > do the proper casting. > > How can I do it? Sorry for the questions, but I am new at creating functions > and I have to hand in this project tomorrow. > > Many thanks > > Miguel > > > > > > > ---------------------------(end of broadcast)--------------------------- > TIP 2: you can get off all lists at once with the unregister command > (send "unregister YourEmailAddressHere" to majordomo@postgresql.org) > >