From b6eec2abc13df1c7cb5ab9127ba45518f338681e Mon Sep 17 00:00:00 2001 From: Pieterjan Spoelders Date: Mon, 26 Apr 2021 16:29:25 +0200 Subject: [PATCH] #36 #59 - add 'insert' statement documentation --- doc/user_guide/statements/insert.md | 54 +++++++++++++++++++++++++++++ doc/user_guide/user_guide.md | 2 +- 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 doc/user_guide/statements/insert.md diff --git a/doc/user_guide/statements/insert.md b/doc/user_guide/statements/insert.md new file mode 100644 index 00000000..54a56c0c --- /dev/null +++ b/doc/user_guide/statements/insert.md @@ -0,0 +1,54 @@ +# INSERT + +You can construct [`INSERT`](https://docs.exasol.com/sql/insert.htm) SQL statements using the `Insert` class. + +## Creating `INSERT` Statements + +Create an `INSERT` statement: + +```java + final Insert insert = StatementFactory.getInstance() + .insertInto("tableName") + .values("value1","value2","value3"); +``` + +Create an `INSERT` statement for specific fields: + +```java + final Insert insert = StatementFactory.getInstance() + .insertInto("tableName") + .field("column1", "column2","column3") + .values("value1","value2","value3"); +``` + +### Using Placeholders + +```java + insert.valuePlaceholder() +``` + +### Using Value Tables + +```java + final Insert insert = StatementFactory.getInstance().insertInto("tableName"); + + final ValueTable table = new ValueTable(insert); + table.appendRow("a", "b") + .appendRow("c", "d"); + + insert.valueTable(table); +``` + +More info on value tables [value tables](../common_constructs/value_tables.md). + +### Rendering `INSERT` Statements + +Use the `InsertRenderer` to render `Insert` objects into SQL strings. + +```java + final StringRendererConfig config = StringRendererConfig.builder().quoteIdentifiers(true).build(); + final InsertRenderer renderer = new InsertRenderer(config); + insert.accept(renderer); + final String sql = renderer.render(); +``` +For a more general introduction please refer to ["Rendering SQL Statements into Strings"](../rendering.md). \ No newline at end of file diff --git a/doc/user_guide/user_guide.md b/doc/user_guide/user_guide.md index 5b891672..46a049b3 100644 --- a/doc/user_guide/user_guide.md +++ b/doc/user_guide/user_guide.md @@ -23,7 +23,7 @@ Data Query Language (DQL) Data Modification Language (DML) -- INSERT +- [INSERT](statements/insert.md) - [MERGE](statements/merge.md) [fluent]: https://en.wikipedia.org/wiki/Fluent_interface \ No newline at end of file