Search code examples
sqldatabasebashgreenplum

Import Text data to Greenplum database


I have a text file with some data and wants to import data to Greenplum database.After online research , I found that its better to use COPY command if your data size is small. So i decided to use this. Here is the scenario: I have placed my Text file at location /bin/bash /data , I can access this file using terminal, but once I run the following COPY sql script at Greenplum database it's says : could not open file "/bin/bash /data/data.txt" for reading: No such file or directory Below is the my sql script:

COPY userdata(customerid,time,trans,quantity) from '/bin/bash /data/data.txt' WITH DELIMITER ',';

From Greenplum database documentation I found the following line : The COPY source file must be accessible to the master host. Specify the COPY source file name relative to the master host location. But I do not know how to make it accessible to master host and relative to master host location.


Solution

  • The path to your file doesn't make any sense.

    /bin/bash /data/data.txt is certainly not a valid name for a path.

    If you data.txt file is located in the /data folder with content in the following format :

    12345,5:32AM,air,2
    67890,6:42PM,rail,4
    

    You could use the below command :

    COPY userdata(customerid,time,trans,quantity) FROM '/data/data.txt' WITH DELIMITER AS ',';
    

    Also sql user you should have the permission to access the the data.txt from the location /data folder.

    Perhaps do a ls -l and check if the sql user can read files from data.txt