CLUSTER ON index_name
SET WITHOUT CLUSTER
SET WITHOUT OIDS
- SET ACCESS METHOD new_access_method
+ SET ACCESS METHOD { new_access_method | DEFAULT }
SET TABLESPACE new_tablespace
SET { LOGGED | UNLOGGED }
SET ( storage_parameter [= value] [, ... ] )
This form changes the access method of the table by rewriting it. See
- for more information.
+ for more information. Writing
+ DEFAULT changes the access method of the table
+ to .
*
* Check that access method exists. If it is the same as the table's current
* access method, it is a no-op. Otherwise, a table rewrite is necessary.
+ * If amname is NULL, select default_table_access_method as access method.
*/
static void
ATPrepSetAccessMethod(AlteredTableInfo *tab, Relation rel, const char *amname)
Oid amoid;
/* Check that the table access method exists */
- amoid = get_table_am_oid(amname, false);
+ amoid = get_table_am_oid(amname ? amname : default_table_access_method,
+ false);
if (rel->rd_rel->relam == amoid)
return;
%type alter_identity_column_option_list
%type alter_identity_column_option
%type set_statistics_value
+%type set_access_method_name
%type createdb_opt_list createdb_opt_items copy_opt_list
transaction_mode_list
n->newowner = $3;
$$ = (Node *) n;
}
- /* ALTER TABLE
SET ACCESS METHOD */
- | SET ACCESS METHOD name
+ /* ALTER TABLE
SET ACCESS METHOD { | DEFAULT } */
+ | SET ACCESS METHOD set_access_method_name
{
AlterTableCmd *n = makeNode(AlterTableCmd);
| DEFAULT { $$ = NULL; }
;
+set_access_method_name:
+ ColId { $$ = $1; }
+ | DEFAULT { $$ = NULL; }
+ ;
+
PartitionBoundSpec:
/* a HASH partition */
FOR VALUES WITH '(' hash_partbound ')'
* AMs.
*/
else if (Matches("ALTER", "TABLE", MatchAny, "SET", "ACCESS", "METHOD"))
- COMPLETE_WITH_QUERY(Query_for_list_of_table_access_methods);
+ COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_table_access_methods,
+ "DEFAULT");
/*
* If we have ALTER TABLE SET TABLESPACE provide a list of
9 | 1
(1 row)
+-- DEFAULT access method
+BEGIN;
+SET LOCAL default_table_access_method TO heap2;
+ALTER TABLE heaptable SET ACCESS METHOD DEFAULT;
+SELECT amname FROM pg_class c, pg_am am
+ WHERE c.relam = am.oid AND c.oid = 'heaptable'::regclass;
+ amname
+--------
+ heap2
+(1 row)
+
+SET LOCAL default_table_access_method TO heap;
+ALTER TABLE heaptable SET ACCESS METHOD DEFAULT;
+SELECT amname FROM pg_class c, pg_am am
+ WHERE c.relam = am.oid AND c.oid = 'heaptable'::regclass;
+ amname
+--------
+ heap
+(1 row)
+
+ROLLBACK;
-- ALTER MATERIALIZED VIEW SET ACCESS METHOD
CREATE MATERIALIZED VIEW heapmv USING heap AS SELECT * FROM heaptable;
SELECT amname FROM pg_class c, pg_am am
-- No support for multiple subcommands
ALTER TABLE heaptable SET ACCESS METHOD heap, SET ACCESS METHOD heap2;
ERROR: cannot have multiple SET ACCESS METHOD subcommands
+ALTER TABLE heaptable SET ACCESS METHOD DEFAULT, SET ACCESS METHOD heap2;
+ERROR: cannot have multiple SET ACCESS METHOD subcommands
ALTER MATERIALIZED VIEW heapmv SET ACCESS METHOD heap, SET ACCESS METHOD heap2;
ERROR: cannot have multiple SET ACCESS METHOD subcommands
DROP MATERIALIZED VIEW heapmv;
SELECT amname FROM pg_class c, pg_am am
WHERE c.relam = am.oid AND c.oid = 'heaptable'::regclass;
SELECT COUNT(a), COUNT(1) FILTER(WHERE a=1) FROM heaptable;
+-- DEFAULT access method
+BEGIN;
+SET LOCAL default_table_access_method TO heap2;
+ALTER TABLE heaptable SET ACCESS METHOD DEFAULT;
+SELECT amname FROM pg_class c, pg_am am
+ WHERE c.relam = am.oid AND c.oid = 'heaptable'::regclass;
+SET LOCAL default_table_access_method TO heap;
+ALTER TABLE heaptable SET ACCESS METHOD DEFAULT;
+SELECT amname FROM pg_class c, pg_am am
+ WHERE c.relam = am.oid AND c.oid = 'heaptable'::regclass;
+ROLLBACK;
-- ALTER MATERIALIZED VIEW SET ACCESS METHOD
CREATE MATERIALIZED VIEW heapmv USING heap AS SELECT * FROM heaptable;
SELECT amname FROM pg_class c, pg_am am
SELECT COUNT(a), COUNT(1) FILTER(WHERE a=1) FROM heapmv;
-- No support for multiple subcommands
ALTER TABLE heaptable SET ACCESS METHOD heap, SET ACCESS METHOD heap2;
+ALTER TABLE heaptable SET ACCESS METHOD DEFAULT, SET ACCESS METHOD heap2;
ALTER MATERIALIZED VIEW heapmv SET ACCESS METHOD heap, SET ACCESS METHOD heap2;
DROP MATERIALIZED VIEW heapmv;
DROP TABLE heaptable;