timescaledb/test/sql/generated_as_identity.sql
Sven Klemm f89fd07c5b Remove year from SQL file license text
This changes the license text for SQL files to be identical
with the license text for C files.
2019-01-13 23:30:22 +01:00

35 lines
1.1 KiB
SQL

-- This file and its contents are licensed under the Apache License 2.0.
-- Please see the included NOTICE for copyright information and
-- LICENSE-APACHE for a copy of the license.
CREATE table test_gen (
id int generated by default AS IDENTITY primary key,
payload text
);
SELECT create_hypertable('test_gen', 'id', chunk_time_interval=>10);
insert into test_gen (payload) select generate_series(1,15) returning *;
select * from test_gen;
\set ON_ERROR_STOP 0
insert into test_gen values('1', 'a');
\set ON_ERROR_STOP 1
ALTER TABLE test_gen ALTER COLUMN id DROP IDENTITY;
\set ON_ERROR_STOP 0
insert into test_gen (payload) select generate_series(15,20) returning *;
\set ON_ERROR_STOP 1
ALTER TABLE test_gen ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY;
\set ON_ERROR_STOP 0
insert into test_gen (payload) select generate_series(15,20) returning *;
\set ON_ERROR_STOP 1
ALTER TABLE test_gen ALTER COLUMN id SET GENERATED BY DEFAULT RESTART 100;
insert into test_gen (payload) select generate_series(15,20) returning *;
select * from test_gen;
SELECT * FROM test.show_subtables('test_gen');