Search in sources :

Example 11 with SequenceNextValueFunction

use of liquibase.statement.SequenceNextValueFunction in project liquibase by liquibase.

the class InsertOrUpdateGeneratorPostgresTest method testInsertSequenceValWithSchema.

@Test
public void testInsertSequenceValWithSchema() {
    PostgresDatabase postgresDatabase = new PostgresDatabase();
    InsertGenerator generator = new InsertGenerator();
    InsertStatement statement = new InsertStatement(CATALOG_NAME, SCHEMA_NAME, TABLE_NAME);
    ColumnConfig columnConfig = new ColumnConfig();
    columnConfig.setValueSequenceNext(new SequenceNextValueFunction(SCHEMA_NAME + '.' + SEQUENCE_NAME));
    columnConfig.setName("col3");
    statement.addColumn(columnConfig);
    Sql[] sql = generator.generateSql(statement, postgresDatabase, null);
    String theSql = sql[0].toSql();
    assertEquals(String.format("INSERT INTO %s.%s (col3) VALUES (nextval('%s.%s'))", SCHEMA_NAME, TABLE_NAME, SCHEMA_NAME, SEQUENCE_NAME), theSql);
}
Also used : PostgresDatabase(liquibase.database.core.PostgresDatabase) ColumnConfig(liquibase.change.ColumnConfig) SequenceNextValueFunction(liquibase.statement.SequenceNextValueFunction) InsertStatement(liquibase.statement.core.InsertStatement) Sql(liquibase.sql.Sql) Test(org.junit.Test)

Aggregations

SequenceNextValueFunction (liquibase.statement.SequenceNextValueFunction)11 DatabaseFunction (liquibase.statement.DatabaseFunction)5 BigInteger (java.math.BigInteger)4 Sql (liquibase.sql.Sql)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 ColumnConfig (liquibase.change.ColumnConfig)2 PostgresDatabase (liquibase.database.core.PostgresDatabase)2 UnexpectedLiquibaseException (liquibase.exception.UnexpectedLiquibaseException)2 UnparsedSql (liquibase.sql.UnparsedSql)2 SequenceCurrentValueFunction (liquibase.statement.SequenceCurrentValueFunction)2 InsertStatement (liquibase.statement.core.InsertStatement)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 BigDecimal (java.math.BigDecimal)1 LinkedList (java.util.LinkedList)1 AddColumnConfig (liquibase.change.AddColumnConfig)1 AddColumnChange (liquibase.change.core.AddColumnChange)1 LoadDataColumnConfig (liquibase.change.core.LoadDataColumnConfig)1