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