Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1jCZX7-0002uv-7C for pgsql-general@arkaria.postgresql.org; Fri, 13 Mar 2020 01:54:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jCZX6-0007Bx-0w for pgsql-general@arkaria.postgresql.org; Fri, 13 Mar 2020 01:54:40 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1jCZX5-0007Bq-ES for pgsql-general@lists.postgresql.org; Fri, 13 Mar 2020 01:54:39 +0000 Received: from mail-il1-x12d.google.com ([2607:f8b0:4864:20::12d]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jCZWz-0003xb-0k for pgsql-general@lists.postgresql.org; Fri, 13 Mar 2020 01:54:38 +0000 Received: by mail-il1-x12d.google.com with SMTP id e8so7408591ilc.13 for ; Thu, 12 Mar 2020 18:54:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=Vcbs8JJ5TSGj2od6fbJHw/fAjMnXGssNZkRB7y476XA=; b=hZB/Uh90qDkJtFBQMgmbz9t66WyvfOcaen6NmmRh3IN8/OUnbIKCK+2VN4OzhpAxu/ qio2Zi68yxOCX6125JWORNei5tc+6OBhQgD3dpxlv4AxiYyEjVay2VJ2TyVVuC4vfYjO 8Q0aVwdQgIiIlyoUNutfkr5k3gUw7LUsHXiwLMcKrv+M/NiZxQzfv69Ki6i74j7eCYXG gaB/uJOILgDLoyPfp5XTK+PRHoCZER7MBTwQf4EFpQkNmYmHoSEGMVtP1Zoimm446w5K YQVaHVTc7NjKMrAYzh4Klqh/cewH4S6zlhFBSlAljO/rd5ihoLY/HDudTO985joD4lO2 keqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=Vcbs8JJ5TSGj2od6fbJHw/fAjMnXGssNZkRB7y476XA=; b=fRmkWFyiWw96ruZLSXMukbgQXcgYG320xgaPWfzlQKr6xvoXN7Jq76BtRyM40caCD/ +7NBmWMR94GavSaEZq5MHC20BUw5El6vpcWpnmOHbjma9GFVzzYopMIfiyGx1PngwUOY 1Q7cBiO49833Gk4mZhPVbMj80mKcY5M3zSQnnCkt9f8braHDgPEKvEXqHOJVfpt/ulfG 7cEO7ny1FBO2sBI9WHpfea1hCnmyCHuvb+DKi5IeH3MvSCRoDfsQrqGmCxxQ9ut/Q+Xt hwP+O7rNcG9TuJ/OvKAD8h3NuYeCfe1qvtu7cCvBn5XumGaf9MKibeIb1Jfu8ZkSlmMU 6ZCg== X-Gm-Message-State: ANhLgQ2m07XmfgSIB11imwKldGAWm3s8u3BDwnk6iC0RvyGMQVOFVZFQ EwDuGOUVLVkL8U2J/gNJhi4= X-Google-Smtp-Source: ADFU+vtpcXQNPgk8iGTsuqb1Vhp/dUmobD3ja+zM6ueNIHmCfLkbPORcLvnLJn407rfg9s5UhY/xSA== X-Received: by 2002:a92:d8cc:: with SMTP id l12mr10328236ilo.92.1584064471982; Thu, 12 Mar 2020 18:54:31 -0700 (PDT) Received: from [192.168.1.108] (c-73-63-59-118.hsd1.ut.comcast.net. [73.63.59.118]) by smtp.gmail.com with ESMTPSA id e16sm8022883ioh.7.2020.03.12.18.54.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Mar 2020 18:54:31 -0700 (PDT) From: Rob Sargent Message-Id: Content-Type: multipart/alternative; boundary="Apple-Mail=_B367A2D9-FE6B-4B5E-98FB-76F1F1C003B7" Mime-Version: 1.0 (Mac OS X Mail 13.0 \(3608.60.0.2.5\)) Subject: Re: plperl syntax question Date: Thu, 12 Mar 2020 19:54:29 -0600 In-Reply-To: <20200313014438.GB6722@panix.com> Cc: "pgsql-generallists.postgresql.org" To: stan References: <20200312223402.GA613@panix.com> <20200313014438.GB6722@panix.com> X-Mailer: Apple Mail (2.3608.60.0.2.5) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --Apple-Mail=_B367A2D9-FE6B-4B5E-98FB-76F1F1C003B7 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Mar 12, 2020, at 7:44 PM, stan wrote: >=20 > On Thu, Mar 12, 2020 at 06:37:02PM -0700, David G. Johnston wrote: >> On Thursday, March 12, 2020, stan wrote: >>>=20 >>> my $rv3 =3D spi_exec_query('$stmt'); >>> What am I doing wrong here? >>>=20 >>=20 >> 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. >=20 > Please look at this. >=20 > Here is the code: >=20 > my $stmt =3D qq('SELECT employee_key from employee where id =3D $user = ;'); > elog( NOTICE, "stmt =3D $stmt" ); > my $rv3 =3D spi_exec_query($stmt); >=20 > As you cna see, I use qq to ahndle the qouting: runtime output looks = like > this: >=20 > OTICE: stmt =3D 'SELECT employee_key from employee where id =3D stan = ;=E2=80=99 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=E2=80=99)= The example I saw for qq on the perl site=20 print(qq(Welcome to GeeksForGeeks));=20 doesn=E2=80=99t have any quotes in arg to qq Try making the sql string without using qq my $select =3D =E2=80=9Cselect....=E2=80=99=E2=80=9D + $user + = =E2=80=9C=E2=80=98;=E2=80=9D; (or perhaps perl has a formatted string function like printf) > ERROR: syntax error at or near "$" at line 22. >=20 > Looks like a very clean string with the variable substituted. >=20 > Anyone have a working example of a call to spi_exec_query() using a = variable? >=20 > also tried: >=20 > my $rv3 =3D spi_exec_query('$stmt'); >=20 > Different trun tiem error message. >=20 >=20 > --=20 > "They that would give up essential liberty for temporary safety = deserve > neither liberty nor safety." > -- Benjamin Franklin >=20 >=20 --Apple-Mail=_B367A2D9-FE6B-4B5E-98FB-76F1F1C003B7 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

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 =3D = 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 =3D qq('SELECT employee_key = from employee where id =3D $user ;');
elog( NOTICE, "stmt = =3D $stmt" );
my $rv3 =3D spi_exec_query($stmt);

As you cna see, I use qq to ahndle the = qouting: runtime output looks like
this:

OTICE:  stmt =3D 'SELECT employee_key from employee = where id =3D stan ;=E2=80=99
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=E2=80=99)

The example I saw for qq on the perl = site 
doesn=E2=80=99t have any quotes in arg to = qq

Try making the = sql string without using qq
my $select =3D =E2=80=9Cselect....=E2=80=99=E2=80=9D&nbs= p;+ $user + =E2=80=9C=E2=80=98;=E2=80=9D;
(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 =3D = 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



= --Apple-Mail=_B367A2D9-FE6B-4B5E-98FB-76F1F1C003B7--