public class Insert extends PostgresSqlPart

Generates an INSERT INTO statement for PostgreSQL.


Sample Generated SQL:

INSERT INTO "tableName" ("col1", "col2", "col3")
VALUES (val1, val2, val3),
       (val1, val2, val3),
       (val1, val2, val3),...
  • Constructor Details

    • Insert

      public Insert(String table)
  • Method Details

    • setPretty

      public Insert setPretty(boolean pretty)
      Indicates if line breaks and indentations should be added to output insert statement (default false).

      Example output (pretty = true):
      INSERT INTO "tableName" ("col1", "col2", "col3")
      VALUES (val1, val2, val3),
             (val1, val2, val3),
             (val1, val2, val3),...

      Example output (pretty = false):
      INSERT INTO "tableName" ("col1", "col2", "col3") VALUES (val1, val2, val3), (val1, val2, val3), (val1, val2, val3),...
      Overrides:
      setPretty in class SqlPart
    • getTable

      public String getTable()
    • nextRow

      public Insert nextRow()
      Starts a new row for subsequent add(String, Object) calls; the first row already exists after construction.
    • add

      public Insert add(String columnName, Object value)
      Adds a column value (an SQL literal, written as-is) to the current row; only the first row's column names are used.
    • getRows

      public List<InsertRow> getRows()
    • getLastRow

      public InsertRow getLastRow()
    • collectSqlFragment

      public void collectSqlFragment(CodeWriter writer)
      Description copied from class: SqlPart
      Writes this part's SQL to the writer; used by SqlPart.getSqlFragment() and by enclosing parts.
      Specified by:
      collectSqlFragment in class SqlPart