Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit31edbad

Browse files
committed
Downgrade implicit casts to text to be assignment-only, except for the ones
from the other string-category types; this eliminates a lot of surprisinginterpretations that the parser could formerly make when there was no directlyapplicable operator.Create a general mechanism that supports casts to and from the standard stringtypes (text,varchar,bpchar) for *every* datatype, by invoking the datatype'sI/O functions. These new casts are assignment-only in the to-string direction,explicit-only in the other, and therefore should create no surprising behavior.Remove a bunch of thereby-obsoleted datatype-specific casting functions.The "general mechanism" is a new expression node type CoerceViaIO that canactually convert between *any* two datatypes if their external textrepresentations are compatible. This is more general than needed for theimmediate feature, but might be useful in plpgsql or other places in future.This commit does nothing about the issue that applying the concatenationoperator || to non-text types will now fail, often with strange error messagesdue to misinterpreting the operator as array concatenation. Since it often(not always) worked before, we should either make it succeed or at least givea more user-friendly error; but details are still under debate.Peter Eisentraut and Tom Lane
1 parent1120b99 commit31edbad

File tree

60 files changed

+848
-1610
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+848
-1610
lines changed

‎contrib/cube/README.cube

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,6 @@ cube_distance(cube, cube) returns double
236236
cube_distance returns the distance between two cubes. If both cubes are
237237
points, this is the normal distance function.
238238

239-
cube(text) returns cube
240-
cube takes text input and returns a cube. This is useful for making cubes
241-
from computed strings.
242-
243239
cube(float8) returns cube
244240
This makes a one dimensional cube with both coordinates the same.
245241
If the type of the argument is a numeric type other than float8 an

‎contrib/cube/cube.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/******************************************************************************
2-
$PostgreSQL: pgsql/contrib/cube/cube.c,v 1.32 2007/03/07 21:21:11 teodor Exp $
2+
$PostgreSQL: pgsql/contrib/cube/cube.c,v 1.33 2007/06/05 21:31:03 tgl Exp $
33
44
This file contains routines that can be bound to a Postgres backend and
55
called by the backend in the process of processing queries. The calling
@@ -173,18 +173,6 @@ cube_in(PG_FUNCTION_ARGS)
173173
PG_RETURN_NDBOX(result);
174174
}
175175

176-
/* Allow conversion from text to cube to allow input of computed strings */
177-
/* There may be issues with toasted data here. I don't know enough to be sure.*/
178-
Datum
179-
cube(PG_FUNCTION_ARGS)
180-
{
181-
char*cstring;
182-
183-
cstring=DatumGetCString(DirectFunctionCall1(textout,PointerGetDatum(PG_GETARG_TEXT_P(0))));
184-
185-
PG_RETURN_DATUM(DirectFunctionCall1(cube_in,PointerGetDatum(cstring)));
186-
}
187-
188176

