How-To Guides
Integration Guides

Work with Tables in SQL Connectors (Create Table and Show Mapping)

12min
when you set up and configure a connection with the following sql connectors, you have the option of selecting how the data will be transferred to database tables db microsoft sql server docid\ qfmrt1sqnixsvnd3 joox db microsoft sql server ssl docid\ jhmj11rjwdpn0cibm09hv db mysql docid\ jv svsuxisjjn45fjprw1 db mysql ssl docid\ ei3zbsz2flbvhqgj9ihlh db postgresql docid 7v8nb835v lgmuljbyqsw db postgresql ssl docid\ gv5zw8ugea37xhjjectp5 db mongodb docid 5wfcdelln25oh4hyahlnd db mongo v4+ docid\ kzyevz3lq w1r0zdo7epd when configuring the connector, make sure to select only one of the following options option 1 create table if you select the create table checkbox, a default table will be created if one doesn't already exist the table will be used to store data sent through the connector if you select this checkbox, make sure to unselect the show mapping checkbox microsoft sql server default table if you set up a connection with db microsoft sql server docid\ qfmrt1sqnixsvnd3 joox or db microsoft sql server ssl docid\ jhmj11rjwdpn0cibm09hv and select create table , an existing table will be used or a new one will be created using the following commands if not exists(select from sysobjects where name = '"table name"' and xtype = 'u') create table "table name" ( id bigint identity(1,1) not null, record uuid char(36) not null, arrived at datetime not null, device id varchar(64) null, register id varchar(64) null, tag name varchar(64) null, datatype varchar(32) null, value text null, success bit null, primary key (id) ) mysql default table if you set up a connection with db mysql docid\ jv svsuxisjjn45fjprw1 or db mysql ssl docid\ ei3zbsz2flbvhqgj9ihlh and select create table , an existing table will be used or a new one will be created using the following commands create table if not exists `table name` ( id bigint auto increment not null, record uuid char(36) not null, arrived at datetime not null, device id varchar(64) null, register id varchar(64) null, tag name varchar(64) null, datatype varchar(32) null, value text null, success tinyint null, primary key (id) ); postgresql default table if you set up a connection with db postgresql docid 7v8nb835v lgmuljbyqsw or db postgresql ssl docid\ gv5zw8ugea37xhjjectp5 and select create table , an existing table will be used or a new one will be created using the following commands create table if not exists "table name" ( id bigserial not null, record uuid uuid not null, arrived at timestamp with time zone not null, device id varchar(64) null, register id varchar(64) null, tag name varchar(64) null, datatype varchar(32) null, value varchar null, success boolean null, primary key (id) ); option 2 show mapping if you select the show mapping checkbox, you can send data to a custom table in the database this table can be configured in your preferred format and structure important if you make any changes to the data type or destination table in the database, make sure to disable and enable the connector if the connector isn't restarted, litmus edge will not have access to the latest table schema this may affect the data transfer when configuring the table, there are no limitations on what data types are supported you can put any field type into the custom table as long as this type can store data from the respective field before you begin make sure you have sufficient knowledge of sql when configuring the mapping for the custom table any errors in the format will cause failures in sending data to the database the database table that will store the data from this connection will be need to be created before completing these steps this task only maps the data that will be sent to the pre existing table configure custom table mapping to configure custom table mapping, begin by following step 1, step 2, and step 3 for one of the following guides microsoft sql server integration guide docid\ l kgb5s37xjw2cfl7kho0 mysql integration guide docid\ zxgqi3wazzgupoxgrul p postgresql integration guide docid\ ktvflztb1xjczqjobgmsn these guides use devicehub data from devices and tags to create the data that will be sent to the database alternatively, you can also use analytics docid\ zaowl1npjlkefhjbxhgvu or the flows manager docid bvxnzlgo8fsoglib4o l to create this data when you get to step 4 to add the connector in litmus edge, configure the following parameters for the custom table table this is the name of the pre existing custom table that will store the transferred data show mapping select this checkbox see the configure key/value pairs section below to learn how to format key/value pairs create table make sure to unselect this checkbox configure key/value pairs once you select the show mapping checkbox, you'll be able to map the key/value pairs for the custom table to configure key/value pairs from the add a connector or edit connector dialog box, select the show mapping checkbox make sure the create table checkbox is not selected the key/value section appears in the key field, enter the name of the first column in the table in the value field, enter the value name that will be stored in the first column in the following format {{ value name}} replace value name with the corresponding key value of the json see the example below click +add the key/value pair is added to the mapping for the connector continue adding columns and corresponding values for your table mapping example you have the following data in json format {“devicename” “plc1”, “timestamp” 1239423823, "value" 123}, {“devicename” “plc1”, “timestamp” 1247382948, "value" 545}, {“devicename” “plc1”, “timestamp” 1294859324, "value" 787} you have created the following database table device name timestamp data value the show mapping section would be formatted as shown below the database table would be updated with the data as shown below device name timestamp data value plc1 1239423823 123 plc1 1247382948 545 plc1 1294859324 787