-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path02-create_table.sql
More file actions
25 lines (21 loc) · 926 Bytes
/
Copy path02-create_table.sql
File metadata and controls
25 lines (21 loc) · 926 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
-- We can use psql metacommands - in this instance we're connecting to a specific database
-- before executing CREATE TABLE
\c audit
CREATE SEQUENCE IF NOT EXISTS logs.access_log_sq MINVALUE 0 START 1 NO CYCLE;
CREATE TABLE logs.access_log (
id BIGINT NOT NULL DEFAULT nextval('logs.access_log_sq') PRIMARY KEY,
ip INET NULL,
content JSONB NOT NULL,
token_valid TSTZRANGE NOT NULL,
time_stamp TIMESTAMPTZ NOT NULL DEFAULT (now())
);
-- Example of using time-series tables, which inherit from parent table
CREATE TABLE logs.access_log_2016 (
PRIMARY KEY (id)
)
INHERITS (logs.access_log);
ALTER TABLE logs.access_log_2016
ADD CONSTRAINT chk_y2016
CHECK (
time_stamp >= '2016-1-1'::timestamptz AND time_stamp < '2017-1-1'::timestamptz
);