... |
h1. MERGE Command |
The MERGE command, also known as UPSERT, is used to add and/or update records. The Teiid specific (non-ANSI) MERGE is simply a modified INSERT statement that requires the target table to have a primary key and for the target columns to cover the primary key. The MERGE operation will then check the existence of each row prior to INSERT and instead perform an UPDATE if the row already exists. |
Example Syntax |
... |
* {code:SQL}MERGE INTO table (column,...) query{code} |
{note:title=Merge Pushdown} The MERGE statement is not currently pushed to sources, but rather will be broken down into the respective insert/update operations. {note} |
h1. EXECUTE Command |
... |
Teiid supports SQL for issuing queries and for defining view transformations; see also Procedure Language for how SQL is used in virtual procedures and update procedures. Nearly all these features follow standard SQL syntax and functionality, so any SQL reference can be used for more information.
There are 4 basic commands for manipulating data in SQL, corresponding to the CRUD create, read, update, and delete operations: INSERT, SELECT, UPDATE, and DELETE. A MERGE statement acts as a combination of INSERT and UPDATE.
In addition, procedures can be executed using the EXECUTE command or through a Procedural Relational Command.
The SELECT command is used to retrieve records any number of relations.
A SELECT command has a number of clauses:
All of these clauses other than OPTION are defined by the SQL specification. The specification also specifies the order that these clauses will be logically processed. Below is the processing order where each stage passes a set of rows to the following stage. Note that this processing model is logical and does not represent the way any actual database engine performs the processing, although it is a useful model for understanding questions about SQL.
![]() | tip The explicit table syntax TABLE x may be used as a shortcut for SELECT * FROM x. |
The INSERT command is used to add a record to a table.
Example Syntax
INSERT INTO table (column,...) VALUES (value,...)
INSERT INTO table (column,...) query
The UPDATE command is used to modify records in a table. The operation may result in 1 or more records being updated, or in no records being updated if none match the criteria.
Example Syntax
UPDATE table SET (column=value,...) [WHERE criteria]
The DELETE command is used to remove records from a table. The operation may result in 1 or more records being deleted, or in no records being deleted if none match the criteria.
Example Syntax
DELETE FROM table [WHERE criteria]
The MERGE command, also known as UPSERT, is used to add and/or update records. The Teiid specific (non-ANSI) MERGE is simply a modified INSERT statement that requires the target table to have a primary key and for the target columns to cover the primary key. The MERGE operation will then check the existence of each row prior to INSERT and instead perform an UPDATE if the row already exists.
Example Syntax
MERGE INTO table (column,...) VALUES (value,...)
MERGE INTO table (column,...) query
![]() | Merge Pushdown The MERGE statement is not currently pushed to sources, but rather will be broken down into the respective insert/update operations. |
The EXECUTE command is used to execute a procedure, such as a virtual procedure or a stored procedure. Procedures may have zero or more scalar input parameters. The return value from a procedure is a result set or the set of inout/out/return scalars. Note that EXEC or CALL can be used as a short form of this command.
Example Syntax
EXECUTE proc()
CALL proc(value, ...)
Named Parameter Syntax
EXECUTE proc(name1=>value1,name4=>param4, ...)
Syntax Rules:
Procedural relational commands use the syntax of a SELECT to emulate an EXEC. In a procedural relational command a procedure group names is used in a FROM clause in place of a table. That procedure will be executed in place of a normal table access if all of the necessary input values can be found in criteria against the procedure. Each combination of input values found in the criteria results in an execution of the procedure.
Example Syntax
select * from proc
select output_param1, output_param2 from proc where input_param1 = 'x'
select output_param1, output_param2 from proc, table where input_param1 = table.col1 and input_param2 = table.col2
Syntax Rules:
![]() | Multiple Execution The usage of 'in' or join criteria can result in the procedure being executed multiple times. |
![]() | Alternative Syntax None of issues listed in the syntax rules above exist if a nested table reference is used. |