Skip to content

Commit 48beec7

Browse files
authored
Merge branch 'main' into transform/base
2 parents 3ce9c95 + c7fd28e commit 48beec7

File tree

67 files changed

+4379
-2025
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+4379
-2025
lines changed

__fixtures__/generated/generated.json

Lines changed: 124 additions & 10 deletions
Large diffs are not rendered by default.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
-- 1. Insert with simple mixed-case string
2+
INSERT INTO users (name) VALUES ('John Doe');
3+
4+
-- 2. Insert with ALL CAPS
5+
INSERT INTO users (name) VALUES ('ADMINISTRATOR');
6+
7+
-- 3. Insert with lowercase only
8+
INSERT INTO users (name) VALUES ('lowercase');
9+
10+
-- 4. Insert with camelCase
11+
INSERT INTO users (name) VALUES ('camelCaseString');
12+
13+
-- 5. Insert with snake_case
14+
INSERT INTO users (name) VALUES ('snake_case_string');
15+
16+
-- 6. Insert with kebab-case (string literal)
17+
INSERT INTO users (name) VALUES ('kebab-case-value');
18+
19+
-- 7. Insert with JSON-looking string
20+
INSERT INTO data.snapshots (metadata) VALUES ('{"Type": "Full", "Status": "OK"}');
21+
22+
-- 8. Insert into quoted table and column
23+
INSERT INTO "AppSchema"."User Data" ("Full Name") VALUES ('Jane Smith');
24+
25+
-- 9. Insert multiple values with mixed casing
26+
INSERT INTO logtable (message) VALUES ('Init'), ('Reboot'), ('ERROR'), ('Warning'), ('info');
27+
28+
-- 10. Insert a string that looks like a function
29+
INSERT INTO metrics.logs (message) VALUES ('NOW()');
30+
31+
-- 11. Insert with exact keyword-looking string
32+
INSERT INTO users (name) VALUES ('SELECT');
33+
34+
-- 12. Insert lowercase string with special characters
35+
INSERT INTO users (name) VALUES ('[email protected]');
36+
37+
-- 13. Select mixed-case string literal
38+
SELECT 'MixedCase';
39+
40+
-- 14. Select all uppercase
41+
SELECT 'UPPERCASE';
42+
43+
-- 15. Select lowercase
44+
SELECT 'lowercase';
45+
46+
-- 16. Select camelCase
47+
SELECT 'camelCase';
48+
49+
-- 17. Select snake_case
50+
SELECT 'snake_case';
51+
52+
-- 18. Select kebab-case
53+
SELECT 'kebab-case';
54+
55+
-- 19. Select string that looks like SQL
56+
SELECT 'SELECT * FROM users';
57+
58+
-- 20. Select string that looks like a function
59+
SELECT 'sum(a + b)';
60+
61+
-- 21. Select with alias and quoted output name
62+
SELECT name AS "UserLabel" FROM users;
63+
64+
-- 22. Select where literal is camelCase
65+
SELECT * FROM users WHERE name = 'camelCaseString';
66+
67+
-- 23. Select where literal is lowercase
68+
SELECT * FROM users WHERE name = 'lowercase';
69+
70+
-- 24. Select where literal is ALL CAPS
71+
SELECT * FROM users WHERE name = 'ADMINISTRATOR';
72+
73+
-- 25. Select where message starts with capital W
74+
SELECT * FROM logs WHERE message LIKE 'Warn%';
75+
76+
-- 26. Select with multiple casing in IN clause
77+
SELECT * FROM alerts WHERE level IN ('Low', 'MEDIUM', 'High', 'CRITICAL');
78+
79+
-- 27. Select string with escaped quote
80+
SELECT 'It''s working';
81+
82+
-- 28. Select with E-prefixed escape string
83+
SELECT E'Line1\\nLine2';
84+
85+
-- 29. Select with Unicode emoji string
86+
SELECT 'Status: ✅';
87+
88+
-- 30. Select into quoted alias
89+
SELECT 'ALERT' AS "Level";
90+
91+
-- 31. Select with quoted function name
92+
SELECT "HandleInsert"('TYPE_A', 'Region-1');
93+
94+
-- 32. Select with quoted table name
95+
SELECT * FROM "dataPoints";

__fixtures__/kitchen-sink/pretty/constraints.sql

