Type | Read/write | Author | Availability |
Write | Finbourne | Provided with LUSID |
The Lusid.Property.Definition.Writer
provider enables you to write a Luminesce SQL query that creates, updates, or deletes one or more property types or derived property types.
Note: The LUSID user running the query must have sufficient access control permissions to both use the provider and interact with property 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 property type per record. Lusid.Property.Definition.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 property type; that is, create a property type if it does not exist, and update certain fields if it does. This is the default operation if you omit
WriteAction
.Insert (create) a property type. This operation fails if the property type already exists.
Update a property type. Note it is only possible to update the
DisplayName
andDescription
fields. This operation fails if the property type does not already exist.Delete a property type.
See also: Lusid.Property.Definition
Basic usage
@table_of_data = <select-statement>;
select * from Lusid.Property.Definition.Writer where toWrite = @table_of_data;
Query parameters
Lusid.Property.Definition.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.Property.Definition.Writer' and FieldType = 'Parameter';
Data fields
Lusid.Property.Definition.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 | For standard property types:
|
Update |
|
Delete |
|
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.Property.Definition.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.Property.Definition.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 'Instrument' as Domain, 'Finbourne-Examples' as PropertyScope, 'ShareClass' as PropertyCode;
select WriteErrorCode, WriteError, WriteErrorDetail from Lusid.Property.Definition.Writer where toWrite = @table_of_data;
... fails because a DisplayName
is not specified.
Examples
Note: For more example Luminesce SQL queries, visit our Github repo.
Example 1: Create a property type
You can create a property type, such as SIC Code in the Instrument domain, by supplying all mandatory fields and by using 'insert' as WriteAction
.
@table_of_data = select 'Instrument' as Domain, 'Finbourne-Examples' as PropertyScope, 'system' as DataTypeScope,
'string' as DataTypeCode, 'property' as ConstraintStyle, 'SICCode' as PropertyCode, 'SIC Code' as DisplayName, 'insert' as WriteAction;
select * from Lusid.Property.Definition.Writer where ToWrite = @table_of_data;
Example 2: Update a property type with additional details
You can update an existing property type, such as adding a description to the SIC Code property type, by supplying the fields comprising the 3-stage key, the fields you want to update, and by using 'update' as WriteAction
.
@table_of_data = select 'Instrument' as Domain, 'Finbourne-Examples' as PropertyScope, 'SICCode' as PropertyCode,
'SIC Code' as DisplayName, 'The industry classification code for the security' as Description, 'update' as WriteAction;
select * from Lusid.Property.Definition.Writer where ToWrite = @table_of_data;
Example 3: Delete an existing property type
You can delete an existing property type by supplying the fields comprising the 3-stage key and by using 'delete' as WriteAction
.
@table_of_data = select 'Instrument' as Domain, 'Finbourne-Examples' as PropertyScope, 'SICCode' as PropertyCode, 'delete' as WriteAction;
select * from Lusid.Property.Definition.Writer where ToWrite = @table_of_data;
Example 4: Create multiple property types at the same time
You can create all your property types at the same time in one Luminesce query. In this example, the query defaults to the 'Upsert' action as no explicit WriteAction
is specified.
@vals = values
('ShareClass', 'Share Class'),
('MarketType', 'Market Type'),
('GICSSector', 'GICS Sector'),
('Rating', 'Rating');
@table_of_data = select 'Instrument' as Domain, 'Finbourne-Examples' as PropertyScope, 'Property' as ConstraintStyle,
'system' as DataTypeScope,'string' as DataTypeCode, column1 as PropertyCode, column2 as DisplayName from @vals;
select * from Lusid.Property.Definition.Writer where ToWrite = @table_of_data;
Example 5: Create a derived property type
You can create a derived property type with a derivation formula that, in this example, concatenates a SICCode with the text "-derived" using the DerivationFormula
field.
@table_of_data = select 'Instrument' as Domain, 'Finbourne-Examples' as PropertyScope, 'inst-derived-prop' as PropertyCode,
'Test Instrument Derived Property' as DisplayName, 'system' as DataTypeScope, 'string' as DataTypeCode,
'Concat(Properties[Instrument/Finbourne-Examples/SICCode], ''-derived'')' as DerivationFormula;
select * from Lusid.Property.Definition.Writer where ToWrite = @table_of_data;