From: Rob Sargent <robjsargent@gmail.com>
To: stan <stanb@panix.com>
Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: plperl syntax question
Date: Thu, 12 Mar 2020 19:54:29 -0600
Message-ID: <F7492779-7336-4E58-92C8-35C7C44FB7C5@gmail.com> (raw)
In-Reply-To: <20200313014438.GB6722@panix.com>
References: <20200312223402.GA613@panix.com>
<CAKFQuwZPcoSsOMWhQ_dXHr2M+Jj-rAEVw1_FiAj3dEGHRJ=_Zw@mail.gmail.com>
<20200313014438.GB6722@panix.com>
> On Mar 12, 2020, at 7:44 PM, stan <stanb@panix.com> wrote:
>
> On Thu, Mar 12, 2020 at 06:37:02PM -0700, David G. Johnston wrote:
>> On Thursday, March 12, 2020, stan <stanb@panix.com> wrote:
>>>
>>> my $rv3 = spi_exec_query('$stmt');
>>> What am I doing wrong here?
>>>
>>
>> Putting a variable name into a single-quoted string and expecting it to
>> resolve to the contents of said variable instead of being treated as a
>> literal.
>> David J.
>
> Please look at this.
>
> Here is the code:
>
> my $stmt = qq('SELECT employee_key from employee where id = $user ;');
> elog( NOTICE, "stmt = $stmt" );
> my $rv3 = spi_exec_query($stmt);
>
> As you cna see, I use qq to ahndle the qouting: runtime output looks like
> this:
>
> OTICE: stmt = 'SELECT employee_key from employee where id = stan ;’
You can see that the entire sql string is quoted, where what you want from the elog is just single quotes around the value (i.e. 'stan’)
The example I saw for qq on the perl site
print(qq(Welcome to GeeksForGeeks));
doesn’t have any quotes in arg to qq
Try making the sql string without using qq
my $select = “select....’” + $user + “‘;”;
(or perhaps perl has a formatted string function like printf)
> ERROR: syntax error at or near "$" at line 22.
>
> Looks like a very clean string with the variable substituted.
>
> Anyone have a working example of a call to spi_exec_query() using a variable?
>
> also tried:
>
> my $rv3 = spi_exec_query('$stmt');
>
> Different trun tiem error message.
>
>
> --
> "They that would give up essential liberty for temporary safety deserve
> neither liberty nor safety."
> -- Benjamin Franklin
>
>
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: robjsargent@gmail.com, stanb@panix.com
Subject: Re: plperl syntax question
In-Reply-To: <F7492779-7336-4E58-92C8-35C7C44FB7C5@gmail.com>
References: <20200312223402.GA613@panix.com> <CAKFQuwZPcoSsOMWhQ_dXHr2M+Jj-rAEVw1_FiAj3dEGHRJ=_Zw@mail.gmail.com> <20200313014438.GB6722@panix.com> <F7492779-7336-4E58-92C8-35C7C44FB7C5@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox