Conversation
While using sqlx's namedquery's i realized that the library believes that all instances of the colon are somehow are named variables, even if there inside a string. In my case with postgres, i had a interval notation as a string that was typed as '01:30:30' that cause the error "unexpected `:` while reading named param at [LOCATION]". I've been trying to fix the error most of the day, and my solution is having a bool flip while its reading a string to continue reading from it, with a sanity check to check if the comma is being escaped or not. try running this code for example var qs = `SELECT * FROM testtable WHERE timeposted BETWEEN (now() AT TIME ZONE 'utc') AND (now() AT TIME ZONE 'utc') - interval '01:30:00') AND name = '\'this is a test\'' and id = :id` previously, this would fail with said error, but now it works! I havent had a chance to add any unit test in, but you can use my scenario above in named_test.go
Owner
Author
|
Added the unit test in a seperate pull request. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
While using sqlx's namedquery's i realized that the library believes that all instances of the colon are somehow are named variables, even if there inside a string. In my case with postgres, i had a interval notation as a string that was typed as '01:30:30' that cause the error "unexpected
:while reading named param at [LOCATION]". I've been trying to fix the error most of the day, and my solution is having a bool flip while its reading a string to continue reading from it, with a sanity check to check if the comma is being escaped or not.try running this code for example
var qs =
SELECT * FROM testtable WHERE timeposted BETWEEN (now() AT TIME ZONE 'utc') AND (now() AT TIME ZONE 'utc') - interval '01:30:00') AND name = '\'this is a test\'' and id = :idpreviously, this would fail with said error, but now it works! I havent had a chance to add any unit test in, but you can use my scenario above in named_test.go