Skip to content

Commit

Permalink
Add JSON support in hopes of reading Overture data
Browse files Browse the repository at this point in the history
  • Loading branch information
pramsey committed Oct 31, 2024
1 parent 2ba5f72 commit e22a6f9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ogr_fdw.c
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,7 @@ ogrCanConvertToPg(OGRFieldType ogr_type, Oid pg_type)
{OFTInteger, {BOOLOID, INT4OID, INT8OID, NUMERICOID, FLOAT4OID, FLOAT8OID, TEXTOID, VARCHAROID, 0}},
{OFTReal, {NUMERICOID, FLOAT4OID, FLOAT8OID, TEXTOID, VARCHAROID, 0}},
{OFTBinary, {BYTEAOID, 0}},
{OFTString, {TEXTOID, VARCHAROID, CHAROID, BPCHAROID, 0}},
{OFTString, {TEXTOID, VARCHAROID, CHAROID, BPCHAROID, JSONBOID, JSONOID, 0}},
{OFTDate, {DATEOID, TIMESTAMPOID, TEXTOID, VARCHAROID, 0}},
{OFTTime, {TIMEOID, TEXTOID, VARCHAROID, 0}},
{OFTDateTime, {TIMESTAMPOID, TEXTOID, VARCHAROID, 0}},
Expand Down
16 changes: 14 additions & 2 deletions ogr_fdw_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,15 @@ static void
ogrTypeToPgType(OGRFieldDefnH ogr_fld, char *pgtype, size_t width)
{
OGRFieldType ogr_type = OGR_Fld_GetType(ogr_fld);
#if GDAL_VERSION_MAJOR >= 2
OGRFieldSubType ogr_subtype = OGR_Fld_GetSubType(ogr_fld);
#endif

switch(ogr_type)
{
case OFTInteger:
#if GDAL_VERSION_MAJOR >= 2
if( OGR_Fld_GetSubType(ogr_fld) == OFSTBoolean )
if (ogr_subtype == OFSTBoolean)
{
snprintf(pgtype, width, "boolean");
break;
Expand All @@ -109,7 +113,15 @@ ogrTypeToPgType(OGRFieldDefnH ogr_fld, char *pgtype, size_t width)
break;
case OFTString:
{
int ogr_fld_width = OGR_Fld_GetWidth(ogr_fld);
int ogr_fld_width;
#if GDAL_VERSION_MAJOR >= 2
if (ogr_subtype == OFSTJSON)
{
snprintf(pgtype, width, "jsonb");
break;
}
#endif
ogr_fld_width = OGR_Fld_GetWidth(ogr_fld);
if (ogr_fld_width > 0)
snprintf(pgtype, width, "varchar(%d)", ogr_fld_width);
else
Expand Down

0 comments on commit e22a6f9

Please sign in to comment.