Qore SqlUtil Module Reference
1.5
|
Functions | |
hash< ColumnOperatorInfo > | SqlUtil::cop_append (auto column, string arg) |
returns a ColumnOperatorInfo hash for the "append" operator with the given argument More... | |
hash< ColumnOperatorInfo > | SqlUtil::cop_as (auto column, string arg) |
returns a ColumnOperatorInfo hash for the "as" operator with the given argument More... | |
hash< ColumnOperatorInfo > | SqlUtil::cop_avg (auto column) |
returns a ColumnOperatorInfo hash for the "avg" operator; returns average column values More... | |
hash< ColumnOperatorInfo > | SqlUtil::cop_cast (auto column, string arg, auto arg1, auto arg2) |
returns a ColumnOperatorInfo hash for the "cast" operator with the given argument(s) More... | |
hash< ColumnOperatorInfo > | SqlUtil::cop_coalesce (auto col1, auto col2) |
returns a ColumnOperatorInfo hash for the "coalesce" operator with the given column arguments; the first non-NULL column value will be returned More... | |
hash< ColumnOperatorInfo > | SqlUtil::cop_count (auto column='') |
returns a ColumnOperatorInfo hash for the "count" operator; returns row counts More... | |
hash< ColumnOperatorInfo > | SqlUtil::cop_cume_dist () |
Analytic/window function: relative rank of the current row. More... | |
hash< ColumnOperatorInfo > | SqlUtil::cop_dense_rank () |
Analytic/window function: rank of the current row without gaps. More... | |
hash< ColumnOperatorInfo > | SqlUtil::cop_distinct (auto column) |
returns a ColumnOperatorInfo hash for the "distinct" operator with the given argument; returns distinct column values More... | |
hash< ColumnOperatorInfo > | SqlUtil::cop_divide (auto column1, auto column2) |
returns a ColumnOperatorInfo hash for the "/" operator with the given arguments More... | |
hash< ColumnOperatorInfo > | SqlUtil::cop_first_value (any column) |
Analytic/window function: value evaluated at the row that is the first row of the window frame. More... | |
hash< ColumnOperatorInfo > | SqlUtil::cop_last_value (any column) |
Analytic/window function: value evaluated at the row that is the last row of the window frame. More... | |
hash< ColumnOperatorInfo > | SqlUtil::cop_length (auto column) |
returns a ColumnOperatorInfo hash for the "len" operator with the given argument; returns the length of the given text field More... | |
hash< ColumnOperatorInfo > | SqlUtil::cop_lower (auto column) |
returns a ColumnOperatorInfo hash for the "lower" operator with the given argument; returns a column value in lower case More... | |
hash< ColumnOperatorInfo > | SqlUtil::cop_max (auto column) |
returns a ColumnOperatorInfo hash for the "max" operator; returns maximum column values More... | |
hash< ColumnOperatorInfo > | SqlUtil::cop_min (auto column) |
returns a ColumnOperatorInfo hash for the "min" operator; returns minimum column values More... | |
hash< ColumnOperatorInfo > | SqlUtil::cop_minus (auto column1, auto column2) |
returns a ColumnOperatorInfo hash for the "-" operator with the given arguments More... | |
hash< ColumnOperatorInfo > | SqlUtil::cop_multiply (auto column1, auto column2) |
returns a ColumnOperatorInfo hash for the "*" operator with the given arguments More... | |
hash< ColumnOperatorInfo > | SqlUtil::cop_ntile (int value) |
Analytic/window function: integer ranging from 1 to the argument value, dividing the partition as equally as possible. More... | |
hash< ColumnOperatorInfo > | SqlUtil::cop_over (auto column, *string partitionby, *string orderby) |
returns a ColumnOperatorInfo hash for the "over" clause More... | |
hash< ColumnOperatorInfo > | SqlUtil::cop_percent_rank () |
Analytic/window function: relative rank of the current row. More... | |
hash< ColumnOperatorInfo > | SqlUtil::cop_plus (auto column1, auto column2) |
returns a ColumnOperatorInfo hash for the "+" operator with the given arguments More... | |
hash< ColumnOperatorInfo > | SqlUtil::cop_prepend (auto column, string arg) |
returns a ColumnOperatorInfo hash for the "prepend" operator with the given argument More... | |
hash< ColumnOperatorInfo > | SqlUtil::cop_rank () |
Analytic/window function: rank of the current row with gaps. More... | |
hash< ColumnOperatorInfo > | SqlUtil::cop_row_number () |
Analytic/window function: number of the current row within its partition, counting from 1. More... | |
hash< ColumnOperatorInfo > | SqlUtil::cop_seq (string seq, *string as) |
returns a ColumnOperatorInfo hash for the "seq" operator with the given argument giving the sequence name whose value should be returned More... | |
hash< ColumnOperatorInfo > | SqlUtil::cop_seq_currval (string seq, *string as) |
returns a ColumnOperatorInfo hash for the "seq_currval" operator with the given argument giving the sequence name whose current value should be returned More... | |
hash< ColumnOperatorInfo > | SqlUtil::cop_substr (auto column, int start, *int count) |
returns a ColumnOperatorInfo hash for the "substr" operator with the given arguments; returns a substring of a column value More... | |
hash< ColumnOperatorInfo > | SqlUtil::cop_sum (auto column) |
returns a ColumnOperatorInfo hash for the "sum" operator; returns the total sum of a numeric column. More... | |
hash< ColumnOperatorInfo > | SqlUtil::cop_trunc_date (auto column, string mask) |
Truncates a date column or value regarding the given mask. The resulting value remains Qore::date (no conversion to eg. string) More... | |
hash< ColumnOperatorInfo > | SqlUtil::cop_upper (auto column) |
returns a ColumnOperatorInfo hash for the "upper" operator with the given argument; returns a column value in upper case More... | |
hash< ColumnOperatorInfo > | SqlUtil::cop_value (auto arg) |
returns a ColumnOperatorInfo hash for the "value" (literal) operator with the given argument More... | |
hash< ColumnOperatorInfo > | SqlUtil::cop_year (auto column) |
returns a ColumnOperatorInfo hash for the "year" operator with the given argument More... | |
hash< ColumnOperatorInfo > | SqlUtil::cop_year_day (auto column) |
returns a ColumnOperatorInfo hash for the "year_day" operator with the given argument More... | |
hash< ColumnOperatorInfo > | SqlUtil::cop_year_hour (auto column) |
returns a ColumnOperatorInfo hash for the "year_hour" operator with the given argument More... | |
hash< ColumnOperatorInfo > | SqlUtil::cop_year_month (auto column) |
returns a ColumnOperatorInfo hash for the "year_month" operator with the given argument More... | |
hash< ColumnOperatorInfo > | SqlUtil::make_cop (string cop, auto column, auto arg) |
returns a ColumnOperatorInfo hash More... | |
These are functions that can be used in the "columns"
argument for select statements:
DISTINCT
to the column name"over"
operator for windowing functionsColumn operator functions can be nested as in the following example:
hash<ColumnOperatorInfo> SqlUtil::cop_append | ( | auto | column, |
string | arg | ||
) |
returns a ColumnOperatorInfo hash for the "append"
operator with the given argument
column | the column specification for the column (string name or dot notation for use in joins) |
arg | the text to append (ie concatenate) to the row values in the output column |
hash<ColumnOperatorInfo> SqlUtil::cop_as | ( | auto | column, |
string | arg | ||
) |
returns a ColumnOperatorInfo hash for the "as"
operator with the given argument
column | the column specification for the column (string name or dot notation for use in joins) or any other column "cop_..." function |
arg | the new name of the output column |
hash<ColumnOperatorInfo> SqlUtil::cop_avg | ( | auto | column | ) |
returns a ColumnOperatorInfo hash for the "avg"
operator; returns average column values
column | the column specification for the column (string name or dot notation for use in joins) |
hash<ColumnOperatorInfo> SqlUtil::cop_cast | ( | auto | column, |
string | arg, | ||
auto | arg1, | ||
auto | arg2 | ||
) |
returns a ColumnOperatorInfo hash for the "cast"
operator with the given argument(s)
column | the column specification for the column (string name or dot notation for use in joins) or any other column "cop_..." function |
arg | the new datatype to cast the column value(s) to |
arg1 | optional, type dependent, specification (e.g. size or precision) |
arg2 | optional, type dependent, specification (e.g. scale) |
hash<ColumnOperatorInfo> SqlUtil::cop_coalesce | ( | auto | col1, |
auto | col2 | ||
) |
returns a ColumnOperatorInfo hash for the "coalesce"
operator with the given column arguments; the first non-NULL column value will be returned
col1 | the name or column operator hash for the first value |
col2 | the name or column operator hash for the second value, additional values should follow this argument |
COALESCE-ERROR | the arguments must be either string column designators or column operator hashes |
hash<ColumnOperatorInfo> SqlUtil::cop_count | ( | auto | column = '' | ) |
returns a ColumnOperatorInfo hash for the "count"
operator; returns row counts
hash<ColumnOperatorInfo> SqlUtil::cop_cume_dist | ( | ) |
Analytic/window function: relative rank of the current row.
Analytic/window function. Must be used with cop_over() with partitionby
and orderby
arguments
hash<ColumnOperatorInfo> SqlUtil::cop_dense_rank | ( | ) |
Analytic/window function: rank of the current row without gaps.
Analytic/window function. Must be used with cop_over() with partitionby
and orderby
arguments
hash<ColumnOperatorInfo> SqlUtil::cop_distinct | ( | auto | column | ) |
returns a ColumnOperatorInfo hash for the "distinct"
operator with the given argument; returns distinct column values
column | the column specification for the column (string name or dot notation for use in joins) |
hash<ColumnOperatorInfo> SqlUtil::cop_divide | ( | auto | column1, |
auto | column2 | ||
) |
returns a ColumnOperatorInfo hash for the "/"
operator with the given arguments
column1 | the column specification for the first argument (string name or dot notation for use in joins) |
column2 | the column specification for the second argument (string name or dot notation for use in joins) |
hash<ColumnOperatorInfo> SqlUtil::cop_first_value | ( | any | column | ) |
Analytic/window function: value evaluated at the row that is the first row of the window frame.
Analytic/window function. Must be used with cop_over() with partitionby
and orderby
arguments
hash<ColumnOperatorInfo> SqlUtil::cop_last_value | ( | any | column | ) |
Analytic/window function: value evaluated at the row that is the last row of the window frame.
Analytic/window function. Must be used with cop_over() with partitionby
and orderby
arguments
hash<ColumnOperatorInfo> SqlUtil::cop_length | ( | auto | column | ) |
returns a ColumnOperatorInfo hash for the "len"
operator with the given argument; returns the length of the given text field
column | the column specification for the column (string name or dot notation for use in joins) |
hash<ColumnOperatorInfo> SqlUtil::cop_lower | ( | auto | column | ) |
returns a ColumnOperatorInfo hash for the "lower"
operator with the given argument; returns a column value in lower case
column | the column specification for the column (string name or dot notation for use in joins) |
hash<ColumnOperatorInfo> SqlUtil::cop_max | ( | auto | column | ) |
returns a ColumnOperatorInfo hash for the "max"
operator; returns maximum column values
column | the column specification for the column (string name or dot notation for use in joins) |
hash<ColumnOperatorInfo> SqlUtil::cop_min | ( | auto | column | ) |
returns a ColumnOperatorInfo hash for the "min"
operator; returns minimum column values
column | the column specification for the column (string name or dot notation for use in joins) |
hash<ColumnOperatorInfo> SqlUtil::cop_minus | ( | auto | column1, |
auto | column2 | ||
) |
returns a ColumnOperatorInfo hash for the "-"
operator with the given arguments
column1 | the column specification for the first argument (string name or dot notation for use in joins) |
column2 | the column specification for the second argument (string name or dot notation for use in joins) |
hash<ColumnOperatorInfo> SqlUtil::cop_multiply | ( | auto | column1, |
auto | column2 | ||
) |
returns a ColumnOperatorInfo hash for the "*"
operator with the given arguments
column1 | the column specification for the first argument (string name or dot notation for use in joins) |
column2 | the column specification for the second argument (string name or dot notation for use in joins) |
hash<ColumnOperatorInfo> SqlUtil::cop_ntile | ( | int | value | ) |
Analytic/window function: integer ranging from 1 to the argument value, dividing the partition as equally as possible.
Analytic/window function. Must be used with cop_over() with partitionby
and orderby
arguments
value | an integer value used as count of sp;it buckets |
hash<ColumnOperatorInfo> SqlUtil::cop_over | ( | auto | column, |
*string | partitionby, | ||
*string | orderby | ||
) |
returns a ColumnOperatorInfo hash for the "over"
clause
hash<ColumnOperatorInfo> SqlUtil::cop_percent_rank | ( | ) |
Analytic/window function: relative rank of the current row.
Analytic/window function. Must be used with cop_over() with partitionby
and orderby
arguments
hash<ColumnOperatorInfo> SqlUtil::cop_plus | ( | auto | column1, |
auto | column2 | ||
) |
returns a ColumnOperatorInfo hash for the "+"
operator with the given arguments
column1 | the column specification for the first argument (string name or dot notation for use in joins) |
column2 | the column specification for the second argument (string name or dot notation for use in joins) |
hash<ColumnOperatorInfo> SqlUtil::cop_prepend | ( | auto | column, |
string | arg | ||
) |
returns a ColumnOperatorInfo hash for the "prepend"
operator with the given argument
column | the column specification for the column (string name or dot notation for use in joins) |
arg | the text to prepend to the row values in the output column |
hash<ColumnOperatorInfo> SqlUtil::cop_rank | ( | ) |
Analytic/window function: rank of the current row with gaps.
Analytic/window function. Must be used with cop_over() with partitionby
and orderby
arguments
hash<ColumnOperatorInfo> SqlUtil::cop_row_number | ( | ) |
Analytic/window function: number of the current row within its partition, counting from 1.
Analytic/window function. Must be used with cop_over() with partitionby
and orderby
arguments
hash<ColumnOperatorInfo> SqlUtil::cop_seq | ( | string | seq, |
*string | as | ||
) |
returns a ColumnOperatorInfo hash for the "seq"
operator with the given argument giving the sequence name whose value should be returned
seq | the name of the sequence whose value should be returned |
as | an optional column name that should be returned for the sequence value (so that SqlUtil::cop_as() need not be used) |
hash<ColumnOperatorInfo> SqlUtil::cop_seq_currval | ( | string | seq, |
*string | as | ||
) |
returns a ColumnOperatorInfo hash for the "seq_currval"
operator with the given argument giving the sequence name whose current value should be returned
seq | the name of the sequence whose current value should be returned |
as | an optional column name that should be returned for the sequence value (so that SqlUtil::cop_as() need not be used) |
hash<ColumnOperatorInfo> SqlUtil::cop_substr | ( | auto | column, |
int | start, | ||
*int | count | ||
) |
returns a ColumnOperatorInfo hash for the "substr"
operator with the given arguments; returns a substring of a column value
column | the column specification for the column (string name or dot notation for use in joins) |
start | position where the substring starts |
count | length of the substring in characters |
hash<ColumnOperatorInfo> SqlUtil::cop_sum | ( | auto | column | ) |
returns a ColumnOperatorInfo hash for the "sum"
operator; returns the total sum of a numeric column.
column | the column specification for the column (string name or dot notation for use in joins) |
hash<ColumnOperatorInfo> SqlUtil::cop_trunc_date | ( | auto | column, |
string | mask | ||
) |
Truncates a date column or value regarding the given mask. The resulting value remains Qore::date (no conversion to eg. string)
column | the column specification for the column (string name or dot notation for use in joins) |
mask | the string with one of specified values rederenced in cop_trunc_date formats |
hash<ColumnOperatorInfo> SqlUtil::cop_upper | ( | auto | column | ) |
returns a ColumnOperatorInfo hash for the "upper"
operator with the given argument; returns a column value in upper case
column | the column specification for the column (string name or dot notation for use in joins) |
hash<ColumnOperatorInfo> SqlUtil::cop_value | ( | auto | arg | ) |
returns a ColumnOperatorInfo hash for the "value"
(literal) operator with the given argument
arg | the value to be returned in the column |
SQL literals can be useful in some cases - as dummy values for select statements where there is exact columns required, unions, expected values for arc.insertFromIterator
(src.getStatement(sh)) "insert as select", etc.
The term literal refers to a fixed data value. For example, 123, 'foobar' etc.
Mapping of Qore values to literals:
Qore Type | SQL Type | Qore Example | SQL interpretation |
Integer | NUMBER as it is | 123 | 123 |
Float | NUMBER as it is | 12.3 | 12.3 |
Numeric | NUMBER as it is | 1.2n | 1.2 |
Date | String representation of the date using DB native implementation like TO_TIMESTAMP for Oracle. | now() | to_timestamp ('20150421104825000000', 'YYYYMMDDHH24MISSFF6') |
Bool | Internal representation of the bool value using DB native implementation | True | 1 |
String | Standard and escaped string literal. No additional literal methods like Oracle's nq{foobar} are supported now | "foo bar" | 'foo bar' |
NULL | Direct null literal | NULL | null |
NOTHING | Direct null literal | NOTHING | null |
The most useful SqlUtil::cop_value() usage is with cooperation of SqlUtil::cop_as() which allows human readable column name aliases.
cop_value(1), cop_value(True)
ends with ORA-00918: column ambiguously defined
because both values are interpreted as 1 in the resulting SQL.Example
hash<ColumnOperatorInfo> SqlUtil::cop_year | ( | auto | column | ) |
returns a ColumnOperatorInfo hash for the "year"
operator with the given argument
column | the column specification for the column (string name or dot notation for use in joins) |
hash<ColumnOperatorInfo> SqlUtil::cop_year_day | ( | auto | column | ) |
returns a ColumnOperatorInfo hash for the "year_day"
operator with the given argument
column | the column specification for the column (string name or dot notation for use in joins) |
hash<ColumnOperatorInfo> SqlUtil::cop_year_hour | ( | auto | column | ) |
returns a ColumnOperatorInfo hash for the "year_hour"
operator with the given argument
column | the column specification for the column (string name or dot notation for use in joins) |
hash<ColumnOperatorInfo> SqlUtil::cop_year_month | ( | auto | column | ) |
returns a ColumnOperatorInfo hash for the "year_month"
operator with the given argument
column | the column specification for the column (string name or dot notation for use in joins) |
hash<ColumnOperatorInfo> SqlUtil::make_cop | ( | string | cop, |
auto | column, | ||
auto | arg | ||
) |
returns a ColumnOperatorInfo hash
cop | the column operator (one of SQL Column Operators) |
column | the column name |
arg | the argument to the operator |