Note a query can be written either for a data provider or a direct provider, and there are some syntactical differences between them. In particular, direct providers have an arbitrary syntax that may differ for each.
Luminesce supports most of the syntax of the SQLite SELECT statement. It does not support data definition language (DDL) syntax for creating or modifying database objects.
- Common table expressions (CTE) are not supported in Luminesce SELECT statements but a re-usable variable syntax is available instead.
- TYPES statements can be used before Luminesce SELECT statements to force type conversion on columns.
- FOR-EACH loops can be emulated using APPLY statements.
- A WAIT modifier is available to pause query execution.
- A number of common SQL functions are supported, and we've supplemented these with sets of custom functions and statistical functions.
- A number of PRAGMA statements specific to Luminesce are supported.
- Dates must be encapsulated in # rather than ' characters, so for example #yyyy-MM-dd HH:mm:ss#
- Strings must be encapsulated in ' rather than " characters, so for example where PortfolioScope = 'Finbourne-Examples'
- Multiple lines can be commented out using /* and */ characters at the beginning and end respectively.
|SELECT statement examples||Explanation|
|select * from Some.Provider||Selects all the columns from Some.Provider|
|select x, y from Some.Provider||Selects the X and Y columns|
|select * (except x, y) from Some.Provider||Selects all the columns except X and Y. Can use the - character in place of except|
|select ^ from Some.Provider||Selects the main columns (those considered most important by the provider author)|
|select ^ (except x, y) from Some.Provider||Selects the main columns except X and Y|
|select * from Some.Provider limit 5||Returns only the first 5 records|
For a Some.Provider that is authored by Finbourne, the fields (columns) available to return or filter can be determined by running the following query:
Data providers may have parameters that can be used to filter a Luminesce query as part of a standard WHERE clause.
Note: Direct providers do not support parameters.
You must assign values to parameters unambiguously (not under an OR clause), and only with the = operator. For example:
For a Some.Provider that is authored by Finbourne, available parameters can be determined by running the following query:
You can use variables to create and populate arbitrary tables of data that can then be used as part of a Luminesce query for either a data provider or a direct provider.
This is similar to a combination of the standard SQL CREATE TABLE...INSERT INTO statements.
|@tablevariable||Stores a table of any size||@abc = select TableName, FieldName from Sys.Field order by 1, 2;|
|@@scalarvariable||Only stores a scalar value (that is, the SELECT statement must resolve to exactly one column and one row of data)||@@abc = select strftime('%Y%m%d', 'now');
@@portfolioscope = select 'Finbourne-Examples';
You can use the TYPES statement before any SELECT statement in a Luminesce query to force type conversion on columns.
Valid types are BIGINT, INT, DOUBLE, DECIMAL, BOOLEAN, TEXT, DATE, TIME and DATETIME.
|TYPES bigint, int, text, boolean;
SELECT 1, 2, 3, 4;
|Returns columns as Int64, Int32, String and Boolean types respectively.|
|TYPES bigint, int, , boolean;
SELECT 1, 2, 3, 4;
|Returns columns 1, 2 and 4 as Int64, Int32 and Boolean types respectively. The data type of column 3 would be inferred in the normal way.|
SELECT SUM(Cost) as X FROM Products;
|Returns the result of the aggregate function as a double.|
You can use the CROSS APPLY or OUTER APPLY statement to emulate a FOR-EACH loop. This is useful to execute a Luminesce query in parallel on a range of parameter inputs.
|CROSS APPLY||Similar to INNER JOIN, in that only records that have matching values on both sides are returned.|
|OUTER APPLY||Similar to LEFT OUTER JOIN, in that all records on the left side are returned, even when there are no matching records on the right side.|
Note: There is no ON clause for either APPLY statement.
For example, the following query uses OUTER APPLY to calculate holdings for the last 3 days:
Note: You must alias all tables inside the SELECT statement of a CROSS APPLY or OUTER APPLY statement (in the example above, h is the alias for the table returned by the Lusid.Portfolio.Holding provider).
You can use the WAIT modifier at any point in a query to wait for all the preceding code to execute before continuing, and optionally for a further specified number of seconds.
For example, if you delete a view in order to change its behavior you might want to wait 5 seconds before creating it again:
You can use the PRAGMA statements in the following table to override default Luminesce settings for a particular query. For example, to allow a query to run for 30 minutes before timing out, specify at the top:
||Defines the maximum number of parallel provider calls within a CROSS APPLY or OUTER APPLY statement in a query.|
||Specifies a number of seconds to wait before a query times out.|
||Names a query.|