From: Oliver Elphick <olly@lfix.co.uk>
To: shyamperi@davlin.co.in
Cc: pgsql-admin@postgresql.org
Subject: Re: error with functions
Date: Mon, 22 Sep 2003 16:43:02 +0100
Message-ID: <1064245382.26041.252.camel@linda.lfix.co.uk> (raw)
In-Reply-To: <2110482.1064209766872.JavaMail.tomcat@mail.davlin.co.in>
References: <2110482.1064209766872.JavaMail.tomcat@mail.davlin.co.in>
On Mon, 2003-09-22 at 06:42, shyamperi@davlin.co.in wrote:
> >You do realize that the shell is going to interpret that string in
> >double quotes right?
> I guess so, for the very same I have tried with
> Command: psql test -c "> CREATE FUNCTION add_one (integer) RETURNS
> INTEGER AS ' BEGIN RETURN ''$1'' + 1; END; ' LANGUAGE
> 'plpgsql';"
> But still it is not taking it as $1, instead empty string.
> Ideeally it shud consider $1 as string... but why isn't it
It's still being interpreted by the shell. The shell takes no notice at
all of the nested quotes; everything inside the double quotes is treated
as literal text, after replacing variables. Look here:
olly@linda$ echo psql test -c "> CREATE FUNCTION add_one
(integer) RETURNS INTEGER AS ' BEGIN RETURN ''$1'' +
1; END; ' LANGUAGE 'plpgsql';"
psql test -c > CREATE FUNCTION add_one (integer) RETURNS INTEGER
AS ' BEGIN RETURN '''' + 1; END; ' LANGUAGE
'plpgsql';
Instead of trying to quote $1, you need to escape the dollar sign:
olly@linda$ echo psql test -c "> CREATE FUNCTION add_one
(integer) RETURNS INTEGER AS ' BEGIN RETURN \$1 +
1; END; ' LANGUAGE 'plpgsql';"
psql test -c > CREATE FUNCTION add_one (integer) RETURNS INTEGER
AS ' BEGIN RETURN $1 + 1; END; ' LANGUAGE
'plpgsql';
--
Oliver Elphick Oliver.Elphick@lfix.co.uk
Isle of Wight, UK http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C
========================================
"Therefore when thou doest thine alms, do not sound a
trumpet before thee, as the hypocrites do in the
synagogues and in the streets, that they may have
glory of men. Verily I say unto you, They have their
reward. But when thou doest alms, let not thy left
hand know what thy right hand doeth; That thine alms
may be in secret; and thy Father which seeth in secret
himself shall reward thee openly." Matthew 6:2-4
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-admin@postgresql.org
Cc: olly@lfix.co.uk, shyamperi@davlin.co.in
Subject: Re: error with functions
In-Reply-To: <1064245382.26041.252.camel@linda.lfix.co.uk>
References: <2110482.1064209766872.JavaMail.tomcat@mail.davlin.co.in> <1064245382.26041.252.camel@linda.lfix.co.uk>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox