Skip to content

Conversation

shivampr
Copy link
Contributor

@shivampr shivampr commented Aug 18, 2025

Description

The .tables command shows confusing output when tables have the same name in different schemas - it just displays the table name twice without indicating which schema each belongs to.

What I Did

I modified the .tables command in tools/shell/shell.cpp to:

  1. Use DuckDB's system tables instead of SQLite's sqlite_schema to get schema information
  2. Detect name conflicts - when the same table name exists in multiple schemas, show schema.table format
  3. Add schema filtering - support patterns like .tables a.% to filter by schema
  4. Keep backward compatibility - when no conflicts exist, show simple table names as before

How I Tested

  • Built and tested manually - verified the feature works with the exact scenario from the issue
  • Added comprehensive tests in tools/shell/tests/test_shell_basics.py covering:
    • Schema disambiguation (core feature)
    • Schema filtering (new capability)
    • Backward compatibility (existing behavior preserved)
    • Views support (tables + views)
  • Ran all tests - both new and existing tests pass
  • Tested edge cases - mixed schemas, pattern filtering, etc.

Fixes #13603

- Replace sqlite_schema with duckdb_tables/duckdb_views for schema awareness
- Implement schema disambiguation: show schema.table when names conflict
- Add schema-qualified filtering support (e.g., .tables a.%)
- Maintain backward compatibility for non-conflicting scenarios
- Include comprehensive test coverage for new functionality

Fixes duckdb#13603
@hannes
Copy link
Member

hannes commented Aug 18, 2025

This looks great, thanks a a lot!

- Run make format-fix to apply clang-format and black formatting

Part of duckdb#13603
@shivampr
Copy link
Contributor Author

shivampr commented Aug 20, 2025

Thanks @hannes 🙏
The previous approval workflow failed because I missed to run make format-fix (I’m a first-time contributor).
Would you mind helping me re-run the approval workflows and guiding me on how to get it committed if everything looks good?

@duckdb-draftbot duckdb-draftbot marked this pull request as draft August 20, 2025 06:57
@Mytherin Mytherin marked this pull request as ready for review August 20, 2025 06:58
Replace manual string parsing with QualifiedName::ParseComponents to support quoted identifiers and add proper error handling for invalid patterns.
@duckdb-draftbot duckdb-draftbot marked this pull request as draft August 25, 2025 07:35
@Mytherin Mytherin marked this pull request as ready for review August 25, 2025 07:35
@Mytherin Mytherin merged commit c393695 into duckdb:main Aug 26, 2025
59 of 69 checks passed
@Mytherin
Copy link
Collaborator

Thanks!

krlmlr added a commit to krlmlr/duckdb-r that referenced this pull request Aug 26, 2025
Add (CSV) file logger (duckdb/duckdb#17692)
feat: enhance .tables command with schema disambiguation and filtering (duckdb/duckdb#18641)
krlmlr added a commit to krlmlr/duckdb-r that referenced this pull request Aug 27, 2025
Add (CSV) file logger (duckdb/duckdb#17692)
feat: enhance .tables command with schema disambiguation and filtering (duckdb/duckdb#18641)
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.

.tables doesn't include catalog/database and schema name
3 participants