Class Upsert
java.lang.Object
com.northconcepts.datapipeline.jdbc.sql.SqlPart
com.northconcepts.datapipeline.sql.postgresql.PostgresSqlPart
com.northconcepts.datapipeline.sql.postgresql.Upsert
Generates an upsert statement for PostgreSQL.
Sample Generated SQL:
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 Summary
ConstructorsConstructorDescriptionCreates an upsert intotablethat uses the given key fields forON CONFLICT; at least one is required.Creates an upsert intotablethat uses the given key fields forON CONFLICT; at least one is required. -
Method Summary
Modifier and TypeMethodDescriptionAdds a column value (an SQL literal, written as-is) to the current row; only the first row's column names are used.voidcollectSqlFragment(CodeWriter writer) Writes this part's SQL to the writer; used bySqlPart.getSqlFragment()and by enclosing parts.Indicates the action to perform on conflict (default ConflictAction.UPDATE).Returns the key fields listed in theON CONFLICTclause.getRows()getTable()nextRow()Starts a new row for subsequentadd(String, Object)calls; the first row already exists after construction.setConflictAction(ConflictAction action) Indicates the action to perform on conflict (defaultConflictAction.UPDATE); null selects the default.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")
VALUES (val1, val2, val3),Methods inherited from class com.northconcepts.datapipeline.sql.postgresql.PostgresSqlPart
escapeKeywordMethods inherited from class com.northconcepts.datapipeline.jdbc.sql.SqlPart
collectParameterValues, getParameterValues, getSqlFragment, isPretty, printSqlParts, toString
-
Constructor Details
-
Upsert
Creates an upsert intotablethat uses the given key fields forON CONFLICT; at least one is required. -
Upsert
Creates an upsert intotablethat uses the given key fields forON CONFLICT; at least one is required.
-
-
Method Details
-
setPretty
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")
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"
Example output (pretty = false):
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" -
getTable
-
nextRow
Starts a new row for subsequentadd(String, Object)calls; the first row already exists after construction. -
add
Adds a column value (an SQL literal, written as-is) to the current row; only the first row's column names are used. -
getRows
-
getLastRow
-
collectSqlFragment
Description copied from class:SqlPartWrites this part's SQL to the writer; used bySqlPart.getSqlFragment()and by enclosing parts.- Specified by:
collectSqlFragmentin classSqlPart
-
getKeyFieldNames
Returns the key fields listed in theON CONFLICTclause. -
setConflictAction
Indicates the action to perform on conflict (defaultConflictAction.UPDATE); null selects the default. -
getConflictAction
Indicates the action to perform on conflict (default ConflictAction.UPDATE).
-