From: | Adrian Klaver <aklaver(at)comcast(dot)net> |
---|---|
To: | PostgreSQL List <pgsql-sql(at)postgresql(dot)org> |
Subject: | Fwd: Re: Creating a function with single quotes |
Date: | 2009-02-19 16:03:08 |
Message-ID: | 200902190803.08458.aklaver@comcast.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Oops, forgot to reply to list.
---------- Forwarded Message ----------
Subject: Re: [SQL] Creating a function with single quotes
Date: Thursday 19 February 2009
From: Adrian Klaver <aklaver(at)comcast(dot)net>
To: stayler(at)washoecounty(dot)us
On Thursday 19 February 2009 7:41:11 am Shawn Tayler wrote:
> Hello,
>
> This has me befuddled. I am trying create a simple experiment, rather
> new to SQL and I am running into an issue with single quotes. All I can
> find on creating a function states the procedure should be contained
> within single quotes. My problem comes when I want to use a textual
> representation of an interval.
>
> create function csd_interval(integer) returns interval as
> 'BEGIN
> RETURN $1 * interval '1 msec'
> END;'
> LANGUAGE 'plpgsql';
>
> it always fails at the '1 msec' point.
>
> Suggestions?
> --
> Sincerely,
>
>
Two suggestions
One, double the quotes
create function csd_interval(integer) returns interval as
'BEGIN
RETURN $1 * interval ''1 msec''
END;'
LANGUAGE 'plpgsql';
Two, better to use dollar quoting
create function csd_interval(integer) returns interval as
$$
BEGIN
RETURN $1 * interval '1 msec'
END;
$$
LANGUAGE 'plpgsql';
See
http://www.postgresql.org/docs/8.3/interactive/plpgsql-development-tips.html
--
Adrian Klaver
aklaver(at)comcast(dot)net
-------------------------------------------------------
--
Adrian Klaver
aklaver(at)comcast(dot)net
From | Date | Subject | |
---|---|---|---|
Next Message | Craig Ringer | 2009-02-19 16:08:52 | Re: Creating a function with single quotes |
Previous Message | Agustin Bialet | 2009-02-19 16:00:32 | Re: Creating a function with single quotes |