PostgreSQL.jl icon indicating copy to clipboard operation
PostgreSQL.jl copied to clipboard

OID-related error

Open daniel-perry opened this issue 9 years ago • 1 comments
trafficstars

I have the following database:

https://physionet.org/mimic2/demo/

I can run simple queries fine, when I run a more complicated query like this:

querystr = """select bucket, count(*) from (
select months_between(mimic2v26.admissions.admit_dt::timestamp::date, mimic2v26.d_patients.dob::timestamp::date)/12 from mimic2v26.admissions, mimic2v26.d_patients, 
width_bucket(
months_between(mimic2v26.admissions.admit_dt::timestamp::date,
mimic2v26.d_patients.dob::timestamp::date)/12, 
15, 100, 85) 
as bucket 
where mimic2v26.admissions.subject_id = mimic2v26.d_patients.subject_id 
and 
months_between(mimic2v26.admissions.admit_dt::timestamp::date,
mimic2v26.d_patients.dob::timestamp::date)/12 between 15 and 199
) 
as 
bucket 
group by bucket order by bucket;"""

stmt = prepare(conn, querystr)
result = execute(stmt)

I get the following error:

LoadError: MethodError: `convert` has no method matching convert(::Type{PostgreSQL.PostgresType{Name}}, ::Type{PostgreSQL.OID{2249}})
This may have arisen from a call to the constructor PostgreSQL.PostgresType{Name}(...),
since type constructors fall back to convert methods.
Closest candidates are:
  call{T}(::Type{T}, ::Any)
  convert(::Type{PostgreSQL.PostgresType{Name}}, !Matched::Type{PostgreSQL.OID{16}})
  convert(::Type{PostgreSQL.PostgresType{Name}}, !Matched::Type{Bool})
  ...
while loading In[5], in expression starting on line 17

This query works fine in both psql and via psycopg2.

Digging around it appears OID's are a little used feature of PosgreSQL (http://www.postgresql.org/docs/8.4/interactive/runtime-config-compatible.html#GUC-DEFAULT-WITH-OIDS), which might be why PostgreSQL.jl is having trouble converting a result using OID. But since psycopg2 supports them, I though it was worth opening the issue.

Julia version: Version 0.4.2 (2015-12-06 21:47 UTC)

daniel-perry avatar Feb 18 '16 00:02 daniel-perry

OID's are actually used all over PostgreSQL for many things; in this case, OIDs are being used for denoting the type of the data, which is a very common use. Basically I have no type conversion defined for PostgreSQL's RECORD type (which is itself just a placeholder for the type of any record). I'm not sure if I even have a good idea of what to do with record types off the top of my head.

Eventually I do need to address all OIDs so these problems stop happening. I have been unable to work on PostgreSQL due to other projects dominating my time, but this will change March 1 and I'll devote most of my time to PostgreSQL again. In the meantime, I'm open to PRs if you have an idea on how to deal with RECORD types.

iamed2 avatar Feb 18 '16 04:02 iamed2