“PostgreSQL -Variable in der Abfrage” Code-Antworten

Postgres deklarieren variable

WITH myconstants (var1, var2) as (
   values (5, 'foo')
)
SELECT *
FROM somewhere, myconstants
WHERE something = var1
   OR something_else = var2;
Coding Cobra

PostgreSQL -Variable in der Abfrage

-- 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)
Muddy Moose

Ähnliche Antworten wie “PostgreSQL -Variable in der Abfrage”

Fragen ähnlich wie “PostgreSQL -Variable in der Abfrage”

Weitere verwandte Antworten zu “PostgreSQL -Variable in der Abfrage” auf Sql

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen