Reputation: 53
What is the best way to automatically import CSVs into a remote Postgres server?
I am using a temperature sensor connected to my raspberry Pi to log data (using a python script) into a CSV file:
2013-11-11 23:00:25,27.187
2013-11-11 23:00:31,27.25
2013-11-11 23:00:36,27.25
2013-11-11 23:00:41,27.5
Using the COPY command in psql, I have no problems importing into a table if the CSV file is on the machine running postgres.
How can I import the data directly into a table on my postgres server from my Raspberry Pi?
(In the future, I would like to have my Pi import data autonomously, updating the current table by adding new rows as the Pi logs more data)
Upvotes: 0
Views: 933
Reputation: 36739
As you say, the COPY
command works with a file residing on the database server host. Instead, you should use the \copy
command in psql, which reads the file from the client host. See the man page of psql for details.
Upvotes: 1
Reputation: 1572
Assuming you have network connectivity, you should be able to make a socket connection to PostgreSQL and insert rows into a table as sensor data is collected.
The Connection Settings will need to have listen_addresses set up so that remote clients can connect with it.
Upvotes: 0