On this page
Package livenorm resolves catalog-dependent normalization residue by round-tripping expressions through a live PostgreSQL server on the diff --live path.
#internal/livenorm
#internal/livenorm
Package livenorm implements LIVE ROUND-TRIP NORMALIZATION (roadmap 1.2, boundary item 4): the concrete diff.LiveNormalizer that resolves the ≈_pg RESIDUE — catalog-dependent cast materialization — that no pure normalizer can reach.
A desired-side boolean predicate is round-tripped through the TARGET database itself: a throwaway TEMP table cloned (LIKE) from the real table carries a temporary CHECK constraint holding the expression; PostgreSQL parses, type- resolves, and stores it, then pg_get_constraintdef renders PG's OWN canonical form (e.g. materializing status = 'active' to status = 'active'::text). The temp object is always dropped.
Identity NEVER consumes this output — livenorm is used only on the diff --live path, which has a database; the pure/encoding path never touches it.
The MINIMAL FORWARD-SIMULATION rule set is N: where a round-trip cannot reach (the real table or a referenced column is absent, so the temp DDL cannot be built), normalization falls to sqlparse.NormalizeExpr — the catalog- independent foldings that survive without a database. This is reachability- determined (a fixed property of the expression against the live schema), not silent degradation: the same expression against the same database always takes the same path.
#Normalizer
type Normalizer structNormalizer holds a session-scoped connection to the target database. Temp objects live in that session's pg_temp schema and vanish when Close is called (or the session ends), in addition to being explicitly dropped per call.
#New
func New(ctx context.Context, dbURL string) (*Normalizer, error)New opens a connection to the target database for round-trip normalization.
#Normalizer.Close
func (n *Normalizer) Close()Close releases the connection (and, with it, all session temp objects).
#Normalizer.NormalizeExprForTable
func (n *Normalizer) NormalizeExprForTable(schema, table, expr string) stringNormalizeExprForTable returns the target DB's canonical form of a boolean predicate expr in the context of schema.table. On any reason the round-trip cannot reach (absent table/column, parse error, or a dead connection), it returns the forward-simulation form: sqlparse.NormalizeExpr(expr).