I tried to use a function to set the n_distinct value for a table. The code is as follows:
create temporary table _temp
(
id integer
);
create function pg_temp.setdistinct(_cnt real)
returns void as $$
begin
alter table _temp
alter column id set (n_distinct=_cnt);
end
$$ language plpgsql;
select pg_temp.setdistinct(1000);
Yet receive the following errors:
ERROR: invalid value for floating point option "n_distinct": _cnt CONTEXT: SQL statement "alter table _temp alter column id set (n_distinct=_cnt)" PL/pgSQL function pg_temp_3.setdistinct(real) line 3 at SQL statement
The issue can be bypassed using an EXECUTE
statement, but I wonder why we can't use a variable in this particular query. Is there any particular rule I overlooked?