typeorm: Data type "geometry" is not supported by "postgres" database.`

Issue type:

[ ] question [x] bug report [ ] feature request [ ] documentation issue

Database system/driver:

[ ] cordova [ ] mongodb [ ] mssql [ ] mysql / mariadb [ ] oracle [x] postgres [ ] sqlite [ ] sqljs [ ] react-native [ ] expo

TypeORM version:

[ ] latest [x] @next [ ] 0.x.x (or put your version here)

Steps to reproduce or a small repository showing the problem:

@Entity()
export class Event {
  @Column() name: string;

  // @ts-ignore (otherwise I get type warning)
  @Column("geometry", { nullable: true })
  location: string;
}

Expected outcome: Create the postgres table with a geometry column

Actual outcome: DataTypeNotSupportedError: Data type "geometry" in "Event.location" is not supported by "postgres" database.

Seems like the latest version of PostgresDriver.ts isn’t in typeorm@next, or latest one as well.


@Entity()
export class Event extends BaseTable {
  @Column() name: string;

  @Column("point", { nullable: true })
  location: string;
}

This seems to work, but documentation says geometry should work as well.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 1
  • Comments: 15 (4 by maintainers)

Most upvoted comments

We are using

@Column({
    type: 'geometry',
    nullable: true,
    spatialFeatureType: 'Point',
    srid: 4326
})

in 0.2.9 and everything is fine. I think this is already resolved.

@AlexMesser at some point we’ll need to add detailed docs on each data type we have and examples on how to use them

Just pass json structure as postgres require:

this.entity.point = {
  type: "Point",
  coordinates: [0, 0]
};
// save

Check our tests https://github.com/typeorm/typeorm/tree/master/test/functional/spatial/postgres

i try this:

import { Geometry } from "geojson";
import { Column, Entity, JoinColumn, OneToOne } from "typeorm";
import { Base } from '../../config/entity.base'
import { User } from "./user.entity";

@Entity({ name: 'marketplaces' })
export class Marketplace extends Base {

  @Column({ type: 'varchar', length: 100, nullable: true })
  market_name: String

  @Column({ type: 'geometry', nullable: true, spatialFeatureType: 'Point', srid: 4326 })
  location: Geometry

  @OneToOne(() => User, user => user.id)
  @JoinColumn({ name: 'user_id' })
  user: User

}

and a got an error:

QueryFailedError: type "geometry" does not exist

inside query log of typeorm :

ERROR:  could not open extension control file "/usr/share/postgresql/12/extension/postgis.control": No such file or directory

STATEMENT:  CREATE EXTENSION IF NOT EXISTS "postgis"

ERROR:  type "geometry" does not exist at character 309

STATEMENT:  CREATE TABLE "marketplaces" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "is_active" boolean NOT NULL DEFAULT true, "is_archived" boolean NOT NULL DEFAULT false, "created_at" TIMESTAMP NOT NULL DEFAULT now(), "updated_at" TIMESTAMP NOT NULL DEFAULT now(), "market_name" character varying(100), "location" geometry(Point,4326), "user_id" uuid, CONSTRAINT "REL_18f8ca2e793c5d481e1442941f" UNIQUE ("user_id"), CONSTRAINT "PK_e4d5b8aa6ae255c4ce370792f79" PRIMARY KEY ("id"))

otherwise using this aprouch everything works fine:

i change type to point.

import { Geometry } from "geojson";
import { Column, Entity, JoinColumn, OneToOne } from "typeorm";
import { Base } from '../../config/entity.base'
import { User } from "./user.entity";

@Entity({ name: 'marketplaces' })
export class Marketplace extends Base {

  @Column({ type: 'varchar', length: 100, nullable: true })
  market_name: String

  @Column({ type: 'point', nullable: true, spatialFeatureType: 'Point', srid: 4326 })
  location: Geometry

  @OneToOne(() => User, user => user.id)
  @JoinColumn({ name: 'user_id' })
  user: User

}

I have a Geography column, but how do I insert data into it?

Any update with the docs @pleerock . Its only been a year 😅

You might want to check https://www.npmjs.com/package/@types/geojson type as it’s compatible with postgis, so it might be helpful to manage your data