Skip to content

Fix: ALL_TAB_COLUMNS view implementation#1336

Merged
gaoxueyu merged 14 commits into
IvorySQL:masterfrom
Adria0615:fix-all-tab-columns
May 16, 2026
Merged

Fix: ALL_TAB_COLUMNS view implementation#1336
gaoxueyu merged 14 commits into
IvorySQL:masterfrom
Adria0615:fix-all-tab-columns

Conversation

@Adria0615
Copy link
Copy Markdown
Contributor

@Adria0615 Adria0615 commented May 13, 2026

fix #1009
This PR completes the implementation of the ALL_TAB_COLUMNS view in the Oracle compatibility layer, addressing key issues identified in the review process.

Changes

  • Updated view definition: Corrected column type mappings, added missing metadata fields (e.g., DATA_TYPE, COLUMN_ID), and fixed boundary cases for NULL values and partition tables.
  • Updated test cases: Refreshed the expected output file (ora_sysview.out) to match the corrected view behavior, ensuring test suite compatibility.
  • Refined SQL implementation: Adjusted the view's query logic to align with Oracle's behavior for data dictionary views.

Verification

  • All changes are limited to the contrib/ivorysql_ora Oracle compatibility module.
  • The PR passes basic merge checks, with no conflicts against the master branch.
  • The implementation maintains consistency with IvorySQL's Oracle compatibility goals.

Related

Closes the remaining implementation requirements for the ALL_TAB_COLUMNS view as part of the Oracle compatibility project.

Summary by CodeRabbit

  • New Features

    • Added an Oracle‑compatible system catalog view that exposes comprehensive table‑column metadata (including types, sizes, defaults, identity and basic statistics) with public read access.
  • Tests

    • Added regression tests that create and analyze a sample table, validate detailed column‑metadata queries and ordering, and confirm expected error handling for unsupported metadata fields.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 13, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds an Oracle-compatible catalog view SYS.ALL_TAB_COLUMNS that exposes per-column metadata derived from PostgreSQL catalogs, plus a regression test and expected-output section that validates the view's projection and asserts an invalid-identifier error for COLLATION_NAME.

Changes

SYS.ALL_TAB_COLUMNS View Implementation

Layer / File(s) Summary
SYS.ALL_TAB_COLUMNS view definition
contrib/ivorysql_ora/src/sysview/sysview--1.0.sql
Creates SYS.ALL_TAB_COLUMNS projecting Oracle-style column attributes (owner/table/column identity, data type and length/precision/scale derivations, nullability, data_default via pg_get_expr and its octet length, stats via pg_stats, character-set/char-length fields, identity_column from pg_attribute.attidentity, and several compatibility columns). Sources: pg_class/pg_namespace/pg_attribute/pg_type; uses LEFT JOIN LATERAL on pg_attrdef; applies relation/attribute filters and has_table_privilege; grants SELECT to PUBLIC.
Regression test script
contrib/ivorysql_ora/sql/ora_sysview.sql
Adds TEST_ALL_TAB_COLUMNS fixture (representative columns including NOT NULL), runs ANALYZE, queries SYS.ALL_TAB_COLUMNS for that table/owner selecting many metadata columns ordered by COLUMN_ID, temporarily disables ON_ERROR_STOP to assert an “invalid identifier” error when selecting COLLATION_NAME, and drops the test table.
Expected test outputs
contrib/ivorysql_ora/expected/ora_sysview.out
Adds -- ALL_TAB_COLUMNS expected-output block: prepares and cleans up TEST_ALL_TAB_COLUMNS, includes the metadata-query expected output (empty result shown), asserts the invalid-identifier error for COLLATION_NAME, and documents cleanup.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested reviewers

  • bigplaice

Poem

