SELECT 'cookie' AS component
, 'session' AS name
, sqlpage.random_string(32) AS value
WHERE sqlpage.cookie('session') IS NULL
;

SELECT 'cookie' AS component
, name AS name
, CASE
    WHEN $apply::bool
    THEN COALESCE(value, 'null')
    WHEN $clear::bool
    THEN 'null'
  END::text AS value
FROM (VALUES
  ('products', $products),
  ('categories', $categories),
  ('groups', $groups),
  ('tags', $tags),
  ('unit_count', $unit_count)
) AS vars(name, value)
WHERE $apply::bool OR $clear::bool
;
SELECT 'cookie' AS component
, name AS name
, CASE
    WHEN $apply::bool
    THEN COALESCE(value, '')
    WHEN $clear::bool
    THEN ''
  END AS value
FROM (VALUES
  ('start', $start),
  ('end', $end),
  ('unit_volume', $unit_volume),
  ('unit_mass', $unit_mass),
  ('log_scale', $log_scale)
) AS vars(name, value)
WHERE $apply::bool OR $clear::bool
;