Как добавить запись в таблицу с полем Polygon

Рейтинг: 0Ответов: 0Опубликовано: 30.06.2023

Всем привет. Как добавить запись с polygon в Postgres

мой запрос

const polygonCoordinates = data.location
      .map(([lon, lat]: any) => `${lon} ${lat}`)
      .join(', ');
    const polygonString = `POLYGON((${polygonCoordinates}))`;
    try {
      await this.prisma.$queryRaw`
        INSERT INTO "shop_delivery" (shop_id, name, price, time, location)
        VALUES (${shopId}, ${data.name}, ${data.price}, ${data.time}, ${polygonString})
        RETURNING *;
      `;
    } catch (error) {
      console.log(error);
    }

данные для вставки

{
    "name": "Zone 1",
    "price": 0,
    "time": "20",
    "location": [
        [
            55.19503399600201,
            30.188493325347896
        ],
        [
            55.193241863325376,
            30.185424878234862
        ],
        [
            55.18936272346971,
            30.189351632232654
        ],
        [
            55.18877808336348,
            30.19608186067614
        ],
        [
            55.197579386122186,
            30.198184712543814
        ],
        [
            55.19772667164176,
            30.18927977861437
        ],
        [
            55.19503399600201,
            30.188493325347896
        ]
    ]
}

выдает ошибку

Raw query failed. Code: 22P02. Message: db error: ERROR: invalid input syntax for type polygon: "POLYGON((55.19503399600201 30.188493325347896, 55.193241863325376 30.185424878234862, 55.18936272346971 30.189351632232654, 55.18877808336348 30.19608186067614, 55.197579386122186 30.198184712543814, 55.19772667164176 30.18927977861437, 55.19503399600201 30.188493325347896))"

docker-compose

version: '3.8'
services:
  fl.api:
    build:
      dockerfile: Dockerfile
      context: .
      # Only will build development stage from our dockerfile
      target: development
    volumes:
      - .:/usr/src/app
    env_file:
      - .env
      # Run a command against the development stage of the image
    command: npm run start:dev
    ports:
      - 6545:6545
    networks:
      - nesjs-network
  redis:
    image: 'redis:alpine'
    ports:
      - '${FORWARD_REDIS_PORT:-6379}:6379'
    volumes:
      - fl-redis:/data
    healthcheck:
      test: [ "CMD", "redis-cli", "ping" ]
      retries: 3
      timeout: 5s
  db:
    image: postgres
    restart: always
    environment:
      POSTGRES_DB: ${POSTGRES_DB}
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
    ports:
      - '5432:5432'
    networks:
      - nesjs-network
    volumes:
      - fl-postgres:/var/lib/postgresql/data

  adminer:
    image: adminer
    restart: always
    depends_on:
      - db
    ports:
      - 8080:8080
    networks:
      - nesjs-network
networks:
  nesjs-network:
volumes:
  fl-redis:
    driver: local
  fl-postgres:
    driver: local

Ответы

Ответов пока нет.