ergon_ident (ergon v0.5.0)
View SourceThe guard on names that reach SQL as identifiers rather than as bind parameters.
Almost everything Ergon sends to PostgreSQL is parameterised. A few things cannot be, and they are the reason this module exists:
- pgmq derives
pgmq.q_<queue>from a queue name, and the notify tick builds its visibility probe withformat('%I'). ergon_migrationbakes a table name intoauto_manage_partitions_<table>, and intoCREATE TABLEstatements generally.ergon_partition_boot_checkcalls that function by name, and a function cannot be addressed by bind parameter.
In each case the name is host-authored rather than user input, so this is not the
last line of defence. It is the cheap one: rejecting anything that could need
quoting is simpler to reason about than quoting correctly everywhere, and it
fails at the call site rather than inside a format/2 three layers down.
Deliberately stricter than PostgreSQL's own rules, which permit quoted identifiers containing almost anything. Ergon allows only what never needs quoting in the first place.
Summary
Functions
The regular expression an identifier must match.
Whether Name is a bare lowercase SQL identifier.
Return Name if it is a bare lowercase SQL identifier, or raise.
Functions
-spec pattern() -> string().
The regular expression an identifier must match.
Whether Name is a bare lowercase SQL identifier.
Return Name if it is a bare lowercase SQL identifier, or raise.
Kind names what is being validated (queue, table, channel) and appears in
the error, since "invalid identifier" on its own tells a caller very little about
which of several names it got wrong.