Обсуждение: Re: CREATE FUNCTION problem

Поиск
Список
Период
Сортировка

Re: CREATE FUNCTION problem

От
Janovszki Levente
Дата:
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@bmk.hu | Bekescsaba, Derkovits sor 1. HUNGARY Zip: 5600 |
 | Linux. Just use it |     *    The operating system collapsed    *   |
 | w/o fear of panic: |     *            OK    Cancel              *   |