EXECUTE 'create temp table ' || tmp_name || ' as select ' || param;
преобразуется (после объединения строк и подстановки значений) в
EXECUTE 'create temp table myresult as select 2019-11-07'; -- => select 2001
Не объединяйте значения таким образом, используйте quote_ident()
и quote_literal()
для правильного цитирования:
EXECUTE 'create temp table ' || quote_ident(tmp_name) || ' as select ' || quote_literal(param);
или с функцией format()
:
EXECUTE format('create %I as select %L', tmp_date, param);
Например:
#= SELECT 'test: ' || current_date as incorrect,
'test: ' || quote_literal(current_date) as correct;
┌──────────────────┬────────────────────┐
│ incorrect │ correct │
├──────────────────┼────────────────────┤
│ test: 2019-11-07 │ test: '2019-11-07' │
└──────────────────┴────────────────────┘