pramsey / pgsql-ogr-fdw

PostgreSQL foreign data wrapper for OGR
MIT License
237 stars 34 forks source link

CSV files will only import fields as varchar #233

Closed bowguy closed 2 years ago

bowguy commented 2 years ago

Using ogr_fdw_info on a CSV file gives all the fields as varchar: CREATE SERVER myserver FOREIGN DATA WRAPPER ogr_fdw OPTIONS ( datasource 'alert5min.csv', format 'CSV');

CREATE FOREIGN TABLE alert5min( fid bigint, pstation_shefid varchar, precip_5m varchar, precip_10m varchar, precip_15m varchar, precip_20m varchar, . . which works fine

However the fields precip_5m, etc. are real. If I change the first one to: precip_5m real,

I get the error message: ERROR: column "precip_5m" of foreign table "alert5min" converts OGR "String" to "real" SQL state: HV004

How can I specify the field type? THX

pramsey commented 2 years ago

Look at the OGR documentation on declaring CSV field types via a CSVT file

bowguy commented 2 years ago

Thanks! Suprising thing it even picks up the .csvt file on a remote server via vsicurl