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 1lDy0D-00029o-WC for pgsql-general@arkaria.postgresql.org; Sun, 21 Feb 2021 23:19:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lDy0C-00061Q-T2 for pgsql-general@arkaria.postgresql.org; Sun, 21 Feb 2021 23:19:00 +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 1lDy0C-00061I-IU for pgsql-general@lists.postgresql.org; Sun, 21 Feb 2021 23:19:00 +0000 Received: from mail-ot1-x332.google.com ([2607:f8b0:4864:20::332]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lDy09-0003gi-1g for pgsql-general@lists.postgresql.org; Sun, 21 Feb 2021 23:18:59 +0000 Received: by mail-ot1-x332.google.com with SMTP id s3so7235451otg.5 for ; Sun, 21 Feb 2021 15:18:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-transfer-encoding:content-language; bh=Q/0O1QYhFTr6N92PyGnLgUxjQJCRBEYBj9rmO+wxdZk=; b=LF3RwaI5V9xWS/EDwMjWCI+q1aMVsX1j9zWKSaqVAc+gZkUzvzrPiVX5msAWArLcHq 0VHkDtYFP07ksjJq+W+3gSS8E12pXoaZS7+ghocAL3d83Elx0qNduf2EpoEXDL+tp5Nr ZRtpfuWvPuHoHV6EEfRvOi8nF2mB+yCmkPgFnsXyT2jIPyhxil5cu2M030AM27dWBYfa 271J6J2TgqGTA2aJECESnp73esn3s+JsQQCkWeezGsDniJXEL86bXvOnYUUd8BD4wrjX ndhkN4zWKaveACSQqFebOYgmxqo9FRBBRxtc+4A+gfXVQt/F5X9xqZ07abXwAH+2q1VE tESQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-transfer-encoding:content-language; bh=Q/0O1QYhFTr6N92PyGnLgUxjQJCRBEYBj9rmO+wxdZk=; b=Ep92TVsbiCs3gvaVg8U9hrlG42udZrqbBNGXEuttDKGmNL6Z2vLvL4QXZEYt7JgApo ZtncaB2Oy3gu3ltaIPg26m1WJWsnIhppvbXlGJhNf5zXPQZNtBBDBhswZ/fnW1gU9XZ5 6WoOf6KXV0tdO1aJhl7ninQktGPNX6Gv/AcRRMx7PKVNerNdp0jSLjZ8EjjTFP6qEd8/ fOhXhsLOtxZ8IP8SIAd6alQr3otMb6atAw0QA+fZMuA1RPKh/DlmLp5avPwJJ0Fuaul4 LlyA4HINjQBDy7Mi6UXrQBzQZjVJ7aOO8D+c5Yk/xJNi+sBZVSEZtQ/XIhfud8qYJNt2 EpPg== X-Gm-Message-State: AOAM5316+Md2IKSKjlG0LO6wsVg5k1bAhvhuaTjjDCvNpCSd5PliHt/v iXrFkbBvMMNYXgWLkJyvPCt+yzrCL2vPag== X-Google-Smtp-Source: ABdhPJySlX2t+3qeznUWgUMQifku65EyNP4EQIuDzTKI122qCEtplUUvsYI/dfcRoq6v3+KXyVMz0w== X-Received: by 2002:a9d:709a:: with SMTP id l26mr243568otj.178.1613949535816; Sun, 21 Feb 2021 15:18:55 -0800 (PST) Received: from [192.168.88.10] (ip174-67-141-204.no.no.cox.net. [174.67.141.204]) by smtp.googlemail.com with ESMTPSA id 22sm1475610oix.11.2021.02.21.15.18.55 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 21 Feb 2021 15:18:55 -0800 (PST) To: pgsql-general@lists.postgresql.org From: Ron Subject: Script checking to see what database it's connected to Message-ID: <0437e8e0-5686-9a10-b204-0b9df86e27ef@gmail.com> Date: Sun, 21 Feb 2021 17:18:54 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Postgresql 12.5 I've got scripts which can run on multiple database (dev, test, QA, Integration, Training, etc, etc), so of course I've got to run them like "psql my_db_name -f script.sql". Of course, I sometimes forget to specify the database name, and so it fails. Thus, I want to add a bit to the top of the script, something like this: \if :DBNAME = postgres     echo "must not run in postgres"     exit \endif However, I can't seem to find the magic sauce. This is what I've tried so far: postgres=# \if :DBNAME == postgres unrecognized value "postgres == postgres" for "\if expression": Boolean expected postgres@# postgres=# \if ':DBNAME' == postgres unrecognized value ":DBNAME == postgres" for "\if expression": Boolean expected postgres@# postgres=# \if :DBNAME == 'postgres' unrecognized value "postgres == postgres" for "\if expression": Boolean expected postgres@# postgres=# \if ':DBNAME' == 'postgres' unrecognized value ":DBNAME == postgres" for "\if expression": Boolean expected postgres@# -- Angular momentum makes the world go 'round.