Using psql variables in DO-blocks - Mailing list pgsql-general

From Andreas Joseph Krogh
Subject Using psql variables in DO-blocks
Date
Msg-id VisenaEmail.ac.52245673f23b65b6.16852332064@tc7-visena
Whole thread Raw
Responses Re: Using psql variables in DO-blocks
Sv: Using psql variables in DO-blocks
List pgsql-general
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
Attachment

pgsql-general by date:

Previous
From: Thomas Kellerer
Date:
Subject: Re: Refining query statement
Next
From: Adrian Klaver
Date:
Subject: Re: Refining query statement