Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions postgresql/examples/regression/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Regression Tests

This directory contains regression tests for specific bugs that were fixed in the parser.

## Test Files

### `function_names_as_identifiers.sql`
**Issue**: After removing `builtin_function_name` tokens, mathematical and string function names should be usable as regular identifiers.

**Tests**:
- Using function names (exp, div, floor, mod, power, sqrt, log, reverse) as column names
- Using function names as table names
- SELECT statements with these identifiers

**Related PR**: #40 - Remove non-standard builtin_function_name tokens

### `json_typecast.sql`
**Issue**: Missing `jsontype` rule caused `::json` and `::jsonb` typecasts to fail with "mismatched input ';' expecting '%'"

**Tests**:
- Basic JSON/JSONB typecast syntax
- JSON with unicode escape sequences
- JSON with surrogate pairs
- JSON type in CREATE TABLE
- JSON typecast with -> operator

**Related PR**: #40 - Add jsontype rule for proper JSON type support

### `complex_joins.sql`
**Issue**: Complex multi-table JOINs with multiple LEFT JOINs and ORDER BY clauses

**Tests**:
- Multiple LEFT JOIN statements
- Column aliases with AS keyword
- WHERE clause filtering
- ORDER BY with multiple columns and mixed ASC/DESC

**Related PR**: #40 - General regression test for complex query patterns

## Running Tests

These tests are automatically included when running the full test suite:

```bash
cd postgresql
make test
```

To run only regression tests:

```bash
go test -run "TestPostgreSQLParser/examples/regression" -v
```

## Adding New Regression Tests

When fixing a parser bug:

1. Create a new `.sql` file in this directory
2. Add a comment at the top describing the issue and fix
3. Include minimal test cases that reproduce the bug
4. The test will be automatically picked up by the test runner
18 changes: 18 additions & 0 deletions postgresql/examples/regression/complex_joins.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-- Regression test: Complex multi-table JOINs with ORDER BY
-- Tests parser handling of multiple LEFT JOINs, aliases, and ordering

SELECT
se.id,
se.name,
se.description,
st.type AS step_type,
st.index AS step_index,
sr.conditional,
sr.index AS sr_index,
script.script_content
FROM test se
LEFT JOIN test_step st ON se.id = st.sequence_id
LEFT JOIN test_rel sr ON sr.step_id = sr.script_id
Copy link

Copilot AI Nov 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The JOIN condition appears incorrect: sr.step_id = sr.script_id compares two columns from the same table alias. This likely should be st.id = sr.step_id to properly join test_step with test_rel.

Suggested change
LEFT JOIN test_rel sr ON sr.step_id = sr.script_id
LEFT JOIN test_rel sr ON st.id = sr.step_id

Copilot uses AI. Check for mistakes.
LEFT JOIN msg_script script ON script.id = sr.script_id
WHERE se.creator_id = 1
ORDER BY se.id DESC, sr_index ASC;
28 changes: 28 additions & 0 deletions postgresql/examples/regression/function_names_as_identifiers.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-- Regression test: Function names should be usable as identifiers
-- Issue: After removing builtin_function_name tokens, mathematical function names
-- should work as regular identifiers (table names, column names, etc.)

-- Mathematical functions as column names
CREATE TABLE test_math (
exp INT,
div INT,
floor INT,
mod INT,
power INT,
sqrt INT,
log INT
);

-- String function REVERSE as column name
CREATE TABLE test_string (
reverse VARCHAR(100)
);

-- Function names as table names
CREATE TABLE exp (id INT);
CREATE TABLE div (id INT);

-- Select from tables with function names
SELECT exp, div, floor, mod FROM test_math;
SELECT reverse FROM test_string;
SELECT * FROM exp;
24 changes: 24 additions & 0 deletions postgresql/examples/regression/json_typecast.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
-- Regression test: JSON and JSONB type casting
-- Issue: Missing jsontype rule caused ::json and ::jsonb typecasts to fail
-- Fix: Added jsontype rule to simpletypename and consttypename

-- Basic JSON typecast
SELECT '{"a": 1}'::json;
SELECT '{"b": 2}'::jsonb;

-- JSON with unicode escapes
SELECT '"\u0000"'::json;
SELECT '"\uaBcD"'::json;

-- JSON with surrogate pairs
SELECT '{ "a": "\ud83d\ude04\ud83d\udc36" }'::json;

-- JSON in table definition
CREATE TABLE json_test (
data json,
data_b jsonb
);

-- JSON typecast in expressions
SELECT '{"a": 1}'::json -> 'a';
SELECT '{"b": 2}'::jsonb -> 'b';