From 6de09aef636d5277a49e1db0011c86fdeab663f4 Mon Sep 17 00:00:00 2001 From: jnasbyupgrade Date: Mon, 10 Aug 2026 17:57:08 -0500 Subject: [PATCH 1/2] CODE_STYLE.md: prefer %TYPE over a hardcoded type for column mirrors An agent working on test_factory#18 replaced an intentional tbl.col%TYPE reference with a hardcoded type, treating the resulting "type reference ... converted to text" NOTICE as a bug rather than expected behavior. Document the convention so it isn't repeated. --- CODE_STYLE.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/CODE_STYLE.md b/CODE_STYLE.md index 1d9dbe2..9db5a8e 100644 --- a/CODE_STYLE.md +++ b/CODE_STYLE.md @@ -35,6 +35,26 @@ across Postgres-Extensions repos. the same comment verbatim in adjacent code — write it once and reference it ("same as above"). +## Prefer `%TYPE` over a hardcoded type + +When a function parameter, variable, or column exists to hold a copy of +another table's column value, declare it as `table.column%TYPE` instead of +hardcoding the type. This ties the declaration to the column's actual +type, so a future column type change doesn't silently create a mismatch +that a hardcoded type would miss. + +Don't "clean up" an existing `%TYPE` reference by replacing it with the +literal type it currently resolves to — that's removing the exact +protection it exists to provide, not simplifying dead weight. PostgreSQL +can't preserve a `%TYPE` reference in a function's parameter list; it +resolves it once at `CREATE FUNCTION` time and emits a NOTICE like `type +reference tbl.col%TYPE converted to text` every time the function is +(re)created. That NOTICE is expected and harmless, not a sign the `%TYPE` +should be replaced (see +[Postgres-Extensions/test_factory#18](https://github.com/Postgres-Extensions/test_factory/pull/18) +for a case where it was mistakenly removed for exactly this reason, then +reverted). + ## Don't set `client_min_messages` inside an extension install script `CREATE EXTENSION`/`ALTER EXTENSION UPDATE` already forces From 143a08abac523c0b7ad9e226684457ac6ce94d68 Mon Sep 17 00:00:00 2001 From: jnasbyupgrade Date: Mon, 10 Aug 2026 18:10:45 -0500 Subject: [PATCH 2/2] CODE_STYLE.md: drop NOTICE detail from %TYPE section The client_min_messages behavior this NOTICE detail was explaining now has its own section (see Postgres-Extensions/ai#11); keep this section focused on the %TYPE convention itself. --- CODE_STYLE.md | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/CODE_STYLE.md b/CODE_STYLE.md index 9db5a8e..b72f8c2 100644 --- a/CODE_STYLE.md +++ b/CODE_STYLE.md @@ -45,15 +45,9 @@ that a hardcoded type would miss. Don't "clean up" an existing `%TYPE` reference by replacing it with the literal type it currently resolves to — that's removing the exact -protection it exists to provide, not simplifying dead weight. PostgreSQL -can't preserve a `%TYPE` reference in a function's parameter list; it -resolves it once at `CREATE FUNCTION` time and emits a NOTICE like `type -reference tbl.col%TYPE converted to text` every time the function is -(re)created. That NOTICE is expected and harmless, not a sign the `%TYPE` -should be replaced (see -[Postgres-Extensions/test_factory#18](https://github.com/Postgres-Extensions/test_factory/pull/18) -for a case where it was mistakenly removed for exactly this reason, then -reverted). +protection it exists to provide, not simplifying dead weight (see +[Postgres-Extensions/test_factory#18](https://github.com/Postgres-Extensions/test_factory/pull/18), +where this was done and then reverted). ## Don't set `client_min_messages` inside an extension install script