0

I'm composing a liquibase script to create a table with Geometry column (from PostGis extenstion of PostGreSQL DB)

However, I couldn't manage to get it working. My script:

  - changeSet:
      id: 5-change-set-places
      comment: Create places table
      author: LongLe
      validCheckSum: 1:any
      changes:
        - sql:
            dbms: postgresql
            endDelimiter: ;
            splitStatements: true
            sql: |
              CREATE TABLE IF NOT EXISTS "${schema}"."places" (
                "id" bigint NOT NULL,
                "geom" GEOMETRY(Geometry, 4326) NOT NULL
              );
              GRANT SELECT, INSERT, UPDATE, DELETE ON "${schema}"."places" TO "${rolename}";
              ALTER TABLE "${schema}"."places"
                DROP CONSTRAINT IF EXISTS "places_pkey",
                ADD CONSTRAINT "places_pkey" PRIMARY KEY ("id");

However, it failed with below error:

ERROR: type "geometry" does not exist

I also referred to liquibase-spatial extension https://github.com/lonnyj/liquibase-spatial and compose the equivalent config:

  - changeSet:
      id: 5-change-set-places
      comment: Create places table
      author: LongLe
      validCheckSum: 1:any
      changes:
        - createTable:
            columns:
              - column:
                  constraints:
                    nullable: false
                    primaryKey: true
                    primaryKeyName: places_pkey
                  name: id
                  type: bigint
              - column:
                  constraints:
                    nullable: false
                  name: geom
                  type: GEOMETRY(Geometry,4326)
            tableName: test

But it still failed with the error:

31-03-2021 21:07:31.587 [main] WARN c.m.ms.block...applyLiquibase - Error applying liquibase attempt 5 : Migration failed for change set classpath:db/changelog/db.changelog-master.yaml::5-change-set-places::LongLe: Reason: liquibase.exception.DatabaseException: ERROR: type "geometry" does not exist Position: 67 [Failed SQL: CREATE TABLE testschema.places (id BIGINT NOT NULL, geom geometry(Geometry, 4326) NOT NULL, CONSTRAINT places_pkey PRIMARY KEY (id))]

But when I took out the SQL from the log to run:

CREATE TABLE testschema.places (id BIGINT NOT NULL, geom geometry(Geometry, 4326) NOT NULL, CONSTRAINT places_pkey PRIMARY KEY (id))

Then it works just fine.

I must have missed some very simple thing, but I checked up & down without any clue. Anyone has a better idea?

3
  • 1
    Not sure but just a thought. Have you tried "CREATE EXTENSION postgis;" before using "geometry" from the extension? Apr 1, 2021 at 5:39
  • Hi @RakhiAgrawal, yes, I do install PostGis before. Having added that in the previous script still produces the same issue Apr 1, 2021 at 6:29
  • Hi @LaurenzAlbe Thanks! This turn out to be the issue. I added one SQL command to include "public" into the search path and it works Apr 1, 2021 at 6:30

1 Answer 1

1

Make sure you have run

CREATE EXTENSION postgis;

Then schema qualify the data type. If the extension was created in public, use

CREATE TABLE places (geom public.geometry, ...);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.