Class: Sequel::SQL::Function

Inherits:
GenericExpression show all
Defined in:
lib/sequel/sql.rb,
lib/sequel/extensions/eval_inspect.rb

Overview

Represents an SQL function call.

Direct Known Subclasses

EmulatedFunction

Constant Summary collapse

WILDCARD =
LiteralString.new('*').freeze
DISTINCT =
["DISTINCT ".freeze].freeze
COMMA_ARRAY =
[LiteralString.new(', ').freeze].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Postgres::HStoreOpMethods

#hstore

Methods included from Postgres::RangeOpMethods

#pg_range

Methods included from Postgres::ArrayOpMethods

#pg_array

Methods included from Postgres::JSONOpMethods

#pg_json

Methods included from Postgres::PGRowOp::ExpressionMethods

#pg_row

Methods included from SubscriptMethods

#sql_subscript

Methods included from StringMethods

#ilike, #like

Methods included from OrderMethods

#asc, #desc

Methods included from NumericMethods

#+

Methods included from ComplexExpressionMethods

#extract, #sql_boolean, #sql_number, #sql_string

Methods included from CastMethods

#cast, #cast_numeric, #cast_string

Methods included from BooleanMethods

#~

Methods included from AliasMethods

#as

Methods inherited from Expression

#==, attr_reader, #eql?, #hash, inherited, #inspect, #lit, #sql_literal

Constructor Details

#initialize(f, *args) ⇒ Function

Set the functions and args to the given arguments



1225
1226
1227
# File 'lib/sequel/sql.rb', line 1225

def initialize(f, *args)
  @f, @args = f, args
end

Instance Attribute Details

#argsObject (readonly)

The array of arguments to pass to the function (may be blank)



1222
1223
1224
# File 'lib/sequel/sql.rb', line 1222

def args
  @args
end

#fObject (readonly)

The SQL function to call



1219
1220
1221
# File 'lib/sequel/sql.rb', line 1219

def f
  @f
end

Instance Method Details

#*(ce = (arg=false;nil)) ⇒ Object

If no arguments are given, return a new function with the wildcard prepended to the arguments.

Sequel.function(:count).*  # count(*)
Sequel.function(:count, 1).*  # count(*, 1)


1233
1234
1235
1236
1237
1238
1239
# File 'lib/sequel/sql.rb', line 1233

def *(ce=(arg=false;nil))
  if arg == false
    Function.new(f, WILDCARD, *args)
  else
    super(ce)
  end
end

#distinctObject

Return a new function with DISTINCT before the method arguments.



1242
1243
1244
# File 'lib/sequel/sql.rb', line 1242

def distinct
  Function.new(f, PlaceholderLiteralString.new(DISTINCT + COMMA_ARRAY * (args.length-1), args))
end

#over(opts = OPTS) ⇒ Object

Create a WindowFunction using the receiver and the appropriate options for the window.



1247
1248
1249
# File 'lib/sequel/sql.rb', line 1247

def over(opts=OPTS)
  WindowFunction.new(self, Window.new(opts))
end