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

Commit89ab5c4

Browse files
committed
Remove grotty special-case code in coerce_to_target_type() that
implemented casts to varchar and bpchar using a cast-to-text function.This is a holdover from before we had pg_cast; it now makes more senseto just list these casts in pg_cast. While at it, add pg_cast entriesfor the other direction (casts from varchar/bpchar) where feasible.
1 parent64fe1fd commit89ab5c4

File tree

5 files changed

+101
-53
lines changed

5 files changed

+101
-53
lines changed

‎src/backend/parser/parse_coerce.c

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/parser/parse_coerce.c,v 2.113 2003/12/17 19:49:39 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/parser/parse_coerce.c,v 2.114 2004/03/15 01:13:40 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -63,50 +63,6 @@ coerce_to_target_type(ParseState *pstate, Node *expr, Oid exprtype,
6363
if (can_coerce_type(1,&exprtype,&targettype,ccontext))
6464
expr=coerce_type(pstate,expr,exprtype,targettype,
6565
ccontext,cformat);
66-
elseif (ccontext >=COERCION_ASSIGNMENT)
67-
{
68-
/*
69-
* String hacks to get transparent conversions for char and
70-
* varchar: if a coercion to text is available, use it for forced
71-
* coercions to char(n) or varchar(n) or domains thereof.
72-
*
73-
* This is pretty grotty, but seems easier to maintain than providing
74-
* entries in pg_cast that parallel all the ones for text.
75-
*/
76-
Oidtargetbasetype=getBaseType(targettype);
77-
78-
if (targetbasetype==BPCHAROID||targetbasetype==VARCHAROID)
79-
{
80-
Oidtext_id=TEXTOID;
81-
82-
if (can_coerce_type(1,&exprtype,&text_id,ccontext))
83-
{
84-
expr=coerce_type(pstate,expr,exprtype,text_id,
85-
ccontext,cformat);
86-
if (targetbasetype!=targettype)
87-
{
88-
/* need to coerce to domain over char or varchar */
89-
expr=coerce_to_domain(expr,targetbasetype,targettype,
90-
cformat);
91-
}
92-
else
93-
{
94-
/*
95-
* need a RelabelType if no typmod coercion will be
96-
* performed
97-
*/
98-
if (targettypmod<0)
99-
expr= (Node*)makeRelabelType((Expr*)expr,
100-
targettype,-1,
101-
cformat);
102-
}
103-
}
104-
else
105-
expr=NULL;
106-
}
107-
else
108-
expr=NULL;
109-
}
11066
else
11167
expr=NULL;
11268

‎src/include/catalog/catversion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
3838
* Portions Copyright (c) 1994, Regents of the University of California
3939
*
40-
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.219 2004/02/14 20:16:17 tgl Exp $
40+
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.220 2004/03/15 01:13:41 tgl Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO200402141
56+
#defineCATALOG_VERSION_NO200403141
5757

5858
#endif

‎src/include/catalog/pg_cast.h

Lines changed: 84 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* Copyright (c) 2002-2003, PostgreSQL Global Development Group
99
*
10-
* $PostgreSQL: pgsql/src/include/catalog/pg_cast.h,v 1.10 2003/11/29 22:40:58 pgsql Exp $
10+
* $PostgreSQL: pgsql/src/include/catalog/pg_cast.h,v 1.11 2004/03/15 01:13:41 tgl Exp $
1111
*
1212
* NOTES
1313
* the genbki.sh script reads this file and generates .bki
@@ -168,11 +168,14 @@ DATA(insert ( 1042 1043 401 i ));
168168
DATA(insert (1043250i ));
169169
DATA(insert (104310420i ));
170170
DATA(insert (1825946i ));
171-
DATA(insert (181042860i ));
171+
DATA(insert (181042860a ));
172+
DATA(insert (181043946a ));
172173
DATA(insert (1925406i ));
173-
DATA(insert (191042408i ));
174-
DATA(insert (1910431401i ));
174+
DATA(insert (191042408a ));
175+
DATA(insert (1910431401a ));
175176
DATA(insert (2518944a ));
177+
DATA(insert (104218944a ));
178+
DATA(insert (104318944a ));
176179
DATA(insert (2519407i ));
177180
DATA(insert (104219409i ));
178181
DATA(insert (1043191400i ));
@@ -281,4 +284,81 @@ DATA(insert (25 1266 938 e ));
281284
DATA(insert (1700251688i ));
282285
DATA(insert (2517001686e ));
283286

287+
/*
288+
* Cross-category casts to and from VARCHAR
289+
*
290+
* We support all the same casts as for TEXT, but none are implicit.
291+
*/
292+
DATA(insert (2010431289a ));
293+
DATA(insert (1043201290e ));
294+
DATA(insert (211043113a ));
295+
DATA(insert (104321818e ));
296+
DATA(insert (231043112a ));
297+
DATA(insert (104323819e ));
298+
DATA(insert (261043114a ));
299+
DATA(insert (104326817e ));
300+
DATA(insert (10436501714e ));
301+
DATA(insert (7001043841a ));
302+
DATA(insert (1043700839e ));
303+
DATA(insert (7011043840a ));
304+
DATA(insert (1043701838e ));
305+
DATA(insert (8291043752e ));
306+
DATA(insert (1043829767e ));
307+
DATA(insert (6501043730e ));
308+
DATA(insert (8691043730e ));
309+
DATA(insert (10438691713e ));
310+
DATA(insert (10821043749a ));
311+
DATA(insert (10431082748e ));
312+
DATA(insert (10831043948a ));
313+
DATA(insert (10431083837e ));
314+
DATA(insert (111410432034a ));
315+
DATA(insert (104311142022e ));
316+
DATA(insert (118410431192a ));
317+
DATA(insert (104311841191e ));
318+
DATA(insert (118610431193a ));
319+
DATA(insert (104311861263e ));
320+
DATA(insert (12661043939a ));
321+
DATA(insert (10431266938e ));
322+
DATA(insert (170010431688a ));
323+
DATA(insert (104317001686e ));
324+
325+
/*
326+
* Cross-category casts to and from BPCHAR
327+
*
328+
* A function supporting cast to TEXT/VARCHAR can be used for cast to BPCHAR,
329+
* but the other direction is okay only if the function treats trailing
330+
* blanks as insignificant. So this is a subset of the VARCHAR list.
331+
* (Arguably the holdouts should be fixed, but I'm not doing that now...)
332+
*/
333+
DATA(insert (2010421289a ));
334+
DATA(insert (1042201290e ));
335+
DATA(insert (211042113a ));
336+
DATA(insert (104221818e ));
337+
DATA(insert (231042112a ));
338+
DATA(insert (104223819e ));
339+
DATA(insert (261042114a ));
340+
DATA(insert (104226817e ));
341+
DATA(insert (7001042841a ));
342+
DATA(insert (1042700839e ));
343+
DATA(insert (7011042840a ));
344+
DATA(insert (1042701838e ));
345+
DATA(insert (8291042752e ));
346+
DATA(insert (1042829767e ));
347+
DATA(insert (6501042730e ));
348+
DATA(insert (8691042730e ));
349+
DATA(insert (10821042749a ));
350+
DATA(insert (10421082748e ));
351+
DATA(insert (10831042948a ));
352+
DATA(insert (10421083837e ));
353+
DATA(insert (111410422034a ));
354+
DATA(insert (104211142022e ));
355+
DATA(insert (118410421192a ));
356+
DATA(insert (104211841191e ));
357+
DATA(insert (118610421193a ));
358+
DATA(insert (104211861263e ));
359+
DATA(insert (12661042939a ));
360+
DATA(insert (10421266938e ));
361+
DATA(insert (170010421688a ));
362+
DATA(insert (104217001686e ));
363+
284364
#endif/* PG_CAST_H */

‎src/test/regress/expected/opr_sanity.out

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,17 @@ WHERE castsource = casttarget OR castsource = 0 OR casttarget = 0
239239
-- Look for cast functions that don't have the right signature. The
240240
-- argument and result types in pg_proc must be the same as, or binary
241241
-- compatible with, what it says in pg_cast.
242+
-- As a special case, we allow casts from CHAR(n) that use functions
243+
-- declared to take TEXT. This does not pass the binary-coercibility test
244+
-- because CHAR(n)-to-TEXT normally invokes rtrim(). However, the results
245+
-- are the same, so long as the function is one that ignores trailing blanks.
242246
SELECT c.*
243247
FROM pg_cast c, pg_proc p
244248
WHERE c.castfunc = p.oid AND
245249
(p.pronargs <> 1
246-
OR NOT binary_coercible(c.castsource, p.proargtypes[0])
250+
OR NOT (binary_coercible(c.castsource, p.proargtypes[0])
251+
OR (c.castsource = 'character'::regtype AND
252+
p.proargtypes[0] = 'text'::regtype))
247253
OR NOT binary_coercible(p.prorettype, c.casttarget));
248254
castsource | casttarget | castfunc | castcontext
249255
------------+------------+----------+-------------

‎src/test/regress/sql/opr_sanity.sql

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,18 @@ WHERE castsource = casttarget OR castsource = 0 OR casttarget = 0
196196
-- Look for cast functions that don't have the right signature. The
197197
-- argument and result types in pg_proc must be the same as, or binary
198198
-- compatible with, what it says in pg_cast.
199+
-- As a special case, we allow casts from CHAR(n) that use functions
200+
-- declared to take TEXT. This does not pass the binary-coercibility test
201+
-- because CHAR(n)-to-TEXT normally invokes rtrim(). However, the results
202+
-- are the same, so long as the function is one that ignores trailing blanks.
199203

200204
SELECT c.*
201205
FROM pg_cast c, pg_proc p
202206
WHEREc.castfunc=p.oidAND
203207
(p.pronargs<>1
204-
OR NOT binary_coercible(c.castsource,p.proargtypes[0])
208+
OR NOT (binary_coercible(c.castsource,p.proargtypes[0])
209+
OR (c.castsource='character'::regtypeAND
210+
p.proargtypes[0]='text'::regtype))
205211
OR NOT binary_coercible(p.prorettype,c.casttarget));
206212

207213
-- Look for binary compatible casts that do not have the reverse

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp