Lusid.CutLabel.Writer

Type

Read/write

Author

Availability

Data provider

Write

Finbourne

Provided with LUSID

The Lusid.CutLabel.Writer provider enables you to write a Luminesce SQL query that creates, updates, or deletes one or more cut labels.

Note: The LUSID user running the query must have sufficient access control permissions to both use the provider and interact with cut labels in LUSID. This should automatically be the case if you are the domain owner.

You must construct a valid table of data to write, one cut label type per record. Lusid.CutLabel.Writer lists the fields (columns) available to populate with values for each record, and has a set of parameters to help you construct a valid table.

Your query can use the WriteAction field to perform one of the following operations:

  • Upsert a cut label; that is, create a cut label if it does not exist, and update certain fields if it does. This is the default operation if you omit WriteAction.

  • Insert (create) a cut label. This operation fails if the cut label already exists.

  • Update a cut label. Note it is possible to update all fields except the Code field. This operation fails if the cut label does not already exist.

  • Delete a cut label.

See also: Lusid.CutLabel

Basic usage

@table_of_data = <select-statement>;
select * from Lusid.CutLabel.Writer where toWrite = @table_of_data;

Query parameters

Lusid.CutLabel.Writer has parameters that help you construct a valid table of data to write.

Note: The toWrite parameter is mandatory and used to actually write the table of data into LUSID.

To list available parameters, their data types, default values, and an explanation for each, run the following query using a suitable tool:

select FieldName, DataType, ParamDefaultValue, Description from Sys.Field where TableName = 'Lusid.CutLabel.Writer' and FieldType = 'Parameter';

Data fields

Lusid.CutLabel.Writer lists the fields you can populate in your table of data to write.

Depending on the operation you want to perform, the following fields are mandatory to include in the table of data:

Operation

Mandatory fields

Upsert, Insert, Update

Code

DisplayName

TimeZone

Delete

Code

To list all available fields, their data types, whether fields are considered 'main', and an explanation for each, run the following query using a suitable tool:

select FieldName, DataType, IsMain, IsPrimaryKey, SampleValues, Description from Sys.Field where TableName = 'Lusid.CutLabel.Writer' and FieldType = 'Column';

Write errors

We recommend examining the results of every write query using one or more of the WriteErrorWriteErrorCode and WriteErrorDetail fields.

For each record in the table of data to write, Lusid.CutLabel.Writer returns an error code. If the operation is successful, the error code is 0. If unsuccessful, a positive error code and explanation help you discover why LUSID considers the operation invalid.  

For example, the query:

@table_of_data = select 'LSE_Close' as DisplayName, 16 as CutLocalTimeHours, 30 as CutLocalTimeMinutes,'Europe/London' as TimeZone;
select WriteErrorCode, WriteError, WriteErrorDetail from Lusid.CutLabel.Writer where toWrite = @table_of_data;

... fails because a Code is not specified.

Examples

Note: For more example Luminesce SQL queries, visit our Github repo.

Example 1: Create a cut label

You can create a cut label, such as New York Stock Exchange (NYSE) open, in your LUSID domain by supplying all mandatory fields and using 'insert' as WriteAction.

@table_of_data = select 'NYSE_open' as Code, 'New York Stock Exchange open' as DisplayName, 'America/New_York' as TimeZone, 'insert' as WriteAction;
select * from Lusid.CutLabel.Writer where ToWrite = @table_of_data;

Example 2: Update a cut label with additional details

You can update an existing cut label, such as adding an opening time to the NYSE open cut label, by supplying the mandatory fields, the fields you want to update, and by using 'update' as WriteAction.

@table_of_data = select  'NYSE_open' as Code, 9 as CutLocalTimeHours, 30 as CutLocalTimeMinutes, 'New York Stock Exchange open' as DisplayName, 'America/New_York' as TimeZone, 
'The opening time for the New York Stock Exchange' as Description, 'update' as WriteAction;
select * from Lusid.CutLabel.Writer where ToWrite = @table_of_data;

Example 3: Delete an existing cut label

You can delete an existing cut label by supplying the mandatory fields and using 'delete' as WriteAction.

@table_of_data = select  'NYSE_open' as Code, 'delete' as WriteAction;
select * from Lusid.CutLabel.Writer where ToWrite = @table_of_data;

Example 4: Create multiple cut labels at the same time

You can create all your cut labels at the same time in one Luminesce query. In this example, the query defaults to an upsert operation as no explicit WriteAction is specified.

@vals = values
('NYSE_close', 'NYSE close', 'America/New_York', 16, 0),
('LSE_open', 'LSE open', 'Europe/London', 8, 0),
('LSE_close', 'LSE close', 'Europe/London', 16, 30);
@table_of_data = select  column1 as Code, column2 as DisplayName, column3 as TimeZone,
column4 as CutLocalTimeHours, column5 as CutLocalTimeMinutes from @vals;
select * from Lusid.CutLabel.Writer where ToWrite = @table_of_data;