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 1jCZNT-0002Qn-S8 for pgsql-general@arkaria.postgresql.org; Fri, 13 Mar 2020 01:44:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jCZNS-0006qB-M1 for pgsql-general@arkaria.postgresql.org; Fri, 13 Mar 2020 01:44:42 +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 1jCZNS-0006q3-9N for pgsql-general@lists.postgresql.org; Fri, 13 Mar 2020 01:44:42 +0000 Received: from mailbackend.panix.com ([166.84.1.89]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jCZNP-0003sP-Lt for pgsql-general@lists.postgresql.org; Fri, 13 Mar 2020 01:44:40 +0000 Received: from panix5.panix.com (panix5.panix.com [166.84.1.5]) by mailbackend.panix.com (Postfix) with ESMTP id 48dpQt5GmLz1Ps0; Thu, 12 Mar 2020 21:44:38 -0400 (EDT) Received: by panix5.panix.com (Postfix, from userid 17622) id 48dpQt3Wd1zfYm; Thu, 12 Mar 2020 21:44:38 -0400 (EDT) Date: Thu, 12 Mar 2020 21:44:38 -0400 From: stan To: "David G. Johnston" Cc: pgsql-general@lists.postgresql.org Subject: Re: plperl syntax question Message-ID: <20200313014438.GB6722@panix.com> References: <20200312223402.GA613@panix.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Editor: gVim List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Thu, Mar 12, 2020 at 06:37:02PM -0700, David G. Johnston wrote: > On Thursday, March 12, 2020, stan 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 ;' 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