🐰 By moonlit stacks I hopped and wrote,
Columns counted, types I note,
Defaults hummed soft in catalog rows,
Stats and lengths in tidy rows,
ALL_TAB_COLUMNS — sleep, I quote.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly describes the main change—implementing the ALL_TAB_COLUMNS view—which aligns with the primary objective of this PR.
Linked Issues check ✅ Passed The PR implementation adds the ALL_TAB_COLUMNS view with comprehensive column metadata, column IDs, proper data-type mappings, and access control, addressing all coding requirements from issue #1009.
Out of Scope Changes check ✅ Passed All changes are confined to contrib/ivorysql_ora and directly support the ALL_TAB_COLUMNS implementation, with no unrelated modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@contrib/ivorysql_ora/sql/ora_sysview.sql`:
- Around line 216-260: The current test mixes a negative "invalid identifier"
check for COLLATION_NAME into the positive assertion that queries
SYS.ALL_TAB_COLUMNS for TEST_ALL_TAB_COLUMNS, so the whole block fails to
validate real column data; remove COLLATION_NAME from the SELECT list in the
successful assertion (the SELECT that lists COLUMN_ID, DATA_TYPE, NULLABLE,
DATA_DEFAULT, etc. and ends with ORDER BY COLUMN_ID) so it returns a valid
result set, and add a separate negative test that intentionally selects
COLLATION_NAME from SYS.ALL_TAB_COLUMNS (targeting TABLE_NAME =
'TEST_ALL_TAB_COLUMNS') asserting it raises an invalid identifier error.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 26e7e03a-d42f-4085-bed8-f9c50ff2662c

📥 Commits

Reviewing files that changed from the base of the PR and between 35e086c and c5bd7a0.

📒 Files selected for processing (3)
  • contrib/ivorysql_ora/expected/ora_sysview.out
  • contrib/ivorysql_ora/sql/ora_sysview.sql
  • contrib/ivorysql_ora/src/sysview/sysview--1.0.sql

Comment thread contrib/ivorysql_ora/sql/ora_sysview.sql
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
contrib/ivorysql_ora/expected/ora_sysview.out (1)

345-403: 🏗️ Heavy lift

Add positive test case to validate ALL_TAB_COLUMNS view returns correct column metadata.

The current test intentionally demonstrates that COLLATION (a PostgreSQL reserved word) causes a syntax error when used unquoted. However, this negative test alone does not verify that the view functions correctly. The test should include at least one successful query—either without the COLLATION column or with it quoted—to validate that the view:

  • Discovers the test table
  • Returns correct column metadata (COLUMN_ID, DATA_TYPE, DATA_PRECISION, NULLABLE, etc.)
  • Properly maps Oracle-compatible types (VARCHAR2, NUMERIC, DATE)

Without a positive test case, there is no evidence that the view implementation produces the expected results.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@contrib/ivorysql_ora/expected/ora_sysview.out` around lines 345 - 403, Add a
positive test that queries SYS.ALL_TAB_COLUMNS for the created
TEST_ALL_TAB_COLUMNS table to verify it returns expected metadata (e.g.,
COLUMN_ID, COLUMN_NAME, DATA_TYPE, DATA_PRECISION, NULLABLE, DATA_DEFAULT) and
correct type mappings for VARCHAR2/NUMERIC/DATE; locate the current failing
negative test that selects COLLATION from SYS.ALL_TAB_COLUMNS and either remove
the unquoted COLLATION reference or replace it with a quoted "COLLATION" (or
simply omit that column) in the SELECT so the query succeeds, then add
assertions that the returned rows include the three columns NAME, AGE,
CREATE_TIME with correct DATA_TYPE and precision values for
TEST_ALL_TAB_COLUMNS.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@contrib/ivorysql_ora/expected/ora_sysview.out`:
- Around line 345-403: Add a positive test that queries SYS.ALL_TAB_COLUMNS for
the created TEST_ALL_TAB_COLUMNS table to verify it returns expected metadata
(e.g., COLUMN_ID, COLUMN_NAME, DATA_TYPE, DATA_PRECISION, NULLABLE,
DATA_DEFAULT) and correct type mappings for VARCHAR2/NUMERIC/DATE; locate the
current failing negative test that selects COLLATION from SYS.ALL_TAB_COLUMNS
and either remove the unquoted COLLATION reference or replace it with a quoted
"COLLATION" (or simply omit that column) in the SELECT so the query succeeds,
then add assertions that the returned rows include the three columns NAME, AGE,
CREATE_TIME with correct DATA_TYPE and precision values for
TEST_ALL_TAB_COLUMNS.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 36dd0f16-9c8d-4eec-88a6-5936b91bb3ec

📥 Commits

Reviewing files that changed from the base of the PR and between c5bd7a0 and 07c662b.

📒 Files selected for processing (3)
  • contrib/ivorysql_ora/expected/ora_sysview.out
  • contrib/ivorysql_ora/sql/ora_sysview.sql
  • contrib/ivorysql_ora/src/sysview/sysview--1.0.sql
🚧 Files skipped from review as they are similar to previous changes (2)
  • contrib/ivorysql_ora/sql/ora_sysview.sql
  • contrib/ivorysql_ora/src/sysview/sysview--1.0.sql

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@ora_sysview.sql`:
- Around line 24-26: The SELECT from ALL_PROCEDURES filtering OBJECT_NAME =
'PROC_DEL_TB' OR 'FUNC_AUTHID' returns multiple rows without a deterministic
order; update that query (and the other dictionary-view query referenced later)
to include an explicit ORDER BY (for example ORDER BY OBJECT_NAME, OBJECT_TYPE
or another stable key) so ora_sysview.out is deterministic; locate the SELECT
against ALL_PROCEDURES and the similar query around the later occurrence and
append a suitable ORDER BY clause to each.
- Around line 258-260: The query against SYS.ALL_TAB_COLUMNS is only filtering
TABLE_NAME and can return same-named tables from other schemas; update the WHERE
clause that queries SYS.ALL_TAB_COLUMNS for 'TEST_ALL_TAB_COLUMNS' to also
filter by OWNER (e.g., AND OWNER = '<EXPECTED_SCHEMA>' or AND OWNER = USER/
SYS_CONTEXT('USERENV','CURRENT_SCHEMA')) so the test only inspects the intended
schema; leave the ORDER BY COLUMN_ID as-is.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0a3afbb2-8716-4df1-8d19-24e853314ff7

