Skip to main content
2 of 2
typo
Erwin Brandstetter
  • 182.2k
  • 28
  • 457
  • 620

Assign the variable at declaration time if it's known at declaration time. Else it's initialized with NULL and you need another statement to assign it. A small waste of code and performance.

DO
$$
DECLARE
   dateval date[] := '{2015-4-12, 2015-4-19}';
BEGIN
   -- do something
END
$$;

You just need the right syntax for either an array literal or an ARRAY constructor.

The string literal above needs no explicit cast, since the type is defined in the assignment implicitly.

Related:

Erwin Brandstetter
  • 182.2k
  • 28
  • 457
  • 620