Internal function returning pg_statistic

From: Konstantin Knizhnik <k(dot)knizhnik(at)postgrespro(dot)ru>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Internal function returning pg_statistic
Date: 2019-11-20 09:59:01
Message-ID: ac83e1e7-5834-adcd-ada9-33a95d082d8b@postgrespro.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi hackers,

Working on global temporary table I need to define function which
returns set of pg_statistic records.
Unfortunately I failed to declare such function!
Type pg_statistic is defined in postgres.bki so I was not able to refer
to it in pg_proc.dat file.
And if I explicitly enumerate columns of this type:

{ oid => '3434',
  descr => 'show local statistics for global temp table',
  proname => 'pg_gtt_statistic_for_relation', provolatile => 'v',
proparallel => 'u',
  prorettype => 'record', proretset => 't', proargtypes => 'oid',
  proallargtypes =>
'{oid,oid,int2,bool,float4,int4,float4,int2,int2,int2,int2,int2,oid,oid,oid,oid,oid,oid,oid,oid,oid,oid,_float4,_float4,_float4,_float4,_float4,anyarray,anyarray,anyarray,anyarray,anyarray}',
  proargmodes =>
'{i,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o}',
  proargnames =>
'{relid,starelid,staattnum,stainherit,stanullfrac,stawidth,stadistinct,stakind1,stakind2,stakind3,stakind4,stakind5,staop1,staop2,staop3,staop4,staop5,stacoll1,stacoll2,stacoll3,stacoll4,stacoll5,stanumbers1,stanumbers2,stanumbers3,stanumbers4,stanumbers5,stavalues1,stavalues2,stavalues3,stavalues4,stavalues5}',
  prosrc => 'pg_gtt_statistic_for_relation' },

then I go the following error when try to use this function:

  a column definition list is required for functions returning "record"
at character 111

The column definition list provided in pg_proc.dat was rejected because
it contains reference to anyarray which can not be resolved.

If I try to declare function in system_views.sql as returning setof
pg_statistic then I got error "cannot change return type of existing
function".

CREATE OR REPLACE FUNCTION
   pg_gtt_statistic_for_relation(relid oid) returns setof pg_statistic
LANGUAGE INTERNAL STRICT
AS 'pg_gtt_statistic_by_relation';

And if I try to declare it as returning record and explicitly cast it to
pg_statistic, then reported error is "cannot cast type record to
pg_statistic".

So the only possible way I found is to create extension and define
function in this extension.
I wonder if there is some better solution?

Thanks in advance,

--
Konstantin Knizhnik
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2019-11-20 10:26:16 Re: Internal function returning pg_statistic
Previous Message Michael Paquier 2019-11-20 08:50:07 Re: pg_waldump and PREPARE