Re: error with functions

Поиск
Список
Период
Сортировка
От Oliver Elphick
Тема Re: error with functions
Дата
Msg-id 1064245382.26041.252.camel@linda.lfix.co.uk
обсуждение исходный текст
Ответ на Re: error with functions  (shyamperi@davlin.co.in)
Список pgsql-admin
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


В списке pgsql-admin по дате отправления:

Предыдущее
От: Jodi Kanter
Дата:
Сообщение: steps to ensure referential integrity
Следующее
От: Stephan Szabo
Дата:
Сообщение: Re: error with functions