From ca0d2197ca1ed1e72243c5a3466d93e4954d30b0 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Mon, 26 Jun 2006 17:24:41 +0000 Subject: Change the row constructor syntax (ROW(...)) so that list elements foo.* will be expanded to a list of their member fields, rather than creating a nested rowtype field as formerly. (The old behavior is still available by omitting '.*'.) This syntax is not allowed by the SQL spec AFAICS, so changing its behavior doesn't violate the spec. The new behavior is substantially more useful since it allows, for example, triggers to check for data changes with 'if row(new.*) is distinct from row(old.*)'. Per my recent proposal. --- doc/src/sgml/syntax.sgml | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/syntax.sgml b/doc/src/sgml/syntax.sgml index 97020845b50..74cc813a681 100644 --- a/doc/src/sgml/syntax.sgml +++ b/doc/src/sgml/syntax.sgml @@ -1,4 +1,4 @@ - + SQL Syntax @@ -1570,6 +1570,31 @@ SELECT ROW(1,2.5,'this is a test'); expression in the list. + + A row constructor can include the syntax + rowvalue.*, + which will be expanded to a list of the elements of the row value, + just as occurs when the .* syntax is used at the top level + of a SELECT list. For example, if table t has + columns f1 and f2, these are the same: + +SELECT ROW(t.*, 42) FROM t; +SELECT ROW(t.f1, t.f2, 42) FROM t; + + + + + + Before PostgreSQL 8.2, the + .* syntax was not expanded, so that writing + ROW(t.*, 42) created a two-field row whose first field + was another row value. The new behavior is usually more useful. + If you need the old behavior of nested row values, write the inner + row value without .*, for instance + ROW(t, 42). + + + By default, the value created by a ROW expression is of an anonymous record type. If necessary, it can be cast to a named @@ -1619,7 +1644,7 @@ SELECT getf1(CAST(ROW(11,'this is a test',2.5) AS myrowtype)); SELECT ROW(1,2.5,'this is a test') = ROW(1, 3, 'not the same'); -SELECT ROW(a, b, c) IS NOT NULL FROM table; +SELECT ROW(table.*) IS NULL FROM table; -- detect all-null rows For more detail see . Row constructors can also be used in connection with subqueries, -- cgit v1.2.3