Skip to content
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

fix: Case Sensitive Quoted Column Names Support for Context.DB #448

Closed
wants to merge 3 commits into from

Conversation

darunrs
Copy link
Collaborator

@darunrs darunrs commented Dec 14, 2023

Postgres treats unquoted strings as non-case-sensitive whereas quoted strings are. This means that blockHeight and "blockHeight" are in fact different and will not match. Currently, context.db puts column names without quotes. This leads to a mismatch causing the column to not be found:

INSERT INTO nearpavel_near_staking_v3."receipts" (blockHeight, blockHash, blockTimestamp, blockDate, depositIn, receiptId, predecessorId, signerId, validatorId) VALUES ('106896621', '8o26GZfSt4z7TrbHdHhDCXttXkG3hUFNkLCL33y52c1d', '1701388833845.7158', '2023-12-01', '900000000000000000000000', 'AZhuyEwThxEHUyUcudiNJ49pBhMekgjgokj9tmfHEgkg', '2ee9129228b532b25181ec6cbd1e09bf058e5169c9a9606fec69b5f635423d97', '2ee9129228b532b25181ec6cbd1e09bf058e5169c9a9606fec69b5f635423d97', 'astro-stakers.poolv1.near') ON CONFLICT (receiptId) DO UPDATE SET depositIn = excluded.depositIn RETURNING *

column "blockheight" of relation "receipts" does not exist

The fix is to quote the column names in the query, if they were quoted in the schema.

In addition, the logs for context.db were being written under the wrong function name. I fixed that too.

@darunrs
Copy link
Collaborator Author

darunrs commented Dec 14, 2023

Needs some more integration testing with postgres to ensure there aren't any existing cases broken. So far I ran the staking v3 indexer with fixed code and verified that worked and inserted into the database.

Need to:

  • Test social feed
  • Test all methods
  • Test with case sensitive quoted columns in schema

Open to more test ideas.

@darunrs
Copy link
Collaborator Author

darunrs commented Jan 4, 2024

Turns out that the reserve of this problem is also problematic. If the schema uses blockHeight, and the query contains "blockHeight", that will also not work. So, I actually need to only quote it if the schema itself quoted the table name. This is a problem because the current way I get tableNames strips the quotes, if they were present.

@darunrs
Copy link
Collaborator Author

darunrs commented Jan 27, 2024

Will create new PR as approach was entirely reworked.

@darunrs darunrs closed this Jan 27, 2024
@darunrs darunrs deleted the fixDbCalls branch January 27, 2024 02:09
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.

Indexers with quoted case-sensitive column names will have context.db calls fail against them
1 participant