ALTER_STATISTICS(7pg18)

๐Ÿ“ฆ version 18.6, in opensuse-leap 16.0

๐Ÿ’– ALTER STATISTICS ๐Ÿ’–

okay bestie, this one's from the PostgreSQL 18.6 Documentation and it's literally called ALTER_STATISTICS โ€” yes it's a whole page about changing the definition of an extended statistics object. iykyk. ๐ŸŽ€


โœจ NAME โœจ

ALTER_STATISTICS โ€” change the definition of an extended statistics object. that's the whole job. periodt.


๐ŸŒธ SYNOPSIS ๐ŸŒธ

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 }

look at her. four little glow-ups she can do. ๐Ÿ’…


๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

so ALTER STATISTICS changes the parameters of an existing extended statistics object. that's it, that's the vibe. and here's the cute part: any parameters you did not specifically set in your ALTER STATISTICS command just... keep their prior settings. no surprise resets. she's not gonna touch what you didn't ask her to touch. ๐Ÿซถ

now, the rules. you must own the statistics object to use ALTER STATISTICS. no owning, no altering, sorry babe.

want to change a statistics object's schema? you also need CREATE privilege on the new schema. yes, both. it's giving "two forms of ID at the club." ๐Ÿ˜ญ

want to alter the owner? you need to be able to SET ROLE to the new owning role, and that role must have CREATE privilege on the statistics object's schema. and why so strict, you ask? because these restrictions enforce that altering the owner doesn't do anything you couldn't do by dropping and recreating the statistics object. like, the shortcut can't be more powerful than the long way. that's the whole point. ๐Ÿ‘‘

ngl there's one little loophole though: a superuser can alter ownership of any statistics object anyway. main character energy, obviously. ๐Ÿ‘‘

โœจ PARAMETERS โœจ

  • name โ€” the name (optionally schema-qualified) of the statistics object you're about to alter. gotta know who we're talking about. ๐ŸŽ€
  • new_owner โ€” the user name of the new owner of the statistics object. new parent, new vibe.
  • new_name โ€” the new name for the statistics object. rebranding era. โœจ
  • new_schema โ€” the new schema for the statistics object. moving out, getting a new address. ๐Ÿ 
  • new_target โ€” the statistic-gathering target for this statistics object for subsequent ANALYZE operations. here's the tea: 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). oh and heads up โ€” setting it to a value of -1 is an obsolete way spelling to get the same outcome. lowkey don't do that, it's giving 2010. ๐Ÿ™ˆ 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. we made this one ourselves. it's a PostgreSQL original. ๐Ÿ’…


๐ŸŒˆ SEE ALSO ๐ŸŒˆ

  • CREATE STATISTICS (CREATE_STATISTICS(7)) โ€” where the baby statistics objects come from ๐Ÿผ
  • DROP STATISTICS (DROP_STATISTICS(7)) โ€” for when it's time to say goodbye ๐Ÿ’€

and that's the whole page, bestie!! you ate. go forth and alter responsibly. ๐Ÿซถโœจ

this masterpiece is from PostgreSQL 18.6, dated 2026 โ€” drink some water, hydrate, and remember: you're doing amazing. ๐Ÿ’–๐Ÿงš๐ŸŒธ

๐Ÿ“ฆ where this page comes from