Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql Postgres插入问题:列';产品1';不存在。博士后插入问题_Sql_Database_Postgresql_Docker_Docker Compose - Fatal编程技术网

Sql Postgres插入问题:列';产品1';不存在。博士后插入问题

Sql Postgres插入问题:列';产品1';不存在。博士后插入问题,sql,database,postgresql,docker,docker-compose,Sql,Database,Postgresql,Docker,Docker Compose,这是我的docker compose.yml文件。在开始向表中插入数据之前,一切都是完美的。根据对其他问题的回答,我尝试了各种postgres图像,如13 alpine,12 alpine,10.5-alpine,但最后还是出现了错误 version: '3.9' services: productservice: build: ./productservice container_name: productservice ports: - '5000

这是我的
docker compose.yml
文件。在开始向表中插入数据之前,一切都是完美的。根据对其他问题的回答,我尝试了各种
postgres
图像,如
13 alpine
12 alpine
10.5-alpine
,但最后还是出现了错误

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:
这是我在
sql
文件夹中创建的
create table.sql
文件

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)
);
最后是
fill table.sql
文件,我尝试在其中向表中插入数据

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);
这是当我构建我的应用程序时,在Docker上得到的错误日志

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),

尝试使用单引号“而不是双引号”


使用单引号。双引号仅用于对象名称(如表名、列名)
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);