CREATE TABLE alter_am(i int);
INSERT INTO alter_am SELECT generate_series(1,1000000);
SELECT * FROM columnar.options WHERE relation = 'alter_am'::regclass;
 relation | chunk_group_row_limit | stripe_row_limit | compression | compression_level
---------------------------------------------------------------------
(0 rows)

SELECT SUM(i) FROM alter_am;
     sum
---------------------------------------------------------------------
 500000500000
(1 row)

ALTER TABLE alter_am
  SET ACCESS METHOD columnar,
  SET (columnar.compression = pglz, fillfactor = 20);
SELECT * FROM columnar.options WHERE relation = 'alter_am'::regclass;
 relation | chunk_group_row_limit | stripe_row_limit | compression | compression_level
---------------------------------------------------------------------
 alter_am |                 10000 |           150000 | pglz        |                 3
(1 row)

SELECT SUM(i) FROM alter_am;
     sum
---------------------------------------------------------------------
 500000500000
(1 row)

ALTER TABLE alter_am SET ACCESS METHOD heap;
-- columnar options should be gone
SELECT * FROM columnar.options WHERE relation = 'alter_am'::regclass;
 relation | chunk_group_row_limit | stripe_row_limit | compression | compression_level
---------------------------------------------------------------------
(0 rows)

SELECT SUM(i) FROM alter_am;
     sum
---------------------------------------------------------------------
 500000500000
(1 row)

-- error: setting columnar options must happen after converting to columnar
ALTER TABLE alter_am
  SET (columnar.stripe_row_limit = 1111),
  SET ACCESS METHOD columnar;
ERROR:  ALTER TABLE cannot alter the access method after altering storage parameters
HINT:  Specify SET ACCESS METHOD before storage parameters, or use separate ALTER TABLE commands.
DROP TABLE alter_am;
