0

I have a single Excel file that is updated every morning with the current inventory of a few items. I would like to know if it's possible to connect that Excel file to PostgreSQL and automate a query that will add new rows on the same table on a daily basis. What I would like to get is something like this:

   -------------------------------     
    col1          col2       col 3
   -------------------------------
    09/10/2019    boxes      5
    09/11/2019    boxes      3
    09/12/2019    boxes      2

2 Answers 2

1

In addition to Dieter's answer. You also need to convert your Excel file to CSV format. You can automate it using xls2csv command-line tool

sudo apt-get update
sudo apt-get install catdoc
xls2csv yourExcelFile.xls > converted.csv

And just add before COPY in crontab:

xls2csv yourExcelFile.xls > converted.csv && psql -c "COPY tbname(col1, col2, col3) FROM 'converted.csv' DELIMITER ';' CSV;"
Sign up to request clarification or add additional context in comments.

Comments

1

You can setup a cronjob to call a simple command to do this:

psql -c "COPY tbname FROM '/tmp/the_file.csv' delimiter ';' csv;"

as described here:

https://www.postgresql.org/docs/current/app-psql.html

And cronjob some like this:

crontab -e then add 6   2   *   *   *   {command as described}

Comments

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.