📥 Commits

Reviewing files that changed from the base of the PR and between 35806b1 and d525ce7.

📒 Files selected for processing (2)
  • ora_sysview.out
  • ora_sysview.sql
✅ Files skipped from review due to trivial changes (1)
  • ora_sysview.out

Comment thread ora_sysview.sql Outdated
Comment thread ora_sysview.sql Outdated
@Adria0615 Adria0615 force-pushed the fix-all-tab-columns branch from 2452af1 to d662428 Compare May 13, 2026 21:12
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@contrib/ivorysql_ora/expected/ora_sysview.out`:
- Around line 345-402: The ALL_TAB_COLUMNS test returns no rows because the
WHERE clause compares OWNER = CURRENT_USER while the view projects OWNER via
sys.ora_case_trans(...), causing a case-mismatch; update the test's WHERE clause
to use the same transformation as the view (i.e., WHERE OWNER =
SYS.ORA_CASE_TRANS(CURRENT_USER::VARCHAR2)) so the OWNER filter matches and the
SELECT from SYS.ALL_TAB_COLUMNS for TEST_ALL_TAB_COLUMNS returns the expected 4
rows to validate DATA_TYPE, DATA_LENGTH, COLUMN_ID ordering, etc.; change the
predicate in the test that references OWNER/CURRENT_USER to use
SYS.ORA_CASE_TRANS(CURRENT_USER::VARCHAR2) and regenerate the expected output.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 592fb916-9913-4f36-81df-9607b3ea3777

📥 Commits

Reviewing files that changed from the base of the PR and between d525ce7 and d662428.

📒 Files selected for processing (2)
  • contrib/ivorysql_ora/expected/ora_sysview.out
  • contrib/ivorysql_ora/sql/ora_sysview.sql
🚧 Files skipped from review as they are similar to previous changes (1)
  • contrib/ivorysql_ora/sql/ora_sysview.sql

Comment thread contrib/ivorysql_ora/expected/ora_sysview.out Outdated
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@contrib/ivorysql_ora/sql/ora_sysview.sql`:
- Line 236: The test/view is flaky because it selects the raw LAST_ANALYZED
timestamp; change the expectation to a deterministic assertion instead of
snapshotting the timestamp: update the code that emits or asserts LAST_ANALYZED
so it checks nullness (e.g., assert LAST_ANALYZED IS NULL or IS NOT NULL) or
returns a stable token (e.g., 'NULL'/'NOT NULL') rather than the real timestamp;
locate occurrences of LAST_ANALYZED in the SQL/view and replace the raw column
output with a deterministic null-check or token.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 01d03d4c-2bd1-48a8-8822-d8debf85b3cc

