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

From: Richard Huxton <dev(at)archonet(dot)com>
To: Shilong Stanley Yao <yao(at)noao(dot)edu>, pgsql-general(at)postgresql(dot)org
Subject: Re: Character escape in "CREATE FUNCTION ..."
Date: 2004-03-15 19:11:13
Message-ID: 200403151911.13260.dev@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Monday 15 March 2004 18:38, Shilong Stanley Yao wrote:
> Dear All,
> 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);

If the box constructor is supposed to take a string, try something like:

SELECT box \'((\' || $1 || \'...etc

That is to say - use string concatenation

--
Richard Huxton
Archonet Ltd

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bruno Wolff III 2004-03-15 19:33:12 Re: Character escape in "CREATE FUNCTION ..."
Previous Message Richard Huxton 2004-03-15 19:08:55 Re: PostgeSQL problem (server crashed?)