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

From David G. Johnston
Subject Re: Using psql variables in DO-blocks
Date
Msg-id CAKFQuwY381xD9u32CSFRwizpApsFUf082CW1yBLJJ062DZifDg@mail.gmail.com
Whole thread Raw
In response to Using psql variables in DO-blocks  (Andreas Joseph Krogh <andreas@visena.com>)
List pgsql-general
On Tue, Jan 15, 2019 at 8:48 AM Andreas Joseph Krogh <andreas@visena.com> wrote:
Hi all.
 
I'm trying to use a psql variable in a DO-block, but it fails:
 [...]
Any hints?

Don't do that.  The body of a DO block is a string literal and psql won't and shouldn't mess with its contents.  You'll need to use an actual function and pass in the psql variable data via an input parameter.

set_config(...)/current_setting(...) is another option to consider.

David J.

Attachment

pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: Refining query statement
Next
From: Andreas Joseph Krogh
Date:
Subject: Sv: Using psql variables in DO-blocks