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

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: How can I manually alter the statistics for a column?
Дата
Msg-id 10977.1243950762@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: How can I manually alter the statistics for a column?  (Douglas Alan <darkwater42@gmail.com>)
Ответы Re: How can I manually alter the statistics for a column?  (Douglas Alan <darkwater42@gmail.com>)
Список 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 по дате отправления:

Предыдущее
От: Merlin Moncure
Дата:
Сообщение: Re: newbie table design question
Следующее
От: "Carlos Oliva"
Дата:
Сообщение: Schema, databse, or tables in different system folder