📥 Commits

Reviewing files that changed from the base of the PR and between d525ce7 and 59ae64a.

📒 Files selected for processing (2)
  • contrib/ivorysql_ora/expected/ora_sysview.out
  • contrib/ivorysql_ora/sql/ora_sysview.sql

Comment thread contrib/ivorysql_ora/sql/ora_sysview.sql Outdated
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 7

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@contrib/ivorysql_ora/src/sysview/sysview--1.0.sql`:
- Around line 1492-1496: The CASE that computes char_used is incorrect: remove
the PostgreSQL internal 'char' token from the first WHEN list and make varchar
and bpchar map consistently (either both to NULL or both to the same value);
specifically, update the CASE over pg_type.typname used to produce char_used so
that bpchar (Oracle CHAR) stays in the 'C' branch, the
oracharchar/oracharbyte/oravarcharchar/oravarcharbyte/orachar* variants remain
split into 'C'/'B' as appropriate, and either drop varchar from the 'B' branch
so both varchar and bpchar fall through to NULL, or place varchar with bpchar
into the same branch—edit the CASE that selects AS char_used accordingly.
- Around line 1479-1483: The scalar subquery that defines avg_col_len reads
pg_statistic directly and duplicates the already-joined pg_stats; replace that
correlated subquery with the avg_width column from the existing LEFT JOIN to
pg_stats (use pg_stats.avg_width cast/alias as needed for numeric and preserve
NULL behavior), remove the pg_statistic lookup in the avg_col_len expression,
and ensure the view continues to expose avg_col_len using the joined pg_stats
value (refer to avg_col_len, pg_stats, and avg_width to locate and update the
code).
- Around line 1425-1426: The DATA_LENGTH expression for plain varchar/bpchar
currently returns pg_attribute.atttypmod - 4 (a character count); change it to
return the byte length by multiplying (pg_attribute.atttypmod - 4) by
pg_encoding_max_length(pg_database.encoding) (the same approach used in the
oracharchar/oravarcharchar branch) so DATA_LENGTH represents bytes, not
characters, or alternatively document the semantic change if you intentionally
want characters; update the WHEN branch that checks pg_type.typname IN
('varchar','bpchar') to use the encoding-aware multiplication.
- Line 1394: The OWNER column is using pg_get_userbyid(pg_class.relowner) (the
role name) but should use the schema name from pg_namespace; replace the
expression
sys.ora_case_trans(pg_get_userbyid(pg_class.relowner)::varchar2)::varchar2(128)
AS owner with an expression that uses pg_namespace.nspname passed through
sys.ora_case_trans (e.g.,
sys.ora_case_trans(pg_namespace.nspname::varchar2)::varchar2(128) AS owner) so
OWNER reflects the schema name rather than the owning role.
- Line 1397: Replace the direct use of pg_attribute.attnum for COLUMN_ID with a
dense sequential ordinal computed per table: compute COLUMN_ID as a row-number
over the non-dropped attributes partitioned by the table (use
pg_attribute.attrelid) and ordered by pg_attribute.attnum so dropped columns
(attisdropped) do not create gaps; update the column expression that currently
references pg_attribute.attnum::numeric to use ROW_NUMBER() OVER (PARTITION BY
pg_attribute.attrelid ORDER BY pg_attribute.attnum) (or equivalent) and ensure
the existing attisdropped filter is applied.
- Line 1528: The ALL_TAB_COLUMNS view currently filters pg_class.relkind IN
('r','v','m','p','f') which lets partition child tables (relkind='r' and
relispartition=true) produce duplicate rows; modify the view's WHERE clause to
add AND NOT pg_class.relispartition to exclude partition children while keeping
partitioned parents, updating the definition of the ALL_TAB_COLUMNS view (search
for the SELECT that references pg_class.relkind) and then add a regression test
that creates a partitioned table fixture and asserts the view returns exactly
one row per logical column for the parent table.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 185ca33a-3c3e-4891-ae85-9586a7bdaf72

📥 Commits

Reviewing files that changed from the base of the PR and between 7fbe496 and c024ae9.

📒 Files selected for processing (1)
  • contrib/ivorysql_ora/src/sysview/sysview--1.0.sql

Comment thread contrib/ivorysql_ora/src/sysview/sysview--1.0.sql Outdated
Comment thread contrib/ivorysql_ora/src/sysview/sysview--1.0.sql Outdated
Comment thread contrib/ivorysql_ora/src/sysview/sysview--1.0.sql Outdated
Comment thread contrib/ivorysql_ora/src/sysview/sysview--1.0.sql Outdated
Comment thread contrib/ivorysql_ora/src/sysview/sysview--1.0.sql Outdated
Comment thread contrib/ivorysql_ora/src/sysview/sysview--1.0.sql
Comment thread contrib/ivorysql_ora/src/sysview/sysview--1.0.sql
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@contrib/ivorysql_ora/src/sysview/sysview--1.0.sql`:
- Around line 1488-1495: The CASE that computes char_col_decl_length wrongly
multiplies pg_attribute.atttypmod-derived character counts by
pg_catalog.pg_encoding_max_length(), converting character counts to bytes;
update the logic in the char_col_decl_length expression (the CASE referencing
pg_type.typname, pg_attribute.atttypmod and
pg_catalog.pg_encoding_max_length(current_database())) to remove the
multiplication for CHAR-semantics types so it returns the declared length in
character units (native units), leaving any byte-size computation for
DATA_LENGTH instead; apply the same fix to the analogous expression earlier in
the file that uses the same pattern near the other CASE at lines ~1438–1439.
- Line 1486: Replace the current_setting('server_encoding')::varchar2(44) AS
character_set_name expression with a CASE that returns 'CHAR_CS' for character
types, 'NCHAR_CS' for national character types and NULL otherwise, reusing the
same type-checking logic already used elsewhere in this file (the expression
testing a.atttypid/a.atttypmod or t.typcategory/format_type). Concretely, locate
the existing type-checking expressions (used for COLLATION_NAME or similar
columns) and copy that pattern into a CASE WHEN ... THEN 'CHAR_CS' WHEN ... THEN
'NCHAR_CS' ELSE NULL END AS character_set_name, replacing the current_setting
call.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: de6e5ca6-3499-4103-9b97-5212a8ac5287

