Lusid.DataType.Writer

Type

Read/write

Author

Availability

Data provider

Write

Finbourne

Provided with LUSID

Providing you have sufficient access control permissions, the Lusid.DataType.Writer provider enables you to write a Luminesce SQL query that creates or updates data types.

Note

The LUSID user running the query must have sufficient access control permissions to both use the provider and interact with data types 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 data type type per record. Lusid.DataType.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:

  • Insert (create) a data type. This operation fails if the data type already exists. This is the default operation if you omit WriteAction.

  • Update a data type. Note it is possible to update all fields except the Scope and Code fields. This operation fails if the data type does not already exist.

See also: Lusid.DataType

Basic usage

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

Query parameters

Lusid.DataType.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.DataType.Writer' and FieldType = 'Parameter';

Data fields

Lusid.DataType.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

Create

Scope

Code

DisplayName

ValueType

TypeValueRange

UnitSchema

Update

Scope

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.DataType.Writer' and FieldType = 'Column';

Write errors

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

For each record in the table of data to write, Lusid.DataType.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 'Finbourne-Examples' as Scope, 'My new data type' as DisplayName;
select WriteErrorCode, WriteError, WriteErrorDetail from Lusid.DataType.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 data type

You can create a data type in your LUSID domain by supplying all mandatory fields and using 'insert' as WriteAction.

@table_of_data = select 'Finbourne-Examples' as Scope, 'my_new_dataType' as Code, 'My new data type' as DisplayName, 'String' as ValueType,
'Closed' as TypeValueRange, 'NoUnits' as UnitSchema, 'A, B, C, D, E, F' as AcceptableValues, 'insert' as WriteAction;

select * from Lusid.DataType.Writer where ToWrite = @table_of_data;

Example 2: Update a data type with additional details

You can update an existing data type by supplying the mandatory and existing fields, the fields you want to update, and by using 'update' as WriteAction.

Note

Fields not supplied are set to null. You should therefore ensure your table of data includes any existing fields and their values.

@table_of_data = select 'Finbourne-Examples' as Scope, 'my_new_dataType' as Code, 'My new data type' as DisplayName, 'String' as ValueType,
'Closed' as TypeValueRange, 'NoUnits' as UnitSchema, 'A, B, C, D, E, F' as AcceptableValues, 
'This data type only accepts letter values.' as Description, 'update' as WriteAction;

select * from Lusid.DataType.Writer where ToWrite = @table_of_data;

Example 3: Create multiple data types at the same time

You can create all your data types at the same time in one Luminesce query. In this example, the query defaults to a create operation as no explicit WriteAction is specified.

@vals = values
('assignedTeam', 'Team Assigned', 'String', 'Closed', 'Team 1, Team 2, Team 3, Team 4'),
('dataType2', 'Reference Data Type 1', 'Decimal', 'Open', null),
('approvalStatus', 'Approval Status', 'String', 'Closed', 'Pending, Confirmed, Rejected');

@table_of_data = select  'Finbourne-Examples' as Scope, column1 as Code, column2 as DisplayName,
column3 as ValueType, column4 as TypeValueRange, 'NoUnits' as UnitSchema, column5 as AcceptableValues from @vals;

select * from Lusid.DataType.Writer where ToWrite = @table_of_data;

Example 4: Create a data type and store reference data

You can use the FieldDefinitionIsUnique, FieldDefinitionIsRequired, FieldDefinitionKey, ReferenceDataValue, ReferenceDataFieldKey and ReferenceDataFieldValue to store additional reference data against the set of allowed values for a data type.

In this example, we create a naceCode data type that simultaneously constrains the user to only entering recognised NACE codes, and additionally stores the full activity definition for each code. This means you don’t have to create additional properties to store this information. Read more.

@toWriteValues = values 
(false, true, 'description','A', 'description', 'Agriculture, forestry and fishing'),
(false, true, 'sectionCode', 'A', 'sectionCode', 'A'),
(false, true, 'sectionDescription', 'A', 'sectionDescription', 'Agriculture, forestry and fishing'),

(null, null, null, '01', 'description', 'Crop and animal production, hunting and related service activities'),
(null, null, null, '01', 'sectionCode', 'A'),
(null, null, null, '01', 'sectionDescription', 'Agriculture, forestry and fishing'),
(false, false, 'divisionCode', '01', 'divisionCode', '01'),
(false, false, 'divisionDescription', '01', 'divisionDescription', 'Crop and animal production, hunting and related service activities'),

(null, null, null, '011', 'description', 'Growing of non-perennial crops'),
(null, null, null, '011', 'sectionCode', 'A'),
(null, null, null, '011', 'sectionDescription', 'Agriculture, forestry and fishing'),
(null, null, null, '011', 'divisionCode', '01'),
(null, null, null, '011', 'divisionDescription', 'Crop and animal production, hunting and related service activities'),
(false, false, 'groupCode', '011', 'groupCode', '011'),
(false, false, 'groupDescription', '011', 'groupDescription', 'Growing of non-perennial crops'),

(null, null, null, '0111', 'description', 'Growing of cereals (except rice), leguminous crops and oil seeds'),
(null, null, null, '0111', 'sectionCode', 'A'),
(null, null, null, '0111', 'sectionDescription', 'Agriculture, forestry and fishing'),
(null, null, null, '0111', 'divisionCode', '01'),
(null, null, null, '0111', 'divisionDescription', 'Crop and animal production, hunting and related service activities'),
(null, null, null, '0111', 'groupCode', '011'),
(null, null, null, '0111', 'groupDescription', 'Growing of non-perennial crops'),
(true, false, 'classCode', '0111', 'classCode', '0111'),
(true, false, 'classDescription', '0111', 'classDescription', 'Growing of cereals (except rice), leguminous crops and oil seeds'),

(null, null, null, '0112', 'description', 'Growing of rice'),
(null, null, null, '0112', 'sectionCode', 'A'),
(null, null, null, '0112', 'sectionDescription', 'Agriculture, forestry and fishing'),
(null, null, null, '0112', 'divisionCode', '01'),
(null, null, null, '0112', 'divisionDescription', 'Crop and animal production, hunting and related service activities'),
(null, null, null, '0112', 'groupCode', '011'),
(null, null, null, '0112', 'groupDescription', 'Growing of non-perennial crops'),
(null, null, null, '0112', 'classCode', '0112'),
(null, null, null, '0112', 'classDescription', 'Growing of rice');


@toWrite =
select
    'industry' as scope,
    'naceCode' as code,
    'NACE Code' as displayName,
    'Statistical classification of economic activities in the European Community' as description,
    'String' as valueType,
    'Closed' as TypeValueRange,
    'NoUnits' as unitSchema,
    column1 as FieldDefinitionIsUnique,
    column2 as FieldDefinitionIsRequired,
    column3 as FieldDefinitionKey,
    column4 as ReferenceDataValue,
    column5 as ReferenceDataFieldKey,
    column6 as ReferenceDataFieldValue,
    'create' as writeAction
from @toWriteValues;

select * from Lusid.DataType.Writer where ToWrite = @toWrite;

The first ten rows of the table of data returned by the query looks like this, with the AcceptableValues column populated based on the values we supplied for ReferenceDataValue: