Skip to content

Commit e503a3e

Browse files
committed
add more test cases
1 parent 36dfffb commit e503a3e

21 files changed

+995
-13
lines changed

__fixtures__/generated/generated.json

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,43 @@
11
{
2+
"pretty/types-1.sql": "CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy')",
3+
"pretty/types-2.sql": "CREATE TYPE \"AlertLevel\" AS ENUM ('Low', 'MEDIUM', 'High', 'CRITICAL')",
4+
"pretty/types-3.sql": "CREATE TYPE address AS (\n street text,\n city text,\n zip_code int\n)",
5+
"pretty/types-4.sql": "CREATE TYPE \"PostalInfo\" AS (\n \"Street\" text,\n \"City\" text,\n \"ZipCode\" integer\n)",
6+
"pretty/types-5.sql": "CREATE TYPE public.user_metadata AS (\n key text,\n value jsonb\n)",
7+
"pretty/types-6.sql": "CREATE TYPE tsrange_custom AS RANGE (\n subtype = timestamp with time zone,\n subtype_diff = timestamp_diff,\n canonical = normalize_tsrange\n)",
8+
"pretty/types-7.sql": "CREATE TYPE version_enum AS ENUM ('1.0', '1.1', '2.0')",
9+
"pretty/types-8.sql": "CREATE TYPE full_location AS (\n address address,\n region_code char(2)\n)",
10+
"pretty/types-9.sql": "CREATE TYPE \"Workflow-State\" AS ENUM ('draft', 'in-review', 'needs-fix', 'finalized')",
11+
"pretty/triggers-1.sql": "CREATE TRIGGER audit_insert_trigger\n AFTER INSERT\n ON public.users\n FOR EACH ROW\n EXECUTE PROCEDURE log_user_insert()",
12+
"pretty/triggers-2.sql": "CREATE TRIGGER \"AuditTrigger\"\n AFTER DELETE\n ON \"SensitiveData\"\n FOR EACH ROW\n EXECUTE PROCEDURE public.log_deletion()",
13+
"pretty/triggers-3.sql": "CREATE TRIGGER archive_if_inactive\n BEFORE UPDATE\n ON accounts\n FOR EACH ROW\n WHEN (OLD.active = false)\n EXECUTE PROCEDURE \"ArchiveFunction\"()",
14+
"pretty/triggers-4.sql": "CREATE TRIGGER update_stats_on_change\n AFTER UPDATE OR INSERT\n ON metrics.stats\n FOR EACH ROW\n EXECUTE PROCEDURE metrics.update_stats('user', true)",
15+
"pretty/triggers-5.sql": "CREATE TRIGGER \"TrickyTrigger\"\n BEFORE DELETE\n ON \"weirdSchema\".\"ComplexTable\"\n FOR EACH ROW\n WHEN (OLD.\"status\" = 'pending')\n EXECUTE PROCEDURE \"weirdSchema\".\"ComplexFn\"('arg1', 42)",
16+
"pretty/triggers-6.sql": "CREATE TRIGGER user_activity_log\n AFTER INSERT OR DELETE OR UPDATE\n ON users\n FOR EACH ROW\n EXECUTE PROCEDURE audit.activity_log()",
17+
"pretty/triggers-7.sql": "CREATE TRIGGER no_schema\n BEFORE INSERT\n ON log_table\n FOR EACH ROW\n EXECUTE PROCEDURE update_log()",
18+
"pretty/triggers-8.sql": "CREATE TRIGGER flag_special_updates\n AFTER UPDATE\n ON profiles\n FOR EACH ROW\n WHEN (NEW.\"accessLevel\" = 'admin')\n EXECUTE PROCEDURE flag_admin_change()",
19+
"pretty/triggers-9.sql": "CREATE TRIGGER \"TriggerMixedCase\"\n BEFORE INSERT\n ON dataPoints\n FOR EACH ROW\n EXECUTE PROCEDURE \"HandleInsert\"('TYPE_A', 'Region-1')",
20+
"pretty/triggers-10.sql": "CREATE TRIGGER cascade_on_partition\n AFTER DELETE\n ON events_log_partition\n FOR EACH ROW\n EXECUTE PROCEDURE propagate_deletion()",
21+
"pretty/tables-1.sql": "CREATE TABLE public.users (\n id serial PRIMARY KEY,\n name text NOT NULL\n)",
22+
"pretty/tables-2.sql": "CREATE TABLE \"App\".\"User Data\" (\n \"User ID\" uuid PRIMARY KEY,\n \"Full Name\" text NOT NULL\n)",
23+
"pretty/tables-3.sql": "CREATE TABLE system.settings (\n setting_key text PRIMARY KEY,\n setting_value text,\n CONSTRAINT \"Default Setting Check\" CHECK (setting_value IS NOT NULL)\n)",
24+
"pretty/tables-4.sql": "CREATE TABLE \"Inventory\".\"StockItems\" (\n \"ItemID\" int PRIMARY KEY,\n \"Tags\" text[]\n)",
25+
"pretty/tables-5.sql": "CREATE TABLE \"Orders\".\"OrderLines\" (\n id serial PRIMARY KEY,\n order_id int,\n CONSTRAINT \"FK Order Reference\" FOREIGN KEY (order_id) REFERENCES \"Orders\".\"Order\"(\"OrderID\")\n)",
26+
"pretty/tables-6.sql": "CREATE TABLE contact_info (\n id int PRIMARY KEY,\n location address -- assumed composite type\n)",
27+
"pretty/tables-7.sql": "CREATE TABLE \"Archive\".\"OldUsers\" (\n archived_at timestamptz DEFAULT now()\n) INHERITS (\"Users\".\"User Data\")",
28+
"pretty/tables-8.sql": "CREATE TABLE logging.audit_trail (\n log_id int GENERATED BY DEFAULT AS IDENTITY,\n message text,\n CONSTRAINT \"PK_Audit\" PRIMARY KEY (log_id)\n)",
29+
"pretty/tables-9.sql": "CREATE TABLE finance.transactions (\n amount numeric,\n tax_rate numeric,\n total numeric GENERATED ALWAYS AS (amount * (1 + tax_rate)) STORED\n)",
30+
"pretty/tables-10.sql": "CREATE TABLE metrics.monthly_stats (\n stat_id serial,\n recorded_at date\n) PARTITION BY RANGE (recorded_at)",
31+
"pretty/tables-11.sql": "CREATE TABLE school.attendance (\n \"Student ID\" uuid,\n \"Class ID\" uuid,\n attended_on date DEFAULT CURRENT_DATE,\n PRIMARY KEY (\"Student ID\", \"Class ID\")\n)",
32+
"pretty/tables-12.sql": "CREATE TABLE secure.sessions (\n session_id uuid PRIMARY KEY,\n user_id uuid,\n CONSTRAINT \"fk-user->session\" FOREIGN KEY (user_id) REFERENCES users(id)\n)",
33+
"pretty/tables-13.sql": "CREATE TABLE public.\"API Keys\" (\n \"KeyID\" uuid PRIMARY KEY,\n \"ClientName\" text,\n \"KeyValue\" text UNIQUE,\n CONSTRAINT \"Unique_ClientName\" UNIQUE (\"ClientName\")\n)",
34+
"pretty/tables-14.sql": "CREATE TABLE alerts (\n alert_id serial PRIMARY KEY,\n level \"AlertLevel\" NOT NULL -- assumed enum type\n)",
35+
"pretty/tables-15.sql": "CREATE TABLE \"Billing\".\"Invoices\" (\n invoice_id uuid PRIMARY KEY,\n \"Client ID\" uuid,\n CONSTRAINT \"FK_Client\" FOREIGN KEY (\"Client ID\") REFERENCES \"Clients\".\"ClientBase\"(\"Client ID\")\n)",
36+
"pretty/tables-16.sql": "CREATE TABLE media.assets (\n id uuid PRIMARY KEY,\n url text,\n CONSTRAINT \"Check-URL-NonEmpty\" CHECK (url <> '')\n)",
37+
"pretty/tables-17.sql": "CREATE TABLE data.snapshots (\n id serial PRIMARY KEY,\n metadata jsonb,\n context address\n)",
38+
"pretty/tables-18.sql": "CREATE TABLE \"x-Schema\".\"z-Table\" (\n \"Z-ID\" int PRIMARY KEY,\n \"Z-Name\" text,\n CONSTRAINT \"z-Name-Check\" CHECK (\"Z-Name\" ~ '^[A-Z]')\n)",
39+
"pretty/tables-19.sql": "CREATE TABLE users.details (\n \"first_name\" text NOT NULL,\n \"last_name\" text,\n CONSTRAINT \"first_name_required\" CHECK (\"first_name\" <> '')\n)",
40+
"pretty/tables-20.sql": "CREATE TABLE \"Calculated\".\"Metrics\" (\n base int,\n adjustment int DEFAULT 0,\n \"Total\" int GENERATED ALWAYS AS (base + adjustment) STORED\n)",
241
"pretty/selects-1.sql": "SELECT 1",
342
"pretty/selects-2.sql": "SELECT 'abc'::text",
443
"pretty/selects-3.sql": "SELECT now() AT TIME ZONE 'UTC'",
@@ -14,6 +53,16 @@
1453
"pretty/selects-13.sql": "SELECT\n id,\n name\nFROM users\nWHERE\n id IN (SELECT\n user_id\nFROM orders\nWHERE\n total > 100)",
1554
"pretty/selects-14.sql": "SELECT\n id,\n name,\n email\nFROM users\nWHERE\n active = true",
1655
"pretty/selects-15.sql": "SELECT\n u.id,\n u.name,\n u.email,\n p.title\nFROM users AS u\nJOIN profiles AS p ON u.id = p.user_id\nWHERE\n u.active = true\n AND u.created_at > '2023-01-01'\nGROUP BY\n u.id,\n u.name,\n u.email,\n p.title\nHAVING\n count(*) > 1\nORDER BY\n u.created_at DESC,\n u.name ASC\nLIMIT 10\nOFFSET 5",
56+
"pretty/procedures-1.sql": "SELECT handle_insert('TYPE_A')",
57+
"pretty/procedures-2.sql": "SELECT \"HandleInsert\"('TYPE_A', 'Region-1')",
58+
"pretty/procedures-3.sql": "SELECT compute_score(42, TRUE)",
59+
"pretty/procedures-4.sql": "SELECT metrics.get_total('2025-01-01', '2025-01-31')",
60+
"pretty/procedures-5.sql": "SELECT * FROM users WHERE is_active(user_id)",
61+
"pretty/procedures-6.sql": "SELECT * FROM get_user_details(1001)",
62+
"pretty/procedures-7.sql": "SELECT * FROM get_recent_events('login') AS events",
63+
"pretty/procedures-8.sql": "SELECT \"Analytics\".\"RunQuery\"('Q-123', '2025-06')",
64+
"pretty/procedures-9.sql": "SELECT calculate_discount(price * quantity, customer_tier)",
65+
"pretty/procedures-10.sql": "SELECT perform_backup('daily', FALSE)",
1766
"pretty/misc-1.sql": "WITH recent_orders AS (\n SELECT o.id, o.user_id, o.created_at\n FROM orders o\n WHERE o.created_at > NOW() - INTERVAL '30 days'\n), high_value_orders AS (\n SELECT r.user_id, COUNT(*) AS order_count, SUM(oi.price * oi.quantity) AS total_spent\n FROM recent_orders r\n JOIN order_items oi ON r.id = oi.order_id\n GROUP BY r.user_id\n)\nSELECT u.id, u.name, h.total_spent\nFROM users u\nJOIN high_value_orders h ON u.id = h.user_id\nWHERE h.total_spent > 1000\nORDER BY h.total_spent DESC",
1867
"pretty/misc-2.sql": "SELECT\n department,\n employee_id,\n COUNT(*) FILTER (WHERE status = 'active') OVER (PARTITION BY department) AS active_count,\n RANK() OVER (PARTITION BY department ORDER BY salary DESC) AS salary_rank\nFROM employee_status\nGROUP BY GROUPING SETS ((department), (department, employee_id))",
1968
"pretty/misc-3.sql": "SELECT u.id, u.name, j.key, j.value\nFROM users u,\nLATERAL jsonb_each_text(u.preferences) AS j(key, value)\nWHERE j.key LIKE 'notif_%' AND j.value::boolean = true",
@@ -47,10 +96,20 @@
4796
"pretty/create_policy-5.sql": "CREATE POLICY \"simple_policy\" ON posts FOR SELECT TO public USING (published = true)",
4897
"pretty/create_policy-6.sql": "CREATE POLICY \"Simple Policy\" ON posts FOR SELECT TO public USING (published = true)",
4998
"pretty/create_policy-7.sql": "CREATE POLICY SimplePolicy ON posts FOR SELECT TO public USING (published = true)",
50-
"pretty/constraints-1.sql": "CREATE TABLE orders (\n id SERIAL PRIMARY KEY,\n user_id INTEGER NOT NULL,\n total DECIMAL(10,2) CHECK (total > 0),\n status VARCHAR(20) DEFAULT 'pending',\n created_at TIMESTAMP DEFAULT now(),\n CONSTRAINT fk_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,\n CONSTRAINT unique_user_date UNIQUE (user_id, created_at),\n CONSTRAINT check_status CHECK (status IN ('pending', 'completed', 'cancelled'))\n)",
51-
"pretty/constraints-2.sql": "ALTER TABLE products ADD CONSTRAINT fk_category \n FOREIGN KEY (category_id) \n REFERENCES categories(id) \n ON UPDATE CASCADE \n ON DELETE SET NULL \n DEFERRABLE INITIALLY DEFERRED",
52-
"pretty/constraints-3.sql": "ALTER TABLE products ADD CONSTRAINT check_price CHECK (price > 0)",
53-
"pretty/constraints-4.sql": "ALTER TABLE users ADD CONSTRAINT unique_email UNIQUE (email)",
99+
"pretty/constraints-1.sql": "ALTER TABLE public.users\n ADD CONSTRAINT users_pkey PRIMARY KEY (id)",
100+
"pretty/constraints-2.sql": "ALTER TABLE \"App\".\"User Data\"\n ADD CONSTRAINT \"Unique_Full Name\" UNIQUE (\"Full Name\")",
101+
"pretty/constraints-3.sql": "ALTER TABLE school.attendance\n ADD CONSTRAINT attendance_unique UNIQUE (\"Student ID\", \"Class ID\")",
102+
"pretty/constraints-4.sql": "ALTER TABLE \"Orders\".\"OrderLines\"\n ADD CONSTRAINT \"FK_Order_Ref\" FOREIGN KEY (order_id)\n REFERENCES \"Orders\".\"Order\"(\"OrderID\")",
103+
"pretty/constraints-5.sql": "ALTER TABLE \"x-Schema\".\"z-Table\"\n ADD CONSTRAINT \"zNameFormatCheck\" CHECK (\"Z-Name\" ~ '^[A-Z]')",
104+
"pretty/constraints-6.sql": "ALTER TABLE data.snapshots\n ADD CONSTRAINT metadata_has_key CHECK (metadata ? 'type')",
105+
"pretty/constraints-7.sql": "ALTER TABLE \"Billing\".\"Invoices\"\n ADD CONSTRAINT \"FK_Client_ID\"\n FOREIGN KEY (\"Client ID\") REFERENCES \"Clients\".\"ClientBase\"(\"Client ID\")",
106+
"pretty/constraints-8.sql": "ALTER TABLE \"API Keys\"\n ADD CONSTRAINT \"PK_KeyID\" PRIMARY KEY (\"KeyID\")",
107+
"pretty/constraints-9.sql": "ALTER TABLE finance.transactions\n ADD CONSTRAINT tax_rate_range CHECK (tax_rate >= 0 AND tax_rate <= 1)",
108+
"pretty/constraints-10.sql": "ALTER TABLE school.enrollments\n ADD CONSTRAINT fk_student_course FOREIGN KEY (student_id, course_id)\n REFERENCES school.courses_students(student_id, course_id)",
109+
"pretty/constraints-11.sql": "CREATE TABLE orders (\n id SERIAL PRIMARY KEY,\n user_id INTEGER NOT NULL,\n total DECIMAL(10,2) CHECK (total > 0),\n status VARCHAR(20) DEFAULT 'pending',\n created_at TIMESTAMP DEFAULT now(),\n CONSTRAINT fk_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,\n CONSTRAINT unique_user_date UNIQUE (user_id, created_at),\n CONSTRAINT check_status CHECK (status IN ('pending', 'completed', 'cancelled'))\n)",
110+
"pretty/constraints-12.sql": "ALTER TABLE products ADD CONSTRAINT fk_category \n FOREIGN KEY (category_id) \n REFERENCES categories(id) \n ON UPDATE CASCADE \n ON DELETE SET NULL \n DEFERRABLE INITIALLY DEFERRED",
111+
"pretty/constraints-13.sql": "ALTER TABLE products ADD CONSTRAINT check_price CHECK (price > 0)",
112+
"pretty/constraints-14.sql": "ALTER TABLE users ADD CONSTRAINT unique_email UNIQUE (email)",
54113
"original/simple-1.sql": "SELECT\n *\nFROM\n table_name\nWHERE\n name = 'test' AND num > 7 AND\n last_name LIKE '%''test''%'",
55114
"original/simple-2.sql": "SELECT\n *\nFROM\n table_name\nWHERE\n name = 'test' AND num > 7 AND\n last_name NOT LIKE '%''test''%'",
56115
"original/simple-3.sql": "SELECT\n *\nFROM\n table_name\nWHERE\n name = 'test' AND num > 7 AND\n last_name ILIKE '%''test''%'",

__fixtures__/kitchen-sink/pretty/constraints.sql

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,47 @@
1+
-- 1. Add a named primary key constraint
2+
ALTER TABLE public.users
3+
ADD CONSTRAINT users_pkey PRIMARY KEY (id);
4+
5+
-- 2. Add a quoted unique constraint on a mixed-case column
6+
ALTER TABLE "App"."User Data"
7+
ADD CONSTRAINT "Unique_Full Name" UNIQUE ("Full Name");
8+
9+
-- 3. Add a composite unique constraint with custom name
10+
ALTER TABLE school.attendance
11+
ADD CONSTRAINT attendance_unique UNIQUE ("Student ID", "Class ID");
12+
13+
-- 4. Add a foreign key with quoted constraint and schema-qualified reference
14+
ALTER TABLE "Orders"."OrderLines"
15+
ADD CONSTRAINT "FK_Order_Ref" FOREIGN KEY (order_id)
16+
REFERENCES "Orders"."Order"("OrderID");
17+
18+
-- 5. Add a check constraint with a regex pattern
19+
ALTER TABLE "x-Schema"."z-Table"
20+
ADD CONSTRAINT "zNameFormatCheck" CHECK ("Z-Name" ~ '^[A-Z]');
21+
22+
-- 6. Add a check constraint on JSON key existence
23+
ALTER TABLE data.snapshots
24+
ADD CONSTRAINT metadata_has_key CHECK (metadata ? 'type');
25+
26+
-- 7. Add a foreign key referencing quoted schema.table.column
27+
ALTER TABLE "Billing"."Invoices"
28+
ADD CONSTRAINT "FK_Client_ID"
29+
FOREIGN KEY ("Client ID") REFERENCES "Clients"."ClientBase"("Client ID");
30+
31+
-- 8. Add a primary key on a quoted identifier
32+
ALTER TABLE "API Keys"
33+
ADD CONSTRAINT "PK_KeyID" PRIMARY KEY ("KeyID");
34+
35+
-- 9. Add a check on numeric range
36+
ALTER TABLE finance.transactions
37+
ADD CONSTRAINT tax_rate_range CHECK (tax_rate >= 0 AND tax_rate <= 1);
38+
39+
-- 10. Add a multi-column foreign key with custom name
40+
ALTER TABLE school.enrollments
41+
ADD CONSTRAINT fk_student_course FOREIGN KEY (student_id, course_id)
42+
REFERENCES school.courses_students(student_id, course_id);
43+
44+
-- 11.
145
CREATE TABLE orders (
246
id SERIAL PRIMARY KEY,
347
user_id INTEGER NOT NULL,
@@ -9,13 +53,21 @@ CREATE TABLE orders (
953
CONSTRAINT check_status CHECK (status IN ('pending', 'completed', 'cancelled'))
1054
);
1155

56+
-- 12.
57+
1258
ALTER TABLE products ADD CONSTRAINT fk_category
1359
FOREIGN KEY (category_id)
1460
REFERENCES categories(id)
1561
ON UPDATE CASCADE
1662
ON DELETE SET NULL
1763
DEFERRABLE INITIALLY DEFERRED;
1864

65+
-- 13
66+
1967
ALTER TABLE products ADD CONSTRAINT check_price CHECK (price > 0);
2068

69+
-- 14
70+
2171
ALTER TABLE users ADD CONSTRAINT unique_email UNIQUE (email);
72+
73+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
-- 1. Simple function call with one string arg
2+
SELECT handle_insert('TYPE_A');
3+
4+
-- 2. Function call with mixed-case literal (should preserve case)
5+
SELECT "HandleInsert"('TYPE_A', 'Region-1');
6+
7+
-- 3. Function call with numeric and boolean args
8+
SELECT compute_score(42, TRUE);
9+
10+
-- 4. Schema-qualified function call
11+
SELECT metrics.get_total('2025-01-01', '2025-01-31');
12+
13+
-- 5. Function call in WHERE clause
14+
SELECT * FROM users WHERE is_active(user_id);
15+
16+
-- 6. Function call returning composite type
17+
SELECT * FROM get_user_details(1001);
18+
19+
-- 7. Function call inside FROM clause (set-returning)
20+
SELECT * FROM get_recent_events('login') AS events;
21+
22+
-- 8. Function call with quoted identifiers and args
23+
SELECT "Analytics"."RunQuery"('Q-123', '2025-06');
24+
25+
-- 9. Function call with nested expressions
26+
SELECT calculate_discount(price * quantity, customer_tier);
27+
28+
-- 10. Procedure-style call (PL/pgSQL do-nothing)
29+
SELECT perform_backup('daily', FALSE);
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
-- 1. Simple table with primary key
2+
CREATE TABLE public.users (
3+
id serial PRIMARY KEY,
4+
name text NOT NULL
5+
);
6+
7+
-- 2. Quoted table and column names
8+
CREATE TABLE "App"."User Data" (
9+
"User ID" uuid PRIMARY KEY,
10+
"Full Name" text NOT NULL
11+
);
12+
13+
-- 3. Table with default values and a quoted constraint name
14+
CREATE TABLE system.settings (
15+
setting_key text PRIMARY KEY,
16+
setting_value text,
17+
CONSTRAINT "Default Setting Check" CHECK (setting_value IS NOT NULL)
18+
);
19+
20+
-- 4. Table with quoted composite column and array
21+
CREATE TABLE "Inventory"."StockItems" (
22+
"ItemID" int PRIMARY KEY,
23+
"Tags" text[]
24+
);
25+
26+
-- 5. Foreign key with a quoted constraint name and target
27+
CREATE TABLE "Orders"."OrderLines" (
28+
id serial PRIMARY KEY,
29+
order_id int,
30+
CONSTRAINT "FK Order Reference" FOREIGN KEY (order_id) REFERENCES "Orders"."Order"("OrderID")
31+
);
32+
33+
-- 6. Table using composite type with mixed-case field names
34+
CREATE TABLE contact_info (
35+
id int PRIMARY KEY,
36+
location address -- assumed composite type
37+
);
38+
39+
-- 7. Inheritance with quoted base table
40+
CREATE TABLE "Archive"."OldUsers" (
41+
archived_at timestamptz DEFAULT now()
42+
) INHERITS ("Users"."User Data");
43+
44+
-- 8. Identity column with quoted constraint
45+
CREATE TABLE logging.audit_trail (
46+
log_id int GENERATED BY DEFAULT AS IDENTITY,
47+
message text,
48+
CONSTRAINT "PK_Audit" PRIMARY KEY (log_id)
49+
);
50+
51+
-- 9. Generated column with expression
52+
CREATE TABLE finance.transactions (
53+
amount numeric,
54+
tax_rate numeric,
55+
total numeric GENERATED ALWAYS AS (amount * (1 + tax_rate)) STORED
56+
);
57+
58+
-- 10. Range partitioned table
59+
CREATE TABLE metrics.monthly_stats (
60+
stat_id serial,
61+
recorded_at date
62+
) PARTITION BY RANGE (recorded_at);
63+
64+
-- 11. Composite multi-column primary key
65+
CREATE TABLE school.attendance (
66+
"Student ID" uuid,
67+
"Class ID" uuid,
68+
attended_on date DEFAULT CURRENT_DATE,
69+
PRIMARY KEY ("Student ID", "Class ID")
70+
);
71+
72+
-- 12. Table with special chars in constraint name
73+
CREATE TABLE secure.sessions (
74+
session_id uuid PRIMARY KEY,
75+
user_id uuid,
76+
CONSTRAINT "fk-user->session" FOREIGN KEY (user_id) REFERENCES users(id)
77+
);
78+
79+
-- 13. Table with multiple unique constraints and quoted keys
80+
CREATE TABLE public."API Keys" (
81+
"KeyID" uuid PRIMARY KEY,
82+
"ClientName" text,
83+
"KeyValue" text UNIQUE,
84+
CONSTRAINT "Unique_ClientName" UNIQUE ("ClientName")
85+
);
86+
87+
-- 14. Enum field reference
88+
CREATE TABLE alerts (
89+
alert_id serial PRIMARY KEY,
90+
level "AlertLevel" NOT NULL -- assumed enum type
91+
);
92+
93+
-- 15. Table with foreign key referencing quoted table/column
94+
CREATE TABLE "Billing"."Invoices" (
95+
invoice_id uuid PRIMARY KEY,
96+
"Client ID" uuid,
97+
CONSTRAINT "FK_Client" FOREIGN KEY ("Client ID") REFERENCES "Clients"."ClientBase"("Client ID")
98+
);
99+
100+
-- 16. Table with special-cased check
101+
CREATE TABLE media.assets (
102+
id uuid PRIMARY KEY,
103+
url text,
104+
CONSTRAINT "Check-URL-NonEmpty" CHECK (url <> '')
105+
);
106+
107+
-- 17. Composite type and JSON field
108+
CREATE TABLE data.snapshots (
109+
id serial PRIMARY KEY,
110+
metadata jsonb,
111+
context address
112+
);
113+
114+
-- 18. Table with quoted schema, table, and constraints
115+
CREATE TABLE "x-Schema"."z-Table" (
116+
"Z-ID" int PRIMARY KEY,
117+
"Z-Name" text,
118+
CONSTRAINT "z-Name-Check" CHECK ("Z-Name" ~ '^[A-Z]')
119+
);
120+
121+
-- 19. Table with lowercase constraint on quoted column
122+
CREATE TABLE users.details (
123+
"first_name" text NOT NULL,
124+
"last_name" text,
125+
CONSTRAINT "first_name_required" CHECK ("first_name" <> '')
126+
);
127+
128+
-- 20. Table using generated stored and quoted default
129+
CREATE TABLE "Calculated"."Metrics" (
130+
base int,
131+
adjustment int DEFAULT 0,
132+
"Total" int GENERATED ALWAYS AS (base + adjustment) STORED
133+
);

0 commit comments

Comments
 (0)