📥 Commits

Reviewing files that changed from the base of the PR and between c024ae9 and c2448e1.

📒 Files selected for processing (2)
  • contrib/ivorysql_ora/expected/ora_sysview.out
  • contrib/ivorysql_ora/src/sysview/sysview--1.0.sql
🚧 Files skipped from review as they are similar to previous changes (1)
  • contrib/ivorysql_ora/expected/ora_sysview.out

NULL::numeric AS num_buckets,
pg_stat_get_last_analyze_time(pg_class.oid) AS last_analyzed,
NULL::numeric AS sample_size,
pg_catalog.current_setting('server_encoding')::varchar2(44) AS character_set_name,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

Oracle ALL_TAB_COLUMNS CHARACTER_SET_NAME semantics for CHAR, VARCHAR2, CLOB, NCHAR, NVARCHAR2, NCLOB, and non-character columns

💡 Result:

In Oracle Database, the ALL_TAB_COLUMNS view (and related views like ALL_TAB_COLS) includes the CHARACTER_SET_NAME column, which indicates the character set semantics for character-type columns [1][2][3][4]. It is populated only for columns of character data types: CHAR, VARCHAR2, NCHAR, NVARCHAR2. For these, it shows 'CHAR_CS' for database character set columns (CHAR, VARCHAR2) or 'NCHAR_CS' for national character set columns (NCHAR, NVARCHAR2) [1][2][3][4]. For LOB types: - CLOB uses the database character set (CHAR_CS) [5][6][7][8]. - NCLOB uses the national character set (NCHAR_CS) [5][6][7]. For non-character columns (e.g., NUMBER, DATE, BLOB), CHARACTER_SET_NAME is NULL, as it does not apply (analogous to CHAR_USED being NULL for non-character types) [9][4][1]. Note: While CLOB/NCLOB have character storage, official data dictionary docs describe CHARACTER_SET_NAME in the context of CHAR/VARCHAR2/NCHAR/NVARCHAR2, with no explicit mention for LOBs, but semantics follow their respective character sets [1][3][4]. In practice, queries on ALL_TAB_COLUMNS show CHAR_CS for CLOB and NCHAR_CS for NCLOB where populated [10].

