7
7
*
8
8
*
9
9
* IDENTIFICATION
10
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.11 1998/02/26 04:33:34 momjian Exp $
10
+ * $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.12 1998/07/08 14: 04:11 thomas Exp $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
20
20
#include "catalog/pg_type.h"
21
21
#include "nodes/makefuncs.h"
22
22
#include "parser/parse_relation.h"
23
+ #include "parser/parse_coerce.h"
23
24
#include "utils/acl.h"
24
25
#include "utils/builtins.h"
25
26
#include "utils/lsyscache.h"
@@ -371,9 +372,8 @@ attnumTypeId(Relation rd, int attid)
371
372
return (rd -> rd_att -> attrs [attid - 1 ]-> atttypid );
372
373
}
373
374
374
- /*
375
- * handleTargetColname -
376
- * use column names from insert
375
+ /* handleTargetColname()
376
+ * Use column names from insert.
377
377
*/
378
378
void
379
379
handleTargetColname (ParseState * pstate , char * * resname ,
@@ -395,9 +395,8 @@ handleTargetColname(ParseState *pstate, char **resname,
395
395
checkTargetTypes (pstate , * resname , refname , colname );
396
396
}
397
397
398
- /*
399
- * checkTargetTypes -
400
- * checks value and target column types
398
+ /* checkTargetTypes()
399
+ * Checks value and target column types.
401
400
*/
402
401
static void
403
402
checkTargetTypes (ParseState * pstate , char * target_colname ,
@@ -432,6 +431,27 @@ checkTargetTypes(ParseState *pstate, char *target_colname,
432
431
resdomno_target = attnameAttNum (pstate -> p_target_relation , target_colname );
433
432
attrtype_target = attnumTypeId (pstate -> p_target_relation , resdomno_target );
434
433
434
+ #if FALSE
435
+ if ((attrtype_id != attrtype_target )
436
+ || (get_atttypmod (rte -> relid , resdomno_id ) !=
437
+ get_atttypmod (pstate -> p_target_relation -> rd_id , resdomno_target )))
438
+ {
439
+ if (can_coerce_type (1 , & attrtype_id , & attrtype_target ))
440
+ {
441
+ Node * expr = coerce_type (pstate , expr , attrtype_id , attrtype_target );
442
+
443
+ elog (ERROR , "Type %s(%d) can be coerced to match target column %s(%d)" ,
444
+ colname , get_atttypmod (rte -> relid , resdomno_id ),
445
+ target_colname , get_atttypmod (pstate -> p_target_relation -> rd_id , resdomno_target ));
446
+ }
447
+ else
448
+ {
449
+ elog (ERROR , "Type or size of %s(%d) does not match target column %s(%d)" ,
450
+ colname , get_atttypmod (rte -> relid , resdomno_id ),
451
+ target_colname , get_atttypmod (pstate -> p_target_relation -> rd_id , resdomno_target ));
452
+ }
453
+ }
454
+ #else
435
455
if (attrtype_id != attrtype_target )
436
456
elog (ERROR , "Type of %s does not match target column %s" ,
437
457
colname , target_colname );
@@ -446,5 +466,5 @@ checkTargetTypes(ParseState *pstate, char *target_colname,
446
466
get_atttypmod (pstate -> p_target_relation -> rd_id , resdomno_target ))
447
467
elog (ERROR , "Length of %s is longer than length of target column %s" ,
448
468
colname , target_colname );
449
-
469
+ #endif
450
470
}
0 commit comments