pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andreas Joseph Krogh <andreas@visena.com>
To: pgsql-general@postgresql.org <pgsql-general@postgresql.org>
Subject: Using psql variables in DO-blocks
Date: Tue, 15 Jan 2019 16:51:09 +0100 (CET)
Message-ID: <VisenaEmail.ac.52245673f23b65b6.16852332064@tc7-visena> (raw)

Hi all.
 
I'm trying to use a psql variable in a DO-block, but it fails:
 
\set resource_group 'Ressurser' \set quoted_resource_group '\'' 
:resource_group '\'' DO $$ begin  if not exists(SELECT * FROM tbl_group WHERE 
groupname = :quoted_resource_group)then  raise notice 'Group % not found, 
creating it.', :quoted_resource_group; end if; end; $$; 
 
ERROR:  syntax error at or near ":" 
 LINE 3: ... exists(SELECT * FROM tbl_group WHERE groupname = :quoted_re...
                                                            ^
  
Any hints?
 
-- 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;

view thread (2+ messages)  latest in thread

Message-ID: <VisenaEmail.ac.52245673f23b65b6.16852332064@tc7-visena>
Permalink:  ../VisenaEmail.ac.52245673f23b65b6.16852332064@tc7-visena/
Also on:    postgresql.org/message-id/VisenaEmail.ac.52245673f23b65b6.16852332064@tc7-visena

 · 

reply

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.ac.52245673f23b65b6.16852332064@tc7-visena>
  References: <VisenaEmail.ac.52245673f23b65b6.16852332064@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