-
Notifications
You must be signed in to change notification settings - Fork 583
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
COPY TO/FROM is overly restrictive on options #1085
Comments
I'm currently working on this, but I wanted to gather opinions on how to properly tackle this, especially in regards to how much backward compatibility (if any) we should strive to preserve. I was initially thinking of removing Thoughts @alamb ? |
Rather than removing Any changes like this will be a breaking change -- I think a key requirement is that sqlparser continues to be able to parse queries it is currently able to (doens't start rejecting queries it used to parse) I think a very valuable property is that the AST that comes out is as typed as possible -- e.g. Copy options probably shouldn't just be a generic set of key/value pairs |
Another potential thought might be to keep the current postgres specific copy options but rename it to |
This should be fine. In fact, it should be more permissive now. It's more about library API breaking changes.
Yeah this is a possibility, as downstream users can then ignore the Postgres specific enum variants (though might be undesirable to have this baggage).
I agree that more typing is better, but in this case the option keyset seems less part of the SQL syntax and more part of engine semantics. Although, postgres does throw an error when it doesn't recognize an option with the error pointing to the SQL so maybe I'm wrong on that:
This is probably the better approach, so users won't have to consider postgres specific options when they are checking the copy options. I'll probably explore in this direction. |
Current parsing of
COPY TO/FROM
options is too restrictive on the how the keys & values can be provided.https://github.com/sqlparser-rs/sqlparser-rs/blob/ce498864dc705f72e9f85d4dc5f7eba3d17b9ef6/src/parser/mod.rs#L5157-L5180
Given this parsing code, the expected format is:
The problems:
WITH ("format" 'text', ...)
format e'csv'
), but this is allowed by postgrestrue
orfalse
but postgres allows these to be passed as string literals (single quoted, double quoted, escaped), e.g.freeze 'true'
Solutions
We could fix these problems for Postgres specifically to make it more permissive, but I was hoping to also fix it to allow usage by other engine dialects (e.g. duckdb and datafusion). This might involve removing the
CopyOption
enum entirely:https://github.com/sqlparser-rs/sqlparser-rs/blob/ce498864dc705f72e9f85d4dc5f7eba3d17b9ef6/src/ast/mod.rs#L4707-L4736
And replacing its usage in
Statement::Copy
with a more generic version that allows any string key with a new value enum to represent different values (e.g. string value, parenthesized column list value, number value):https://github.com/sqlparser-rs/sqlparser-rs/blob/ce498864dc705f72e9f85d4dc5f7eba3d17b9ef6/src/ast/mod.rs#L1466-L1478
I'm not sure how the legacy options will fit into this, it could just be left as is and probably tackled as part of another ticket (as the original reason here was for interop with datafusion copy statement)
The text was updated successfully, but these errors were encountered: