Postgres Inserting issue: column ‘Product 1’ does not exist. Postgres inserting issue

  database, docker, docker-compose, postgresql, sql

This is the docker-compose.yml file I have. Everything is perfect until it starts inserting data into table. I have tried various postgres images like 13-alpine, 12-alpine, 10.5-alpine according to answers replied to other questions but still getting the error at the end.

version: '3.9'

services:
  productservice:
    build: ./productservice
    container_name: productservice
    ports: 
      - '5000:5000'
    depends_on: 
      - 'db'
  db:
    image: 'postgres:13-alpine'
    restart: always
    container_name: postgre-db
    environment:
      POSTGRES_DB: microservice
      POSTGRES_USER: postgres 
      POSTGRES_PASSWORD: 123
    volumes: 
      - data:/var/lib/postgresql/data
      - ./productservice/sql/create-table.sql:/docker-entrypoint-initdb.d/create_table.sql
      - ./productservice/sql/fill-table.sql:/docker-entrypoint-initdb.d/fill_table.sql

volumes: 
  data:

here is my create-table.sql file inside sql folder.

CREATE TABLE IF NOT EXISTS product (
    product_id INT NOT NULL,
    product_name varchar(20) NOT NULL,
    product_description varchar(100) NOT NULL,
    product_price FLOAT NOT NULL,
    PRIMARY KEY (product_id)
);

and lastly the fill-table.sql file where I try to insert data to table.

INSERT INTO product (product_id, product_name, product_description, product_price)
VALUES
     (1001, "Product 1", "A product", 12.99),
     (1002, "Product 2", "A product", 13.99),
     (1003, "Product 3", "A product", 14.99),
     (1004, "Product 4", "A product", 15.99),
     (1005, "Product 5", "A product", 16.99),
     (1006, "Product 6", "A product", 18.99),
     (1007, "Product 7", "A product", 19.99),
     (1008, "Product 8", "A product", 20.99),
     (1009, "Product 9", "A product", 21.99),
     (1010, "Product 10", "A product", 22.99);

This is the error log I get on Docker when I docker-compose up --build my application.

postgre-db        | /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/fill_table.sql
postgre-db        | 2021-04-25 12:24:19.668 UTC [51] ERROR:  column "Product 1" does not exist at character 103
postgre-db        | 2021-04-25 12:24:19.668 UTC [51] STATEMENT:  INSERT INTO product (product_id, product_name, product_description, product_price)
postgre-db        |     VALUES
postgre-db        |          (1001, "Product 1", "A product", 12.99),
postgre-db        |          (1002, "Product 2", "A product", 13.99),
postgre-db        |          (1003, "Product 3", "A product", 14.99),
postgre-db        |          (1004, "Product 4", "A product", 15.99),
postgre-db        |          (1005, "Product 5", "A product", 16.99),
postgre-db        |          (1006, "Product 6", "A product", 18.99),
postgre-db        |          (1007, "Product 7", "A product", 19.99),
postgre-db        |          (1008, "Product 8", "A product", 20.99),
postgre-db        |          (1009, "Product 9", "A product", 21.99),
postgre-db        |          (1010, "Product 10", "A product", 22.99);
postgre-db        | psql:/docker-entrypoint-initdb.d/fill_table.sql:12: ERROR:  column "Product 1" does not exist
postgre-db        | LINE 3:      (1001, "Product 1", "A product", 12.99),

Source: Docker Questions

LEAVE A COMMENT