You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This fails to parse, but it can be successfully executed by SQLite (after providing a value for the parameter):
#[test]
fn go() {
use sqlparser::dialect::SQLiteDialect;
use sqlparser::parser::Parser;
let sql = "select * from test_table where test_column = ?;";
let dialect = SQLiteDialect {}; // or AnsiDialect, or your own dialect ...
let ast = Parser::parse_sql(&dialect, sql).unwrap();
println!("AST: {:#?}", ast);
}
Any idea why I get this error message?:
called Result::unwrap() on an Err value: ParserError("Expected an expression, found: ?")
thread 'dynamic_queries::go' panicked at 'called Result::unwrap() on an Err value: ParserError("Expected an expression, found: ?")',
Reacted by Árpád Goretity , mikoto2000 and Andrew Baxter
I was just going to open an issue about the same thing. Support for other flavors of parameterized queries like :named, @named, and $named would be nice as well.
@H2CO3 It should make sense to support this if it's a valid syntax for SQLite. And PR #265 was closed due to a lack of activity. I will have a look and support this feature if you want.
@H2CO3 I found this issue has been resolved by #420 after checking the code. Would you mind having a try and close this issue if it works well for you?
@git-hulk Hi, and thanks for getting back to this!
The current implementation largely works indeed. Unfortunately, it still seems to have a bug that is blocking in my case. I slightly modified one of the cases in the test suite to reproduce it, and – at least in the case of the SQLite dialect – it appears that $ placeholders are incorrectly recognized as an identifier. The following code:
fnmain(){let ast = sqlparser::parser::Parser::parse_sql(&sqlparser::dialect::SQLiteDialect{},"SELECT * FROM student WHERE id = $foo",);dbg!(ast);}
prints the following AST (irrelevant parts excluded for clarity):
This should be caused by SQLite dialect marks $ as the identifier start: dialect/sqlite.rs#L44. And the identifier in SQLite must start with ALPHABETIC from the documentation:
H41130: SQLite shall recognize as an ID token any sequence of characters that begins with an ALPHABETIC character and continue with zero or more ALPHANUMERIC characters and/or "$" (u0024) characters and which is not a keyword token.
Activity
Dandandan commentedon Jan 24, 2021
Thanks @Jasperav .
In think the
?is not something that's supported yet.H2CO3 commentedon Jan 27, 2021
I was just going to open an issue about the same thing. Support for other flavors of parameterized queries like
:named,@named, and$namedwould be nice as well.alex-dukhno commentedon Jan 28, 2021
see discussions in #265
mikoto2000 commentedon Aug 16, 2024
I would also be happy to have this feature.
I would like to support the MyBatis's
#{named}method.H2CO3 commentedon Aug 16, 2024
That issue is closed. Of what use is it? Does that mean that we're decidedly not getting parameter support?
git-hulk commentedon Aug 16, 2024
@H2CO3 It should make sense to support this if it's a valid syntax for SQLite. And PR #265 was closed due to a lack of activity. I will have a look and support this feature if you want.
git-hulk commentedon Aug 19, 2024
@H2CO3 I found this issue has been resolved by #420 after checking the code. Would you mind having a try and close this issue if it works well for you?
H2CO3 commentedon Aug 26, 2024
@git-hulk Hi, and thanks for getting back to this!
The current implementation largely works indeed. Unfortunately, it still seems to have a bug that is blocking in my case. I slightly modified one of the cases in the test suite to reproduce it, and – at least in the case of the SQLite dialect – it appears that
$placeholders are incorrectly recognized as an identifier. The following code:prints the following AST (irrelevant parts excluded for clarity):
git-hulk commentedon Aug 26, 2024
@H2CO3 Thanks for your feedback.
This should be caused by
SQLitedialect marks$as the identifier start: dialect/sqlite.rs#L44. And the identifier in SQLite must start withALPHABETICfrom the documentation:Please refer to: https://www.sqlite.org/draft/tokenreq.html
So I guess it should be a bug for the SQLite dialect. I can fix this issue if this change sounds good to you. cc @alamb @iffyio
H2CO3 commentedon Aug 26, 2024
Perfect, thanks!
Fix identifier starts with `$` should be regarded as a placeholder in…
git-hulk commentedon Sep 2, 2024
@H2CO3 You now can try again.
LucaCappelletti94 commentedon Sep 22, 2026
Closing as resolved by #1402 #1979 and #420