Here it is.The patch does not apply and git also whines about trailing space. It needs a v3...
The attachement here works for me. Could you be more precise about the issue? postgresql> git branch test master postgresql> git checkout test Switched to branch 'test' postgresql> patch -p1 < ../as_explicit-v2.patch patching file doc/src/sgml/ref/create_cast.sgml patching file src/backend/parser/gram.y patching file src/include/parser/kwlist.h patching file src/test/regress/expected/create_cast.out patching file src/test/regress/sql/create_cast.sql
Please note that a community-agreed behavior on this patch is not yet acquired, you should consider that too.
Sure. I've sent my argumentation against Robert objections. -- Fabien.
diff --git a/doc/src/sgml/ref/create_cast.sgml b/doc/src/sgml/ref/create_cast.sgml index 29ea298..0ace996 100644 --- a/doc/src/sgml/ref/create_cast.sgml +++ b/doc/src/sgml/ref/create_cast.sgml @@ -20,15 +20,15 @@ <synopsis> CREATE CAST (<replaceable>source_type</replaceable> AS <replaceable>target_type</replaceable>) WITH FUNCTION <replaceable>function_name</replaceable> (<replaceable>argument_type</replaceable> [, ...]) - [ AS ASSIGNMENT | AS IMPLICIT ] + [ AS ASSIGNMENT | AS EXPLICIT | AS IMPLICIT ] CREATE CAST (<replaceable>source_type</replaceable> AS <replaceable>target_type</replaceable>) WITHOUT FUNCTION - [ AS ASSIGNMENT | AS IMPLICIT ] + [ AS ASSIGNMENT | AS EXPLICIT | AS IMPLICIT ] CREATE CAST (<replaceable>source_type</replaceable> AS <replaceable>target_type</replaceable>) WITH INOUT - [ AS ASSIGNMENT | AS IMPLICIT ] + [ AS ASSIGNMENT | AS EXPLICIT | AS IMPLICIT ] </synopsis> </refsynopsisdiv> @@ -74,7 +74,8 @@ SELECT CAST(42 AS float8); </para> <para> - By default, a cast can be invoked only by an explicit cast request, + By default, or if the cast is declared <literal>AS EXPLICIT</>, + a cast can be invoked only by an explicit cast request, that is an explicit <literal>CAST(<replaceable>x</> AS <replaceable>typename</>)</literal> or <replaceable>x</><literal>::</><replaceable>typename</> @@ -239,6 +240,21 @@ SELECT CAST ( 2 AS numeric ) + 4.0; </varlistentry> <varlistentry> + <term><literal>AS EXPLICIT</literal></term> + + <listitem> + <para> + Indicates that the cast can be invoked only with an explicit + cast request, that is an explicit <literal>CAST(<replaceable>x</> AS + <replaceable>typename</>)</literal> or + <replaceable>x</><literal>::</><replaceable>typename</> + construct. + This is the default. + </para> + </listitem> + </varlistentry> + + <varlistentry> <term><literal>AS IMPLICIT</literal></term> <listitem> diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 5094226..2c0694f 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -533,7 +533,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query); DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P DOUBLE_P DROP EACH ELSE ENABLE_P ENCODING ENCRYPTED END_P ENUM_P ESCAPE EVENT EXCEPT - EXCLUDE EXCLUDING EXCLUSIVE EXECUTE EXISTS EXPLAIN + EXCLUDE EXCLUDING EXCLUSIVE EXECUTE EXISTS EXPLAIN EXPLICIT EXTENSION EXTERNAL EXTRACT FALSE_P FAMILY FETCH FIRST_P FLOAT_P FOLLOWING FOR FORCE FOREIGN FORWARD @@ -6720,6 +6720,7 @@ CreateCastStmt: CREATE CAST '(' Typename AS Typename ')' cast_context: AS IMPLICIT_P { $$ = COERCION_IMPLICIT; } | AS ASSIGNMENT { $$ = COERCION_ASSIGNMENT; } + | AS EXPLICIT { $$ = COERCION_EXPLICIT; } | /*EMPTY*/ { $$ = COERCION_EXPLICIT; } ; @@ -12723,6 +12724,7 @@ unreserved_keyword: | EXCLUSIVE | EXECUTE | EXPLAIN + | EXPLICIT | EXTENSION | EXTERNAL | FAMILY diff --git a/src/include/parser/kwlist.h b/src/include/parser/kwlist.h index 68a13b7..f97389b 100644 --- a/src/include/parser/kwlist.h +++ b/src/include/parser/kwlist.h @@ -149,6 +149,7 @@ PG_KEYWORD("exclusive", EXCLUSIVE, UNRESERVED_KEYWORD) PG_KEYWORD("execute", EXECUTE, UNRESERVED_KEYWORD) PG_KEYWORD("exists", EXISTS, COL_NAME_KEYWORD) PG_KEYWORD("explain", EXPLAIN, UNRESERVED_KEYWORD) +PG_KEYWORD("explicit", EXPLICIT, UNRESERVED_KEYWORD) PG_KEYWORD("extension", EXTENSION, UNRESERVED_KEYWORD) PG_KEYWORD("external", EXTERNAL, UNRESERVED_KEYWORD) PG_KEYWORD("extract", EXTRACT, COL_NAME_KEYWORD) diff --git a/src/test/regress/expected/create_cast.out b/src/test/regress/expected/create_cast.out index 56cd86e..a8858fa 100644 --- a/src/test/regress/expected/create_cast.out +++ b/src/test/regress/expected/create_cast.out @@ -27,8 +27,8 @@ ERROR: function casttestfunc(text) does not exist LINE 1: SELECT casttestfunc('foo'::text); ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. --- Try binary coercion cast -CREATE CAST (text AS casttesttype) WITHOUT FUNCTION; +-- Try binary coercion cast and verbose AS EXPLICIT +CREATE CAST (text AS casttesttype) WITHOUT FUNCTION AS EXPLICIT; SELECT casttestfunc('foo'::text); -- doesn't work, as the cast is explicit ERROR: function casttestfunc(text) does not exist LINE 1: SELECT casttestfunc('foo'::text); @@ -54,7 +54,7 @@ SELECT 1234::int4::casttesttype; -- No cast yet, should fail ERROR: cannot cast type integer to casttesttype LINE 1: SELECT 1234::int4::casttesttype; ^ -CREATE CAST (int4 AS casttesttype) WITH INOUT; +CREATE CAST (int4 AS casttesttype) WITH INOUT; -- default AS EXPLICIT SELECT 1234::int4::casttesttype; -- Should work now casttesttype -------------- diff --git a/src/test/regress/sql/create_cast.sql b/src/test/regress/sql/create_cast.sql index ad348da..91123ca 100644 --- a/src/test/regress/sql/create_cast.sql +++ b/src/test/regress/sql/create_cast.sql @@ -27,8 +27,8 @@ $$ SELECT 1; $$; SELECT casttestfunc('foo'::text); -- fails, as there's no cast --- Try binary coercion cast -CREATE CAST (text AS casttesttype) WITHOUT FUNCTION; +-- Try binary coercion cast and verbose AS EXPLICIT +CREATE CAST (text AS casttesttype) WITHOUT FUNCTION AS EXPLICIT; SELECT casttestfunc('foo'::text); -- doesn't work, as the cast is explicit SELECT casttestfunc('foo'::text::casttesttype); -- should work DROP CAST (text AS casttesttype); -- cleanup @@ -40,7 +40,7 @@ SELECT casttestfunc('foo'::text); -- Should work now -- Try I/O conversion cast. SELECT 1234::int4::casttesttype; -- No cast yet, should fail -CREATE CAST (int4 AS casttesttype) WITH INOUT; +CREATE CAST (int4 AS casttesttype) WITH INOUT; -- default AS EXPLICIT SELECT 1234::int4::casttesttype; -- Should work now DROP CAST (int4 AS casttesttype);
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers