Search code examples
sqldatabasepostgresqldockernosql

Create a table in postgress on jupyter results in syntax error?


I try to create a table in postgress in my jupyter lab! but there comes this bug!

 %%bash

cat <<"EOF" | sudo docker exec -i dbis-postgres-db-1 psql -U postgres

DROP DATABASE IF EXISTS satisfaction;
CREATE DATABASE satisfaction;
\c satisfaction;


CREATE TABLE department (
    id_dept SERIAL PRIMARY KEY,
    dept VARCHAR(50) NOT NULL,
    city VARCHAR(50) NOT NULL,
    zip_code INTEGER NOT NULL

);

COPY department 
    
FROM '/home/heyoka/Schreibtisch/master/DE/data-engineering-infrastructure.git/workspace/data/departments.csv'
WITH (
    FORMAT CSV,
    DELIMITER ',',
    HEADER false,
    NULL ''
);

...

EOF


This is the error i received now :

ERROR: could not open file "/home/heyoka/Schreibtisch/master/DE/data-engineering-infrastructure.git/workspace/data/departments.csv" for reading: No such file or directory HINT: COPY FROM instructs the PostgreSQL server process to read a file. You may want a client-side facility such as psql's \copy. ERROR: syntax error at or near ".." LINE 1: ...


Solution

  • The reason why this not worked was because starting the docker container resulted in mounting ! The docker container mounted the files in this path '/mnt/workspace'. So the files were all the time there