public class Upsert extends PostgresSqlPart
Generates an upsert statement for PostgreSQL.
INSERT INTO "tableName" ("col1", "col2", "col3")
VALUES (val1, val2, val3),
(val1, val2, val3),
(val1, val2, val3)
ON CONFLICT ("id") DO UPDATE SET "col1" = EXCLUDED."col1", "col2" = EXCLUDED."col2", "col3" = EXCLUDED."col3"
Constructor and Description |
---|
Upsert(String table,
List<String> keyFieldNames) |
Upsert(String table,
String... keyFieldNames) |
Modifier and Type | Method and Description |
---|---|
Upsert |
add(String columnName,
Object value) |
void |
collectSqlFragment(CodeWriter writer) |
ConflictAction |
getConflictAction()
Indicates the action to perform on conflict (default ConflictAction.UPDATE).
|
List<String> |
getKeyFieldNames() |
InsertRow |
getLastRow() |
List<InsertRow> |
getRows() |
String |
getTable() |
Upsert |
nextRow() |
Upsert |
setConflictAction(ConflictAction action) |
Upsert |
setPretty(boolean pretty)
Indicates if line breaks and indentations should be added to output upsert statement (default false).
Example output (pretty = true): INSERT INTO "tableName" ("col1", "col2", "col3") |
escapeKeyword
collectParameterValues, getParameterValues, getSqlFragment, isPretty, printSqlParts, toString
public Upsert setPretty(boolean pretty)
INSERT INTO "tableName" ("col1", "col2", "col3")
VALUES (val1, val2, val3),
(val1, val2, val3),
(val1, val2, val3)
ON CONFLICT ("id") DO UPDATE SET "col1" = EXCLUDED."col1", "col2" = EXCLUDED."col2", "col3" = EXCLUDED."col3"
INSERT INTO "tableName" ("col1", "col2", "col3") VALUES (val1, val2, val3), (val1, val2, val3), (val1, val2, val3) ON CONFLICT ("id") DO UPDATE SET "col1" = EXCLUDED."col1", "col2" = EXCLUDED."col2", "col3" = EXCLUDED."col3"
public String getTable()
public Upsert nextRow()
public InsertRow getLastRow()
public void collectSqlFragment(CodeWriter writer)
collectSqlFragment
in class SqlPart
public Upsert setConflictAction(ConflictAction action)
public ConflictAction getConflictAction()
Copyright (c) 2006-2024 North Concepts Inc. All Rights Reserved.