Kexi/Plugins/Queries/SQL Functions: Difference between revisions

From KDE Community Wiki
< Kexi‎ | Plugins‎ | Queries
Line 494: Line 494:
*[http://dev.mysql.com/doc/refman/5.0/en/compatibility.html MySQL Standards Compliance]
*[http://dev.mysql.com/doc/refman/5.0/en/compatibility.html MySQL Standards Compliance]
*[http://www.contrib.andrew.cmu.edu/~shadow/sql/sql1992.txt sql-92 standard]
*[http://www.contrib.andrew.cmu.edu/~shadow/sql/sql1992.txt sql-92 standard]
*[https://wiki.postgresql.org/wiki/Things_to_find_out_about_when_moving_from_MySQL_to_PostgreSQL Things to find out about when moving from MySQL to PostgreSQL]
*[http://troels.arvin.dk/db/rdbms Comparison of different SQL implementations]

Revision as of 21:32, 2 September 2015

This page lists SQL functions that Kexi supports or wants to support. Aggregate functions are included. Support in particular SQL backends is compared (SQLite, PostgreSQL, MySQL). For practical reasons emphasis is put on concrete implementation instead of focusing on an SQL standard.

Note

This is work in progress. You can contribute to this page or request updates.


TODO: Model sections after pgsql, which probably has one of the larger feature set: [1]

Sections TODO:

  • Logical Operators
  • Comparison Operators
  • Mathematical Functions and Operators
  • String Functions and Operators
  • Binary String Functions and Operators
  • Bit String Functions and Operators
  • Pattern Matching
  • Data Type Formatting Functions
  • Conditional Expressions
  • Subquery Expressions
  • Row and Array Comparisons
  • System Information Functions

Functions

TODO: taken from sqlite, split to categories


Name Description sqlite pgsql mysql mssql xbase
abs(X) DONE 2.9.7 DONE 2.9.7 DONE 2.9.7
char(X1,X2,...,XN) DONE 2.9.7
coalesce(X,Y,...) DONE 2.9.7 DONE 2.9.7 DONE 2.9.7
ifnull(X,Y) DONE 2.9.7 DONE 2.9.7, use coalesce() DONE 2.9.7
instr(X,Y) DONE 2.9.7 TODO use CREATE FUNCTION [2] DONE 2.9.7
hex(X) DONE 2.9.7 DONE 2.9.7 using ENCODE(v, 'hex') DONE 2.9.7
length(X) DONE 2.9.7 DONE 2.9.7, for BLOBs octet_length() is used because length() for BLOB returns number of bits DONE 2.9.7, char_length() is used because length() in mysql returns number of bytes, what is not right for multibyte (unicode) encodings
lower(X)
ltrim(X)
ltrim(X,Y)
max(X,Y,...)
min(X,Y,...)
nullif(X,Y)
random()
replace(X,Y,Z)
round(X)
round(X,Y)
rtrim(X)
rtrim(X,Y)
soundex(X)
substr(X,Y,Z) DONE 2.9.1 DONE 2.9.1 DONE 2.9.1
substr(X,Y) DONE 2.9.1 DONE 2.9.1 DONE 2.9.1
trim(X)
trim(X,Y)
typeof(X)
unicode(X)
upper(X)

Date And Time Functions


Name Description sqlite pgsql mysql mssql xbase
date(timestring, modifier, modifier, ...)
time(timestring, modifier, modifier, ...)
datetime(timestring, modifier, modifier, ...)
julianday(timestring, modifier, modifier, ...)
strftime(format, timestring, modifier, modifier, ...)

Aggregate functions


Name Description sqlite pgsql mysql mssql xbase
avg(X)
count(X)
count(*)
group_concat(X)
group_concat(X,Y)
max(X)
min(X)
sum(X)
total(X)

SQLite-specific Functions


Name Description sqlite pgsql mysql mssql xbase
changes() Returns the number of database rows that were changed or inserted or deleted by the most recently completed INSERT, DELETE, or UPDATE statement, exclusive of statements in lower-level triggers. The changes() SQL function is a wrapper around the sqlite3_changes() C/C++ function and hence follows the same rules for counting changes.
last_insert_rowid() Returns the ROWID of the last row insert from the database connection which invoked the function. The last_insert_rowid() SQL function is a wrapper around the sqlite3_last_insert_rowid() C/C++ interface function.
glob(X,Y) The glob(X,Y) function is equivalent to the expression "Y GLOB X". Note that the X and Y arguments are reversed in the glob() function relative to the infix GLOB operator. DONE 2.9.7 but ifdef'd won't add; and even GLOB operator missing
like(X,Y), like(X,Y,Z) The like() function is used to implement the "Y LIKE X [ESCAPE Z]" expression. If the optional ESCAPE clause is present, then the like() function is invoked with three arguments. Otherwise, it is invoked with two arguments only. Note that the X and Y parameters are reversed in the like() function relative to the infix LIKE operator. DONE 2.9.7 but ifdef'd won't add: use LIKE operator instead
likelihood(X,Y) Returns argument X unchanged. The value Y in likelihood(X,Y) must be a floating point constant between 0.0 and 1.0, inclusive. The likelihood(X) function is a no-op that the code generator optimizes away so that it consumes no CPU cycles during run-time (that is, during calls to sqlite3_step()). The purpose of the likelihood(X,Y) function is to provide a hint to the query planner that the argument X is a boolean that is true with a probability of approximately Y. The unlikely(X) function is short-hand for likelihood(X,0.0625). The likely(X) function is short-hand for likelihood(X,0.9375).
likely(X) Returns the argument X unchanged. The likely(X) function is a no-op that the code generator optimizes away so that it consumes no CPU cycles at run-time (that is, during calls to sqlite3_step()). The purpose of the likely(X) function is to provide a hint to the query planner that the argument X is a boolean value that is usually true. The likely(X) function is equivalent to likelihood(X,0.9375). See also: unlikely(X).
load_extension(X)
load_ extension(X,Y)
Loads SQLite extensions out of the shared library file named X using the entry point Y. The result of load_extension() is always a NULL. If Y is omitted then the default entry point name is used. The load_extension() function raises an exception if the extension fails to load or initialize correctly.
The load_extension() function will fail if the extension attempts to modify or delete an SQL function or collating sequence. The extension can add new functions or collating sequences, but cannot modify or delete existing functions or collating sequences because those functions and/or collating sequences might be used elsewhere in the currently running SQL statement. To load an extension that changes or deletes functions or collating sequences, use the sqlite3_load_extension() C-language API.
For security reasons, extension loaded is turned off by default and must be enabled by a prior call to sqlite3_enable_load_extension().
printf(FORMAT,...) Works like the sqlite3_mprintf() C-language function and the printf() function from the standard C library. The first argument is a format string that specifies how to construct the output string using values taken from subsequent arguments. If the FORMAT argument is missing or NULL then the result is NULL. The %n format is silently ignored and does not consume an argument. The %p format is an alias for %X. The %z format is interchangeable with %s. If there are too few arguments in the argument list, missing arguments are assumed to have a NULL value, which is translated into 0 or 0.0 for numeric formats or an empty string for %s.
quote(X) Returns the text of an SQL literal which is the value of its argument suitable for inclusion into an SQL statement. Strings are surrounded by single-quotes with escapes on interior quotes as needed. BLOBs are encoded as hexadecimal literals. Strings with embedded NUL characters cannot be represented as string literals in SQL and hence the returned string literal is truncated prior to the first NUL.
randomblob(N) Returns an N-byte blob containing pseudo-random bytes. If N is less than 1 then a 1-byte random blob is returned.
Hint: applications can generate globally unique identifiers using this function together with hex() and/or lower() like this:
hex(randomblob(16))
lower(hex(randomblob(16)))
sqlite_ compileoption_ get(N) A wrapper around the sqlite3_compileoption_get() C/C++ function. This routine returns the N-th compile-time option used to build SQLite or NULL if N is out of range. See also the compile_options pragma.
sqlite_ compileoption_ used(X) A wrapper around the sqlite3_compileoption_used() C/C++ function. When the argument X to sqlite_compileoption_used(X) is a string which is the name of a compile-time option, this routine returns true (1) or false (0) depending on whether or not that option was used during the build.
sqlite_ source_id() Returns a string that identifies the specific version of the source code that was used to build the SQLite library. The string returned by sqlite_source_id() begins with the date and time that the source code was checked in and is follows by an SHA1 hash that uniquely identifies the source tree. This function is an SQL wrapper around the sqlite3_sourceid() C interface.
sqlite_version() Returns the version string for the SQLite library that is running. This function is an SQL wrapper around the sqlite3_libversion() C-interface.
total_changes() Returns the number of row changes caused by INSERT, UPDATE or DELETE statements since the current database connection was opened. This function is a wrapper around the sqlite3_total_changes() C/C++ interface.
unlikely(X) Returns the argument X unchanged. The unlikely(X) function is a no-op that the code generator optimizes away so that it consumes no CPU cycles at run-time (that is, during calls to sqlite3_step()). The purpose of the unlikely(X) function is to provide a hint to the query planner that the argument X is a boolean value that is usually not true. The unlikely(X) function is equivalent to likelihood(X, 0.0625).
zeroblob(N) Returns a BLOB consisting of N bytes of 0x00. SQLite manages these zeroblobs very efficiently. Zeroblobs can be used to reserve space for a BLOB that is later written using incremental BLOB I/O. This SQL function is implemented using the sqlite3_result_zeroblob() routine from the C/C++ interface.

Further work

Add comparison for other backends: Sybase/MSSQL, xBase.

Links