diff --git a/doc/src/sgml/ref/alter_foreign_table.sgml b/doc/src/sgml/ref/alter_foreign_table.sgml index 7ca03f3ac9..d056dc1bb1 100644 --- a/doc/src/sgml/ref/alter_foreign_table.sgml +++ b/doc/src/sgml/ref/alter_foreign_table.sgml @@ -41,7 +41,7 @@ ALTER FOREIGN TABLE [ IF EXISTS ] namecolumn_name SET STATISTICS integer ALTER [ COLUMN ] column_name SET ( attribute_option = value [, ... ] ) ALTER [ COLUMN ] column_name RESET ( attribute_option [, ... ] ) - ALTER [ COLUMN ] column_name SET STORAGE { PLAIN | EXTERNAL | EXTENDED | MAIN } + ALTER [ COLUMN ] column_name SET STORAGE { PLAIN | EXTERNAL | EXTENDED | MAIN | DEFAULT } ALTER [ COLUMN ] column_name OPTIONS ( [ ADD | SET | DROP ] option ['value'] [, ... ]) ADD table_constraint [ NOT VALID ] VALIDATE CONSTRAINT constraint_name diff --git a/doc/src/sgml/ref/alter_materialized_view.sgml b/doc/src/sgml/ref/alter_materialized_view.sgml index cae135c27a..040ae53f98 100644 --- a/doc/src/sgml/ref/alter_materialized_view.sgml +++ b/doc/src/sgml/ref/alter_materialized_view.sgml @@ -39,7 +39,7 @@ ALTER MATERIALIZED VIEW ALL IN TABLESPACE namecolumn_name SET STATISTICS integer ALTER [ COLUMN ] column_name SET ( attribute_option = value [, ... ] ) ALTER [ COLUMN ] column_name RESET ( attribute_option [, ... ] ) - ALTER [ COLUMN ] column_name SET STORAGE { PLAIN | EXTERNAL | EXTENDED | MAIN } + ALTER [ COLUMN ] column_name SET STORAGE { PLAIN | EXTERNAL | EXTENDED | MAIN | DEFAULT } ALTER [ COLUMN ] column_name SET COMPRESSION compression_method CLUSTER ON index_name SET WITHOUT CLUSTER diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml index f0f912a56c..43d782fea9 100644 --- a/doc/src/sgml/ref/alter_table.sgml +++ b/doc/src/sgml/ref/alter_table.sgml @@ -53,7 +53,7 @@ ALTER TABLE [ IF EXISTS ] name ALTER [ COLUMN ] column_name SET STATISTICS integer ALTER [ COLUMN ] column_name SET ( attribute_option = value [, ... ] ) ALTER [ COLUMN ] column_name RESET ( attribute_option [, ... ] ) - ALTER [ COLUMN ] column_name SET STORAGE { PLAIN | EXTERNAL | EXTENDED | MAIN } + ALTER [ COLUMN ] column_name SET STORAGE { PLAIN | EXTERNAL | EXTENDED | MAIN | DEFAULT } ALTER [ COLUMN ] column_name SET COMPRESSION compression_method ADD table_constraint [ NOT VALID ] ADD table_constraint_using_index @@ -367,7 +367,7 @@ WITH ( MODULUS numeric_literal, REM - SET STORAGE { PLAIN | EXTERNAL | EXTENDED | MAIN } + SET STORAGE { PLAIN | EXTERNAL | EXTENDED | MAIN | DEFAULT } TOAST per-column storage settings @@ -376,20 +376,24 @@ WITH ( MODULUS numeric_literal, REM This form sets the storage mode for a column. This controls whether this - column is held inline or in a secondary TOAST table, and - whether the data + column is held inline or in a secondary TOAST table, + and whether the data should be compressed or not. PLAIN must be used for fixed-length values such as integer and is inline, uncompressed. MAIN is for inline, compressible data. EXTERNAL is for external, uncompressed data, and EXTENDED is for external, - compressed data. EXTENDED is the default for most - data types that support non-PLAIN storage. + compressed data. + Writing DEFAULT sets the storage mode to the default + mode for the column's data type. EXTENDED is the + default for most data types that support non-PLAIN + storage. Use of EXTERNAL will make substring operations on very large text and bytea values run faster, - at the penalty of increased storage space. Note that - SET STORAGE doesn't itself change anything in the table, - it just sets the strategy to be pursued during future table updates. + at the penalty of increased storage space. + Note that ALTER TABLE ... SET STORAGE doesn't itself + change anything in the table; it just sets the strategy to be pursued + during future table updates. See for more information. diff --git a/doc/src/sgml/ref/create_table.sgml b/doc/src/sgml/ref/create_table.sgml index c14b2010d8..c98223b2a5 100644 --- a/doc/src/sgml/ref/create_table.sgml +++ b/doc/src/sgml/ref/create_table.sgml @@ -22,7 +22,7 @@ PostgreSQL documentation CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXISTS ] table_name ( [ - { column_name data_type [ STORAGE { PLAIN | EXTERNAL | EXTENDED | MAIN } ] [ COMPRESSION compression_method ] [ COLLATE collation ] [ column_constraint [ ... ] ] + { column_name data_type [ STORAGE { PLAIN | EXTERNAL | EXTENDED | MAIN | DEFAULT } ] [ COMPRESSION compression_method ] [ COLLATE collation ] [ column_constraint [ ... ] ] | table_constraint | LIKE source_table [ like_option ... ] } [, ... ] @@ -299,7 +299,7 @@ WITH ( MODULUS numeric_literal, REM - STORAGE { PLAIN | EXTERNAL | EXTENDED | MAIN } + STORAGE { PLAIN | EXTERNAL | EXTENDED | MAIN | DEFAULT } TOAST per-column storage settings @@ -314,12 +314,14 @@ WITH ( MODULUS numeric_literal, REM inline, uncompressed. MAIN is for inline, compressible data. EXTERNAL is for external, uncompressed data, and EXTENDED is for external, compressed data. - EXTENDED is the default for most data types that - support non-PLAIN storage. Use of - EXTERNAL will make substring operations on very large - text and bytea values run faster, at the penalty - of increased storage space. See for more - information. + Writing DEFAULT sets the storage mode to the default + mode for the column's data type. EXTENDED is the + default for most data types that support non-PLAIN + storage. + Use of EXTERNAL will make substring operations on + very large text and bytea values run faster, + at the penalty of increased storage space. + See for more information. diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 6007e10730..fc4bd0de91 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -19311,6 +19311,8 @@ GetAttributeStorage(Oid atttypid, const char *storagemode) cstorage = TYPSTORAGE_EXTENDED; else if (pg_strcasecmp(storagemode, "main") == 0) cstorage = TYPSTORAGE_MAIN; + else if (pg_strcasecmp(storagemode, "default") == 0) + cstorage = get_typstorage(atttypid); else ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 2dddd8f302..2a910ded15 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -3758,6 +3758,7 @@ opt_column_compression: column_storage: STORAGE ColId { $$ = $2; } + | STORAGE DEFAULT { $$ = pstrdup("default"); } ; opt_column_storage: diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 4c45e4747a..7b73886ce1 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -2420,7 +2420,7 @@ psql_completion(const char *text, int start, int end) /* ALTER TABLE ALTER [COLUMN] SET STORAGE */ else if (Matches("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny, "SET", "STORAGE") || Matches("ALTER", "TABLE", MatchAny, "ALTER", MatchAny, "SET", "STORAGE")) - COMPLETE_WITH("PLAIN", "EXTERNAL", "EXTENDED", "MAIN"); + COMPLETE_WITH("DEFAULT", "PLAIN", "EXTERNAL", "EXTENDED", "MAIN"); /* ALTER TABLE ALTER [COLUMN] SET STATISTICS */ else if (Matches("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny, "SET", "STATISTICS") || Matches("ALTER", "TABLE", MatchAny, "ALTER", MatchAny, "SET", "STATISTICS")) diff --git a/src/test/regress/expected/alter_table.out b/src/test/regress/expected/alter_table.out index ca13f0c13a..600e603bdf 100644 --- a/src/test/regress/expected/alter_table.out +++ b/src/test/regress/expected/alter_table.out @@ -2262,7 +2262,7 @@ select reltoastrelid <> 0 as has_toast_table f (1 row) -alter table test_storage alter a set storage extended; -- re-add TOAST table +alter table test_storage alter a set storage default; -- re-add TOAST table select reltoastrelid <> 0 as has_toast_table from pg_class where oid = 'test_storage'::regclass; has_toast_table diff --git a/src/test/regress/sql/alter_table.sql b/src/test/regress/sql/alter_table.sql index b85b6c7398..f58b2f75d5 100644 --- a/src/test/regress/sql/alter_table.sql +++ b/src/test/regress/sql/alter_table.sql @@ -1535,7 +1535,7 @@ alter table test_storage alter a set storage plain; alter table test_storage add b int default random()::int; select reltoastrelid <> 0 as has_toast_table from pg_class where oid = 'test_storage'::regclass; -alter table test_storage alter a set storage extended; -- re-add TOAST table +alter table test_storage alter a set storage default; -- re-add TOAST table select reltoastrelid <> 0 as has_toast_table from pg_class where oid = 'test_storage'::regclass;