pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ray O'Donnell <ray@rodonnell.ie>
To: Glenn Schultz <glenn@bondlab.io>
To: pgsql-general@lists.postgresql.org
Subject: Re: initialize and use variable in query
Date: Sat, 29 Dec 2018 15:47:39 +0000
Message-ID: <e8d1a269-24c2-2d05-33a7-c3ed1e925aae@rodonnell.ie> (raw)
In-Reply-To: <CAE-4=KFP9T+RD4kNfu4jY2SHKJEEsSVsF9wUTFzUm01P1vJigw@mail.gmail.com>
References: <CAE-4=KFP9T+RD4kNfu4jY2SHKJEEsSVsF9wUTFzUm01P1vJigw@mail.gmail.com>

On 29/12/2018 15:40, Glenn Schultz wrote:
> All,
> 
> I need to initialize a variable and then use it in query.  
> Ultimately this will part of a recursive CTE but for now I just need to 
> work this out.  I followed the docs and thought I needed something like 
> this.  But does not work-maybe I have misunderstood.  Is this possible?

Hi there,

What does "does not work" mean? What error do you get?

> 
> SET max_parallel_workers_per_gather = 8;
> SET random_page_cost = 1;
> SET enable_partitionwise_aggregate = on;
> Do $$
> Declare startdate date;
> BEGIN
> startdate := (select max(fctrdt) from fnmloan);
> END $$;

A couple of things off the top of my head:

(i) I think you need "language plpgsql" (or whatever) after the DO block.

(ii) That assignment in the DO should probably be:

   select max(fctrdt) into startdate from fnmloan;


I hope this helps.

Ray.


-- 
Raymond O'Donnell // Galway // Ireland
ray@rodonnell.ie




view thread (6+ messages)  latest in thread

Message-ID: <e8d1a269-24c2-2d05-33a7-c3ed1e925aae@rodonnell.ie>
Permalink:  ../e8d1a269-24c2-2d05-33a7-c3ed1e925aae@rodonnell.ie/
Also on:    postgresql.org/message-id/e8d1a269-24c2-2d05-33a7-c3ed1e925aae@rodonnell.ie

 · 

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: ray@rodonnell.ie, glenn@bondlab.io
  Subject: Re: initialize and use variable in query
  In-Reply-To: <e8d1a269-24c2-2d05-33a7-c3ed1e925aae@rodonnell.ie>
  References: <CAE-4=KFP9T+RD4kNfu4jY2SHKJEEsSVsF9wUTFzUm01P1vJigw@mail.gmail.com> <e8d1a269-24c2-2d05-33a7-c3ed1e925aae@rodonnell.ie>

* 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