Re: Using psql variables in DO-blocks

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Andreas Joseph Krogh <andreas(at)visena(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Using psql variables in DO-blocks
Date: 2019-01-15 15:56:01
Message-ID: CAKFQuwY381xD9u32CSFRwizpApsFUf082CW1yBLJJ062DZifDg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Jan 15, 2019 at 8:48 AM Andreas Joseph Krogh <andreas(at)visena(dot)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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Andreas Joseph Krogh 2019-01-15 16:00:16 Sv: Using psql variables in DO-blocks
Previous Message Adrian Klaver 2019-01-15 15:54:57 Re: Refining query statement