jackc / pgx

PostgreSQL driver and toolkit for Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pgx.NamedArgs only support names which start with a letter

eteran opened this issue · comments

I am working on a project where the schema is generated at build time, so named arguments make working with it a lot simpler.

Some of these tables have columns that are considered to be "internal" and are by convention, prefixed with an underscore (_).

When using code that we've generated from the schemas to populate these tables, I've run into an issue where columns with names like _object_id don't get processed by the NamedArgs rewriter because they don't start with a letter.

Yes, of course I can work around it by having the code that generates the queries special case columns that start with an _ and replace it with some other magic prefix. In fact, that's what I've done and it seems work. But now other code which wants to refer to those columns using the NamedArgs and knows which field it wants to refer to has to also know about this magical rename.

So it would be very helpful if a leading underscore were also allowed. In fact, I see no reason why a named argument like @_object_id couldn't be supported. This is at least consistent with most programming languages where the regex for an identifier is: [_a-zA-Z][_a-zA-Z0-9]* (usually because parsers like to be able to look at the next character and decide if it's an identifier or a number) which wouldn't be a problem here.

Thanks!

Seems reasonable. Done.