Re: How can I manually alter the statistics for a column?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Douglas Alan <darkwater42(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How can I manually alter the statistics for a column?
Date: 2009-06-02 13:52:42
Message-ID: 10977.1243950762@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Douglas Alan <darkwater42(at)gmail(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2009-06-02 14:19:12 Re: Accessing pg_controldata information from SQL
Previous Message Carlos Oliva 2009-06-02 13:44:44 Schema, databse, or tables in different system folder