diff options
| author | Tom Lane | 2010-11-07 18:03:19 +0000 |
|---|---|---|
| committer | Tom Lane | 2010-11-07 18:03:19 +0000 |
| commit | 543d22fc7423747afd59fe7214f2ddf6259efc62 (patch) | |
| tree | b7c5be5456509ed805cae6ad5488f74530651bb9 /src/test | |
| parent | e43fb604d6db229d70d3101aa53348cc16a5473a (diff) | |
Prevent invoking I/O conversion casts via functional/attribute notation.
PG 8.4 added a built-in feature for casting pretty much any data type to
string types (text, varchar, etc). We allowed this to work in any of the
historically-allowed syntaxes: CAST(x AS text), x::text, text(x), or
x.text. However, multiple complaints have shown that it's too easy to
invoke such casts unintentionally in the latter two styles, particularly
field selection. To cure the problem with the narrowest possible change
of behavior, disallow use of I/O conversion casts from composite types to
string types via functional/attribute syntax. The new functionality is
still available via cast syntax.
In passing, document the equivalence of functional and attribute syntax
in a more visible place.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/regress/expected/rowtypes.out | 46 | ||||
| -rw-r--r-- | src/test/regress/sql/rowtypes.sql | 15 |
2 files changed, 61 insertions, 0 deletions
diff --git a/src/test/regress/expected/rowtypes.out b/src/test/regress/expected/rowtypes.out index a21f7b8c06b..e5cd71421c6 100644 --- a/src/test/regress/expected/rowtypes.out +++ b/src/test/regress/expected/rowtypes.out @@ -324,3 +324,49 @@ select * from price; (3 rows) rollback; +-- +-- We allow I/O conversion casts from composite types to strings to be +-- invoked via cast syntax, but not functional syntax. This is because +-- the latter is too prone to be invoked unintentionally. +-- +select cast (fullname as text) from fullname; + fullname +---------- +(0 rows) + +select fullname::text from fullname; + fullname +---------- +(0 rows) + +select text(fullname) from fullname; -- error +ERROR: function text(fullname) does not exist +LINE 1: select text(fullname) from fullname; + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +select fullname.text from fullname; -- error +ERROR: column fullname.text does not exist +LINE 1: select fullname.text from fullname; + ^ +-- same, but RECORD instead of named composite type: +select cast (row('Jim', 'Beam') as text); + row +------------ + (Jim,Beam) +(1 row) + +select (row('Jim', 'Beam'))::text; + row +------------ + (Jim,Beam) +(1 row) + +select text(row('Jim', 'Beam')); -- error +ERROR: function text(record) does not exist +LINE 1: select text(row('Jim', 'Beam')); + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +select (row('Jim', 'Beam')).text; -- error +ERROR: could not identify column "text" in record data type +LINE 1: select (row('Jim', 'Beam')).text; + ^ diff --git a/src/test/regress/sql/rowtypes.sql b/src/test/regress/sql/rowtypes.sql index e5a77f79f65..9041df147fe 100644 --- a/src/test/regress/sql/rowtypes.sql +++ b/src/test/regress/sql/rowtypes.sql @@ -157,3 +157,18 @@ UPDATE price select * from price; rollback; + +-- +-- We allow I/O conversion casts from composite types to strings to be +-- invoked via cast syntax, but not functional syntax. This is because +-- the latter is too prone to be invoked unintentionally. +-- +select cast (fullname as text) from fullname; +select fullname::text from fullname; +select text(fullname) from fullname; -- error +select fullname.text from fullname; -- error +-- same, but RECORD instead of named composite type: +select cast (row('Jim', 'Beam') as text); +select (row('Jim', 'Beam'))::text; +select text(row('Jim', 'Beam')); -- error +select (row('Jim', 'Beam')).text; -- error |
