ergon_ident (ergon v0.5.0)

View Source

The 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 with format('%I').
  • ergon_migration bakes a table name into auto_manage_partitions_<table>, and into CREATE TABLE statements generally.
  • ergon_partition_boot_check calls 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

pattern()

-spec pattern() -> string().

The regular expression an identifier must match.

valid(Name)

-spec valid(binary()) -> boolean().

Whether Name is a bare lowercase SQL identifier.

validate(Name, Kind)

-spec validate(binary(), atom()) -> binary().

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.