Skip to content

Conversation

@yuval-illumex
Copy link
Contributor

The following query is valid in Redshift:

SELECT #_of_values
FROM foo

In postgres, when running using pgadmin, the query is not valid and must written as the following:
(I'm not sure what is the behavior in other drivers/apps that can query postgres).

SELECT foo."#_of_values"
FROM foo

As redshift is based on postgres, for me it makes sense to change the postgres dialect.
I would love for some feedback.

Thanks!

@yuval-illumex yuval-illumex changed the title Fix redshift column Fix redshift specific character Apr 27, 2022
@coveralls
Copy link

coveralls commented Apr 27, 2022

Pull Request Test Coverage Report for Build 2233206158

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 16 of 20 (80.0%) changed or added relevant lines in 2 files are covered.
  • 46 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.1%) to 90.302%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/tokenizer.rs 14 18 77.78%
Files with Coverage Reduction New Missed Lines %
src/tokenizer.rs 46 88.76%
Totals Coverage Status
Change from base Build 2219792542: -0.1%
Covered Lines: 8036
Relevant Lines: 8899

💛 - Coveralls

@yuval-illumex
Copy link
Contributor Author

@alamb appreciate your feedback on this one, as it's more complicated then other PRs

// We don't yet support identifiers beginning with "letters with
// diacritical marks and non-Latin letters"
('a'..='z').contains(&ch) || ('A'..='Z').contains(&ch) || ch == '_'
('a'..='z').contains(&ch) || ('A'..='Z').contains(&ch) || ch == '_' || ch == '#'
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I am torn on this one - I worry about causing trouble for someone who is relaying on # not being a valid pg identifiers. I don't really have a great understanding of what people are doing / using sqlparser for and I would say it is not particularly consistent about disallowing constructs that are not valid other dialects of SQL 🤔

What do you think about adding a RedshiftSqlDialect to avoid unintended consquences? I think it could be pretty straightforward, something like:

impl Dialect for RedshiftSqlDialect {
    fn is_identifier_start(&self, ch: char) -> bool {
      PostgreSqlDialect::is_identifier_start(ch) || ch == '#'
    }
}

return Ok(Some(Token::Number(s, false)));
}
Ok(Some(Token::make_word(&s, None)))
if s == "#" {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@alamb What do you think about this change?
I'm worried about clash with lines 610:
I didn't found a better way to solve it.

'#' if dialect_of!(self is SnowflakeDialect) => { chars.next(); // consume the '#', starting a snowflake single-line comment let comment = self.tokenize_single_line_comment(chars); Ok(Some(Token::Whitespace(Whitespace::SingleLineComment { prefix: "#".to_owned(), comment, }))) }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe we should check if the dialect is RedshiftSqlDialect?

Copy link
Contributor

Choose a reason for hiding this comment

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

The change doesn't feel right to me (because it effectively skips #s so wouldn't it mean that things like #SELECT will parse as SELECT (not just identifiers)?

@alamb
Copy link
Contributor

alamb commented May 4, 2022

I just noticed an outstanding PR from @mskrzypkows that adds a RedshiftSqlDialect as well -- what do you think #471

@yuval-illumex
Copy link
Contributor Author

yuval-illumex commented May 4, 2022

I just noticed an outstanding PR from @mskrzypkows that adds a RedshiftSqlDialect as well -- what do you think #471

I totally agree. I think that I will wait for #471 to be merged, and then I will try to make this PR to work only on Redshift.

@yuval-illumex yuval-illumex deleted the bugfix/redshift branch May 8, 2022 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants