1

I am new to PostgreSQL and odo. I've created the following: (I am working on Ubuntu).

I've created superuser testuser and with this user (role) I've created postgresql database testuser (by running psql and then CREATE DATABASE testuser;). In this database is a table called testtable. I have no troubles inserting into this database with psycopg2. But I've come across the odo module for python. Since my goal is to load some_file.csv into the postgresql database I thought I would use it. The usage seemed rather straightforward

import odo
odo.odo('some_file.csv', 'postgresql://testuser:<password>@127.0.0.1:5432/testuser::testtable')

But it does not work, and I get

NotImplementedError: Unable to parse uri to data resource: postgresql://testuser:<password>@localhost:5432/testuser 

Note: instead <password> I have the testuser's password.

Maybe it is obvious and I have to implement it.. (as in the last paragraph here), but I thought postgresql is supported (because postgresql is mentioned few times there, with examples). I've tried to look here under Connection URIs, but could not find a mistake. And here is odo documentation.

quapka
  • 2,799
  • 4
  • 21
  • 35
  • Are you trying to insert a CSV file as a single data blob or into a structured table (or multiple tables). Do you understand the basics of RDBMS, do you know the table structure? Do you know the structure of your CSV data (if any)? – roadrunner66 Mar 26 '16 at 19:50
  • Yes, I am trying to insert it in a _single_ step into single table(at least start at that, as I assume that's the basic step). I read somewhere, that `odo` uses COPY command for that. I've created the table, e.g like this "CREATE TABLE testtable(id serial PRIMARY KEY, age integer, name varchar);" and the testing csv looks like this "25, John\n34, Petr",`\n` represents new line. – quapka Mar 26 '16 at 19:54

1 Answers1

2

I have used odo to insert a csv file into postgresql, so it is supported. Your connection URI and code are essentially the same as mine. Do you have the sqlalchemy package installed? I believe odo uses both sqlalchemy and psycopg2 in the background. I was able to replicate your error on a system without sqlalchemy installed, and installing sqlalchemy got me past the error.

root
  • 32,715
  • 6
  • 74
  • 87
  • That might really be it. I did not install sqlalchemy.. I thought I would get the _standard_ import missing error. I'll try that! Thanks – quapka Mar 29 '16 at 07:41
  • I found a similar [issue](https://github.com/blaze/odo/issues/279) on github with the same resolution. It's not specifically related to postgres, but I imagine that the underlying code traces back to the same source for most databases that are implemented. – root Mar 29 '16 at 15:09
  • Ok, thanks. By the way, don't you know, whether conversion from xls->csv works? I don't have it in front of me, but I think i got similar error with `odo('', 'my.csv')`. I feel dumb, since odo seems really easy to use, or is it _too good to be true_? – quapka Mar 30 '16 at 05:55
  • I get a similar `NotImplementedError` trying to convert an xls file, but according to [github](https://github.com/blaze/odo/issues/210) it's actually not implemented in this case, as opposed to just being due to missing packages. – root Mar 30 '16 at 15:15