Simple trick to insert a static date in Postgres using Golang sqlx

While writing some tests I tried to use a static date in a NamedExec call and got this message: I was surprised that the pgsql driver would mistake a static value for a named parameter. Turns out that the issue lies in the way the sqlx NamedExec function parses the input SQL string before handing it off. There’s a simple work around that didn’t seem well documented. You can escape the ‘:’ character with another ‘:’ character. So to format a date to pass through cleanly this is how I format it: Hope this helps someone, or me when I [Read on…]