From 2e6bb7157f5ccfca96e32adf47d19e5bc9c55e50 Mon Sep 17 00:00:00 2001 From: Paul Ramsey Date: Tue, 12 Dec 2023 15:53:35 -0800 Subject: [PATCH] tests run --- input/pgsql.source | 16 ++++++---------- ogr_fdw.c | 5 ++--- ogr_fdw.h | 25 +++++++++++-------------- 3 files changed, 19 insertions(+), 27 deletions(-) diff --git a/input/pgsql.source b/input/pgsql.source index 140abd3..a7eefe5 100644 --- a/input/pgsql.source +++ b/input/pgsql.source @@ -45,11 +45,10 @@ CREATE FOREIGN TABLE bytea_fdw ( tm time, dttm timestamp, varch char(8), - txtarr text[], yn char ) SERVER pgserver OPTIONS (layer 'bytea_local'); -SELECT fid, name, geom, age, size, value, num, dt, tm, dttm, varch, txtarr, yn FROM bytea_fdw; +SELECT fid, name, geom, age, size, value, num, dt, tm, dttm, varch, yn FROM bytea_fdw; SELECT a.name, b.name FROM bytea_local a @@ -135,9 +134,10 @@ SELECT a.fid, a.name, b.name USING (fid); ---------------------------------------------------------------------- --- Array support +-- Populate local array table + +SET client_min_messages = NOTICE; -DROP TABLE IF EXISTS array_local; CREATE TABLE array_local ( fid integer primary key, geom bytea, @@ -147,18 +147,14 @@ CREATE TABLE array_local ( b boolean[] ); ----------------------------------------------------------------------- --- Populate local table - INSERT INTO array_local (fid,txt, int, flt, b) VALUES (1, ARRAY['Jim'], ARRAY[1,2,3], ARRAY[3.4,5.6,7.8], ARRAY[true,false]), (2, ARRAY['Jim',NULL,'Joe'], ARRAY[1,3,NULL,4], ARRAY[4.5,NULL,3.4], ARRAY[false,NULL]), (3, NULL, NULL, NULL, NULL); ---------------------------------------------------------------------- --- Create remote table +-- Create remote array table -DROP FOREIGN TABLE IF EXISTS array_fdw; CREATE FOREIGN TABLE array_fdw ( fid bigint, geom bytea, @@ -171,7 +167,7 @@ CREATE FOREIGN TABLE array_fdw ( SELECT fid, txt, int, flt, b FROM array_fdw; ---------------------------------------------------------------------- --- Update remote table +-- Update remote array table UPDATE array_fdw SET txt = ARRAY['newJim', 'newJoe'], diff --git a/ogr_fdw.c b/ogr_fdw.c index 01cafeb..a935e68 100644 --- a/ogr_fdw.c +++ b/ogr_fdw.c @@ -1401,7 +1401,6 @@ ogrReadColumnData(OgrFdwState* state) { /* Extra type info needed to form the array */ col.pgisarray = true; - get_typlenbyvalalign(col.pgelmtype, &col.pgtyplen, &col.pgtypbyval, &col.pgtypalign); } else col.pgelmtype = col.pgtype; @@ -1414,9 +1413,9 @@ ogrReadColumnData(OgrFdwState* state) /* Get the PgSQL column name */ #if PG_VERSION_NUM >= 110000 - col.pgname = get_attname(rel->rd_id, att_tuple->attnum, false); + col.pgname = pstrdup(get_attname(rel->rd_id, att_tuple->attnum, false)); #else - col.pgname = get_attname(rel->rd_id, att_tuple->attnum); + col.pgname = pstrdup(get_attname(rel->rd_id, att_tuple->attnum)); #endif /* Handle FID first */ diff --git a/ogr_fdw.h b/ogr_fdw.h index 4540cc7..f04f359 100644 --- a/ogr_fdw.h +++ b/ogr_fdw.h @@ -98,28 +98,25 @@ typedef enum { typedef struct OgrFdwColumn { /* PgSQL metadata */ - int pgattnum; /* PostgreSQL attribute number */ - int pgattisdropped; /* PostgreSQL attribute dropped? */ - char* pgname; /* PostgreSQL column name */ - Oid pgtype; /* PostgreSQL data type */ - int pgtypmod; /* PostgreSQL type modifier */ + int pgattnum; /* PgSQL attribute number */ + int pgattisdropped; /* PgSQL attribute dropped? */ + char* pgname; /* PgSQL column name */ + Oid pgtype; /* PgQL data type */ + int pgtypmod; /* PgSQL type modifier */ bool pgisarray; Oid pgelmtype; /* If column is array then this is nonzero */ - int16 pgtyplen; - bool pgtypbyval; - char pgtypalign; - /* For reading */ - Oid pginputfunc; /* PostgreSQL function to convert cstring to type */ + /* For reading. If array, for array element type. */ + Oid pginputfunc; /* PgSQL convert cstring to type */ Oid pginputioparam; - Oid pgrecvfunc; /* PostgreSQL function to convert binary to type */ + Oid pgrecvfunc; /* PgSQL convert binary to type */ Oid pgrecvioparam; - /* For writing */ - Oid pgoutputfunc; /* PostgreSQL function to convert type to cstring */ + /* For writing. If array, for array element type. */ + Oid pgoutputfunc; /* PgSQL convert type to cstring */ bool pgoutputvarlena; - Oid pgsendfunc; /* PostgreSQL function to convert type to binary */ + Oid pgsendfunc; /* PgSQL convert type to binary */ bool pgsendvarlena; /* OGR metadata */