↑↓ select↵ open⌫ change scopeOpen full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

Wiki / SQL Commands

ALTER STATISTICS

change the definition of an extended statistics object

English manual coverage begins with PostgreSQL 6.4. Source history and runtime observations have their own recorded version boundaries.

Reading PG 18·Select a recorded version

anchor
SQL-ALTERSTATISTICS
file
sql-alterstatistics.html
lang
en
name
ALTER STATISTICS
purpose
change the definition of an extended statistics object
purpose zh
更改扩展统计对象的定义
sections same as
Unknown
slug
18
synopsis text
ALTER STATISTICS name OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER } ALTER STATISTICS name RENAME TO new_name ALTER STATISTICS name SET SCHEMA new_schema ALTER STATISTICS name SET STATISTICS { new_target | DEFAULT }

Syntax

ALTER STATISTICS name OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }
ALTER STATISTICS name RENAME TO new_name
ALTER STATISTICS name SET SCHEMA new_schema
ALTER STATISTICS name SET STATISTICS { new_target | DEFAULT }
Syntax diagrams

Read left to right. Branches are choices, bypasses are optional, loops repeat. Select an underlined parameter to open its rule.

ALTER STATISTICS name OWNER TO new_owner CURRENT_ROLE CURRENT_USER SESSION_USER
ALTER STATISTICS · Syntax 2
ALTER STATISTICS name RENAME TO new_name
ALTER STATISTICS · Syntax 3
ALTER STATISTICS name SET SCHEMA new_schema
ALTER STATISTICS · Syntax 4
ALTER STATISTICS name SET STATISTICS new_target DEFAULT

Definition PG 18

ALTER STATISTICS name OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }
ALTER STATISTICS name RENAME TO new_name
ALTER STATISTICS name SET SCHEMA new_schema
ALTER STATISTICS name SET STATISTICS { new_target | DEFAULT }

Description

ALTER STATISTICS changes the parameters of an existing extended statistics object. Any parameters not specifically set in the ALTER STATISTICS command retain their prior settings.

You must own the statistics object to use ALTER STATISTICS. To change a statistics object's schema, you must also have CREATE privilege on the new schema. To alter the owner, you must be able to SET ROLE to the new owning role, and that role must have CREATE privilege on the statistics object's schema. (These restrictions enforce that altering the owner doesn't do anything you couldn't do by dropping and recreating the statistics object. However, a superuser can alter ownership of any statistics object anyway.)

Parameters

name

The name (optionally schema-qualified) of the statistics object to be altered.

new_owner

The user name of the new owner of the statistics object.

new_name

The new name for the statistics object.

new_schema

The new schema for the statistics object.

new_target

The statistic-gathering target for this statistics object for subsequent ANALYZE operations. The target can be set in the range 0 to 10000. Set it to DEFAULT to revert to using the system default statistics target (default_statistics_target). (Setting to a value of -1 is an obsolete way spelling to get the same outcome.) For more information on the use of statistics by the PostgreSQL query planner, refer to Section 14.2.

Compatibility

There is no ALTER STATISTICS command in the SQL standard.

See Also

CREATE STATISTICS, DROP STATISTICS

Compare versions

Complete source facts

synopsis html

ALTER STATISTICS <em class="replaceable"><code>name</code></em> OWNER TO { <em class="replaceable"><code>new_owner</code></em> | CURRENT_ROLE | CURRENT_USER | SESSION_USER }
ALTER STATISTICS <em class="replaceable"><code>name</code></em> RENAME TO <em class="replaceable"><code>new_name</code></em>
ALTER STATISTICS <em class="replaceable"><code>name</code></em> SET SCHEMA <em class="replaceable"><code>new_schema</code></em>
ALTER STATISTICS <em class="replaceable"><code>name</code></em> SET STATISTICS { <em class="replaceable"><code>new_target</code></em> | DEFAULT }

Source references

Full definition and evidence JSON

Definition sources

center · PostgreSQL 18 · wiki-repair-20261023:86a6fb97f75caf571a80293d6c0aa14cba01ed49e90c55611e8275202aab54e2

Text language: en · wiki-repair-20261023:86a6fb97f75caf571a80293d6c0aa14cba01ed49e90c55611e8275202aab54e2