189177
/*
190178
** Allows the construction of a cube from 2 float[]'s

‎contrib/cube/cube.sql.in

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,6 @@ CREATE TYPE cube (
3131

3232
COMMENT ON TYPE cube IS 'multi-dimensional cube ''(FLOAT-1, FLOAT-2, ..., FLOAT-N), (FLOAT-1, FLOAT-2, ..., FLOAT-N)''';
3333

34-
-- Convert from text to cube
35-
36-
CREATE OR REPLACE FUNCTION cube(text) RETURNS cube
37-
AS 'MODULE_PATHNAME'
38-
LANGUAGE C IMMUTABLE STRICT;
39-
40-
COMMENT ON FUNCTION cube(text) IS 'convert text to cube';
41-
42-
CREATE CAST (text AS cube) WITH FUNCTION cube(text) AS ASSIGNMENT;
43-
4434
--
4535
-- External C-functions for R-tree methods
4636
--

‎contrib/cube/expected/cube.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ SELECT cube_distance('(0)'::cube,'(.3,.4)'::cube);
826826

827827
-- Test of cube function (text to cube)
828828
--
829-
SELECT cube('('||1||','||1.2||')');
829+
SELECT cube('(1,1.2)'::text);
830830
cube
831831
----------
832832
(1, 1.2)

‎contrib/cube/expected/cube_1.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ SELECT cube_distance('(0)'::cube,'(.3,.4)'::cube);
826826

827827
-- Test of cube function (text to cube)
828828
--
829-
SELECT cube('('||1||','||1.2||')');
829+
SELECT cube('(1,1.2)'::text);
830830
cube
831831
----------
832832
(1, 1.2)

‎contrib/cube/expected/cube_2.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ SELECT cube_distance('(0)'::cube,'(.3,.4)'::cube);
826826

827827
-- Test of cube function (text to cube)
828828
--
829-
SELECT cube('('||1||','||1.2||')');
829+
SELECT cube('(1,1.2)'::text);
830830
cube
831831
----------
832832
(1, 1.2)

‎contrib/cube/sql/cube.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ SELECT cube_distance('(0)'::cube,'(.3,.4)'::cube);
223223

224224
-- Test of cube function (text to cube)
225225
--
226-
SELECT cube('('||1||','||1.2||')');
226+
SELECT cube('(1,1.2)'::text);
227227
SELECT cube(NULL);
228228

229229
-- Test of cube_dim function (dimensions stored in cube)

‎contrib/cube/uninstall_cube.sql

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,4 @@ DROP FUNCTION cube_ne(cube, cube);
9292

9393
DROPFUNCTION cube_eq(cube, cube);
9494

95-
DROP CAST (textAS cube);
96-
97-
DROPFUNCTION cube(text);
98-
9995
DROPTYPE cube CASCADE;

‎contrib/isn/isn.c

Lines changed: 1 addition & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/contrib/isn/isn.c,v 1.5 2007/01/0522:19:18 momjian Exp $
10+
* $PostgreSQL: pgsql/contrib/isn/isn.c,v 1.6 2007/06/0521:31:03 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -39,10 +39,6 @@ static const char *isn_names[] = {"EAN13/UPC/ISxN", "EAN13/UPC/ISxN", "EAN13", "
3939
staticboolg_weak= false;
4040
staticboolg_initialized= false;
4141

42-
/* Macros for converting TEXT to and from c-string */
43-
#defineGET_TEXT(cstrp) DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(cstrp)))
44-
#defineGET_STR(textp) DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(textp)))
45-
4642

4743
/***********************************************************************
4844
**
@@ -1042,30 +1038,6 @@ upc_in(PG_FUNCTION_ARGS)
10421038

10431039
/* casting functions
10441040
*/
1045-
PG_FUNCTION_INFO_V1(ean13_cast_to_text);
1046-
Datum
1047-
ean13_cast_to_text(PG_FUNCTION_ARGS)
1048-
{
1049-
ean13val=PG_GETARG_EAN13(0);
1050-
charbuf[MAXEAN13LEN+1];
1051-
1052-
(void)ean2string(val, false,buf, false);
1053-
1054-
PG_RETURN_TEXT_P(GET_TEXT(buf));
1055-
}
1056-
1057-
PG_FUNCTION_INFO_V1(isn_cast_to_text);
1058-
Datum
1059-
isn_cast_to_text(PG_FUNCTION_ARGS)
1060-
{
1061-
ean13val=PG_GETARG_EAN13(0);
1062-
charbuf[MAXEAN13LEN+1];
1063-
1064-
(void)ean2string(val, false,buf, true);
1065-
1066-
PG_RETURN_TEXT_P(GET_TEXT(buf));
1067-
}
1068-
10691041
PG_FUNCTION_INFO_V1(isbn_cast_from_ean13);
10701042
Datum
10711043
isbn_cast_from_ean13(PG_FUNCTION_ARGS)
@@ -1115,61 +1087,6 @@ upc_cast_from_ean13(PG_FUNCTION_ARGS)
11151087
}
11161088

11171089

