Re: How can I manually alter the statistics for a column? - Mailing list pgsql-general

From Tom Lane
Subject Re: How can I manually alter the statistics for a column?
Date
Msg-id 10977.1243950762@sss.pgh.pa.us
Whole thread Raw
In response to Re: How can I manually alter the statistics for a column?  (Douglas Alan <darkwater42@gmail.com>)
Responses Re: How can I manually alter the statistics for a column?
List pgsql-general
Douglas Alan <darkwater42@gmail.com> writes:
> delete from pg_statistic s
> where exists ( select 1
> from pg_class as c, pg_attribute as a
> where a.attrelid = c.relfilenode
> and s.starelid = c.relfilenode
> and s.staattnum = a.attnum
> and c.relname = 'maindb_astobject'
> and attname = 'survey_id'
> );

Use c.oid, not c.relfilenode.

Also, the join to pg_class is both more and less than needed --- it
won't handle the situation where there are multiple tables of the same
name in different schemas.  You could add pg_namespace into the join,
but it's the hard way.  The way I'd do it is probably

delete from pg_statistic
where (starelid, staattnum) in
  (select attrelid, attnum from pg_attribute
   where attrelid = 'my_relation'::regclass and attname = 'my_attribute');

regclass knows about schemas and search paths, so stuff like
'my_schema.my_relation'::regclass will work unsurprisingly.

            regards, tom lane

pgsql-general by date:

Previous
From: Merlin Moncure
Date:
Subject: Re: newbie table design question
Next
From: "Carlos Oliva"
Date:
Subject: Schema, databse, or tables in different system folder