Remove Value::String
Its existence alongside SingleQuotedString simply doesn't make sense:
`'a string'` is a string literal, while `a string` is not a "value".
It's only used in postgresql-specific tab-separated-values parser to
store the string representation of a field's value. For that use-case
Option<String> looks like a more appropriate choice than Value.
diff --git a/src/sqlast/mod.rs b/src/sqlast/mod.rs
index 66040ea..54b650a 100644
--- a/src/sqlast/mod.rs
+++ b/src/sqlast/mod.rs
@@ -103,7 +103,7 @@
/// COLUMNS
columns: Vec<String>,
/// VALUES a vector of values to be copied
- values: Vec<Value>,
+ values: Vec<Option<String>>,
},
/// UPDATE
SQLUpdate {
@@ -290,7 +290,7 @@
"\n{}",
values
.iter()
- .map(|v| v.to_string())
+ .map(|v| v.clone().unwrap_or("\\N".to_string()))
.collect::<Vec<String>>()
.join("\t")
);
diff --git a/src/sqlast/value.rs b/src/sqlast/value.rs
index a441987..ec11b17 100644
--- a/src/sqlast/value.rs
+++ b/src/sqlast/value.rs
@@ -2,15 +2,13 @@
use uuid::Uuid;
-/// SQL values such as int, double, string timestamp
+/// SQL values such as int, double, string, timestamp
#[derive(Debug, Clone, PartialEq)]
pub enum Value {
/// Literal signed long
Long(i64),
/// Literal floating point value
Double(f64),
- /// Unquoted string
- String(String),
/// Uuid value
Uuid(Uuid),
/// 'string value'
@@ -34,7 +32,6 @@
match self {
Value::Long(v) => v.to_string(),
Value::Double(v) => v.to_string(),
- Value::String(v) => v.to_string(),
Value::Uuid(v) => v.to_string(),
Value::SingleQuotedString(v) => format!("'{}'", v),
Value::Boolean(v) => v.to_string(),
diff --git a/src/sqlparser.rs b/src/sqlparser.rs
index 5465256..42a39b0 100644
--- a/src/sqlparser.rs
+++ b/src/sqlparser.rs
@@ -690,7 +690,7 @@
/// Parse a tab separated values in
/// COPY payload
- fn parse_tsv(&mut self) -> Result<Vec<Value>, ParserError> {
+ fn parse_tsv(&mut self) -> Result<Vec<Option<String>>, ParserError> {
let values = self.parse_tab_value()?;
Ok(values)
}
@@ -699,17 +699,17 @@
Ok(ASTNode::SQLValue(self.parse_value()?))
}
- fn parse_tab_value(&mut self) -> Result<Vec<Value>, ParserError> {
+ fn parse_tab_value(&mut self) -> Result<Vec<Option<String>>, ParserError> {
let mut values = vec![];
let mut content = String::from("");
while let Some(t) = self.next_token_no_skip() {
match t {
Token::Whitespace(Whitespace::Tab) => {
- values.push(Value::String(content.to_string()));
+ values.push(Some(content.to_string()));
content.clear();
}
Token::Whitespace(Whitespace::Newline) => {
- values.push(Value::String(content.to_string()));
+ values.push(Some(content.to_string()));
content.clear();
}
Token::Backslash => {
@@ -718,7 +718,7 @@
}
if let Some(token) = self.next_token() {
if token == Token::Identifier("N".to_string()) {
- values.push(Value::Null);
+ values.push(None);
}
} else {
continue;