Re: error with functions

From: Oliver Elphick <olly(at)lfix(dot)co(dot)uk>
To: shyamperi(at)davlin(dot)co(dot)in
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: error with functions
Date: 2003-09-22 15:43:02
Message-ID: 1064245382.26041.252.camel@linda.lfix.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On Mon, 2003-09-22 at 06:42, shyamperi(at)davlin(dot)co(dot)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(at)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(at)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(dot)Elphick(at)lfix(dot)co(dot)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

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Stephan Szabo 2003-09-22 15:43:38 Re: error with functions
Previous Message Karsten Hilbert 2003-09-22 11:19:49 Re: Warning: PostgreSQL query failed