User Tools

Site Tools

A PCRE internal error occured. This might be caused by a faulty plugin

Sidebar

**HPL/SQL is included to Apache Hive since version 2.0** * [[home|Home]]\\ * [[why|Why HPL/SQL]]\\ * [[features|Key Features]]\\ * [[start|Get Started]]\\ * [[doc|HPL/SQL Reference]]\\ * [[download|Download]]\\ * [[new|What's New]]\\ * [[about|About]]

insert

====== INSERT Statement ====== INSERT statement inserts rows into a table. **Syntax**: Insert from SELECT: <code language=sql> INSERT OVERWRITE TABLE table_name select_statement | INSERT INTO [TABLE] table_name select_statement </code> Insert values: <code language=sql> INSERT INTO [TABLE] table_name VALUES (exrp, expr2, ...) [, (exrp, expr2, ...), ...] </code> ===== INSERT VALUES ===== HPL/SQL provides you with two options to run INSERT VALUES statement: **native** and **select**. Use the [[configuration#hplsqlinsertvalues|hplsql.insert.values]] option to define how to handle INSERT VALUES statement, the default value is **native**. ==== Native INSERT VALUES ==== If [[configuration#hplsqlinsertvalues|hplsql.insert.values]] is set to **native** HPL/SQL relies on the database that must support INSERT VALUES syntax. Note that INSERT VALUES is available in Hive since version 0.14 only and can only be performed on tables that support ACID. ==== Transform into INSERT SELECT ==== If [[configuration#hplsqlinsertvalues|hplsql.insert.values]] is set to **select** HPL/SQL transforms VALUES clause to the list of SELECT FROM dual UNION ALL ... clauses. For example, if you execute the following INSERT statement: <code language=sql> INSERT INTO dept VALUES (10, 'ACCOUNTING', 'NEW YORK'), (20, 'RESEARCH', 'DALLAS'), (30, 'SALES', 'CHICAGO'), (40, 'OPERATIONS', 'BOSTON'); </code> HPL/SQL transforms it to: <code language=sql> INSERT INTO dept SELECT 10, 'ACCOUNTING', 'NEW YORK' FROM default.dual UNION ALL SELECT 20, 'RESEARCH', 'DALLAS' FROM default.dual UNION ALL SELECT 30, 'SALES', 'CHICAGO' FROM default.dual UNION ALL SELECT 40, 'OPERATIONS', 'BOSTON' FROM default.dual; </code> You can specify the single row, single column dual table using [[configuration#hplsqldualtable|hplsql.dual.table]] option. **Important Note:** Such approach leads to creating one HDFS file **per** INSERT statement, and must not be used to insert large number of rows. **Compatibility:** Oracle, Microsoft SQL Server, IBM DB2, Teradata, PostgreSQL and MySQL **Version**: HPL/SQL 0.3