Type | Read/write | Author | Availability |
Data provider | Write | Finbourne | Provided with LUSID |
Providing you have access control permissions, you can use the Lusid.Property.Writer
property provider to write a Luminesce SQL query that upserts or deletes one or more properties to or from either:
- Portfolios
- Portfolio groups
- Instruments
- Persons
- Legal entities
Note: For transactions, use the dedicated Lusid.Portfolio.Txn.Property.Writer property provider. For other entities, configure its entity provider to 'inline' properties into the Luminesce catalog first.
You must construct a valid table of data to write, one property per record. Lusid.Property.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; that is, add a property to an entity if it doesn't exist, and update the value if it does. This is the default operation if you omit
WriteAction
. - Delete a property.
See also: Lusid.Property
Basic usage
@table_of_data = <select-statement>;
select * from Lusid.Property.Writer where toWrite = @table_of_data;
Query parameters
Lusid.Property.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.
You must identify the parent entity for each property. Note that identifiers for different entity types have different components:
Entity type | Components of identifier |
LegalEntity , Person | idTypeScope , idTypeCode , code |
Instrument | identifierType , identifierValue , scope (if not in the default scope) |
Portfolio and PortfolioGroup | scope , code |
For more information, consult this table of entities and their identifiers.
Use the following data fields in the select
statement for toWrite
to identify each property in the table of data to write unambiguously:
Data field | Status | Explanation | ||||||||
Domain | Required | The type of the parent entity. Must be a string that is one of the supported entity types, for example either Portfolio , PortfolioGroup , LegalEntity , Person or Instrument . | ||||||||
EntityScope | Required for all except Instrument . If omitted for Instrument , uses the default instrument scope. | Part of the identifier for the parent entity. The origin of this value depends on the entity type:
| ||||||||
EntityIdType | Required for LegalEntity and Person . If omitted for Instrument , defaults to LusidInstrumentId . | Part of the identifier for the parent entity. The origin of this value depends on the entity type:
| ||||||||
EntityId | Required | Part of the identifier for the parent entity. The origin of this value depends on the entity type:
| ||||||||
PropertyScope , PropertyCode | Required | The scope and code of the property, as defined by the underlying property type. | ||||||||
Value | Required if upserting | The property value. Note this is a text field, so you should supply the value as a string, for example |
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.Writer' and FieldType = 'Parameter';
Data fields
Lusid.Property.Writer
lists the fields you can populate in your table of data to write.
Note: Some of these fields are mandatory to specify in your query; see the section above.
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.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.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.
Examples
Note: For more example Luminesce SQL queries, visit our Github repo. For more information on nuances of writing different kinds of property to LUSID entities, see this article.
Example 1: Add a property to an instrument
In this example, LUSID adds a SIC code property to an instrument. The query defaults to the default
instrument scope since no EntityScope
is specified. The underlying property type has a numeric data type, so Luminesce automatically casts the (meaningful) string specified for Value
to a number.
@table_of_data = select 'LUID_00003DDE' as EntityId, 'Instrument' as Domain, 'Finbourne-Examples' as PropertyScope,
'SICCode' as PropertyCode, '7010' as Value, 'upsert' as WriteAction;
select * from Lusid.Property.Writer where ToWrite = @table_of_data;
Example 2: Add a property to a legal entity
In this example, LUSID adds a SIC code property to a legal entity with a 3-stage property key of LegalEntity/InternationalBanks/BankId
. The query specifies the second stage in the property key as the EntityScope
, the third stage in the property key as the EntityIdType
and the label value as the EntityId
.
@table_of_data = select 'LegalEntity' as Domain, 'InternationalBanks' as EntityScope, 'BankId' as EntityIdType, 'AcmeInc' as EntityId,
'Finbourne-Examples' as PropertyScope, 'SICCode' as PropertyCode, '7010' as Value, 'upsert' as WriteAction;
select * from Lusid.Property.Writer where ToWrite = @table_of_data;
Example 3: Add a time-variant property effective from a particular date
In this example, LUSID adds a time-variant property representing an address to a person entity effective from a particular date. If omitted for time-variant properties, EffectiveFrom
defaults to the current date when the query runs. Note the underlying property type must have a Lifetime
of TimeVariant
.
@table_of_data = select 'Person' as Domain, 'PortfolioManagers' as EntityScope, 'ManagerId' as EntityIdType, 'PortMan1' as EntityId,
'Finbourne-Examples' as PropertyScope, 'WorkAddress' as PropertyCode, '1 Main Street' as Value, #2022-01-01# as EffectiveFrom, 'upsert' as WriteAction;
select * from Lusid.Property.Writer where ToWrite = @table_of_data;
Example 4: Delete a property from an entity
In this example, the explicit use of 'Delete' as WriteAction
deletes a property for an instrument; you can omit the Value
.
@table_of_data = select 'LusidInstrumentId' as EntityIdType, 'LUID_00003DDE' as EntityId, 'Instrument' as Domain, 'Finbourne-Examples' as PropertyScope,
'SICCode' as PropertyCode, 'delete' as WriteAction;
select * from Lusid.Property.Writer where ToWrite = @table_of_data;
Example 5: Add a multi-value property to an entity
In this example, multiple values are specified for a portfolio property by using a comma-separated list. Note the underlying property type must have a ConstraintStyle
of Collection
.
@table_of_data = select 'Portfolio' as Domain, 'Manager' as PropertyScope, 'Name' as PropertyCode, 'Finbourne-Examples' as EntityScope,
'FR-Equities' as EntityId, 'Joe Bloggs,Jane Doe,Matt Smith' as Value;
select * from Lusid.Property.Writer where ToWrite = @table_of_data;
Example 6: Add multiple property values to multiple entities
In this example, five SIC code properties are added to five different instruments at the same time using the default WriteAction
.
@vals = values ('LUID_00003DDE', '7010'), ('LUID_00003DCK', '4711'), ('LUID_00003DCH', '6190'), ('LUID_00003DCS', '3600'), ('LUID_00003DD1', '4772'); @table_of_data = select 'Instrument' as Domain, 'Finbourne-Examples' as PropertyScope, 'SICCode' as PropertyCode, 'LusidInstrumentId' as EntityIdType, column1 as EntityId, column2 as Value from @vals; select * from Lusid.Property.Writer where ToWrite = @table_of_data;