@@ -16,7 +16,7 @@ use super::{keywords, Context};
1616use crate :: ir:: generic:: { ColumnSort , SortDirection , WindowFrame , WindowKind } ;
1717use crate :: ir:: pl:: { self , Ident , Literal } ;
1818use crate :: ir:: rq;
19- use crate :: sql:: dialect:: IdentQuotingStyle ;
19+ use crate :: sql:: dialect:: { IdentQuotingStyle , IntervalQuotingStyle } ;
2020use crate :: sql:: pq:: context:: ColumnDecl ;
2121use crate :: utils:: { valid_ident, OrMap } ;
2222use crate :: { Error , Result , Span , WithErrorInfo } ;
@@ -428,27 +428,46 @@ pub(super) fn translate_literal(l: Literal, ctx: &Context) -> Result<sql_ast::Ex
428428 ) ) )
429429 }
430430 } ;
431- if ctx. dialect . requires_quotes_intervals ( ) {
432- //postgres requires quotes around number and unit together eg '3 WEEK'
433- let value = Box :: new ( sql_ast:: Expr :: Value (
434- Value :: SingleQuotedString ( format ! ( "{} {}" , vau. n, sql_parser_datetime) ) . into ( ) ,
435- ) ) ;
436- sql_ast:: Expr :: Interval ( sqlparser:: ast:: Interval {
437- value,
438- leading_field : None , //set to none since field is now contained in string
439- leading_precision : None ,
440- last_field : None ,
441- fractional_seconds_precision : None ,
442- } )
443- } else {
444- let value = Box :: new ( translate_literal ( Literal :: Integer ( vau. n ) , ctx) ?) ;
445- sql_ast:: Expr :: Interval ( sqlparser:: ast:: Interval {
446- value,
447- leading_field : Some ( sql_parser_datetime) ,
448- leading_precision : None ,
449- last_field : None ,
450- fractional_seconds_precision : None ,
451- } )
431+ match ctx. dialect . interval_quoting_style ( & sql_parser_datetime) {
432+ IntervalQuotingStyle :: ValueAndUnitQuoted => {
433+ //postgres requires quotes around number and unit together eg '3 WEEK'
434+ let value = Box :: new ( sql_ast:: Expr :: Value (
435+ Value :: SingleQuotedString ( format ! ( "{} {}" , vau. n, sql_parser_datetime) )
436+ . into ( ) ,
437+ ) ) ;
438+ sql_ast:: Expr :: Interval ( sqlparser:: ast:: Interval {
439+ value,
440+ leading_field : None , //set to none since field is now contained in string
441+ leading_precision : None ,
442+ last_field : None ,
443+ fractional_seconds_precision : None ,
444+ } )
445+ }
446+ IntervalQuotingStyle :: NoQuotes => {
447+ let value = Box :: new ( translate_literal ( Literal :: Integer ( vau. n ) , ctx) ?) ;
448+ sql_ast:: Expr :: Interval ( sqlparser:: ast:: Interval {
449+ value,
450+ leading_field : Some ( sql_parser_datetime) ,
451+ leading_precision : None ,
452+ last_field : None ,
453+ fractional_seconds_precision : None ,
454+ } )
455+ }
456+ // Redshift requires quotes around the number only, otherwise months and years are
457+ // not supported. eg '3' MONTH
458+ IntervalQuotingStyle :: ValueQuoted => {
459+ // Adding single quotes around the number
460+ let value = Box :: new ( sql_ast:: Expr :: Value (
461+ Value :: SingleQuotedString ( vau. n . to_string ( ) ) . into ( ) ,
462+ ) ) ;
463+ sql_ast:: Expr :: Interval ( sqlparser:: ast:: Interval {
464+ value,
465+ leading_field : Some ( sql_parser_datetime) ,
466+ leading_precision : None ,
467+ last_field : None ,
468+ fractional_seconds_precision : None ,
469+ } )
470+ }
452471 }
453472 }
454473 } )
0 commit comments