3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/rgviz_rails/adapters/postgresql_adapter.rb', line 3
def accept_scalar_function_column(node, visitor)
case node.function
when ScalarFunctionColumn::Year
visitor << "date_part('year',"
node.arguments[0].accept visitor
visitor << ")"
when ScalarFunctionColumn::Month
visitor << "date_part('month',"
node.arguments[0].accept visitor
visitor << ")"
when ScalarFunctionColumn::Day
visitor << "date_part('day',"
node.arguments[0].accept visitor
visitor << ")"
when ScalarFunctionColumn::Hour
visitor << "date_part('hour',"
node.arguments[0].accept visitor
visitor << ")"
when ScalarFunctionColumn::Minute
visitor << "date_part('minute',"
node.arguments[0].accept visitor
visitor << ")"
when ScalarFunctionColumn::Second
visitor << "date_part('second',"
node.arguments[0].accept visitor
visitor << ")"
when ScalarFunctionColumn::Millisecond
visitor << "date_part('milliseconds',"
node.arguments[0].accept visitor
visitor << ")"
when ScalarFunctionColumn::Quarter
visitor << "date_part('quarter',"
node.arguments[0].accept visitor
visitor << ")"
when ScalarFunctionColumn::DayOfWeek
visitor << "1 + date_part('dow',"
node.arguments[0].accept visitor
visitor << ")"
when ScalarFunctionColumn::Now
visitor << "now()"
when ScalarFunctionColumn::DateDiff
visitor << "(date "
node.arguments[0].accept visitor
visitor << " - date "
node.arguments[1].accept visitor
visitor << ")"
when ScalarFunctionColumn::ToDate
visitor << "to_char("
arg = node.arguments[0]
if arg.kind_of?(StringColumn) || arg.kind_of?(DateColumn) || arg.kind_of?(DateTimeColumn) || arg.kind_of?(TimeOfDayColumn)
visitor << "date "
end
arg.accept visitor
visitor << ", 'yyyy-mm-dd')"
when ScalarFunctionColumn::Upper
visitor << "upper("
node.arguments[0].accept visitor
visitor << ")"
when ScalarFunctionColumn::Lower
visitor << "lower("
node.arguments[0].accept visitor
visitor << ")"
when ScalarFunctionColumn::Concat
visitor << "("
node.arguments.each_with_index do |arg, i|
visitor << " || " if i > 0
arg.accept visitor
end
visitor << ")"
end
end
|