1118-
PG_FUNCTION_INFO_V1(ean13_cast_from_text);
1119-
Datum
1120-
ean13_cast_from_text(PG_FUNCTION_ARGS)
1121-
{
1122-
constchar*str=GET_STR(PG_GETARG_TEXT_P(0));
1123-
ean13result;
1124-
1125-
(void)string2ean(str, false,&result,EAN13);
1126-
PG_RETURN_EAN13(result);
1127-
}
1128-
1129-
PG_FUNCTION_INFO_V1(isbn_cast_from_text);
1130-
Datum
1131-
isbn_cast_from_text(PG_FUNCTION_ARGS)
1132-
{
1133-
constchar*str=GET_STR(PG_GETARG_TEXT_P(0));
1134-
ean13result;
1135-
1136-
(void)string2ean(str, false,&result,ISBN);
1137-
PG_RETURN_EAN13(result);
1138-
}
1139-
1140-
PG_FUNCTION_INFO_V1(ismn_cast_from_text);
1141-
Datum
1142-
ismn_cast_from_text(PG_FUNCTION_ARGS)
1143-
{
1144-
constchar*str=GET_STR(PG_GETARG_TEXT_P(0));
1145-
ean13result;
1146-
1147-
(void)string2ean(str, false,&result,ISMN);
1148-
PG_RETURN_EAN13(result);
1149-
}
1150-
1151-
PG_FUNCTION_INFO_V1(issn_cast_from_text);
1152-
Datum
1153-
issn_cast_from_text(PG_FUNCTION_ARGS)
1154-
{
1155-
constchar*str=GET_STR(PG_GETARG_TEXT_P(0));
1156-
ean13result;
1157-
1158-
(void)string2ean(str, false,&result,ISSN);
1159-
PG_RETURN_EAN13(result);
1160-
}
1161-
1162-
PG_FUNCTION_INFO_V1(upc_cast_from_text);
1163-
Datum
1164-
upc_cast_from_text(PG_FUNCTION_ARGS)
1165-
{
1166-
constchar*str=GET_STR(PG_GETARG_TEXT_P(0));
1167-
ean13result;
1168-
1169-
(void)string2ean(str, false,&result,UPC);
1170-
PG_RETURN_EAN13(result);
1171-
}
1172-
11731090
/* is_valid - returns false if the "invalid-check-digit-on-input" is set
11741091
*/
11751092
PG_FUNCTION_INFO_V1(is_valid);

‎contrib/isn/isn.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/contrib/isn/isn.h,v 1.3 2007/01/0522:19:18 momjian Exp $
10+
* $PostgreSQL: pgsql/contrib/isn/isn.h,v 1.4 2007/06/0521:31:03 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -38,13 +38,6 @@ extern Datum ismn_in(PG_FUNCTION_ARGS);
3838
externDatumissn_in(PG_FUNCTION_ARGS);
3939
externDatumupc_in(PG_FUNCTION_ARGS);
4040

41-
externDatumean13_cast_to_text(PG_FUNCTION_ARGS);
42-
externDatumisn_cast_to_text(PG_FUNCTION_ARGS);
43-
externDatumean13_cast_from_text(PG_FUNCTION_ARGS);
44-
externDatumisbn_cast_from_text(PG_FUNCTION_ARGS);
45-
externDatumismn_cast_from_text(PG_FUNCTION_ARGS);
46-
externDatumissn_cast_from_text(PG_FUNCTION_ARGS);
47-
externDatumupc_cast_from_text(PG_FUNCTION_ARGS);
4841
externDatumisbn_cast_from_ean13(PG_FUNCTION_ARGS);
4942
externDatumismn_cast_from_ean13(PG_FUNCTION_ARGS);
5043
externDatumissn_cast_from_ean13(PG_FUNCTION_ARGS);

‎contrib/isn/isn.sql.in

