Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mgWFu-0000VR-F6 for pgsql-general@arkaria.postgresql.org; Fri, 29 Oct 2021 18:05:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mgWFt-0004q0-0l for pgsql-general@arkaria.postgresql.org; Fri, 29 Oct 2021 18:05:29 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mgWFs-0004pr-NQ for pgsql-general@lists.postgresql.org; Fri, 29 Oct 2021 18:05:28 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mgWFq-0005ex-Nt for pgsql-general@lists.postgresql.org; Fri, 29 Oct 2021 18:05:27 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 19TI5Ojg714332; Fri, 29 Oct 2021 14:05:24 -0400 From: Tom Lane To: "David G. Johnston" cc: Philip Semanchuk , PostgreSQL General Subject: Re: psql syntax for array of strings in a variable? In-reply-to: References: <8A98A8A6-7AFE-42C8-884B-984323381269@americanefficient.com> Comments: In-reply-to "David G. Johnston" message dated "Fri, 29 Oct 2021 10:34:42 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <714330.1635530724.1@sss.pgh.pa.us> Date: Fri, 29 Oct 2021 14:05:24 -0400 Message-ID: <714331.1635530724@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "David G. Johnston" writes: > On Friday, October 29, 2021, Philip Semanchuk > wrote: >> I would appreciate help with the syntax for querying an array of strings >> declared as a psql variable. Here's an example. >> >> \set important_days ARRAY['monday', 'friday'] > Not sure why the single quotes are getting stripped out but that is the > issue. Maybe double them up to escape them like in a normal text literal? Yeah, that's just the way that \set works (and most other psql backslash commands, I believe). You've likely got an issue with whitespace disappearing, too, though that might be harmless in this specific example. regression=# \set foo 'bar baz' regression=# \echo :foo bar baz regression=# \set foo 'bar ''baz' regression=# \echo :foo bar 'baz regression=# \set foo bar ''baz regression=# \echo :foo barbaz Not sure offhand how well-documented this is. regards, tom lane