public inbox for [email protected]  
help / color / mirror / Atom feed
From: Greg Sabino Mullane <[email protected]>
To: JORGE MALDONADO <[email protected]>
Cc: [email protected]
Subject: Re: Declaring a constant or variable in a query
Date: Tue, 25 Jul 2023 12:51:14 -0400
Message-ID: <CAKAnmmKVdAgEdDYhyxnHuks_d=xdEY0_Q1GZy9ab8rVqM9mhpg@mail.gmail.com> (raw)
In-Reply-To: <CAAY=A7_x27sHHgWzDRyWmdhMSVoF0CzDH5121f1=VwJ+iv8RXQ@mail.gmail.com>
References: <CAAY=A7_x27sHHgWzDRyWmdhMSVoF0CzDH5121f1=VwJ+iv8RXQ@mail.gmail.com>

Not sure how exactly DataGrip works for prompting input, but a CTE should
allow you to declare the constant once:

WITH x AS (SELECT :myinput AS alias5)
SELECT fld1 as alias1, fld2 as alias2, fld3 as alias3, fld4 as alias4,
alias5 FROM table1, x WHERE condition1
UNION
SELECT fld1 as alias1, fld2 as alias2, fld3 as alias3, fld4 as
alias4, alias5 FROM table2, x WHERE condition2
UNION
SELECT fld1 as alias1, fld2 as alias2, fld3 as alias3, fld4 as
alias4, alias5 FROM table3, x WHERE condition3
UNION
SELECT fld1 as alias1, fld2 as alias2, fld3 as alias3, fld4 as
alias4, alias5 FROM table4, x WHERE condition4

Cheers,
Greg


view thread (2+ messages)

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 using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: Declaring a constant or variable in a query
  In-Reply-To: <CAKAnmmKVdAgEdDYhyxnHuks_d=xdEY0_Q1GZy9ab8rVqM9mhpg@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox