Re: Character escape in "CREATE FUNCTION ..."

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Shilong Stanley Yao <yao(at)noao(dot)edu>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Character escape in "CREATE FUNCTION ..."
Date: 2004-03-15 19:37:27
Message-ID: 25135.1079379447@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Shilong Stanley Yao <yao(at)noao(dot)edu> writes:
> I am trying to write a function in Postgresql, which takes 2 floats and
> returns a box. But seems the nested single-quote in the AS clause
> prevent $1 and $2 from being expanded. Besides writing a C function
> instead of a SQL one, is there any way to solve this problem?

> CREATE OR REPLACE FUNCTION func_radec_to_box(float, float) RETURNS box
> AS 'SELECT box \'(($1, $2), (1.3, 1.4))\''
> LANGUAGE 'sql'
> WITH (ISCACHABLE);

This is never going to work because you are trying to use the
typed-literal syntax with something that you don't actually want to
be a literal constant. You need to think in terms of a function, not
a literal. In this case I think what you want is the box-from-two-points
constructor function, together with the point-from-two-floats constructor:

... AS 'SELECT box(point($1, $2), point(1.3, 1.4))'

If you had a mind to, you could write the constant point as a literal:

... AS 'SELECT box(point($1, $2), point \'1.3, 1.4\')'

but you can't write the variable point as a literal.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message V i s h a l Kashyap @ [Sai Hertz And Control Systems] 2004-03-15 20:06:26 Re: boolean to int
Previous Message Mage 2004-03-15 19:36:25 Re: boolean to int