Conversation
📝 WalkthroughWalkthroughA new SQL view Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@contrib/ivorysql_ora/src/sysview/sysview_procedures.sql`:
- Line 278: The view all_cons_columns is not schema-qualified and lacks an
explicit GRANT; change the CREATE OR REPLACE VIEW invocation to create
SYS.all_cons_columns (i.e., qualify the view with the SYS schema) and add an
explicit grant statement (GRANT SELECT ON SYS.all_cons_columns TO PUBLIC)
alongside the other SYS compatibility grants near the existing grant block so
the view is created in SYS and accessible to PUBLIC; update any nearby
references in this file to the qualified name if needed.
- Line 311: The relkind filter in the sysview that builds constraint listings
currently omits partitioned tables by using cls.relkind IN ('r','v','m'); update
that filter to include partitioned tables (add 'p') so constraints on
partitioned tables are returned—modify the clause that references cls.relkind in
sysview_procedures.sql accordingly.
🪄 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: 83c01960-c4fa-4cfb-b2c4-5325d492595d
📒 Files selected for processing (1)
contrib/ivorysql_ora/src/sysview/sysview_procedures.sql
| OBJECT_ID | ||
| ; | ||
|
|
||
| CREATE OR REPLACE VIEW all_cons_columns AS |
There was a problem hiding this comment.
Create the view in SYS and grant it explicitly.
At Line 278, all_cons_columns is not schema-qualified, and there is no GRANT for this new view near Line 319–Line 320. In this file, SYS compatibility views are created as SYS.<view> and granted to PUBLIC; this one currently breaks that pattern and can end up inaccessible or in the wrong schema.
🔧 Proposed fix
-CREATE OR REPLACE VIEW all_cons_columns AS
+CREATE OR REPLACE VIEW SYS.ALL_CONS_COLUMNS AS
...
ORDER BY
owner, table_name, constraint_name, position;
/* GRANT SELECT PRIVILEGE TO PUBLIC */
GRANT SELECT ON SYS.USER_PROCEDURES TO PUBLIC;
+GRANT SELECT ON SYS.ALL_CONS_COLUMNS TO PUBLIC;Also applies to: 319-320
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@contrib/ivorysql_ora/src/sysview/sysview_procedures.sql` at line 278, The
view all_cons_columns is not schema-qualified and lacks an explicit GRANT;
change the CREATE OR REPLACE VIEW invocation to create SYS.all_cons_columns
(i.e., qualify the view with the SYS schema) and add an explicit grant statement
(GRANT SELECT ON SYS.all_cons_columns TO PUBLIC) alongside the other SYS
compatibility grants near the existing grant block so the view is created in SYS
and accessible to PUBLIC; update any nearby references in this file to the
qualified name if needed.
| WHERE | ||
| con.contype IN ('p', 'u', 'f', 'c') | ||
| AND nsp.nspname NOT IN ('pg_catalog', 'information_schema', 'pg_toast') | ||
| AND cls.relkind IN ('r', 'v', 'm') |
There was a problem hiding this comment.
🧩 Analysis chain
🌐 Web query:
In PostgreSQL system catalog pg_class, what relkind value represents partitioned tables, and can table constraints (primary key/unique/check/foreign key) exist on relkind 'p' relations?
💡 Result:
In PostgreSQL system catalog pg_class, the relkind value 'p' represents partitioned tables. Table constraints can exist on relkind 'p' relations (partitioned tables): - CHECK constraints: Yes, but they are inherited by all partitions; NO INHERIT CHECK constraints are not allowed on partitioned tables. - Primary key and unique constraints: Yes, but with limitations—the constraint must include all partition key columns (no expressions or function calls in partition key for these), as uniqueness is enforced per-partition relying on partitioning to prevent cross-partition duplicates. - Foreign key constraints: Can be declared on partitioned tables (referencing them or referenced by them), but with practical limitations—FKs referencing partitioned tables check all partitions, which can be slow for detach/drop operations; recommended to define FKs between matching partitions instead.
Citations:
- 1: https://www.postgresql.org/docs/current/catalog-pg-class.html
- 2: http://www.postgresql.org/docs/15/catalog-pg-class.html
- 3: http://www.postgresql.org/docs/15/ddl-partitioning.html
- 4: https://www.postgresql.org/docs/current/ddl-partitioning.html
- 5: https://www.postgresql.org/docs/current/sql-createtable.html
- 6: https://postgrespro.com/docs/postgresql/current/catalog-pg-class
- 7: https://stackoverflow.com/questions/76071450/postgresql-unique-constraint-on-partitioned-table-must-include-all-partitioning
- 8: https://dba.stackexchange.com/questions/276291/error-insufficient-columns-in-primary-key-constraint-definition/276293
🏁 Script executed:
cd contrib/ivorysql_ora/src/sysview && head -n 320 sysview_procedures.sql | tail -n 20Repository: IvorySQL/IvorySQL
Length of output: 953
🏁 Script executed:
cd contrib/ivorysql_ora/src/sysview && sed -n '300,320p' sysview_procedures.sqlRepository: IvorySQL/IvorySQL
Length of output: 958
🏁 Script executed:
cd contrib/ivorysql_ora/src/sysview && sed -n '280,315p' sysview_procedures.sqlRepository: IvorySQL/IvorySQL
Length of output: 1777
🏁 Script executed:
cd contrib/ivorysql_ora/src/sysview && sed -n '260,285p' sysview_procedures.sqlRepository: IvorySQL/IvorySQL
Length of output: 833
Include partitioned tables in relkind filter.
Line 311 excludes relkind = 'p', so constraints defined on partitioned tables will be missing from this view. PostgreSQL partitioned tables can have primary key, unique, foreign key, and check constraints, all of which are supported by this query's constraint type filter.
Current code
AND cls.relkind IN ('r', 'v', 'm')
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@contrib/ivorysql_ora/src/sysview/sysview_procedures.sql` at line 311, The
relkind filter in the sysview that builds constraint listings currently omits
partitioned tables by using cls.relkind IN ('r','v','m'); update that filter to
include partitioned tables (add 'p') so constraints on partitioned tables are
returned—modify the clause that references cls.relkind in sysview_procedures.sql
accordingly.
view all_cons_columns make it
Summary by CodeRabbit
all_cons_columnsview that exposes constraint-to-column mappings across database objects. This view provides comprehensive visibility into constraint relationships, including constraint names, associated columns, position information, and normalized data types, while respecting schema and table access permissions.