Re: Minor systax error but not able to resolve it...

Поиск
Список
Период
Сортировка
От dipti shah
Тема Re: Minor systax error but not able to resolve it...
Дата
Msg-id d5b05a951002230915t192ba31dq1af3ab5f50658bba@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Minor systax error but not able to resolve it...  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: Minor systax error but not able to resolve it...  (Richard Huxton <dev@archonet.com>)
Список pgsql-general
Thanks. Putting $cmd in single quote resolve the error but it generated other error. :(

mydb=> CREATE OR REPLACE FUNCTION test_create()
  RETURNS void AS
$BODY$
$cmd = "CREATE TABLE testtable(col varchar not null);";
spi_exec_query("CREATE OR REPLACE FUNCTION myfunc() RETURNS void AS '$cmd' LANGUAGE plperl;");
spi_exec_query("SELECT myfunc();");
$BODY$
  LANGUAGE 'plperl';
CREATE FUNCTION
mydb=> SELECT test_create();
ERROR:  error from Perl function "test_create": error from Perl function "myfunc": Can't locate object method "col" via package "varchar" (perhaps you forgot to load "varchar"?) at line 1. at line 3.

this is also related to quoting?

On Tue, Feb 23, 2010 at 9:23 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Richard Huxton <dev@archonet.com> writes:
> You're interpolating $cmd here but not quoting it, so you end up with:
> ... RETURNS void AS CREATE TABLE test-table...
> whereas you want:
> ... RETURNS void AS 'CREATE TABLE test-table...'...

> Probably best to use dollar-quoting: $TMP$ or similar, but don't forget
> to escapt the $ or perl will think it's a variable.

Dollar-quoting is really dangerous when you're trying to quote
nonconstant text.  I'd suggest passing the string through
quote_literal() instead.

                       regards, tom lane

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

Предыдущее
От: Belka Lambda
Дата:
Сообщение: FOREIGN KEY composite_type.its_field REFERENCES ....
Следующее
От: Greg Smith
Дата:
Сообщение: Re: tuning bgwriter in 8.4.2