Re: CREATE FUNCTION problem

From: Janovszki Levente <levi(at)bmk(dot)hu>
To: Jan Wieck <JanWieck(at)yahoo(dot)com>
Cc: pgsql-general(at)hub(dot)org
Subject: Re: CREATE FUNCTION problem
Date: 2000-05-15 16:36:43
Message-ID: Pine.LNX.3.96.1000515180903.17273E-100000@mail.bmk.hu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sun, 14 May 2000, Jan Wieck wrote:

> Janovszki Levente wrote:
> > Hello !
> >
> > I would like to use a function like that:
> >
> > CREATE FUNCTION keres_ugyfel( bpchar ) RETURNS bpchar
> > AS 'SELECT ugyfel_kod AS RESULT FROM keres_kinal WHERE ugyfel_kod=\'$1\';'
> > LANGUAGE 'sql';
>
> $1 is a PARAMETER. In the above example you use the string
> '$1' as LITERAL. Omit the single quotes and it should work.
OK. What about this ???

psql=>
psql=> CREATE FUNCTION keres_ugyfel( bpchar ) RETURNS bpchar
eplakat-> AS 'SELECT ugyfel_kod AS RESULT FROM keres_kinal WHERE
ugyfel_kod=$1;' LANGUAGE 'sql';

ERROR: There is no operator '=$' for types 'bpchar' and 'int4'
You will either have to retype this query using an explicit cast,
or you will have to define the operator using CREATE OPERATOR

psql=>
psql=> CREATE FUNCTION keres_ugyfel( bpchar ) RETURNS bpchar
psql-> AS 'SELECT ugyfel_kod AS RESULT FROM keres_kinal WHERE
ugyfel_kod=\$1::bpchar ;' LANGUAGE 'sql';

ERROR: There is no operator '=$' for types 'bpchar' and 'bpchar'
You will either have to retype this query using an explicit cast,
or you will have to define the operator using CREATE OPERATOR

BUT HERE IS THE RIGHT SOLUTION ! LET THAT BE THE LESSON FOR EVERYBODY !

I've tried the function without single quotes before but as you see above
, I've got errors. Now it come to my mind to try to insert a space after
the operator (in ... WHERE ugyfel_kod= $1 ...)
^ it works with \$1 too ????

Thanks for making me thinking!

Levente

| Levente Janovszki | Bekes County Library JUST 4 lines 4 U |
| e-mail:levi(at)bmk(dot)hu | Bekescsaba, Derkovits sor 1. HUNGARY Zip: 5600 |
| Linux. Just use it | * The operating system collapsed * |
| w/o fear of panic: | * OK Cancel * |

Browse pgsql-general by date

  From Date Subject
Next Message Jurgen Defurne 2000-05-15 16:52:36 Re: Storing Pairs?
Previous Message Tom Lane 2000-05-15 15:20:53 Re: Storing Pairs?