Class: Arel::Visitors::PostgreSQL
- Inherits:
-
Object
- Object
- Arel::Visitors::PostgreSQL
- Defined in:
- lib/arel_extensions/visitors/postgresql.rb
Constant Summary collapse
- DATE_MAPPING =
{ 'd' => 'DAY', 'm' => 'MONTH', 'w' => 'WEEK', 'y' => 'YEAR', 'wd' => 'DOW', 'h' => 'HOUR', 'mn' => 'MINUTE', 's' => 'SECOND' }.freeze
- DATE_FORMAT_DIRECTIVES =
{ '%Y' => 'YYYY', '%C' => 'CC', '%y' => 'YY', '%m' => 'MM', '%B' => 'TMMonth', '%^B' => 'TMMONTH', '%b' => 'TMMon', '%^b' => 'TMMON', '%V' => 'IW', '%G' => 'IYYY', # ISO week number and year of week '%d' => 'DD', '%e' => 'FMDD', '%j' => 'DDD', '%w' => '', '%a' => 'TMDy', '%A' => 'TMDay', # day, weekday '%H' => 'HH24', '%k' => '', '%I' => 'HH', '%l' => '', '%P' => 'am', '%p' => 'AM', # hours '%M' => 'MI', '%S' => 'SS', '%L' => 'MS', '%N' => 'US', '%z' => 'tz', # seconds, subseconds '%%' => '%', }.freeze
- NUMBER_COMMA_MAPPING =
{ 'en_US' => '.,', 'fr_FR' => ',', 'sv_SE' => ', ' }.freeze
Instance Method Summary collapse
- #visit_Aggregate_For_AggregateFunction(o, collector) ⇒ Object
- #visit_Arel_Attributes_Attribute(o, collector) ⇒ Object
- #visit_Arel_Nodes_As(o, collector) ⇒ Object
- #visit_Arel_Nodes_NotRegexp(o, collector) ⇒ Object
- #visit_Arel_Nodes_Regexp(o, collector) ⇒ Object
- #visit_Arel_Nodes_SelectStatement(o, collector) ⇒ Object
- #visit_Arel_Nodes_TableAlias(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_AiIMatches(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_AiMatches(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Cast(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Collate(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Concat(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_DateAdd(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_DateDiff(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Duration(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Format(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_FormattedDate(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_FormattedNumber(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_GroupConcat(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_IsNotNull(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_IsNull(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Json(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_JsonGet(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_JsonGroup(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_JsonMerge(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_JsonSet(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Locate(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Log10(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Ltrim(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Power(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Rand(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_RegexpReplace(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Repeat(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Rtrim(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_SMatches(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Std(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Substring(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Sum(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Trim(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Variance(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Wday(o, collector) ⇒ Object
Instance Method Details
#visit_Aggregate_For_AggregateFunction(o, collector) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/arel_extensions/visitors/postgresql.rb', line 102 def visit_Aggregate_For_AggregateFunction o, collector if !o.order.blank? || !o.group.blank? collector << ' OVER (' if !o.group.blank? collector << ' PARTITION BY ' o.group.each_with_index do |group, i| collector << COMMA if i != 0 visit group, collector end end if !o.order.blank? collector << ' ORDER BY ' o.order.each_with_index do |order, i| collector << COMMA if i != 0 visit order, collector end end collector << ')' end collector end |
#visit_Arel_Attributes_Attribute(o, collector) ⇒ Object
495 496 497 498 499 500 501 |
# File 'lib/arel_extensions/visitors/postgresql.rb', line 495 def visit_Arel_Attributes_Attribute o, collector join_name = o.relation.table_alias || o.relation.name if join_name.length > 63 join_name = Arel.shorten(join_name) end collector << "#{quote_table_name join_name}.#{quote_column_name o.name}" end |
#visit_Arel_Nodes_As(o, collector) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/arel_extensions/visitors/postgresql.rb', line 82 def visit_Arel_Nodes_As o, collector if o.left.is_a?(Arel::Nodes::Binary) collector << '(' collector = visit o.left, collector collector << ')' else collector = visit o.left, collector end collector << ' AS ' # sometimes these values are already quoted, if they are, don't double quote it quote = o.right.is_a?(Arel::Nodes::SqlLiteral) && o.right[0] != '"' && o.right[-1] != '"' collector << '"' if quote collector = visit o.right, collector collector << '"' if quote collector end |
#visit_Arel_Nodes_NotRegexp(o, collector) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/arel_extensions/visitors/postgresql.rb', line 64 def visit_Arel_Nodes_NotRegexp o, collector collector = visit o.left, collector collector << ' !~ ' collector = visit o.right, collector collector end |
#visit_Arel_Nodes_Regexp(o, collector) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/arel_extensions/visitors/postgresql.rb', line 56 def visit_Arel_Nodes_Regexp o, collector collector = visit o.left, collector collector << ' ~ ' collector = visit o.right, collector collector end |
#visit_Arel_Nodes_SelectStatement(o, collector) ⇒ Object
477 478 479 480 481 482 483 484 |
# File 'lib/arel_extensions/visitors/postgresql.rb', line 477 def visit_Arel_Nodes_SelectStatement o, collector if !(collector.value.blank? || (collector.value.is_a?(Array) && collector.value[0].blank?)) && o.limit.blank? && o.offset.blank? o = o.dup o.orders = [] end old_visit_Arel_Nodes_SelectStatement(o, collector) end |
#visit_Arel_Nodes_TableAlias(o, collector) ⇒ Object
487 488 489 490 491 492 |
# File 'lib/arel_extensions/visitors/postgresql.rb', line 487 def visit_Arel_Nodes_TableAlias o, collector if o.name.length > 63 o = Arel::Table.new(o.table_name).alias(Arel.shorten(o.name)) end old_visit_Arel_Nodes_TableAlias(o, collector) end |
#visit_ArelExtensions_Nodes_AiIMatches(o, collector) ⇒ Object
224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/arel_extensions/visitors/postgresql.rb', line 224 def visit_ArelExtensions_Nodes_AiIMatches o, collector collector = visit o.left.ai_collate, collector collector << ' ILIKE ' collector = visit o.right.ai_collate, collector if o.escape collector << ' ESCAPE ' visit o.escape, collector else collector end end |
#visit_ArelExtensions_Nodes_AiMatches(o, collector) ⇒ Object
212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/arel_extensions/visitors/postgresql.rb', line 212 def visit_ArelExtensions_Nodes_AiMatches o, collector collector = visit o.left.ai_collate, collector collector << ' LIKE ' collector = visit o.right.ai_collate, collector if o.escape collector << ' ESCAPE ' visit o.escape, collector else collector end end |
#visit_ArelExtensions_Nodes_Cast(o, collector) ⇒ Object
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 |
# File 'lib/arel_extensions/visitors/postgresql.rb', line 378 def visit_ArelExtensions_Nodes_Cast o, collector as_attr = case o.as_attr when :string 'varchar' when :text, :ntext 'text' when :time 'time' when :int collector << 'CAST(CAST(' collector = visit o.left, collector collector << ' AS numeric) AS int)' return collector when :number, :decimal, :float 'numeric' when :datetime 'timestamp without time zone' when :date 'date' when :binary 'binary' when :jsonb 'jsonb' else o.as_attr.to_s end collector << 'CAST(' collector = visit o.left, collector collector << ' AS ' collector = visit Arel::Nodes::SqlLiteral.new(as_attr), collector collector << ')' collector end |
#visit_ArelExtensions_Nodes_Collate(o, collector) ⇒ Object
248 249 250 251 252 253 254 255 256 257 258 259 |
# File 'lib/arel_extensions/visitors/postgresql.rb', line 248 def visit_ArelExtensions_Nodes_Collate o, collector if o.ai collector << 'unaccent(' collector = visit o.expressions.first, collector collector << ')' elsif o.ci collector = visit o.expressions.first, collector else collector = visit o.expressions.first, collector end collector end |
#visit_ArelExtensions_Nodes_Concat(o, collector) ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/arel_extensions/visitors/postgresql.rb', line 71 def visit_ArelExtensions_Nodes_Concat o, collector collector << '(' o.expressions.each_with_index { |arg, i| collector = visit arg, collector collector << ' || ' unless i == o.expressions.length - 1 } collector << ')' collector end |
#visit_ArelExtensions_Nodes_DateAdd(o, collector) ⇒ Object
261 262 263 264 265 266 |
# File 'lib/arel_extensions/visitors/postgresql.rb', line 261 def visit_ArelExtensions_Nodes_DateAdd o, collector collector = visit o.left, collector collector << ' + ' # (o.right.value >= 0 ? ' + ' : ' - ') collector = visit o.postgresql_value(o.right), collector collector end |
#visit_ArelExtensions_Nodes_DateDiff(o, collector) ⇒ Object
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
# File 'lib/arel_extensions/visitors/postgresql.rb', line 268 def visit_ArelExtensions_Nodes_DateDiff o, collector if o.right_node_type == :ruby_date || o.right_node_type == :ruby_time || o.right_node_type == :date || o.right_node_type == :datetime || o.right_node_type == :time collector << if o.left_node_type == :ruby_time || o.left_node_type == :datetime || o.left_node_type == :time "DATEDIFF('second', " else "DATEDIFF('day', " end collector = visit o.right, collector collector << (o.right_node_type == :date ? '::date' : '::timestamp') collector << COMMA collector = visit o.left, collector collector << (o.left_node_type == :date ? '::date' : '::timestamp') collector << ')' else collector << '(' collector = visit o.left, collector collector << ' - (' if o.right.is_a?(ArelExtensions::Nodes::Duration) o.right.with_interval = true end collector = visit o.right, collector collector << '))' end collector end |
#visit_ArelExtensions_Nodes_Duration(o, collector) ⇒ Object
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
# File 'lib/arel_extensions/visitors/postgresql.rb', line 294 def visit_ArelExtensions_Nodes_Duration o, collector if o.with_interval interval = case o.left when 'd', 'm', 'y' 'DAY' when 'h', 'mn', 's' 'SECOND' when /i\z/ collector << '(' collector = visit o.right, collector collector << ')' collector << " * (INTERVAL '1' #{DATE_MAPPING[o.left[0..-2]]})" return collector end end collector << "EXTRACT(#{DATE_MAPPING[o.left]} FROM CAST(" collector = visit o.right, collector collector << ' AS TIMESTAMP WITH TIME ZONE))' collector << " * (INTERVAL '1' #{interval})" if interval && o.with_interval collector end |
#visit_ArelExtensions_Nodes_Format(o, collector) ⇒ Object
176 177 178 |
# File 'lib/arel_extensions/visitors/postgresql.rb', line 176 def visit_ArelExtensions_Nodes_Format o, collector visit_ArelExtensions_Nodes_FormattedDate o, collector end |
#visit_ArelExtensions_Nodes_FormattedDate(o, collector) ⇒ Object
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/arel_extensions/visitors/postgresql.rb', line 180 def visit_ArelExtensions_Nodes_FormattedDate o, collector fmt = ArelExtensions::Visitors::strftime_to_format(o.iso_format, DATE_FORMAT_DIRECTIVES) collector << 'TO_CHAR(' collector << '(' if o.time_zone collector = visit o.left, collector case o.time_zone when Hash src_tz, dst_tz = o.time_zone.first collector << ') AT TIME ZONE ' collector = visit Arel.quoted(src_tz), collector collector << ' AT TIME ZONE ' collector = visit Arel.quoted(dst_tz), collector when String collector << ") AT TIME ZONE 'UTC' AT TIME ZONE " collector = visit Arel.quoted(o.time_zone), collector end collector << COMMA collector = visit Arel.quoted(fmt), collector collector << ')' collector end |
#visit_ArelExtensions_Nodes_FormattedNumber(o, collector) ⇒ Object
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 |
# File 'lib/arel_extensions/visitors/postgresql.rb', line 414 def visit_ArelExtensions_Nodes_FormattedNumber o, collector col = o.left.coalesce(0) comma = o.precision == 0 ? '' : (NUMBER_COMMA_MAPPING[o.locale][0] || '.') thousand_separator = NUMBER_COMMA_MAPPING[o.locale][1] || (NUMBER_COMMA_MAPPING[o.locale] ? '' : 'G') nines_after = (1..o.precision).map{'9'}.join('') nines_before = ("999#{thousand_separator}" * 4 + '990') sign = Arel.when(col < 0). then('-'). else(o.flags.include?('+') ? '+' : (o.flags.include?(' ') ? ' ' : '')) sign_length = ArelExtensions::Nodes::Length.new([sign]) number = if o.scientific_notation ArelExtensions::Nodes::Concat.new([ Arel::Nodes::NamedFunction.new('TRIM', [ Arel::Nodes::NamedFunction.new('TO_CHAR', [ Arel.when(col.not_eq 0).then(col.abs / Arel.quoted(10).pow(col.abs.log10.floor)).else(1), Arel.quoted("FM#{nines_before}\"#{comma}\"V#{nines_after}") ])]), o.type, Arel::Nodes::NamedFunction.new('TRIM', [ Arel::Nodes::NamedFunction.new('TO_CHAR', [ Arel.when(col.not_eq 0).then(col.abs.log10.floor).else(0), Arel.quoted("FM#{nines_before}") ])]) ]) else Arel::Nodes::NamedFunction.new('TRIM', [ Arel::Nodes::NamedFunction.new('TO_CHAR', [ Arel.quoted(col.abs), Arel.quoted("FM#{nines_before}\"#{comma}\"V#{nines_after}") ])]) end repeated_char = if o.width == 0 Arel.quoted('') else Arel .when(Arel.quoted(o.width).abs - (number.length + sign_length) > 0) .then(Arel.quoted( o.flags.include?('-') ? ' ' : (o.flags.include?('0') ? '0' : ' ') ).repeat(Arel.quoted(o.width).abs - (number.length + sign_length)) ) .else('') end before = !o.flags.include?('0') && !o.flags.include?('-') ? repeated_char : '' middle = o.flags.include?('0') && !o.flags.include?('-') ? repeated_char : '' after = o.flags.include?('-') ? repeated_char : '' full_number = ArelExtensions::Nodes::Concat.new([ before, sign, middle, number, after ]) collector = visit ArelExtensions::Nodes::Concat.new([Arel.quoted(o.prefix), full_number, Arel.quoted(o.suffix)]), collector collector end |
#visit_ArelExtensions_Nodes_GroupConcat(o, collector) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/arel_extensions/visitors/postgresql.rb', line 124 def visit_ArelExtensions_Nodes_GroupConcat o, collector collector << 'array_to_string(array_agg(' collector = visit o.left, collector if o.order && !o.order.blank? collector << ' ORDER BY' o.order.each_with_index do |order, i| collector << COMMA if i != 0 collector << ' ' visit order, collector end end collector << ')' o.order = nil visit_Aggregate_For_AggregateFunction o, collector collector << COMMA collector = if o.separator && o.separator != 'NULL' visit o.separator, collector else visit Arel.quoted(','), collector end collector << ')' collector end |
#visit_ArelExtensions_Nodes_IsNotNull(o, collector) ⇒ Object
357 358 359 360 361 |
# File 'lib/arel_extensions/visitors/postgresql.rb', line 357 def visit_ArelExtensions_Nodes_IsNotNull o, collector collector = visit o.expr, collector collector << ' IS NOT NULL' collector end |
#visit_ArelExtensions_Nodes_IsNull(o, collector) ⇒ Object
351 352 353 354 355 |
# File 'lib/arel_extensions/visitors/postgresql.rb', line 351 def visit_ArelExtensions_Nodes_IsNull o, collector collector = visit o.expr, collector collector << ' IS NULL' collector end |
#visit_ArelExtensions_Nodes_Json(o, collector) ⇒ Object
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 |
# File 'lib/arel_extensions/visitors/postgresql.rb', line 519 def visit_ArelExtensions_Nodes_Json o, collector case o.dict when Array collector << 'to_jsonb(array[' o.dict.each.with_index do |v, i| if i != 0 collector << Arel::Visitors::MySQL::COMMA end collector = visit v, collector end collector << '])' when Hash collector << 'jsonb_build_object(' o.dict.each.with_index do |(k, v), i| if i != 0 collector << Arel::Visitors::MySQL::COMMA end collector = visit k, collector collector << Arel::Visitors::MySQL::COMMA collector = visit v, collector end collector << ')' when String, Numeric, TrueClass, FalseClass collector = visit Arel.quoted("#{o.dict}"), collector collector << '::jsonb' when NilClass collector << %Q['null'::jsonb] else collector = visit o.dict, collector collector << '::jsonb' end collector end |
#visit_ArelExtensions_Nodes_JsonGet(o, collector) ⇒ Object
563 564 565 566 567 568 |
# File 'lib/arel_extensions/visitors/postgresql.rb', line 563 def visit_ArelExtensions_Nodes_JsonGet o, collector collector = visit o.dict, collector collector << ' ->> ' collector = visit o.key, collector collector end |
#visit_ArelExtensions_Nodes_JsonGroup(o, collector) ⇒ Object
584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 |
# File 'lib/arel_extensions/visitors/postgresql.rb', line 584 def visit_ArelExtensions_Nodes_JsonGroup o, collector if o.as_array collector << 'jsonb_agg(' collector = visit o.dict, collector collector << ')' else case o.dict when Hash o.dict.each.with_index do |(k, v), i| if i != 0 collector << ' || ' end collector << 'jsonb_object_agg(' collector = visit k, collector collector << Arel::Visitors::MySQL::COMMA collector = visit v, collector collector << ')' end else collector << 'jsonb_object_agg(' collector = visit o.dict, collector collector << ')' end end collector end |
#visit_ArelExtensions_Nodes_JsonMerge(o, collector) ⇒ Object
553 554 555 556 557 558 559 560 561 |
# File 'lib/arel_extensions/visitors/postgresql.rb', line 553 def visit_ArelExtensions_Nodes_JsonMerge o, collector o.expressions.each.with_index do |v, i| if i != 0 collector << ' || ' end collector = visit v, collector end collector end |
#visit_ArelExtensions_Nodes_JsonSet(o, collector) ⇒ Object
570 571 572 573 574 575 576 577 578 579 580 581 582 |
# File 'lib/arel_extensions/visitors/postgresql.rb', line 570 def visit_ArelExtensions_Nodes_JsonSet o, collector collector << 'jsonb_set(' collector = visit o.dict, collector collector << Arel::Visitors::MySQL::COMMA collector << 'array[' collector = visit o.key, collector collector << ']' collector << Arel::Visitors::MySQL::COMMA collector = visit o.value, collector collector << Arel::Visitors::MySQL::COMMA collector << 'true)' collector end |
#visit_ArelExtensions_Nodes_Locate(o, collector) ⇒ Object
316 317 318 319 320 321 322 323 |
# File 'lib/arel_extensions/visitors/postgresql.rb', line 316 def visit_ArelExtensions_Nodes_Locate o, collector collector << 'POSITION(' collector = visit o.right, collector collector << ' IN ' collector = visit o.left, collector collector << ')' collector end |
#visit_ArelExtensions_Nodes_Log10(o, collector) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/arel_extensions/visitors/postgresql.rb', line 44 def visit_ArelExtensions_Nodes_Log10 o, collector collector << 'LOG(' o.expressions.each_with_index { |arg, i| collector << Arel::Visitors::ToSql::COMMA if i != 0 collector = visit arg, collector } collector << ')' collector end |
#visit_ArelExtensions_Nodes_Ltrim(o, collector) ⇒ Object
158 159 160 161 162 163 164 165 |
# File 'lib/arel_extensions/visitors/postgresql.rb', line 158 def visit_ArelExtensions_Nodes_Ltrim o, collector collector << 'TRIM(LEADING ' collector = visit o.right, collector collector << ' FROM ' collector = visit o.left, collector collector << ')' collector end |
#visit_ArelExtensions_Nodes_Power(o, collector) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/arel_extensions/visitors/postgresql.rb', line 34 def visit_ArelExtensions_Nodes_Power o, collector collector << 'POWER(' o.expressions.each_with_index { |arg, i| collector << Arel::Visitors::ToSql::COMMA if i != 0 collector = visit arg, collector } collector << ')' collector end |
#visit_ArelExtensions_Nodes_Rand(o, collector) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/arel_extensions/visitors/postgresql.rb', line 23 def visit_ArelExtensions_Nodes_Rand o, collector collector << 'RANDOM(' if (o.left != nil && o.right != nil) collector = visit o.left, collector collector << COMMA collector = isit o.right, collector end collector << ')' collector end |
#visit_ArelExtensions_Nodes_RegexpReplace(o, collector) ⇒ Object
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 |
# File 'lib/arel_extensions/visitors/postgresql.rb', line 335 def visit_ArelExtensions_Nodes_RegexpReplace o, collector collector << 'REGEXP_REPLACE(' visit o.left, collector collector << Arel::Visitors::ToSql::COMMA tab = o.pattern.inspect + 'g' # Make it always global pattern = tab.split('/')[1..-2].join('/') flags = tab.split('/')[-1] visit Arel.quoted(pattern), collector collector << Arel::Visitors::ToSql::COMMA visit o.substitute, collector collector << Arel::Visitors::ToSql::COMMA visit Arel.quoted(flags + 'g'), collector collector << ')' collector end |
#visit_ArelExtensions_Nodes_Repeat(o, collector) ⇒ Object
202 203 204 205 206 207 208 209 210 |
# File 'lib/arel_extensions/visitors/postgresql.rb', line 202 def visit_ArelExtensions_Nodes_Repeat o, collector collector << 'REPEAT(' o.expressions.each_with_index { |arg, i| collector << Arel::Visitors::ToSql::COMMA if i != 0 collector = visit arg, collector } collector << ')' collector end |
#visit_ArelExtensions_Nodes_Rtrim(o, collector) ⇒ Object
167 168 169 170 171 172 173 174 |
# File 'lib/arel_extensions/visitors/postgresql.rb', line 167 def visit_ArelExtensions_Nodes_Rtrim o, collector collector << 'TRIM(TRAILING ' collector = visit o.right, collector collector << ' FROM ' collector = visit o.left, collector collector << ')' collector end |
#visit_ArelExtensions_Nodes_SMatches(o, collector) ⇒ Object
236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/arel_extensions/visitors/postgresql.rb', line 236 def visit_ArelExtensions_Nodes_SMatches o, collector collector = visit o.left, collector collector << ' LIKE ' collector = visit o.right, collector if o.escape collector << ' ESCAPE ' visit o.escape, collector else collector end end |
#visit_ArelExtensions_Nodes_Std(o, collector) ⇒ Object
503 504 505 506 507 508 509 |
# File 'lib/arel_extensions/visitors/postgresql.rb', line 503 def visit_ArelExtensions_Nodes_Std o, collector collector << (o.unbiased_estimator ? 'STDDEV_SAMP(' : 'STDDEV_POP(') visit o.left, collector collector << ')' visit_Aggregate_For_AggregateFunction o, collector collector end |
#visit_ArelExtensions_Nodes_Substring(o, collector) ⇒ Object
325 326 327 328 329 330 331 332 333 |
# File 'lib/arel_extensions/visitors/postgresql.rb', line 325 def visit_ArelExtensions_Nodes_Substring o, collector collector << 'SUBSTR(' o.expressions.each_with_index { |arg, i| collector << COMMA if i != 0 collector = visit arg, collector } collector << ')' collector end |
#visit_ArelExtensions_Nodes_Sum(o, collector) ⇒ Object
363 364 365 366 367 368 369 |
# File 'lib/arel_extensions/visitors/postgresql.rb', line 363 def visit_ArelExtensions_Nodes_Sum o, collector collector << 'sum(' collector = visit o.expr, collector collector << ')' visit_Aggregate_For_AggregateFunction o, collector collector end |
#visit_ArelExtensions_Nodes_Trim(o, collector) ⇒ Object
149 150 151 152 153 154 155 156 |
# File 'lib/arel_extensions/visitors/postgresql.rb', line 149 def visit_ArelExtensions_Nodes_Trim o, collector collector << 'TRIM(BOTH ' collector = visit o.right, collector collector << ' FROM ' collector = visit o.left, collector collector << ')' collector end |
#visit_ArelExtensions_Nodes_Variance(o, collector) ⇒ Object
511 512 513 514 515 516 517 |
# File 'lib/arel_extensions/visitors/postgresql.rb', line 511 def visit_ArelExtensions_Nodes_Variance o, collector collector << (o.unbiased_estimator ? 'VAR_SAMP(' : 'VAR_POP(') visit o.left, collector collector << ')' visit_Aggregate_For_AggregateFunction o, collector collector end |
#visit_ArelExtensions_Nodes_Wday(o, collector) ⇒ Object
371 372 373 374 375 376 |
# File 'lib/arel_extensions/visitors/postgresql.rb', line 371 def visit_ArelExtensions_Nodes_Wday o, collector collector << 'EXRTACT(DOW, ' collector = visit o.date, collector collector << ')' collector end |