Skip site navigation (1) Skip section navigation (2)

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

From: dipti shah <shahdipti1980(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, dev(at)archonet(dot)com
Cc: pgsql-general(at)postgresql(dot)org, pgsql-novice <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Minor systax error but not able to resolve it...
Date: 2010-02-23 17:15:37
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-generalpgsql-novice
Thanks. Putting $cmd in single quote resolve the error but it generated
other error. :(

mydb=> CREATE OR REPLACE FUNCTION test_create()
$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();");
  LANGUAGE 'plperl';
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(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> Richard Huxton <dev(at)archonet(dot)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

In response to


pgsql-novice by date

Next:From: dipti shahDate: 2010-02-23 17:21:24
Subject: Re: SET Role doesn't work from Security Definer Function...
Previous:From: Michael WoodDate: 2010-02-23 16:58:58
Subject: Re: Function Error

pgsql-general by date

Next:From: Greg SmithDate: 2010-02-23 17:20:54
Subject: Re: tuning bgwriter in 8.4.2
Previous:From: Alex HunsakerDate: 2010-02-23 17:01:34
Subject: Re: Sorting performance vs. MySQL

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group