Skip to content

Commit 8480dcc

Browse files
committed
rs/pg: AT TIME ZONE
1 parent 5c61e96 commit 8480dcc

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

src/ast/mod.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,14 @@ pub enum Expr {
199199
right: Box<Expr>,
200200
},
201201
/// Unary operation e.g. `NOT foo`
202-
UnaryOp { op: UnaryOperator, expr: Box<Expr> },
202+
UnaryOp {
203+
op: UnaryOperator,
204+
expr: Box<Expr>,
205+
},
206+
AtTimeZone {
207+
expr: Box<Expr>,
208+
tz: String,
209+
},
203210
/// CAST an expression to a different data type e.g. `CAST(foo AS VARCHAR(123))`
204211
Cast {
205212
/// try_cast is a snowflake feature
@@ -229,7 +236,10 @@ pub enum Expr {
229236
/// A constant of form `<data_type> 'value'`.
230237
/// This can represent ANSI SQL `DATE`, `TIME`, and `TIMESTAMP` literals (such as `DATE '2020-01-01'`),
231238
/// as well as constants of other types (a non-standard PostgreSQL extension).
232-
TypedString { data_type: DataType, value: String },
239+
TypedString {
240+
data_type: DataType,
241+
value: String,
242+
},
233243
/// Scalar function call e.g. `LEFT(foo, 5)`
234244
Function(Function),
235245
/// `CASE [<operand>] WHEN <condition> THEN <result> ... [ELSE <result>] END`
@@ -326,6 +336,8 @@ impl fmt::Display for Expr {
326336
write!(f, "{} {}", op, expr)
327337
}
328338
}
339+
// rs/pg: https://docs.aws.amazon.com/redshift/latest/dg/r_AT_TIME_ZONE.html
340+
Expr::AtTimeZone { expr, tz } => write!(f, "{} AT TIME ZONE '{}'", expr, tz),
329341
Expr::Cast {
330342
try_cast,
331343
expr,

src/parser.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,16 @@ impl<'a> Parser<'a> {
817817
))
818818
} else if let Token::Word(w) = &tok {
819819
match w.keyword {
820+
Keyword::AT if self.parse_keywords(&[Keyword::TIME, Keyword::ZONE]) => {
821+
let tz = self.parse_literal_string()?;
822+
Ok((
823+
Expr::AtTimeZone {
824+
expr: Box::new(expr),
825+
tz,
826+
},
827+
true,
828+
))
829+
}
820830
Keyword::IS => {
821831
if self.parse_keyword(Keyword::NULL) {
822832
Ok((Expr::IsNull(Box::new(expr)), true))
@@ -969,6 +979,7 @@ impl<'a> Parser<'a> {
969979
_ => Ok(0),
970980
},
971981
Token::Word(w) if w.keyword == Keyword::IS => Ok(17),
982+
Token::Word(w) if w.keyword == Keyword::AT => Ok(Self::BETWEEN_PREC),
972983
Token::Word(w) if w.keyword == Keyword::IN => Ok(Self::BETWEEN_PREC),
973984
Token::Word(w) if w.keyword == Keyword::BETWEEN => Ok(Self::BETWEEN_PREC),
974985
Token::Word(w)

0 commit comments

Comments
 (0)