-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
29 lines (25 loc) · 868 Bytes
/
schema.sql
File metadata and controls
29 lines (25 loc) · 868 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
26
27
28
29
-- =============================================================
-- Section 13 — Common Table Expressions (CTEs)
-- =============================================================
DROP SCHEMA IF EXISTS adv_cte CASCADE;
CREATE SCHEMA adv_cte;
SET search_path TO adv_cte;
-- Classic self-referencing employee table for the recursive CTE
CREATE TABLE employee (
id SERIAL PRIMARY KEY,
full_name VARCHAR(200) NOT NULL,
title VARCHAR(100) NOT NULL,
manager_id INTEGER REFERENCES employee(id),
salary INTEGER NOT NULL
);
-- Category tree for the other recursive CTE
CREATE TABLE category (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
parent_id INTEGER REFERENCES category(id)
);
CREATE TABLE sale (
id SERIAL PRIMARY KEY,
sold_at DATE NOT NULL,
amount_cents INTEGER NOT NULL
);