pg.ddx.io pgsql-odbc@postgresql.org mailing list archive
help / color / mirror / Atom feedrelkind check in info.c
5+ messages / 3 participants
[nested] [flat]
* relkind check in info.c
@ 2014-03-18 18:39 Alvaro Herrera <alvherre@2ndquadrant.com>
0 siblings, 1 reply; 5+ messages in thread
From: Alvaro Herrera @ 2014-03-18 18:39 UTC (permalink / raw)
To: pgsql-odbc
Hi,
I see that PGAPI_Tables() has a relkind check that only seems to include
tables and views. Does it make sense to have it consider materialized
views as well?
I don't know anything about psqlodbc -- I'm just going by a question in
the spanish list:
http://www.postgresql.org/message-id/53287159.7040009@gmail.com
--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: relkind check in info.c
@ 2014-03-18 23:07 Michael Paquier <michael.paquier@gmail.com>
parent: Alvaro Herrera <alvherre@2ndquadrant.com>
0 siblings, 1 reply; 5+ messages in thread
From: Michael Paquier @ 2014-03-18 23:07 UTC (permalink / raw)
To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: pgsql-odbc
On Wed, Mar 19, 2014 at 3:39 AM, Alvaro Herrera
<alvherre@2ndquadrant.com> wrote:
> Hi,
>
> I see that PGAPI_Tables() has a relkind check that only seems to include
> tables and views. Does it make sense to have it consider materialized
> views as well?
>
> I don't know anything about psqlodbc -- I'm just going by a question in
> the spanish list:
> http://www.postgresql.org/message-id/53287159.7040009@gmail.com
Yeah, it would make sense to list it by adding 'm' to the relkind
queries. I am noting as well that we should list it when invocating
SQL_ALL_TABLE_TYPES. A patch to do that is simple, and not worth an
additional regression test IMO, just to avoid the pain to have
version-related regression tests...
Regards,
--
Michael
--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: relkind check in info.c
@ 2014-03-18 23:17 Michael Paquier <michael.paquier@gmail.com>
parent: Michael Paquier <michael.paquier@gmail.com>
0 siblings, 1 reply; 5+ messages in thread
From: Michael Paquier @ 2014-03-18 23:17 UTC (permalink / raw)
To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: pgsql-odbc
On Wed, Mar 19, 2014 at 8:07 AM, Michael Paquier
<michael.paquier@gmail.com> wrote:
> On Wed, Mar 19, 2014 at 3:39 AM, Alvaro Herrera
> <alvherre@2ndquadrant.com> wrote:
>> Hi,
>>
>> I see that PGAPI_Tables() has a relkind check that only seems to include
>> tables and views. Does it make sense to have it consider materialized
>> views as well?
>>
>> I don't know anything about psqlodbc -- I'm just going by a question in
>> the spanish list:
>> http://www.postgresql.org/message-id/53287159.7040009@gmail.com
>
> Yeah, it would make sense to list it by adding 'm' to the relkind
> queries. I am noting as well that we should list it when invocating
> SQL_ALL_TABLE_TYPES. A patch to do that is simple, and not worth an
> additional regression test IMO, just to avoid the pain to have
> version-related regression tests...
Just adding that a similar thing should be done with foreign tables.
--
Michael
--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: relkind check in info.c
@ 2014-05-14 13:46 Heikki Linnakangas <hlinnakangas@vmware.com>
parent: Michael Paquier <michael.paquier@gmail.com>
0 siblings, 1 reply; 5+ messages in thread
From: Heikki Linnakangas @ 2014-05-14 13:46 UTC (permalink / raw)
To: Michael Paquier <michael.paquier@gmail.com>; Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: pgsql-odbc
On 03/19/2014 01:17 AM, Michael Paquier wrote:
> On Wed, Mar 19, 2014 at 8:07 AM, Michael Paquier
> <michael.paquier@gmail.com> wrote:
>> On Wed, Mar 19, 2014 at 3:39 AM, Alvaro Herrera
>> <alvherre@2ndquadrant.com> wrote:
>>> Hi,
>>>
>>> I see that PGAPI_Tables() has a relkind check that only seems to include
>>> tables and views. Does it make sense to have it consider materialized
>>> views as well?
>>>
>>> I don't know anything about psqlodbc -- I'm just going by a question in
>>> the spanish list:
>>> http://www.postgresql.org/message-id/53287159.7040009@gmail.com
>>
>> Yeah, it would make sense to list it by adding 'm' to the relkind
>> queries. I am noting as well that we should list it when invocating
>> SQL_ALL_TABLE_TYPES. A patch to do that is simple, and not worth an
>> additional regression test IMO, just to avoid the pain to have
>> version-related regression tests...
> Just adding that a similar thing should be done with foreign tables.
We need to decide to what to return in the table_type column for them.
"FOREIGN TABLE" and "MATERIALIZED VIEW" would be natural choices.
But it would be good to return the same string that other DBMS's return
for those things. What does SQL Server's driver return for materialized
views? I'm not aware of any other DBMS that implements foreign tables
per the spec, but e.g DB2 has "remote tables" and Oracle has "database
links", which are similar features. I wonder what table type do they return.
- Heikki
--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: relkind check in info.c
@ 2014-05-15 07:41 Michael Paquier <michael.paquier@gmail.com>
parent: Heikki Linnakangas <hlinnakangas@vmware.com>
0 siblings, 0 replies; 5+ messages in thread
From: Michael Paquier @ 2014-05-15 07:41 UTC (permalink / raw)
To: Heikki Linnakangas <hlinnakangas@vmware.com>; +Cc: Alvaro Herrera <alvherre@2ndquadrant.com>; pgsql-odbc
On Wed, May 14, 2014 at 10:46 PM, Heikki Linnakangas
<hlinnakangas@vmware.com> wrote:
> We need to decide to what to return in the table_type column for them.
> "FOREIGN TABLE" and "MATERIALIZED VIEW" would be natural choices.
This choice makes sense.
> But it would be good to return the same string that other DBMS's return for
> those things. What does SQL Server's driver return for materialized views?
> I'm not aware of any other DBMS that implements foreign tables per the spec,
> but e.g DB2 has "remote tables" and Oracle has "database links", which are
> similar features. I wonder what table type do they return.
Poking a little bit that, I finished with the patch attached, with
some regression tests attached. It may not be the most beautiful patch
ever, but it is consistent with the current way code is made and it
has the merit to be simple.
Regards,
--
Michael
--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc
Attachments:
0001-Add-support-for-foreign-tables-and-matviews.patch (text/plain, 8.1K) download
From f4481b14eea23621344e97d62e2133778ebba396 Mon Sep 17 00:00:00 2001
From: Michael Paquier <michael@otacoo.com>
Date: Thu, 15 May 2014 16:38:28 +0900
Subject: [PATCH] Add support for foreign tables and matviews in SQLTables
Regression tests are added in consequence.
---
info.c | 66 +++++++++++++++++++++++++++++++++-----
test/expected/catalogfunctions.out | 7 ++++
test/expected/sampletables.out | 8 +++++
test/sql/sampletables.sql | 11 +++++++
4 files changed, 84 insertions(+), 8 deletions(-)
diff --git a/info.c b/info.c
index 81bfe6d..958e23d 100644
--- a/info.c
+++ b/info.c
@@ -1470,6 +1470,8 @@ mylog("adjust output=%s(%d)\n", dest, outlen);
#define CSTR_SYS_TABLE "SYSTEM TABLE"
#define CSTR_TABLE "TABLE"
#define CSTR_VIEW "VIEW"
+#define CSTR_FOREIGN_TABLE "FOREIGN TABLE"
+#define CSTR_MATVIEW "MATVIEW"
CSTR like_op_sp = "like ";
CSTR like_op_ext = "like E";
@@ -1546,9 +1548,13 @@ PGAPI_Tables(HSTMT hstmt,
int nprefixes;
char show_system_tables,
show_regular_tables,
- show_views;
+ show_views,
+ show_matviews,
+ show_foreign_tables;
char regular_table,
view,
+ matview,
+ foreign_table,
systable;
int i;
SQLSMALLINT internal_asis_type = SQL_C_CHAR, cbSchemaName;
@@ -1626,7 +1632,19 @@ retry_public_schema:
if (list_cat)
strncpy_null(tables_query, "select NULL, NULL, NULL", sizeof(tables_query));
else if (list_table_types)
- strncpy_null(tables_query, "select NULL, NULL, relkind from (select 'r' as relkind union select 'v') as a", sizeof(tables_query));
+ {
+ /*
+ * Query relations depending on what is available:
+ * - 9.3 and newer versions have materialized views
+ * - 9.1 and newer versions have foreign tables
+ */
+ strncpy_null(tables_query,
+ "select NULL, NULL, relkind from (select 'r' as relkind "
+ "union select 'v' "
+ "union select 'm' "
+ "union select 'f') as a",
+ sizeof(tables_query));
+ }
else if (list_schemas)
{
if (conn->schema_support)
@@ -1637,10 +1655,15 @@ retry_public_schema:
}
else if (conn->schema_support)
{
- /* view is represented by its relkind since 7.1 */
- strcpy(tables_query, "select relname, nspname, relkind"
- " from pg_catalog.pg_class c, pg_catalog.pg_namespace n");
- strcat(tables_query, " where relkind in ('r', 'v')");
+ /*
+ * View is represented by its relkind since 7.1,
+ * Materialized views are added in 9.3, and foreign
+ * tables in 9.1.
+ */
+ strncpy_null(tables_query, "select relname, nspname, relkind "
+ "from pg_catalog.pg_class c, pg_catalog.pg_namespace n "
+ "where relkind in ('r', 'v', 'm', 'f')",
+ sizeof(tables_query));
}
else if (PG_VERSION_GE(conn, 7.1))
{
@@ -1698,18 +1721,24 @@ retry_public_schema:
show_system_tables = FALSE;
show_regular_tables = FALSE;
show_views = FALSE;
+ show_foreign_tables = FALSE;
+ show_matviews = FALSE;
/* TABLE_TYPE */
if (!tableType)
{
show_regular_tables = TRUE;
show_views = TRUE;
+ show_foreign_tables = TRUE;
+ show_matviews = TRUE;
}
#if (ODBCVER >= 0x0300)
else if (list_some || stricmp(tableType, SQL_ALL_TABLE_TYPES) == 0)
{
show_regular_tables = TRUE;
show_views = TRUE;
+ show_foreign_tables = TRUE;
+ show_matviews = TRUE;
}
#endif /* ODBCVER */
else
@@ -1739,6 +1768,10 @@ retry_public_schema:
show_regular_tables = TRUE;
else if (strnicmp(typestr, CSTR_VIEW, strlen(CSTR_VIEW)) == 0)
show_views = TRUE;
+ else if (strnicmp(typestr, CSTR_FOREIGN_TABLE, strlen(CSTR_FOREIGN_TABLE)) == 0)
+ show_foreign_tables = TRUE;
+ else if (strnicmp(typestr, CSTR_MATVIEW, strlen(CSTR_MATVIEW)) == 0)
+ show_matviews = TRUE;
}
}
@@ -1902,10 +1935,13 @@ retry_public_schema:
else
view = (relkind_or_hasrules[0] == '1');
+ /* Check for foreign tables and materialized views ... */
+ foreign_table = (relkind_or_hasrules[0] == 'f');
+ matview = (relkind_or_hasrules[0] == 'm');
+
/* It must be a regular table */
regular_table = (!systable && !view);
-
/* Include the row in the result set if meets all criteria */
/*
@@ -1914,6 +1950,8 @@ retry_public_schema:
*/
if ((systable && show_system_tables) ||
(view && show_views) ||
+ (foreign_table && show_foreign_tables) ||
+ (matview && show_matviews) ||
(regular_table && show_regular_tables))
{
tuple = QR_AddNew(res);
@@ -1943,7 +1981,19 @@ retry_public_schema:
else
set_tuplefield_string(&tuple[TABLES_TABLE_NAME], table_name);
if (list_table_types || !list_some)
- set_tuplefield_string(&tuple[TABLES_TABLE_TYPE], systable ? "SYSTEM TABLE" : (view ? "VIEW" : "TABLE"));
+ {
+ char buffer[64];
+ if (systable)
+ set_tuplefield_string(&tuple[TABLES_TABLE_TYPE], CSTR_SYS_TABLE);
+ else if (view)
+ set_tuplefield_string(&tuple[TABLES_TABLE_TYPE], CSTR_VIEW);
+ else if (matview)
+ set_tuplefield_string(&tuple[TABLES_TABLE_TYPE], CSTR_MATVIEW);
+ else if (foreign_table)
+ set_tuplefield_string(&tuple[TABLES_TABLE_TYPE], CSTR_FOREIGN_TABLE);
+ else
+ set_tuplefield_string(&tuple[TABLES_TABLE_TYPE], CSTR_TABLE);
+ }
else
set_tuplefield_null(&tuple[TABLES_TABLE_TYPE]);
set_tuplefield_string(&tuple[TABLES_REMARKS], NULL_STRING);
diff --git a/test/expected/catalogfunctions.out b/test/expected/catalogfunctions.out
index dba7d55..88c3290 100644
--- a/test/expected/catalogfunctions.out
+++ b/test/expected/catalogfunctions.out
@@ -34,6 +34,8 @@ Result set:
contrib_regression public booltab TABLE
contrib_regression public byteatab TABLE
contrib_regression public intervaltable TABLE
+contrib_regression public testforeign FOREIGN TABLE
+contrib_regression public testmatview MATVIEW
contrib_regression public testtab1 TABLE
contrib_regression public testtab_fk TABLE
Check for SQLColumns
@@ -72,11 +74,16 @@ contrib_regression public byteatab t -3 bytea
contrib_regression public intervaltable id 4 int4
contrib_regression public intervaltable iv 12 interval
contrib_regression public intervaltable d 12 varchar
+contrib_regression public testforeign c1 4 int4
+contrib_regression public testmatview id 4 int4
+contrib_regression public testmatview t 12 varchar
contrib_regression public testtab1 id 4 int4
contrib_regression public testtab1 t 12 varchar
contrib_regression public testtab1_pkey id 4 int4
contrib_regression public testtab_fk id 4 int4
contrib_regression public testtab_fk t 12 varchar
+contrib_regression public testview id 4 int4
+contrib_regression public testview t 12 varchar
Check for SQLSpecialColumns
Result set metadata:
SCOPE: SMALLINT(5) digits: 0, nullable
diff --git a/test/expected/sampletables.out b/test/expected/sampletables.out
index e4fcb71..7af70b9 100644
--- a/test/expected/sampletables.out
+++ b/test/expected/sampletables.out
@@ -23,6 +23,14 @@ INSERT INTO booltab VALUES (2, 'yes', true);
INSERT INTO booltab VALUES (3, 'true', true);
INSERT INTO booltab VALUES (4, 'false', false);
INSERT INTO booltab VALUES (5, 'not', false);
+-- View
+CREATE VIEW testview AS SELECT * FROM testtab1;
+-- Materialized view
+CREATE MATERIALIZED VIEW testmatview AS SELECT * FROM testtab1;
+-- Foreign table
+CREATE FOREIGN DATA WRAPPER testfdw;
+CREATE SERVER testserver FOREIGN DATA WRAPPER testfdw;
+CREATE FOREIGN TABLE testforeign (c1 int) SERVER testserver;
-- Procedure for catalog function checks
CREATE FUNCTION simple_add(in int, in int, out int)
AS $$ SELECT $1 + $2;
diff --git a/test/sql/sampletables.sql b/test/sql/sampletables.sql
index a917de7..94684f3 100644
--- a/test/sql/sampletables.sql
+++ b/test/sql/sampletables.sql
@@ -29,6 +29,17 @@ INSERT INTO booltab VALUES (3, 'true', true);
INSERT INTO booltab VALUES (4, 'false', false);
INSERT INTO booltab VALUES (5, 'not', false);
+-- View
+CREATE VIEW testview AS SELECT * FROM testtab1;
+
+-- Materialized view
+CREATE MATERIALIZED VIEW testmatview AS SELECT * FROM testtab1;
+
+-- Foreign table
+CREATE FOREIGN DATA WRAPPER testfdw;
+CREATE SERVER testserver FOREIGN DATA WRAPPER testfdw;
+CREATE FOREIGN TABLE testforeign (c1 int) SERVER testserver;
+
-- Procedure for catalog function checks
CREATE FUNCTION simple_add(in int, in int, out int)
AS $$ SELECT $1 + $2;
--
1.9.3
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2014-05-15 07:41 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2014-03-18 18:39 relkind check in info.c Alvaro Herrera <alvherre@2ndquadrant.com>
2014-03-18 23:07 ` Michael Paquier <michael.paquier@gmail.com>
2014-03-18 23:17 ` Michael Paquier <michael.paquier@gmail.com>
2014-05-14 13:46 ` Heikki Linnakangas <hlinnakangas@vmware.com>
2014-05-15 07:41 ` Michael Paquier <michael.paquier@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox