postgres declare variable
WITH myconstants (var1, var2) as (
values (5, 'foo')
)
SELECT *
FROM somewhere, myconstants
WHERE something = var1
OR something_else = var2;
postgres declare variable
WITH myconstants (var1, var2) as (
values (5, 'foo')
)
SELECT *
FROM somewhere, myconstants
WHERE something = var1
OR something_else = var2;
postgresql variable in query
-- with myVar as (select "any value really")
-- then, to get access to the value stored in this construction, you do
-- (select * from myVar)
-- for example
with var as (select 123)
... where id = (select * from var)
-- You could event re-cast the value (e.g. from INT to VARCHAR)
with var as (select 123)
... where id = ((select * from var)::VARCHAR)
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us