Citations:


🏁 Script executed:

sed -n '1480,1495p' contrib/ivorysql_ora/src/sysview/sysview--1.0.sql

Repository: IvorySQL/IvorySQL

Length of output: 795


🏁 Script executed:

# Search for existing type-checking patterns in the file to understand how types are compared
rg -n "typname IN|CASE.*typname|pg_type.typname" contrib/ivorysql_ora/src/sysview/sysview--1.0.sql -A 3

Repository: IvorySQL/IvorySQL

Length of output: 4582


🏁 Script executed:

# Check if the type names mentioned in the suggested fix exist in the codebase
rg -n "oracharchar|oravarcharchar" contrib/ivorysql_ora/src/sysview/sysview--1.0.sql

Repository: IvorySQL/IvorySQL

Length of output: 493


🏁 Script executed:

rg -n "nchar|nvarchar2|nclob" contrib/ivorysql_ora/src/sysview/sysview--1.0.sql

Repository: IvorySQL/IvorySQL

Length of output: 523


🏁 Script executed:

# Also check what character types are actually supported
rg -n "typname IN.*char|typname IN.*varchar" contrib/ivorysql_ora/src/sysview/sysview--1.0.sql | head -20

Repository: IvorySQL/IvorySQL

Length of output: 948


CHARACTER_SET_NAME returns database encoding for all columns instead of character-set semantics.

Line 1486 uses current_setting('server_encoding') which returns the same value (e.g., UTF8) for every column, including NUMBER and DATE. Oracle requires this field to be CHAR_CS for character types, NCHAR_CS for national character types, and NULL otherwise. Reuse the type-checking pattern already established in this file:

Suggested fix
-  pg_catalog.current_setting('server_encoding')::varchar2(44) AS character_set_name,
+  CASE
+    WHEN pg_type.typname IN ('bpchar', 'varchar', 'oracharchar', 'oravarcharchar', 'text', 'clob')
+      THEN 'CHAR_CS'
+    WHEN pg_type.typname IN ('nchar', 'nvarchar2', 'nclob')
+      THEN 'NCHAR_CS'
+    ELSE NULL
+  END::varchar2(44) AS character_set_name,
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@contrib/ivorysql_ora/src/sysview/sysview--1.0.sql` at line 1486, Replace the
current_setting('server_encoding')::varchar2(44) AS character_set_name
expression with a CASE that returns 'CHAR_CS' for character types, 'NCHAR_CS'
for national character types and NULL otherwise, reusing the same type-checking
logic already used elsewhere in this file (the expression testing
a.atttypid/a.atttypmod or t.typcategory/format_type). Concretely, locate the
existing type-checking expressions (used for COLLATION_NAME or similar columns)
and copy that pattern into a CASE WHEN ... THEN 'CHAR_CS' WHEN ... THEN
'NCHAR_CS' ELSE NULL END AS character_set_name, replacing the current_setting
call.

Comment thread contrib/ivorysql_ora/src/sysview/sysview--1.0.sql
Copy link
Copy Markdown
Collaborator

@bigplaice bigplaice left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@gaoxueyu gaoxueyu merged commit abbf86a into IvorySQL:master May 16, 2026
7 checks passed
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.

oracle compatibility feature: ALL_TAB_COLUMNS

3 participants