-
Notifications
You must be signed in to change notification settings - Fork 175
Implement ALL_TAB_COLUMNS view and add test case #1290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -90,3 +90,19 @@ SELECT * | |||||||||||||||||||||||
| FROM SYS.V$PARAMETER | ||||||||||||||||||||||||
| WHERE NAME IN ('listen_addresses','application_name','archive_command','archive_mode','block_size') | ||||||||||||||||||||||||
| ORDER BY NAME; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| -- Test ALL_TAB_COLUMNS | ||||||||||||||||||||||||
| DROP TABLE IF EXISTS test_user_cons; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| CREATE TABLE test_user_cons ( | ||||||||||||||||||||||||
| id int primary key, | ||||||||||||||||||||||||
| name varchar(50) not null | ||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| SELECT OWNER, TABLE_NAME, COLUMN_NAME, COLUMN_ID, | ||||||||||||||||||||||||
| DATA_TYPE, DATA_LENGTH, DATA_PRECISION, DATA_SCALE, | ||||||||||||||||||||||||
| NULLABLE | ||||||||||||||||||||||||
| FROM ALL_TAB_COLUMNS | ||||||||||||||||||||||||
| WHERE TABLE_NAME = 'test_user_cons'; | ||||||||||||||||||||||||
|
Comment on lines
+102
to
+106
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Scope the assertion to schema to avoid cross-schema flakiness. At Line 106, filtering only by Suggested fix SELECT OWNER, TABLE_NAME, COLUMN_NAME, COLUMN_ID,
DATA_TYPE, DATA_LENGTH, DATA_PRECISION, DATA_SCALE,
NULLABLE
FROM ALL_TAB_COLUMNS
-WHERE TABLE_NAME = 'test_user_cons';
+WHERE TABLE_NAME = 'test_user_cons'
+ AND OWNER = current_schema();📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| DROP TABLE IF EXISTS test_user_cons; | ||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1273,3 +1273,39 @@ SELECT | |||||||||
| SHORT_DESC::VARCHAR2(255) AS DESCRIPTION | ||||||||||
| FROM PG_SETTINGS; | ||||||||||
|
|
||||||||||
| /* | ||||||||||
| * ALL_TAB_COLUMNS - Oracle-compatible columns view | ||||||||||
| */ | ||||||||||
| CREATE OR REPLACE VIEW ALL_TAB_COLUMNS AS | ||||||||||
| SELECT | ||||||||||
| n.nspname AS owner, | ||||||||||
| c.relname AS table_name, | ||||||||||
| a.attname AS column_name, | ||||||||||
| a.attnum AS column_id, | ||||||||||
| t.typname AS data_type, | ||||||||||
| CASE | ||||||||||
| WHEN t.typname IN ('varchar', 'char', 'bpchar') THEN (a.atttypmod - 4) | ||||||||||
| WHEN t.typname = 'numeric' THEN ((a.atttypmod - 4) >> 16) | ||||||||||
| ELSE a.attlen | ||||||||||
| END AS data_length, | ||||||||||
| CASE | ||||||||||
| WHEN t.typname = 'numeric' THEN ((a.atttypmod - 4) >> 16) | ||||||||||
| ELSE NULL | ||||||||||
| END AS data_precision, | ||||||||||
| CASE | ||||||||||
| WHEN t.typname = 'numeric' THEN ((a.atttypmod - 4) & 65535) | ||||||||||
| ELSE NULL | ||||||||||
| END AS data_scale, | ||||||||||
| CASE WHEN a.attnotnull THEN 'N' ELSE 'Y' END AS nullable | ||||||||||
| FROM pg_class c | ||||||||||
| JOIN pg_attribute a ON a.attrelid = c.oid | ||||||||||
| JOIN pg_type t ON a.atttypid = t.oid | ||||||||||
| JOIN pg_namespace n ON n.oid = c.relnamespace | ||||||||||
| WHERE a.attnum > 0 | ||||||||||
| AND NOT a.attisdropped | ||||||||||
| AND c.relkind IN ('r', 'v') | ||||||||||
| AND n.nspname NOT IN ('pg_catalog', 'information_schema') | ||||||||||
| ORDER BY n.nspname, c.relname, a.attnum; | ||||||||||
|
Comment on lines
+1279
to
+1308
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Missing All other views in this file are created under the
Proposed fix for schema and consistency-CREATE OR REPLACE VIEW ALL_TAB_COLUMNS AS
+CREATE OR REPLACE VIEW SYS.ALL_TAB_COLUMNS AS
SELECT
- n.nspname AS owner,
- c.relname AS table_name,
- a.attname AS column_name,
+ SYS.ORA_CASE_TRANS(n.nspname::VARCHAR2)::VARCHAR2(128) AS owner,
+ SYS.ORA_CASE_TRANS(c.relname::VARCHAR2)::VARCHAR2(128) AS table_name,
+ SYS.ORA_CASE_TRANS(a.attname::VARCHAR2)::VARCHAR2(128) AS column_name,
a.attnum AS column_id,
t.typname AS data_type,
...
WHERE a.attnum > 0
AND NOT a.attisdropped
AND c.relkind IN ('r', 'v')
AND n.nspname NOT IN ('pg_catalog', 'information_schema')
+ AND HAS_SCHEMA_PRIVILEGE(n.oid, 'USAGE')
ORDER BY n.nspname, c.relname, a.attnum;🤖 Prompt for AI Agents |
||||||||||
|
|
||||||||||
| GRANT SELECT ON ALL_TAB_COLUMNS TO PUBLIC; | ||||||||||
| COMMENT ON VIEW ALL_TAB_COLUMNS IS 'Oracle-style ALL_TAB_COLUMNS view'; | ||||||||||
|
Comment on lines
+1310
to
+1311
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Update GRANT to reference the correct schema. If the view is moved to Proposed fix-GRANT SELECT ON ALL_TAB_COLUMNS TO PUBLIC;
-COMMENT ON VIEW ALL_TAB_COLUMNS IS 'Oracle-style ALL_TAB_COLUMNS view';
+GRANT SELECT ON SYS.ALL_TAB_COLUMNS TO PUBLIC;
+COMMENT ON VIEW SYS.ALL_TAB_COLUMNS IS 'Oracle-style ALL_TAB_COLUMNS view';📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expand this test to cover untested ALL_TAB_COLUMNS branches.
Current case validates only
int4andvarcharwithNOT NULL. It misses numeric precision/scale andNULLABLE = 'Y'paths implemented by the view.Suggested expansion
CREATE TABLE test_user_cons ( id int primary key, - name varchar(50) not null + name varchar(50) not null, + amount numeric(10,2), + code char(3) );SELECT OWNER, TABLE_NAME, COLUMN_NAME, COLUMN_ID, DATA_TYPE, DATA_LENGTH, DATA_PRECISION, DATA_SCALE, NULLABLE FROM ALL_TAB_COLUMNS WHERE TABLE_NAME = 'test_user_cons' AND OWNER = current_schema(); +ORDER BY COLUMN_ID;Also applies to: 102-104
🤖 Prompt for AI Agents