This question already has an answer here:
- Escape Variables with Printf 1 answer
I have an SQL query that looks like this:
SELECT name FROM sessions WHERE name ILIKE 'org_name.%';
but I'm actually interested in replacing 'org_name' with format string (%s).
I was trying to do something like this:
query := fmt.Sprintf("SELECT name FROM sessions WHERE name ILIKE '%s.%'", "org_name2")
but go seems to not like it, since writing %' isn't valid as format string.
I know I can solve it with do it in that way:
orgName := "org_name2"
condition := fmt.Sprintf("%s", orgName) + ".%"
query := fmt.Sprintf("SELECT name FROM sessions WHERE name ILIKE '%s'", condition)
but, I'd rather not, since the variable here is solely the org_name.
Is there a solution for this?
Thanks!
</div>