UPSERT
This topic describes the syntax for writing data to spatio-temporal data tables.
Syntax
upsert_statement ::= UPSERT [hint_clause] INTO table_name
'('columns| _l_ts_')'
VALUES '(' values ')'
[ ON DUPLICATE KEY update_column = update_value |IGNORE ]?
columns ::= column_name, columns
values ::= term, values,'(' values ')'
| function_name '(' term ( ',' term )* ')'
update_column ::= column_name
update_value ::= term
hint_clause::=/*+hint_items*/
hint_items::=hint_item(','hint_item)*
hint_item::=identifier('('hint_option(','hint_option)*')')
hint_option::=expressionBatch writes are supported. You can specify the columns to write to and define multiple rows of data in the VALUES clause.
The UPSERT ON DUPLICATE KEY operation is supported. It is similar to a check-and-put operation in which the specified value must identify a unique row. If you attempt to insert a row with a key that already exists, an exception is thrown. Updating a value based on the key's existence is not supported. You can add the ON DUPLICATE KEY IGNORE clause to skip the insertion if the key already exists, which prevents an exception from being thrown.
Lindorm SQL supports standard Java Database Connectivity (JDBC) access methods, including Statement and PreparedStatement. However, standard JDBC batch inserts that use PreparedStatement are supported only in Lindorm 2.2.16 and later.
Examples
The following examples show two ways to insert a row into a spatio-temporal data table.
Method 1
UPSERT INTO dt(id, g, t) VALUES(0,ST_MakePoint(0.0,1.0),1000);Method 2
UPSERT INTO dt(id, g, t) VALUES(0,ST_GeomFromText('POINT (0.0 1.0)'),1000);
Batch insert data into a spatio-temporal data table.
UPSERT INTO dt (id, g, t) VALUES(1,ST_MakePoint(1.23,2.34),2000),(2,ST_MakePoint(3.45,5.67),3000),(3,ST_MakePoint(4.56,5.67),4000);
For more information about the spatio-temporal functions used to write data, see Function overview.
For an example of writing data using Java JDBC, see Quick Start.