Re: CREATE FUNCTION problem - Mailing list pgsql-general

From Janovszki Levente
Subject Re: CREATE FUNCTION problem
Date
Msg-id Pine.LNX.3.96.1000515180903.17273E-100000@mail.bmk.hu
Whole thread Raw
List 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@bmk.hu | Bekescsaba, Derkovits sor 1. HUNGARY Zip: 5600 |
 | Linux. Just use it |     *    The operating system collapsed    *   |
 | w/o fear of panic: |     *            OK    Cancel              *   |



pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Dumping and reloading stuff in 6.5.3
Next
From: Tom Lane
Date:
Subject: Re: Storing Pairs?