Lines changed: 1 addition & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
--PostgreSQL code for ISNs (ISBN, ISMN, ISSN, EAN13, UPC)
33
-- Copyright (c) 2004-2006, German Mendez Bravo (Kronuz)
44
--
5-
--$PostgreSQL: pgsql/contrib/isn/isn.sql.in,v 1.4 2006/11/24 18:44:37 tgl Exp $
5+
--$PostgreSQL: pgsql/contrib/isn/isn.sql.in,v 1.5 2007/06/05 21:31:03 tgl Exp $
66
--
77
-- Example:
88
-- create table test ( id isbn );
@@ -2966,73 +2966,6 @@ AS 'MODULE_PATHNAME', 'upc_cast_from_ean13'
29662966
LANGUAGE 'C' IMMUTABLE STRICT;
29672967

29682968

2969-
CREATE FUNCTION ean13(text)
2970-
RETURNS ean13
2971-
AS 'MODULE_PATHNAME', 'ean13_cast_from_text'
2972-
LANGUAGE 'C' IMMUTABLE STRICT;
2973-
CREATE FUNCTION isbn13(text)
2974-
RETURNS isbn13
2975-
AS 'MODULE_PATHNAME', 'isbn_cast_from_text'
2976-
LANGUAGE 'C' IMMUTABLE STRICT;
2977-
CREATE FUNCTION ismn13(text)
2978-
RETURNS ismn13
2979-
AS 'MODULE_PATHNAME', 'ismn_cast_from_text'
2980-
LANGUAGE 'C' IMMUTABLE STRICT;
2981-
CREATE FUNCTION issn13(text)
2982-
RETURNS issn13
2983-
AS 'MODULE_PATHNAME', 'issn_cast_from_text'
2984-
LANGUAGE 'C' IMMUTABLE STRICT;
2985-
CREATE FUNCTION isbn(text)
2986-
RETURNS isbn
2987-
AS 'MODULE_PATHNAME', 'isbn_cast_from_text'
2988-
LANGUAGE 'C' IMMUTABLE STRICT;
2989-
CREATE FUNCTION ismn(text)
2990-
RETURNS ismn
2991-
AS 'MODULE_PATHNAME', 'ismn_cast_from_text'
2992-
LANGUAGE 'C' IMMUTABLE STRICT;
2993-
CREATE FUNCTION issn(text)
2994-
RETURNS issn
2995-
AS 'MODULE_PATHNAME', 'issn_cast_from_text'
2996-
LANGUAGE 'C' IMMUTABLE STRICT;
2997-
CREATE FUNCTION upc(text)
2998-
RETURNS upc
2999-
AS 'MODULE_PATHNAME', 'upc_cast_from_text'
3000-
LANGUAGE 'C' IMMUTABLE STRICT;
3001-
3002-
3003-
CREATE FUNCTION text(ean13)
3004-
RETURNS text
3005-
AS 'MODULE_PATHNAME', 'ean13_cast_to_text'
3006-
LANGUAGE 'C' IMMUTABLE STRICT;
3007-
CREATE FUNCTION text(isbn13)
3008-
RETURNS text
3009-
AS 'MODULE_PATHNAME', 'ean13_cast_to_text'
3010-
LANGUAGE 'C' IMMUTABLE STRICT;
3011-
CREATE FUNCTION text(ismn13)
3012-
RETURNS text
3013-
AS 'MODULE_PATHNAME', 'ean13_cast_to_text'
3014-
LANGUAGE 'C' IMMUTABLE STRICT;
3015-
CREATE FUNCTION text(issn13)
3016-
RETURNS text
3017-
AS 'MODULE_PATHNAME', 'ean13_cast_to_text'
3018-
LANGUAGE 'C' IMMUTABLE STRICT;
3019-
CREATE FUNCTION text(isbn)
3020-
RETURNS text
3021-
AS 'MODULE_PATHNAME', 'isn_cast_to_text'
3022-
LANGUAGE 'C' IMMUTABLE STRICT;
3023-
CREATE FUNCTION text(ismn)
3024-
RETURNS text
3025-
AS 'MODULE_PATHNAME', 'isn_cast_to_text'
3026-
LANGUAGE 'C' IMMUTABLE STRICT;
3027-
CREATE FUNCTION text(issn)
3028-
RETURNS text
3029-
AS 'MODULE_PATHNAME', 'isn_cast_to_text'
3030-
LANGUAGE 'C' IMMUTABLE STRICT;
3031-
CREATE FUNCTION text(upc)
3032-
RETURNS text
3033-
AS 'MODULE_PATHNAME', 'isn_cast_to_text'
3034-
LANGUAGE 'C' IMMUTABLE STRICT;
3035-
30362969
CREATE CAST (ean13 AS isbn13) WITH FUNCTION isbn13(ean13);
30372970
CREATE CAST (ean13 AS isbn) WITH FUNCTION isbn(ean13);
30382971
CREATE CAST (ean13 AS ismn13) WITH FUNCTION ismn13(ean13);
@@ -3056,24 +2989,6 @@ CREATE CAST (ismn13 AS ismn) WITHOUT FUNCTION AS ASSIGNMENT;
30562989
CREATE CAST (issn AS issn13) WITHOUT FUNCTION AS ASSIGNMENT;
30572990
CREATE CAST (issn13 AS issn) WITHOUT FUNCTION AS ASSIGNMENT;
30582991

