Repository navigation
fix: allow parenthesized expressions in SELECT INTO statements - #989
Conversation
WalkthroughThe PL/iSQL parser grammar was modified to correctly handle SELECT INTO statements with parenthesized expressions. Previously, patterns like Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/pl/plisql/src/sql/plisql_simple.sql (1)
128-203: Comprehensive test coverage for parenthesized SELECT expressions.The test cases thoroughly validate the parser fix across a wide range of scenarios including nested parentheses, nested SELECTs, function calls, CASE expressions, CAST operations, and complex arithmetic. The progressive complexity from simple to edge cases is well-structured.
Consider adding one additional test case to verify that regular function calls (non-SELECT) followed by parentheses still work correctly, ensuring the fix doesn't break existing functionality:
-- Verify function calls still work create function test_call_func() returns int language plisql as $$begin return 42; end$$; / do $$ declare result int; begin result := test_call_func(); raise notice 'Function call: %', result; end; $$;This would provide defense against regressions in the call path routing.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
src/pl/plisql/src/expected/plisql_simple.outis excluded by!**/*.out
📒 Files selected for processing (2)
src/pl/plisql/src/pl_gram.y(1 hunks)src/pl/plisql/src/sql/plisql_simple.sql(1 hunks)
🔇 Additional comments (1)
src/pl/plisql/src/pl_gram.y (1)
2671-2678: LGTM! Parser fix correctly handles SELECT followed by parentheses.The logic correctly distinguishes between SELECT statements (SQL) and function calls by adding a case-insensitive check for the "select" keyword. When the word is SELECT, it bypasses the call path and routes to EXECSQL, allowing parenthesized expressions like
SELECT (100 - x) * 0.01 INTO ...to parse correctly.Logic verification:
pg_strcasecmp($1.ident, "select") != 0→ true when word is NOT "select", routes to call path- When word IS "select" (any case) → condition false, falls through to
make_execsql_stmt✓- Handles both
SELECT(...)andSELECT;cases ✓Note: This gives SQL keywords precedence over potential user-defined functions with the same name (e.g., a function named "select"), which is standard PL/pgSQL behavior.
|
Closing for testing purposes |
| * like SELECT (100 - x) * 0.01 INTO ... | ||
| */ | ||
| if ((tok == '(' || tok == ';') && | ||
| pg_strcasecmp($1.ident, "select") != 0) |
There was a problem hiding this comment.
Good solution, in procedural languages body, the statement SELECT (100 - x) * 0.01 INTO result;is wrongly treated as a function call.
Fixes #981
The PL/iSQL parser rejected SELECT INTO statements when the select list started with a parenthesized expression, incorrectly treating them as procedure calls.
Changed the parser to recognize SELECT as a SQL statement even when followed by '('.
Summary by CodeRabbit
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.