From: Andreas Joseph Krogh <andreas@visena.com>
To: pgsql-general@lists.postgresql.org
Subject: Sv: Using psql variables in DO-blocks
Date: Tue, 15 Jan 2019 17:00:16 +0100 (CET)
Message-ID: <VisenaEmail.ae.b3ae5af6d6b5af5a.168523d524e@tc7-visena> (raw)
In-Reply-To: <VisenaEmail.ac.52245673f23b65b6.16852332064@tc7-visena>
På tirsdag 15. januar 2019 kl. 16:51:09, skrev Andreas Joseph Krogh <
andreas@visena.com <mailto:andreas@visena.com>>:
Hi all.
I'm trying to use a psql variable in a DO-block, but it fails:
[snip]
Seems I was a bit lazy, here's what works:
\set resource_group 'Ressurser' \set quoted_resource_group '\''
:resource_group '\'' set myvars.quoted_resource_group to :quoted_resource_group;
DO$$ begin if not exists(SELECT * FROM onp_group WHERE groupname =
current_setting('myvars.quoted_resource_group')) then raise notice 'Group %
not found, creating it.', current_setting('myvars.quoted_resource_group'); end
if; end; $$;
-- Andreas Joseph Krogh
CTO / Partner - Visena AS
Mobile: +47 909 56 963
andreas@visena.com <mailto:andreas@visena.com>
www.visena.com <https://www.visena.com;
<https://www.visena.com;
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: andreas@visena.com
Subject: Re: Using psql variables in DO-blocks
In-Reply-To: <VisenaEmail.ae.b3ae5af6d6b5af5a.168523d524e@tc7-visena>
References: <VisenaEmail.ac.52245673f23b65b6.16852332064@tc7-visena> <VisenaEmail.ae.b3ae5af6d6b5af5a.168523d524e@tc7-visena>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox