0

I have a problem with PostgreSQL script runing with docker-compose. I want to create only ONE table in PostgreSQL.

My script is:

DROP TABLE IF EXISTS person;
CREATE TABLE person
(
    id      INT NOT NULL,
    name    VARCHAR(255),
    surname VARCHAR(255),
    age     INT,
    email   VARCHAR(255) UNIQUE
);

Log from drocker-compose Error message is:

postgres     | Success. You can now start the database server using:
postgres     |
postgres     |     pg_ctl -D /var/lib/postgresql/data -l logfile start
postgres     |
postgres     | waiting for server to start....2022-07-11 08:39:50.970 UTC [48] LOG:  starting PostgreSQL 14.4 (Debian 14.4-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
postgres     | 2022-07-11 08:39:50.978 UTC [48] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres     | 2022-07-11 08:39:51.000 UTC [49] LOG:  database system was shut down at 2022-07-11 08:39:50 UTC
postgres     | 2022-07-11 08:39:51.008 UTC [48] LOG:  database system is ready to accept connections
postgres     |  done
postgres     | server started
postgres     | CREATE DATABASE
postgres     |
postgres     |
postgres     | /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/create-table-person.sql
postgres     | 2022-07-11 08:39:51.431 UTC [62] ERROR:  syntax error at or near "CREATE" at character 30
postgres     | 2022-07-11 08:39:51.431 UTC [62] STATEMENT:  DROP TABLE IF EXISTS person
postgres     |  CREATE TABLE person
postgres     |  (
postgres     |      id      integer NOT NULL PRIMARY KEY,
postgres     |      name    VARCHAR(255),
postgres     |      surname VARCHAR(255),
postgres     |      age     integer,
postgres     |      email   VARCHAR(255)
postgres     |  );
postgres     | psql:/docker-entrypoint-initdb.d/create-table-person.sql:9: ERROR:  syntax error at or near "CREATE"
postgres     | LINE 2: CREATE TABLE person
postgres     |         ^
postgres exited with code 3

and my Dockerfile for PostgreSQL is:

FROM postgres
ENV POSTGRES_DB testdatabase1

COPY create-table-person.sql /docker-entrypoint-initdb.d/
3
  • stackoverflow.com/questions/66713670/… Looks like a similar problem to the one I'm linking above Commented Jul 11, 2022 at 8:53
  • It works for me, when I try to reproduce it. Since it complains on line 2 of your script, I'm thinking that you might have saved the script with Windows CRLF line endings instead of Linux LF line endings. Commented Jul 11, 2022 at 9:08
  • Ok thanks. i dont know why, but its works. Commented Jul 12, 2022 at 13:13

0

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.