Skip to content

Conversation

@mattbrown-msb
Copy link

Allow clients to opt-in to handling long-comment tables by using a SHOW TABLES query. The fetch_all function is using a bound 'remarks' column that is configured to have a max_length of 254 characters. That max length is not configurable and the column cannot be unbound. So when a table with a comment longer than 254 characters exists in the result set, we run into the negative string size (or size too big) error.

This change uses a show tables query which generates a comment column definition with the max length allowed in snowflake. This allows us to pull down tables with any size comment. Since the result set is different between the show tables query and the fetch_all function on the tables ODBC:Statement object, the application must opt-in to using this functionality by defining silo_fetch_all_tables in the database.yml file (see below).

snowflake_predict_db_ads:
  adapter: odbc
  dsn: PredictDbAds
  pool: <%= ENV.fetch("RAILS_DB_CONNECTIONS") { 15 } %>
  silo_fetch_all_tables: true

@chelsea76 chelsea76 merged commit b61b90b into master Jun 27, 2024
zokioki added a commit to doximity/odbc_adapter that referenced this pull request Aug 30, 2024
… comments

This change fixes an issue with the `tables` call erroring out if attempting to
fetch any tables that have longer than 254 character comments on them. This fix
is based on the approach used by the patterninc fork of the gem, whose PR does
a great job of explaining the issue and idea behind the solution:

> The fetch_all function is using a bound 'remarks' column that is configured to
> have a max_length of 254 characters. That max length is not configurable and the
> column cannot be unbound. So when a table with a comment longer than 254 characters
> exists in the result set, we run into the negative string size (or size too big) error.

- patterninc#9

The primary difference here is that we're using `SHOW TABLES IN ACCOUNT` query,
which should return the same set of tables as `fetch_all` was returning before,
eliminating the need for an opt-in config flag.

Snowflake docs on the SHOW TABLES query:
https://docs.snowflake.com/en/sql-reference/sql/show-tables
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.

4 participants