From: | Jasen Betts <jasen(at)xnet(dot)co(dot)nz> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Creating a function with single quotes |
Date: | 2009-02-20 08:11:46 |
Message-ID: | gnlok2$8qq$3@reversiblemaps.ath.cx |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On 2009-02-19, Shawn Tayler <stayler(at)washoecounty(dot)us> 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?
you need to quote the inner quotes,
create function csd_interval(integer) returns interval as
'BEGIN
RETURN $1 * interval ''1 msec''
END;'
LANGUAGE 'plpgsql';
when the function itself uses single quotes in literals this quickly
becomes confusing, and so "dollar quoting" was invented.
create function csd_interval(integer) returns interval as
$$BEGIN
RETURN $1 * interval '1 msec'
END;$$
LANGUAGE 'plpgsql';
From | Date | Subject | |
---|---|---|---|
Next Message | Shawn Tayler | 2009-02-20 14:03:10 | Re: Creating a function with single quotes |
Previous Message | Craig Ringer | 2009-02-19 16:08:52 | Re: Creating a function with single quotes |