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 1us3N7-00GiPf-66 for pgsql-admin@arkaria.postgresql.org; Fri, 29 Aug 2025 17:58:46 +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 1us3N6-00BhBg-D3 for pgsql-admin@arkaria.postgresql.org; Fri, 29 Aug 2025 17:58:45 +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 1us3N6-00BhBX-1y for pgsql-admin@lists.postgresql.org; Fri, 29 Aug 2025 17:58:44 +0000 Received: from mail-ot1-x32b.google.com ([2607:f8b0:4864:20::32b]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1us3N4-002Y2m-0U for pgsql-admin@lists.postgresql.org; Fri, 29 Aug 2025 17:58:44 +0000 Received: by mail-ot1-x32b.google.com with SMTP id 46e09a7af769-74542b1b2f7so1907959a34.3 for ; Fri, 29 Aug 2025 10:58:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1756490320; x=1757095120; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=76LziKgqmYkGuT/gBh91K/s7OglG9yyFAr1XEL6bqBA=; b=KSz5m6KBo1yxciLLQSfFMz5sUL6LrSIU4FFnu+lRvgcuNpGpoKvOv1Dq8YzCJtRG4C hgCc+TYU3+Xls7oePVPKEznO9dvaldcDizZk21jUIzoqPkiAhhTvghCGqFTMJ6TL5laz 0vWXu3T5YFRv7rsMoXQKmSFQ0WNJdsHlvFekzZ4YqHX9BWr/2YDdBZZwBYInYkDZ3x39 Ye3/xvh0QzAKIseMnUtA7TyJxzTv0h+5OVhUbwC+MPidMIP2peKSd5GXlLqYLwp7ceGk J8ZBrs1fGcyDNKtstHpqSEQpd1iX3xofRN7FLV7bSHqJx9MYKlwY/MFhu8fy/zTRi/zx YstQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756490320; x=1757095120; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=76LziKgqmYkGuT/gBh91K/s7OglG9yyFAr1XEL6bqBA=; b=QlEXL98wSh2AmiFYf8lWY8Tk2fRF7/GUMlggIoAweRtnDP9zpkVkAJhZyinpYWGh1x 7BXWr0Wf2X717BJtpfhjKO9rY/ygSNpujMgBDcHt/gFiZT24MZ9S4sv2SiInMLPE1Sys rKSNHlErKhVoz2oWaAu11du9/NuKuuBdlplTGUElb4DnpOEfRp57HNCQ2wCMiJ07L8fS M1dUilpongDQBOaYgFm4MBJXfWEDKGVanCGzmOLJRzUx5edgUYqWfltaf8XZUZA+/sLa AWWhewOf1rtWTLflGtzk9VAExJbRFcjiiq86cMRnDM3KNjO9MsOlfOTFXcAvKTbFDQ/j xpSA== X-Gm-Message-State: AOJu0YyfSvcjcH3fWasKbXsmkfTFb/duKTCkPVf6lUr8bDQn+OHV6NOB ZIqRMyQUUaq9MMQlrO+ft7Y2lq8j0mbkBOBXFSLfDZZUxeri5FzkwaAnXroYuIDQiaHSLy5tWXf dgai1Nh/iVZydlYiwNWb24in3k2Rx138= X-Gm-Gg: ASbGncuVvvKhRETm6NpwiuuH8bvaS8LQK8zmC/dkQVS1XN27gGlSuq/o5s5Sgc8bg86 IDTeJOeuao++IsZsCwMxXJCNw2+bG/Rz5aExzDEfINeeNyIl32DPsJth32M6nKc30dES/jT1fjd pBqyglBGVSrNly5p6NbO++xTtpCY3h+u80xklpnWXvhix6XkS1gSHeGQ2Hyrk87R7UdInmE6Os2 vpsIS7Toq4E9mRgqlH5mI6BDL5IbZPEde+2e1Sq X-Google-Smtp-Source: AGHT+IGU/REKphh7Pj6FZbT7+C0Mlvg6j/tsONcKRgwZUkBJJ5C3Sh2AP67ykpP2iienQmq73qov5kgp5UuOfipHvVw= X-Received: by 2002:a05:6830:3709:b0:745:571d:2843 with SMTP id 46e09a7af769-745571dd181mr2244195a34.8.1756490319922; Fri, 29 Aug 2025 10:58:39 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: "David G. Johnston" Date: Fri, 29 Aug 2025 10:58:03 -0700 X-Gm-Features: Ac12FXxfwrkybW2x_1WhZMZpwoiXNL46vlFJ9XYrjVvxAYa_QBCWX-nGlcEk2oI Message-ID: Subject: Re: Having trouble passing a shell variable to a query from psql command line To: Murthy Nunna Cc: Pgsql-admin Content-Type: multipart/alternative; boundary="000000000000920bd0063d84c59a" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000920bd0063d84c59a Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Aug 29, 2025 at 10:52=E2=80=AFAM Murthy Nunna wro= te: > > psql -d mydb -t -A -c "SELECT relkind FROM pg_class WHERE relname =3D > :'SHELL_VAR' ;" -v SHELL_VAR=3D"$SHELL_VAR" > > ERROR: syntax error at or near ":" > > LINE 1: SELECT relkind FROM pg_class WHERE relname =3D :'SHELL_VAR' ; > > ^ > > Is psql script necessary to pass shell variable? > > > I appreciate any help you can provide. > I provide the documentation. Under psql -c: "command must be either a command string that is completely parsable by the server (i.e., it contains no psql-specific features)" Variable-substitution is a psql-specific feature. David J. --000000000000920bd0063d84c59a Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Fri, Aug 29, 2025 at 10:52=E2=80=AFAM Murthy Nunna <= mnunna@fnal.gov> wrote:


psql -d mydb -t -A -c "SELECT relkind FROM pg_c= lass WHERE relname =3D :'SHELL_VAR' ;" -v SHELL_VAR=3D"$S= HELL_VAR"

ERROR:=C2=A0 syntax error at or near ":"

LINE 1: SELECT relkind FROM pg_class WHERE relname = =3D :'SHELL_VAR' ;

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ^

Is psql script necessary to pass shell variable?=C2= =A0

=C2=A0

I appreciate any help you can provide.


I provide the documentation.=C2=A0 U= nder psql -c:

"command must be either a command s= tring that is completely parsable by the server (i.e., it contains no psql-= specific features)"

Variable-substitution is a ps= ql-specific feature.

David J.

--000000000000920bd0063d84c59a--