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 1jl0LM-0004W7-Eu for pgsql-general@arkaria.postgresql.org; Tue, 16 Jun 2020 01:24:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jl0LJ-0004mU-AA for pgsql-general@arkaria.postgresql.org; Tue, 16 Jun 2020 01:24:49 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jl0LJ-0004ll-2B for pgsql-general@lists.postgresql.org; Tue, 16 Jun 2020 01:24:49 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jl0LF-0007Mq-Of for pgsql-general@postgresql.org; Tue, 16 Jun 2020 01:24:47 +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 05G1OeNY1270459; Mon, 15 Jun 2020 21:24:40 -0400 From: Tom Lane To: Edson Richter cc: pgsql-general Subject: Re: How to double-quote a double quoted identifier? In-reply-to: References: Comments: In-reply-to Edson Richter message dated "Tue, 16 Jun 2020 00:52:08 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1270457.1592270680.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 15 Jun 2020 21:24:40 -0400 Message-ID: <1270458.1592270680@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Edson Richter writes: > How do I remote execute que following command: > CREATE EXTENSION "uuid-ossp" > SCHEMA public > VERSION "1.1"; > I'm using PostgreSQL 9.6, Linux x64, and bash. > I've tried the following: > ssh -l postgres -2 -C -p 2022 192.168.0.70 "psql -h 127.0.0.1 -d test_db= -p 5432 -c \"CREATE EXTENSION \\\\""uuid-ossp\\\\"" SCHEMA pg_catalog;\" = " Yeah, nesting quoting levels in shell is kind of a bear. > I know this is a kind of "bash-psql" issue, but I would appreciate if an= yone could share experience with this. Since you're using bash, you can get bash to do the work for you, via multiple iterations of the ${variable@Q} construct. $ SQLCMD=3D'CREATE EXTENSION "uuid-ossp" SCHEMA pg_catalog;' $ echo $SQLCMD CREATE EXTENSION "uuid-ossp" SCHEMA pg_catalog; $ echo ${SQLCMD@Q} 'CREATE EXTENSION "uuid-ossp" SCHEMA pg_catalog;' -- not too exciting so far, but wrap it into another layer of quoting: $ SHCMD=3D"psql -h 127.0.0.1 -d test_db -p 5432 -c ${SQLCMD@Q}" $ echo $SHCMD psql -h 127.0.0.1 -d test_db -p 5432 -c 'CREATE EXTENSION "uuid-ossp" SCHE= MA pg_catalog;' $ echo ${SHCMD@Q} 'psql -h 127.0.0.1 -d test_db -p 5432 -c '\''CREATE EXTENSION "uuid-ossp" = SCHEMA pg_catalog;'\''' -- and now your answer is: $ echo ssh -l postgres -2 -C -p 2022 192.168.0.70 ${SHCMD@Q} ssh -l postgres -2 -C -p 2022 192.168.0.70 'psql -h 127.0.0.1 -d test_db -= p 5432 -c '\''CREATE EXTENSION "uuid-ossp" SCHEMA pg_catalog;'\''' You could, of course, just use the end result of that -- but it's probably better to have a shell script recalculate it on the fly given the desired SQL command as input. regards, tom lane