Use variables in pure SQL

June 25, 2021 — Ulysse

Here’s the hack:

WITH vars as (
  SELECT 'my-very-long-long-name' as foo,
         112098237449803127134987 as num,
         '{"hello":"there"}'::json as js
)
SELECT vars.foo, vars.js->'hello', num / 2
FROM vars;