-1

Does anyone know if it's possible to use a generate_series function as a default value for a function?

current_date works fine but would also like to specify a value range by default but get the set-returning function are not allow in default expressions. In this scenario, it would sure be nice to insert a default value not to fire off some unbounded query. I suppose you could add logic in the function itself???

CREATE OR REPLACE FUNCTION foo(
        start_date date DEFAULT current_date
    ,   end_date date DEFAULT (current_date - interval '60 days')
    ,   sites int[] DEFAULT (generate_series(1, 10, 1))
    ,   details bool DEFAULT false
) RETURNS text
AS $$
select 'foo'
$$ LANGUAGE SQL;
select foo();
Kip
  • 97
  • 6
  • 1
    You need to use a constant: `DEFAULT (array[1,2,3,4,5,6,7,8,9,10])` –  Feb 08 '19 at 17:17

1 Answers1

0

Why not use a range function?

https://www.postgresql.org/docs/9.3/functions-range.html

'[1,10]'::int4range

But I'm pretty sure this will not result in something like you seem to want, like (1,2,3,2,1) - if I interpret that correctly.

cslotty
  • 1,696
  • 20
  • 28