From: | Greg Sabino Mullane <htamfids(at)gmail(dot)com> |
---|---|
To: | JORGE MALDONADO <jorgemal1960(at)gmail(dot)com> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Declaring a constant or variable in a query |
Date: | 2023-07-25 16:51:14 |
Message-ID: | CAKAnmmKVdAgEdDYhyxnHuks_d=xdEY0_Q1GZy9ab8rVqM9mhpg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
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
From | Date | Subject | |
---|---|---|---|
Next Message | Shaozhong SHI | 2023-08-08 22:13:54 | Very odd message |
Previous Message | JORGE MALDONADO | 2023-07-25 14:35:45 | Declaring a constant or variable in a query |