Type | Read/write | Author | Availability |
Write | Finbourne | Provided with LUSID |
Providing you have sufficient access control permissions, the Lusid.PortfolioGroup.Writer
provider enables you to write a Luminesce SQL query that either creates, updates or deletes portfolio groups in LUSID, and also adds and removes portfolios and sub-groups.
Note: By default,
Lusid.PortfolioGroup.Writer
cannot add properties to portfolio groups. To do this, you must first configureLusid.PortfolioGroup.Writer
to 'inline' properties. See how to do this.
You must construct a valid table of data to write, one portfolio group or portfolio per record, depending on the operation. Lusid.PortfolioGroup.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 portfolio group; that is, create a portfolio group if it does not exist, and update certain fields if it does. This is the default operation if you omit
WriteAction
.Delete a portfolio group.
Add a portfolio or a sub-group to a portfolio group.
Remove a portfolio or a sub-group from a portfolio group.
See also: Lusid.PortfolioGroup
Basic usage
@table_of_data = <select-statement>;
select * from Lusid.PortfolioGroup.Writer where toWrite = @table_of_data;
Query parameters
Lusid.PortfolioGroup.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.PortfolioGroup.Writer' and FieldType = 'Parameter';
Data fields
Lusid.PortfolioGroup.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 | Specify using... | Mandatory fields | Notes |
Upsert |
|
| The |
Insert |
|
| |
Update |
| You can only update | |
Delete |
|
|
|
Add |
|
|
|
Remove |
|
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.PortfolioGroup.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.PortfolioGroup.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.
The examples in this section refer to the following portfolio group structure. For simplicity, all the portfolio groups and portfolios are in the same Ibor
scope; the label in each box represents the code:
Example 1: Create portfolio groups
This query creates three portfolio groups, without structure. It defaults to an upsert operation as no explicit WriteAction
is specified.
@@scope = select 'Ibor';
@portfolio_groups = values
('Global', 'Global portfolio group', 'A portfolio group representing global operations'),
('NorthAmerica', 'North American portfolio group', 'A portfolio group representing NA operations'),
('EMEA', 'EMEA portfolio group', 'A portfolio group representing NA operations');
@data_to_write = select @@scope as TopGroupScope, column1 as TopGroupCode,
column2 as TopGroupName, column3 as TopGroupDescription from @portfolio_groups;
select * from Lusid.PortfolioGroup.Writer where ToWrite = @data_to_write;
Example 2: Add sub-groups to group
This query adds NorthAmerica
and EMEA
as sub-groups to the Global
portfolio group:
@@scope = select 'Ibor';
@sub_groups = values
('NorthAmerica'),
('EMEA');
@data_to_write = select @@scope as TopGroupScope, 'Global' as TopGroupCode,
@@scope as BottomGroupScope, column1 as BottomGroupCode, 'Add' as WriteAction from @sub_groups;
select * from Lusid.PortfolioGroup.Writer where ToWrite = @data_to_write;
Example 3: Add portfolios to groups
This query adds (pre-existing) portfolios to the NorthAmerica
and EMEA
sub-groups, creating the structure at the top of this section.
@@scope = select 'Ibor';
@portfolios = values
('Canada', 'NorthAmerica'),
('US', 'NorthAmerica')
('UK', 'EMEA')
('France', 'EMEA')
('Spain', 'EMEA');
@data_to_write = select @@scope as TopGroupScope, column2 as TopGroupCode,
@@scope as PortfolioScope, column1 as PortfolioCode, 'Add' as WriteAction from @portfolios;
select * from Lusid.PortfolioGroup.Writer where ToWrite = @data_to_write;