Search code examples
snowflake-cloud-data-platformliquibasesnowflake-schema

Cannot perform CREATE TABLE using Liquibase update for Snowflake as this session does not have a current database?


I am trying to run Snowflake update using Liquibase as the following command which has fully qualified name of the server, database and the schema.

liquibase --username=myusername --password=mypassword --url="jdbc:snowflake://myserver-name-europe.azure.snowflakecomputing.com/?db=mydb&schema=public" --changelog-file=/samplechangelog.snowflake.sql update

But it just gives me error that I didn't specify the database which I did. Also, the same command work with other Snowflake account? I just even copy and paste it from other project, it's just the name of the server URL and DB is the different.

Here is the error message:

Unexpected error running Liquibase: Cannot perform CREATE TABLE. This session does not have a current database. Call 'USE DATABASE', or use a qualified name. [Failed SQL: (90105) CREATE TABLE DATABASECHANGELOGLOCK (ID INT NOT NULL, LOCKED BOOLEAN NOT NULL, LOCKGRANTED TIMESTAMP_NTZ, LOCKEDBY VARCHAR(255), CONSTRAINT PK_DATABASECHANGELOGLOCK PRIMARY KEY (ID))]

enter image description here


Solution

  • I suggest setting up a default role for user "username":

    ALTER USER myusername SET DEFAULT_ROLE = my_default_role;
    

    If user does not have default warehouse assigned then:

    ALTER USER myusername SET DEFAULT_WAHREOUSE = my_warehouse_name;
    

    It is also possible to set dabatabase/schema/warehouse/... in db.properties file. Related: Specifying Properties in a Connection Profile