3059-
CREATE CAST (text AS ean13) WITH FUNCTION ean13(text);
3060-
CREATE CAST (text AS isbn13) WITH FUNCTION isbn13(text);
3061-
CREATE CAST (text AS ismn13) WITH FUNCTION ismn13(text);
3062-
CREATE CAST (text AS issn13) WITH FUNCTION issn13(text);
3063-
CREATE CAST (text AS isbn) WITH FUNCTION isbn(text);
3064-
CREATE CAST (text AS ismn) WITH FUNCTION ismn(text);
3065-
CREATE CAST (text AS issn) WITH FUNCTION issn(text);
3066-
CREATE CAST (text AS upc) WITH FUNCTION upc(text);
3067-
3068-
CREATE CAST (ean13 AS text) WITH FUNCTION text(ean13);
3069-
CREATE CAST (isbn13 AS text) WITH FUNCTION text(isbn13);
3070-
CREATE CAST (ismn13 AS text) WITH FUNCTION text(ismn13);
3071-
CREATE CAST (issn13 AS text) WITH FUNCTION text(issn13);
3072-
CREATE CAST (isbn AS text) WITH FUNCTION text(isbn);
3073-
CREATE CAST (ismn AS text) WITH FUNCTION text(ismn);
3074-
CREATE CAST (issn AS text) WITH FUNCTION text(issn);
3075-
CREATE CAST (upc AS text) WITH FUNCTION text(upc);
3076-
30772992
--
30782993
-- Validation stuff for lose types:
30792994
--

‎doc/src/sgml/catalogs.sgml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/catalogs.sgml,v 2.152 2007/05/15 19:13:54 neilc Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/catalogs.sgml,v 2.153 2007/06/05 21:31:03 tgl Exp $ -->
22
<!--
33
Documentation of the system catalogs, directed toward PostgreSQL developers
44
-->
@@ -1358,11 +1358,22 @@
13581358
</indexterm>
13591359

13601360
<para>
1361-
The catalog <structname>pg_cast</structname> stores data type conversion paths,
1362-
both built-in paths and those defined with
1361+
The catalog <structname>pg_cast</structname> stores data type conversion
1362+
paths,both built-in paths and those defined with
13631363
<xref linkend="sql-createcast" endterm="sql-createcast-title">.
13641364
</para>
13651365

1366+
<para>
1367+
It should be noted that <structname>pg_cast</structname> does not represent
1368+
every type conversion that the system knows how to perform; only those that
1369+
cannot be deduced from some generic rule. For example, casting between a
1370+
domain and its base type is not explicitly represented in
1371+
<structname>pg_cast</structname>. Another important exception is that
1372+
<quote>I/O conversion casts</>, those performed using a data type's own
1373+
I/O functions to convert to or from <type>text</> or other string types,
1374+
are not explicitly represented in <structname>pg_cast</structname>.
1375+
</para>
1376+
13661377
<table>
13671378
<title><structfield>pg_cast</> Columns</title>
13681379

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp