From 8b29c5852762bacb637fab021a06b12ab5cd7f93 Mon Sep 17 00:00:00 2001 From: Erik Wienhold Date: Fri, 8 Mar 2024 04:21:56 +0100 Subject: [PATCH v4] Document that typed tables rely on CREATE TYPE CREATE TABLE OF requires a stand-alone composite type. Clarify that in the error message. Also reword the docs to better explain the connection between created table and stand-alone composite type. Reworded docs provided by David G. Johnston. --- doc/src/sgml/ref/create_table.sgml | 18 +++++++++--------- src/backend/commands/tablecmds.c | 2 +- src/test/regress/expected/typed_table.out | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/doc/src/sgml/ref/create_table.sgml b/doc/src/sgml/ref/create_table.sgml index dfb7822985..586ccb190b 100644 --- a/doc/src/sgml/ref/create_table.sgml +++ b/doc/src/sgml/ref/create_table.sgml @@ -249,19 +249,19 @@ WITH ( MODULUS numeric_literal, REM OF type_name - Creates a typed table, which takes its - structure from the specified composite type (name optionally - schema-qualified). A typed table is tied to its type; for - example the table will be dropped if the type is dropped - (with DROP TYPE ... CASCADE). + Creates a typed table, which takes its structure + from an existing (name optionally schema-qualified) stand-alone composite + type (i.e., created using ) though it + still produces a new composite type as well. The table will have + a dependency on the referenced type such that cascaded alter and drop + actions on the type will propagate to the table. - When a typed table is created, then the data types of the - columns are determined by the underlying composite type and are - not specified by the CREATE TABLE command. + A typed table always has the same column names and data types as the + type it is derived from, and you cannot specify additional columns. But the CREATE TABLE command can add defaults - and constraints to the table and can specify storage parameters. + and constraints to the table, as well as specify storage parameters. diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 317b89f67c..d756d2b200 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -6994,7 +6994,7 @@ check_of_type(HeapTuple typetuple) if (!typeOk) ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE), - errmsg("type %s is not a composite type", + errmsg("type %s is not a stand-alone composite type", format_type_be(typ->oid)))); } diff --git a/src/test/regress/expected/typed_table.out b/src/test/regress/expected/typed_table.out index 2e47ecbcf5..745fbde811 100644 --- a/src/test/regress/expected/typed_table.out +++ b/src/test/regress/expected/typed_table.out @@ -89,7 +89,7 @@ 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 stand-alone composite type DROP TABLE stuff; -- implicit casting CREATE TYPE person_type AS (id int, name text); -- 2.44.0