Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1us4ZC-00H09p-Sa for pgsql-admin@arkaria.postgresql.org; Fri, 29 Aug 2025 19:15:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1us4ZC-00CNU2-5V for pgsql-admin@arkaria.postgresql.org; Fri, 29 Aug 2025 19:15:18 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1us4ZB-00CNTt-Sc for pgsql-admin@lists.postgresql.org; Fri, 29 Aug 2025 19:15:18 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1us4ZA-002YbV-0b for pgsql-admin@lists.postgresql.org; Fri, 29 Aug 2025 19:15:18 +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 57TJFCZP2343916; Fri, 29 Aug 2025 15:15:12 -0400 From: Tom Lane To: Ron Johnson cc: Pgsql-admin Subject: Re: Having trouble passing a shell variable to a query from psql command line In-reply-to: References: Comments: In-reply-to Ron Johnson message dated "Fri, 29 Aug 2025 14:27:49 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2343914.1756494912.1@sss.pgh.pa.us> Date: Fri, 29 Aug 2025 15:15:12 -0400 Message-ID: <2343915.1756494912@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Ron Johnson writes: > Yeah. From the cli KISS and do regular bash variable string expansion. > psql -d mydb -tAc "SELECT relkind FROM pg_class WHERE relname = > ${SHELL_VAR} ;" This isn't a great recommendation because bash is not aware of SQL's quoting rules. It'll work in simple cases, but there's a risk of SQL injection if the value of SHELL_VAR comes from an untrustworthy source. regards, tom lane