0

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: ...

8
  • \copy is a command for the psql client, it's not a SQL command. Most likely you need COPY without the \ Commented Jan 5 at 22:34
  • Please don't use images to present information that is fundamentally textual (see Why not upload images of code/errors when asking a question?).
    – JohnH
    Commented Jan 6 at 5:29
  • i add the code and did it without \ ! This is what i get now :( Actually this is the local path of the csv file ! ^
    – heyoka955
    Commented Jan 6 at 8:38
  • Yes but it is not local to the Postgres server(nor does the server have permissions on the file) which is in the Docker container I presume. Commented Jan 6 at 16:36
  • Since you where using Jupyter to begin with I'm going to use assume you are programming with Python. I would suggest using psycopg2 in a Python script and use it's COPY to transfer the data. Commented Jan 6 at 16:41

1 Answer 1

0

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.