Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8296,8 +8296,8 @@ pub enum CopyLegacyOption {
IamRole(IamRoleKind),
/// IGNOREHEADER \[ AS \] number_rows
IgnoreHeader(u64),
/// JSON
Json,
/// JSON \[ AS \] 'json_option'
Json(Option<String>),
/// MANIFEST \[ VERBOSE \]
Manifest { verbose: bool },
/// MAXFILESIZE \[ AS \] max-size \[ MB | GB \]
Expand Down Expand Up @@ -8388,7 +8388,13 @@ impl fmt::Display for CopyLegacyOption {
Header => write!(f, "HEADER"),
IamRole(role) => write!(f, "IAM_ROLE {role}"),
IgnoreHeader(num_rows) => write!(f, "IGNOREHEADER {num_rows}"),
Json => write!(f, "JSON"),
Json(opt) => {
write!(f, "JSON")?;
if let Some(opt) = opt {
write!(f, " AS '{}'", value::escape_single_quote_string(opt))?;
}
Ok(())
}
Manifest { verbose } => write!(f, "MANIFEST{}", if *verbose { " VERBOSE" } else { "" }),
MaxFileSize(file_size) => write!(f, "MAXFILESIZE {file_size}"),
Null(string) => write!(f, "NULL '{}'", value::escape_single_quote_string(string)),
Expand Down
10 changes: 9 additions & 1 deletion src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10621,7 +10621,15 @@ impl<'a> Parser<'a> {
let num_rows = self.parse_literal_uint()?;
CopyLegacyOption::IgnoreHeader(num_rows)
}
Some(Keyword::JSON) => CopyLegacyOption::Json,
Some(Keyword::JSON) => {
let _ = self.parse_keyword(Keyword::AS);
let fmt = if matches!(self.peek_token().token, Token::SingleQuotedString(_)) {
Some(self.parse_literal_string()?)
} else {
None
};
CopyLegacyOption::Json(fmt)
}
Some(Keyword::MANIFEST) => {
let verbose = self.parse_keyword(Keyword::VERBOSE);
CopyLegacyOption::Manifest { verbose }
Expand Down
6 changes: 6 additions & 0 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17398,6 +17398,9 @@ fn parse_copy_options() {
"EMPTYASNULL ",
"IAM_ROLE DEFAULT ",
"IGNOREHEADER AS 1 ",
"JSON ",
"JSON 'auto' ",
"JSON AS 'auto' ",
"TIMEFORMAT AS 'auto' ",
"TRUNCATECOLUMNS ",
"REMOVEQUOTES ",
Expand All @@ -17423,6 +17426,9 @@ fn parse_copy_options() {
"EMPTYASNULL ",
"IAM_ROLE DEFAULT ",
"IGNOREHEADER 1 ",
"JSON ",
"JSON AS 'auto' ",
"JSON AS 'auto' ",
"TIMEFORMAT 'auto' ",
"TRUNCATECOLUMNS ",
"REMOVEQUOTES ",
Expand Down
Loading