Lines changed: 81 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,50 @@ 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+
74+
-- 15
75+
76+
ALTER TABLE school.enrollments
77+
ADD CONSTRAINT fk_student_course
78+
FOREIGN KEY (student_id, course_id)
79+
REFERENCES school.courses_students (student_id, course_id);
80+
81+
-- 16
82+
83+
ALTER TABLE school.enrollments
84+
ADD CONSTRAINT chk_enrollment_date
85+
CHECK (
86+
enrollment_date <= CURRENT_DATE
87+
AND status IN ('active', 'completed', 'withdrawn')
88+
);
89+
90+
-- 17
91+
92+
CREATE TABLE school.enrollments (
93+
student_id INT NOT NULL,
94+
course_id INT NOT NULL,
95+
enrollment_date DATE NOT NULL,
96+
status TEXT CHECK (
97+
status IN ('active', 'completed', 'withdrawn')
98+
),
99+
CHECK (
100+
enrollment_date <= CURRENT_DATE
101+
)
102+
);

__fixtures__/kitchen-sink/pretty/create_policy.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,9 @@ CREATE POLICY complex_policy ON documents
2020
);
2121

2222
CREATE POLICY simple_policy ON posts FOR SELECT TO public USING (published = true);
23+
24+
CREATE POLICY "simple_policy" ON posts FOR SELECT TO public USING (published = true);
25+
26+
CREATE POLICY "Simple Policy" ON posts FOR SELECT TO public USING (published = true);
27+
28+
CREATE POLICY SimplePolicy ON posts FOR SELECT TO public USING (published = true);

__fixtures__/kitchen-sink/pretty/create_table.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,12 @@ CREATE TEMPORARY TABLE temp_calculations (
3737
value DECIMAL(15,5),
3838
result TEXT
3939
);
40+
41+
CREATE TABLE orders (
42+
id SERIAL PRIMARY KEY,
43+
user_id INTEGER NOT NULL,
44+
total DECIMAL(10,2) CHECK (total > 0),
45+
status VARCHAR(20) DEFAULT 'pending',
46+
created_at TIMESTAMP DEFAULT now(),
47+
FOREIGN KEY (user_id) REFERENCES users(id)
48+
);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
WITH regional_sales AS (SELECT region, SUM(sales_amount) as total_sales FROM sales GROUP BY region) SELECT * FROM regional_sales;
2+
3+
WITH regional_sales AS (SELECT region, SUM(sales_amount) as total_sales FROM sales GROUP BY region), top_regions AS (SELECT region FROM regional_sales WHERE total_sales > 1000000) SELECT * FROM top_regions;
4+
5+
WITH RECURSIVE employee_hierarchy AS (SELECT id, name, manager_id, 1 as level FROM employees WHERE manager_id IS NULL UNION ALL SELECT e.id, e.name, e.manager_id, eh.level + 1 FROM employees e JOIN employee_hierarchy eh ON e.manager_id = eh.id) SELECT * FROM employee_hierarchy;
6+
7+
WITH sales_summary AS (SELECT region, product_category, SUM(amount) as total FROM sales GROUP BY region, product_category), regional_totals AS (SELECT region, SUM(total) as region_total FROM sales_summary GROUP BY region) SELECT s.region, s.product_category, s.total, r.region_total FROM sales_summary s JOIN regional_totals r ON s.region = r.region;

__fixtures__/kitchen-sink/pretty/misc.sql

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,20 @@ SELECT
212212
ELSE 'normal'
213213
END AS tier
214214
FROM players;
215+
216+
-- 14. A trigger
217+
218+
CREATE TRIGGER decrease_job_queue_count_on_delete
219+
AFTER DELETE ON dashboard_jobs.jobs
220+
FOR EACH ROW
221+
WHEN ( OLD.queue_name IS NOT NULL )
222+
EXECUTE PROCEDURE dashboard_jobs.tg_decrease_job_queue_count ();
223+
224+
-- 15. default privileges
225+
226+
ALTER DEFAULT PRIVILEGES IN SCHEMA dashboard_jobs
227+
GRANT EXECUTE ON FUNCTIONS TO administrator;
228+
229+
-- 16. grant execute on function
230+
231+
GRANT EXECUTE ON FUNCTION dashboard_private.uuid_generate_seeded_uuid TO PUBLIC;
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);

__fixtures__/kitchen-sink/pretty/select_statements.sql

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)