Skip to content

dbListTables now queries for view as well as table names - #29

Closed
currymj wants to merge 1 commit into
r-dbi:masterfrom
currymj:tables_views
Closed

currymj wants to merge 1 commit into
r-dbi:masterfrom
currymj:tables_views

Conversation

@currymj

@currymj currymj commented Apr 4, 2015

Copy link
Copy Markdown

Changes the query for listing tables as per #27.

@bosr

bosr commented Oct 5, 2015

Copy link
Copy Markdown

Hi,

I also need the ability to query views. Could you merge it please?

Thank you!
Regards

Comment thread R/tables.R

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this include temporary tables?

@msjgriffiths

Copy link
Copy Markdown

This query -

SELECT table_name FROM INFORMATION_SCHEMA.tables WHERE table_schema = ANY (current_schemas(false));

.... only gets tables in the current search_path. This might be OK, but I'm not sure we should require users to have the search_path set correctly ahead of time. The current query, which excludes information_schema and pg_catalog, does not rely on the search_path being set; and pulls all schemas that are in the database (excluding the system tables). Reverting to the search_path might be seen as a regression.

For example, running that on a database I'm connecting to (Redshift), I get:

table_name
table_taxonomy

That's a real table, but it's only one of 33 real tables (it's the only table in the public schema, since select current_schemas(false); returns {public}).

I'd suggest instead:

SELECT table_name 
FROM INFORMATION_SCHEMA.tables 
WHERE table_schema not in ('information_schema', 'pg_catalog');

This produces:

table_name
table_taxonomy
table1
table2
table3
...

(for all 33)

This should include views, temporary tables, and tables for all schema.

However, it might break if there are tables/views/etc with duplicate names.

@krlmlr

krlmlr commented Feb 2, 2016

Copy link
Copy Markdown
Member

I'd like to postpone this until schema support is available in DBI (r-dbi/DBI#24).

@krlmlr

krlmlr commented Nov 27, 2017

Copy link
Copy Markdown
Member

Thanks! Implemented a similar version in cc7a835.

@krlmlr krlmlr closed this Nov 27, 2017
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Dec 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants