Support two-argument TRIM(string, characters) in PostgreSQL#2240
Support two-argument TRIM(string, characters) in PostgreSQL#2240yoavcloud merged 4 commits intoapache:mainfrom
TRIM(string, characters) in PostgreSQL#2240Conversation
src/parser/mod.rs
Outdated
| }) | ||
| } else if self.consume_token(&Token::Comma) | ||
| && dialect_of!(self is DuckDbDialect | SnowflakeDialect | BigQueryDialect | GenericDialect) | ||
| && dialect_of!( |
There was a problem hiding this comment.
Can you turn this into a function of the Dialect trait? For example: self.dialect.supports_comma_separated_trim.
There was a problem hiding this comment.
Ok, I will try to run a review of which dialects supports it, I hope it won't become a nightmare of little differences.
There was a problem hiding this comment.
I didn't mean to send you on a wild goose chase, just use whatever is already supported in code: DuckDbDialect, SnowflakeDialect, BigQueryDialect, GenericDialect and now PostgreSQL
There was a problem hiding this comment.
I am currently just double checking the dialects I actively work with, just in case there are small differences. I found this missing feature via differential fuzzing and not with direct use, so I am not THAT familiar with it.
There was a problem hiding this comment.
And done, a couple of dialects were still missing, it was a good thing to spend a bit more time to check these.
tests/sqlparser_postgres.rs
Outdated
| } | ||
|
|
||
| #[test] | ||
| fn parse_postgres_two_argument_trim() { |
There was a problem hiding this comment.
Perhaps this unit test can be moved to sqlparser_common.rs so it will cover all supporting dialects?
…gument TRIM syntax
Add a new Dialect::supports_comma_separated_trim() capability with a false default and opt in the dialects that currently support TRIM(expr, characters). Use this capability in parse_trim() instead of a hardcoded dialect list so dialect support is declared at the dialect layer.
Move two-argument TRIM assertions from postgres-only tests into the common parser suite and select dialects via supports_comma_separated_trim(). Keep explicit failure coverage for dialects that do not support comma syntax and remove the redundant postgres-specific test.
11dbdea to
0f87df0
Compare
|
Thank you @LucaCappelletti94! |
PostgreSQL supports
TRIM(string, characters)as a function form, butsqlparser-rsrejected it underPostgreSqlDialectwith:ParserError("Expected: ), found: ,").This PR adds PostgreSQL support for the comma-style
TRIMform and adds regression coverage.