agora inbox for [email protected]help / color / mirror / Atom feed
[PATCH v1] Document that typed tables rely on CREATE TYPE 2+ messages / 2 participants [nested] [flat]
* [PATCH v1] Document that typed tables rely on CREATE TYPE @ 2024-03-08 03:21 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 2+ messages in thread From: Erik Wienhold @ 2024-03-08 03:21 UTC (permalink / raw) CREATE TABLE OF accepts only composite types that were created with CREATE TYPE. Clarify that also in the error message. --- doc/src/sgml/ref/create_table.sgml | 2 ++ src/backend/commands/tablecmds.c | 8 +++++++- src/test/regress/expected/typed_table.out | 6 +++++- src/test/regress/sql/typed_table.sql | 4 ++++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/doc/src/sgml/ref/create_table.sgml b/doc/src/sgml/ref/create_table.sgml index 4cbaaccaf7..889496cf0a 100644 --- a/doc/src/sgml/ref/create_table.sgml +++ b/doc/src/sgml/ref/create_table.sgml @@ -254,6 +254,8 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM schema-qualified). A typed table is tied to its type; for example the table will be dropped if the type is dropped (with <literal>DROP TYPE ... CASCADE</literal>). + Expects the composite type to have been created with + <xref linkend="sql-createtype"/>. </para> <para> diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 7014be8039..bef630139d 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -6975,8 +6975,14 @@ check_of_type(HeapTuple typetuple) * the type before the typed table creation/conversion commits. */ relation_close(typeRelation, NoLock); + + if (!typeOk) + ereport(ERROR, + (errcode(ERRCODE_WRONG_OBJECT_TYPE), + errmsg("type %s is not a composite type created with CREATE TYPE", + format_type_be(typ->oid)))); } - if (!typeOk) + else ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE), errmsg("type %s is not a composite type", diff --git a/src/test/regress/expected/typed_table.out b/src/test/regress/expected/typed_table.out index 2e47ecbcf5..bb21b69a1a 100644 --- a/src/test/regress/expected/typed_table.out +++ b/src/test/regress/expected/typed_table.out @@ -89,8 +89,12 @@ drop cascades to function get_all_persons() drop cascades to table persons2 drop cascades to table persons3 CREATE TABLE persons5 OF stuff; -- only CREATE TYPE AS types may be used -ERROR: type stuff is not a composite type +ERROR: type stuff is not a composite type created with CREATE TYPE DROP TABLE stuff; +CREATE TYPE simple AS ENUM ('a'); +CREATE TABLE of_simple OF simple; -- not a composite type +ERROR: type simple is not a composite type +DROP TYPE simple; -- implicit casting CREATE TYPE person_type AS (id int, name text); CREATE TABLE persons OF person_type; diff --git a/src/test/regress/sql/typed_table.sql b/src/test/regress/sql/typed_table.sql index 9ef0cdfcc7..eaa11b0f94 100644 --- a/src/test/regress/sql/typed_table.sql +++ b/src/test/regress/sql/typed_table.sql @@ -50,6 +50,10 @@ CREATE TABLE persons5 OF stuff; -- only CREATE TYPE AS types may be used DROP TABLE stuff; +CREATE TYPE simple AS ENUM ('a'); +CREATE TABLE of_simple OF simple; -- not a composite type +DROP TYPE simple; + -- implicit casting -- 2.44.0 --3rqrwxze3hgjbv2c-- ^ permalink raw reply [nested|flat] 2+ messages in thread
* [PATCH v2 2/4] Deprecate XLogRecPtrIsInvalid() @ 2025-10-29 10:57 Bertrand Drouvot <[email protected]> 0 siblings, 0 replies; 2+ messages in thread From: Bertrand Drouvot @ 2025-10-29 10:57 UTC (permalink / raw) Emit a warning message at compilation time if XLogRecPtrIsInvalid() is in use in the code base. --- src/include/access/xlogdefs.h | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) 100.0% src/include/access/ diff --git a/src/include/access/xlogdefs.h b/src/include/access/xlogdefs.h index 33b9913e71e..6eebf86342e 100644 --- a/src/include/access/xlogdefs.h +++ b/src/include/access/xlogdefs.h @@ -26,9 +26,27 @@ typedef uint64 XLogRecPtr; * record can begin at zero. */ #define InvalidXLogRecPtr 0 -#define XLogRecPtrIsInvalid(r) ((r) == InvalidXLogRecPtr) #define XLogRecPtrIsValid(r) ((r) != InvalidXLogRecPtr) +/* + * XLogRecPtrIsInvalid + * + * Deprecated: Use XLogRecPtrIsValid() instead. + */ +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L || defined(__cplusplus) && __cplusplus >= 201402L +[[deprecated("use XLogRecPtrIsValid() instead")]] +#elif defined(__GNUC__) || defined(__clang__) +__attribute__((deprecated("use XLogRecPtrIsValid() instead"))) +#elif defined(_MSC_VER) +__declspec(deprecated("use XLogRecPtrIsValid() instead")) +#endif + +static inline bool +XLogRecPtrIsInvalid(XLogRecPtr ptr) +{ + return ptr == InvalidXLogRecPtr; +} + /* * First LSN to use for "fake" LSNs. * -- 2.34.1 --RP3OEw+JChfNR0gk Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0003-Replace-InvalidXLogRecPtr-comparisons-with-XLogRe.patch" ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2025-10-29 10:57 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2024-03-08 03:21 [PATCH v1] Document that typed tables rely on CREATE TYPE Erik Wienhold <[email protected]> 2025-10-29 10:57 [PATCH v2 2/4] Deprecate XLogRecPtrIsInvalid() Bertrand Drouvot <[email protected]>
This inbox is served by agora; see mirroring instructions for how to clone and mirror all data and code used for this inbox