Re: initialize and use variable in query

From: Олег Самойлов <splarv(at)ya(dot)ru>
To: Glenn Schultz <glenn(at)bondlab(dot)io>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: initialize and use variable in query
Date: 2020-02-05 15:22:22
Message-ID: C5FE4D63-1B63-4067-93A2-F0DD692D010F@ya.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Just refactor DO block to function that returns row set and put SELECT inside.

> 29 дек. 2018 г., в 18:40, Glenn Schultz <glenn(at)bondlab(dot)io> написал(а):
>
> 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?
>
> 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 $$;
>
> select
> fnmloan.loanseqnum
> ,fnmloan.currrpb
> from
> fnmloan
>
> join
> fnmloan_data
> on
> fnmloan_data.loanseqnum = fnmloan.loanseqnum
>
> where
> fnmloan.fctrdt = (select * from startdate)
>
> limit 10

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Raul Kaubi 2020-02-05 15:23:38 Re: Error handling: Resume work after error
Previous Message hubert depesz lubaczewski 2020-02-05 15:03:50 Re: Error handling: Resume work after error