Skip to content

docs: Show how to find tables in a non-default schema - #675

Merged
krlmlr merged 6 commits into
mainfrom
claude/review-583
Nov 29, 2026
Merged

krlmlr merged 6 commits into
mainfrom
claude/review-583

Conversation

@krlmlr

@krlmlr krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

Closes #399.

This PR documents the two existing ways to find tables in a schema other than public. Its content comes from #583 by LeonidasZhak: their two commits are cherry-picked here with their authorship intact, and our own commits on top fix the findings of the review of #583. Kirill asked for this: "Take the contents to this PR and fix findings."

Changes

  • ?postgres-tables, section "Schemas, catalogs, tablespaces" (R/tables.R):
    • It points to dbListObjects(conn, Id(schema = )) for listing the tables in one schema, and to dbExistsTable(conn, Id(schema = , table = )) for checking a single table.
    • It explains that dbListTables() lists the tables in all schemas on the search path except pg_catalog, temporary tables included.
    • It shows options = "-c search_path=my_schema,public" in dbConnect(). It also says that this replaces the default path, that a schema that does not exist is skipped silently, and how to quote a schema name.
    • For servers that reject options, such as some connection poolers, it names SET search_path as the alternative.
  • The ?postgres-tables example gains the only full walk-through. It creates a schema with a unique name (basename(tempfile())), quotes it with dbQuoteIdentifier(), lists the schema's tables both ways, and removes only the table and schema it created, with no CASCADE.
  • ?Postgres gains a short "Schemas" section that links to ?postgres-tables. Its dbConnect() example and its ... parameter are unchanged from main, so ?Redshift, which inherits ..., makes no claim about options on Redshift.
  • tests/testthat/test-dbConnect.R gets one test. It checks dbListObjects() with a schema prefix and dbListTables() on connections with search_path=<schema> and search_path=<schema>,public. Cleanup uses withr::defer(), and the test prints no server notices.

Review findings on #583 and how they were addressed

  • Medium, the path is replaced and not extended: the example now keeps public, and the docs say so.
  • Medium, the example appeared three times: it now appears once, and ?Postgres links to it.
  • Medium, the Redshift claim was unverified: it is dropped from the inherited ... text, and options is described as rejected by some servers, such as connection poolers.
  • Low, paste0() with a raw schema name: the example now uses dbQuoteIdentifier(), and the docs explain how to escape spaces.
  • Low, DROP SCHEMA ... CASCADE on a fixed name: the example now uses a unique name and drops only what it created.
  • Low, the test: it is slimmed, as decided.
  • Low, no semantic line breaks: the new roxygen now uses them.

Checks

Run locally against PostgreSQL 16: devtools::document() (the Rd files are in sync, and man/Redshift.Rd is identical to main), air format, and both example("postgres-tables") and example("Postgres"). Both examples run cleanly and leave no schema behind. devtools::test(filter = "dbConnect") gives 13 passed and 0 failed. A clean review found nothing above Low, and its Lows are applied. Quoting was checked by hand: a schema named My Schema works with options = "-c search_path=\"My\\ Schema\",public", and so does SET search_path. A full R CMD check has not been run, and nothing was verified against Redshift. See Accepted limitations.

Open question: what to tell the contributor on #583. Resolved: how to proceed, keep the test.


https://claude.ai/code/session_01Hr1rd6e5NcxC9GSrNJDokc


Generated by Claude Code

krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member Author

Resolved: How to proceed with #583?

#583 documents the two existing ways to find tables in a non-default schema: dbListObjects(con, Id(schema = )) and options = "-c search_path=...". Its claims check out against main and on PostgreSQL 16. It does have problems, though: it shows the same example three times, it does not say that search_path=myschema hides public, it puts an unverified claim into the inherited ?Redshift docs, and its roxygen does not use semantic line breaks (findings 1-7 in the PR body). The contributor last asked a question there about the format-suggest failure, and nobody answered. That failure is fixed on main.

Kirill has the say. If nobody decides, #583 stays open and unanswered, and so does the contributor's CI question from October.


Generated by Claude Code

krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member Author

Resolved: What to tell the contributor on #583?

Nothing has been posted on #583. Following the "how to proceed" decision, #583's two commits were cherry-picked into #675 with their authorship intact, and the findings were fixed in commits on top. Here is a draft for Kirill to post (or edit) on #583 once #675 merges:

Thank you for picking up #399, and sorry for the slow reply! The content was accurate, so I took your two commits, with you as their author, into #675 and made a few changes on top:

- `-c search_path=myschema` replaces the search path, so the example now uses `myschema,public` to keep the tables in `public` visible.
- The full example now lives only in `?postgres-tables`, and `?Postgres` links to it. This also keeps the claim out of the `...` parameter that `?Redshift` inherits.
- The example quotes the schema with `dbQuoteIdentifier()`, creates a uniquely named schema, and removes only what it created.
- The roxygen uses semantic line breaks, and the test is shorter.

The `format-suggest` failure here was a problem in our workflow, and it has been fixed on `main` since. I'm closing this in favor of #675. Thanks again!

Kirill asked in chat (relayed): "Post everything that needs posting". Posted on #583 with "which is now merged" added, and #583 closed.


Generated by Claude Code

krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member Author

Resolved: Keep the new test from #583?

The test at test-dbConnect.R L57-L102 passes, and it is self-contained. However, its search_path half tests libpq and the server rather than RPostgres code, and 20 of its 46 lines are an on.exit() cleanup. It also prints two server NOTICEs into the test output. Its dbListObjects() half does cover an RPostgres code path (the schema-prefix branch of dbListObjects_PqConnection_ANY()).

  • Keep a slimmed version (recommended): only the dbListObjects() prefix check plus one dbListTables() check, with withr::defer() for cleanup, possibly moved to a test file about table listing. This costs about 15 lines.
  • Drop it: a docs PR then stays docs-only, and the examples run in R CMD check anyway wherever a database is available.
  • Keep it as is.

Kirill has the say. If nobody decides, the recommendation goes into the request to the contributor.


Generated by Claude Code

@krlmlr

krlmlr commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Take the contents to this PR and fix findings.

LeonidasZhak and others added 4 commits November 29, 2026 19:33
…s the path

Keeps the full example in `?postgres-tables` only and links to it from `?Postgres`.
The `search_path` example keeps `public`,
quotes the schema with `dbQuoteIdentifier()`,
and the claim stays out of the `...` parameter that `?Redshift` inherits.
The example creates a schema with a unique name and removes only what it created.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd6e5NcxC9GSrNJDokc
Cleans up with `withr::defer()`, creates a uniquely named schema without a preceding `DROP`,
and removes only what it created, so the test prints no server notices.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd6e5NcxC9GSrNJDokc
@krlmlr krlmlr changed the title chore: Review #583 docs: Show how to find tables in a non-default schema Nov 29, 2026
…ic` form

Says that `dbListTables()` skips `pg_catalog`,
and covers `search_path=<schema>,public` in the test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd6e5NcxC9GSrNJDokc

krlmlr commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Accepted limitations

  • R/tables.R L16-L23: options = "-c search_path=..." was not checked on Redshift, because no cluster was available. The text therefore makes no Redshift claim, and the inherited ?Redshift docs are unchanged from main. Relevance: low, since Redshift users fall back to SET search_path. Confidence: high that the docs claim nothing unverified.
  • Checks for this PR: a full R CMD check was not run locally. Only devtools::document(), air format, both man examples, and test-dbConnect.R were run against PostgreSQL 16; CI runs the full check. Relevance: low. Confidence: high.

Generated by Claude Code

@krlmlr
krlmlr merged commit ab7e713 into main Nov 29, 2026
9 checks passed
@krlmlr
krlmlr deleted the claude/review-583 branch November 29, 2026 19:53
krlmlr pushed a commit that referenced this pull request Nov 29, 2026
…-dir

Keep both the "Default host" section from this branch and the "Schemas" section from #675 in ?Postgres.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd6e5NcxC9GSrNJDokc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

List tables in schema with dbListTables

3 participants