Skip to content

Conversation

@taras-dubyk
Copy link
Contributor

@taras-dubyk taras-dubyk commented Sep 30, 2025

Sub-taskHCK-12924 Use fallback approach to get columns metadata if a user doesn't have permissions

Technical details

In the RE, we currently use the information_schema.columns system view to retrieve table columns. However, this requires at least SELECT permissions on the target table.

An alternative is to query pg_* system catalogs directly. While the data is spread across multiple tables and type-related values can differ slightly, this approach works even without SELECT permissions.

This PR introduces a fallback query that retrieves table columns from the system catalogs when information_schema.columns returns no results (likely due to insufficient permissions). Implementing this required composing a complex query with several joins and mappings to match the output of information_schema.columns.

Additionally:

  • The foreign key retrieval query was updated to avoid relying on information_schema.columns.
  • Views mapping was slightly refactored to be safer when permissions are limited. In such cases, not all expected properties may be available.
    ...

@taras-dubyk taras-dubyk self-assigned this Sep 30, 2025
LEFT JOIN pg_catalog.pg_description AS pg_description ON (pg_description.objsubid=pg_attribute.attnum
AND pg_description.objoid = pg_attribute.attrelid)
WHERE pg_attribute.attrelid = $1;`,
GET_TABLE_COLUMNS_FROM_CATALOG: `
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like this one is from the view select statement, could you please add a comment leading to the original view. Like it is done in GET_TRIGGERS

-- This is information_schema.triggers view but without permitions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, correct. I have a comment about that in the place where this query is used.
Added one more here, thanks.

@sonarqubecloud
Copy link

@Vitalii4as Vitalii4as enabled auto-merge (squash) September 30, 2025 12:32
@Vitalii4as Vitalii4as merged commit dd5077c into develop Sep 30, 2025
8 checks passed
@Vitalii4as Vitalii4as deleted the fix/HCK-12924 branch September 30, 2025 14:16
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.

3 participants