Creating a boolean function

From: Miguel González <iafmgc(at)unileon(dot)es>
To: "Haller Christoph" <ch(at)rodos(dot)fzk(dot)de>
Cc: "PostgreSQL SQL" <pgsql-sql(at)postgresql(dot)org>
Subject: Creating a boolean function
Date: 2001-09-19 18:55:49
Message-ID: 000901c1413c$b29fe0f0$1301a8c0@uimagen
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Brett Schwarz 2001-09-19 19:01:05 Re: Holiday Calculations?
Previous Message Miguel González 2001-09-19 18:23:50 Re: Registring a C function in PostgreSQL II