@@ -49,6 +49,11 @@ def self.parse_atomic(tokens)
49
49
else
50
50
Variable . parse ( tokens )
51
51
end
52
+ elsif SQLTree ::Token ::STRING_ESCAPE == tokens . peek
53
+ tokens . consume ( SQLTree ::Token ::STRING_ESCAPE )
54
+ Value . parse ( tokens )
55
+ elsif SQLTree ::Token ::INTERVAL === tokens . peek
56
+ IntervalValue . parse ( tokens )
52
57
else
53
58
Value . parse ( tokens )
54
59
end
@@ -333,7 +338,35 @@ def self.parse(tokens)
333
338
return function_call
334
339
end
335
340
end
336
-
341
+
342
+
343
+ # Represents a postgresql INTERVAL value. Example: interval '2 days'.
344
+ #
345
+ # The value is the literal text of the interval (e.g. "2 days").
346
+ class IntervalValue < SQLTree ::Node ::Expression
347
+ # The actual value this node represents.
348
+ leaf :value
349
+
350
+ def initialize ( value ) # :nodoc:
351
+ @value = value
352
+ end
353
+
354
+ # Generates an SQL representation for this value.
355
+ def to_sql ( options = { } )
356
+ "interval " + quote_str ( @value )
357
+ end
358
+
359
+ def self . parse ( tokens )
360
+ tokens . consume ( SQLTree ::Token ::INTERVAL )
361
+ if SQLTree ::Token ::String === tokens . peek
362
+ self . new ( tokens . next . literal )
363
+ else
364
+ raise SQLTree ::Parser ::UnexpectedToken . new ( tokens . current , :literal )
365
+ end
366
+ end
367
+ end
368
+
369
+
337
370
# Represents alitreal value in an SQL expression. This node is a leaf node
338
371
# and thus has no child nodes.
339
372
#
@@ -345,14 +378,14 @@ def self.parse(tokens)
345
378
# * an integer or decimal value, which is represented by an appropriate
346
379
# <tt>Numeric</tt> instance.
347
380
class Value < SQLTree ::Node ::Expression
348
-
381
+
349
382
# The actual value this node represents.
350
383
leaf :value
351
384
352
385
def initialize ( value ) # :nodoc:
353
386
@value = value
354
387
end
355
-
388
+
356
389
# Generates an SQL representation for this value.
357
390
#
358
391
# This method supports nil, string, numeric, date and time values.
@@ -389,7 +422,7 @@ def self.parse(tokens)
389
422
end
390
423
end
391
424
end
392
-
425
+
393
426
# Represents a variable within an SQL expression. This is a leaf node, so it
394
427
# does not have any child nodes. A variale can point to a field of a table or
395
428
# to another expression that was declared elsewhere.
0 commit comments