8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $PostgreSQL: pgsql/src/backend/parser/parse_relation.c,v 1.143 2009/07/16 06:33:43 petere Exp $
11
+ * $PostgreSQL: pgsql/src/backend/parser/parse_relation.c,v 1.144 2009/10/21 20:22:38 tgl Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
32
32
#include "utils/syscache.h"
33
33
34
34
35
- /* GUC parameter */
36
- bool add_missing_from ;
37
-
38
35
static RangeTblEntry * scanNameSpaceForRefname (ParseState * pstate ,
39
36
const char * refname , int location );
40
37
static RangeTblEntry * scanNameSpaceForRelid (ParseState * pstate , Oid relid ,
@@ -51,7 +48,6 @@ static void expandTupleDesc(TupleDesc tupdesc, Alias *eref,
51
48
int location , bool include_dropped ,
52
49
List * * colnames , List * * colvars );
53
50
static int specialAttNum (const char * attname );
54
- static void warnAutoRange (ParseState * pstate , RangeVar * relation );
55
51
56
52
57
53
/*
@@ -249,7 +245,7 @@ isFutureCTE(ParseState *pstate, const char *refname)
249
245
* visible in the p_relnamespace lists. This behavior is invalid per the SQL
250
246
* spec, and it may give ambiguous results (there might be multiple equally
251
247
* valid matches, but only one will be returned). This must be used ONLY
252
- * as a heuristic in giving suitable error messages. See warnAutoRange .
248
+ * as a heuristic in giving suitable error messages. See errorMissingRTE .
253
249
*
254
250
* Notice that we consider both matches on actual relation (or CTE) name
255
251
* and matches on alias.
@@ -573,22 +569,15 @@ qualifiedNameToVar(ParseState *pstate,
573
569
char * schemaname ,
574
570
char * refname ,
575
571
char * colname ,
576
- bool implicitRTEOK ,
577
572
int location )
578
573
{
579
574
RangeTblEntry * rte ;
580
575
int sublevels_up ;
581
576
582
577
rte = refnameRangeTblEntry (pstate , schemaname , refname , location ,
583
578
& sublevels_up );
584
-
585
579
if (rte == NULL )
586
- {
587
- if (!implicitRTEOK )
588
- return NULL ;
589
- rte = addImplicitRTE (pstate ,
590
- makeRangeVar (schemaname , refname , location ));
591
- }
580
+ return NULL ;
592
581
593
582
return scanRTEForColumn (pstate , rte , colname , location );
594
583
}
@@ -1527,42 +1516,6 @@ addRTEtoQuery(ParseState *pstate, RangeTblEntry *rte,
1527
1516
pstate -> p_varnamespace = lappend (pstate -> p_varnamespace , rte );
1528
1517
}
1529
1518
1530
- /*
1531
- * Add a POSTQUEL-style implicit RTE.
1532
- *
1533
- * We assume caller has already checked that there is no RTE or join with
1534
- * a conflicting name.
1535
- */
1536
- RangeTblEntry *
1537
- addImplicitRTE (ParseState * pstate , RangeVar * relation )
1538
- {
1539
- CommonTableExpr * cte = NULL ;
1540
- Index levelsup = 0 ;
1541
- RangeTblEntry * rte ;
1542
-
1543
- /* issue warning or error as needed */
1544
- warnAutoRange (pstate , relation );
1545
-
1546
- /* if it is an unqualified name, it might be a CTE reference */
1547
- if (!relation -> schemaname )
1548
- cte = scanNameSpaceForCTE (pstate , relation -> relname , & levelsup );
1549
-
1550
- /*
1551
- * Note that we set inFromCl true, so that the RTE will be listed
1552
- * explicitly if the parsetree is ever decompiled by ruleutils.c. This
1553
- * provides a migration path for views/rules that were originally written
1554
- * with implicit-RTE syntax.
1555
- */
1556
- if (cte )
1557
- rte = addRangeTableEntryForCTE (pstate , cte , levelsup , NULL , true);
1558
- else
1559
- rte = addRangeTableEntry (pstate , relation , NULL , false, true);
1560
- /* Add to joinlist and relnamespace, but not varnamespace */
1561
- addRTEtoQuery (pstate , rte , true, true, false);
1562
-
1563
- return rte ;
1564
- }
1565
-
1566
1519
/*
1567
1520
* expandRTE -- expand the columns of a rangetable entry
1568
1521
*
@@ -2417,21 +2370,21 @@ attnumTypeId(Relation rd, int attid)
2417
2370
}
2418
2371
2419
2372
/*
2420
- * Generate a warning or error about an implicit RTE, if appropriate .
2373
+ * Generate a suitable error about a missing RTE.
2421
2374
*
2422
- * If ADD_MISSING_FROM is not enabled, raise an error. Otherwise, emit
2423
- * a warning .
2375
+ * Since this is a very common type of error, we work rather hard to
2376
+ * produce a helpful message .
2424
2377
*/
2425
- static void
2426
- warnAutoRange (ParseState * pstate , RangeVar * relation )
2378
+ void
2379
+ errorMissingRTE (ParseState * pstate , RangeVar * relation )
2427
2380
{
2428
2381
RangeTblEntry * rte ;
2429
2382
int sublevels_up ;
2430
2383
const char * badAlias = NULL ;
2431
2384
2432
2385
/*
2433
2386
* Check to see if there are any potential matches in the query's
2434
- * rangetable. This affects the message we provide.
2387
+ * rangetable.
2435
2388
*/
2436
2389
rte = searchRangeTable (pstate , relation );
2437
2390
@@ -2452,39 +2405,21 @@ warnAutoRange(ParseState *pstate, RangeVar *relation)
2452
2405
& sublevels_up ) == rte )
2453
2406
badAlias = rte -> eref -> aliasname ;
2454
2407
2455
- if (!add_missing_from )
2456
- {
2457
- if (rte )
2458
- ereport (ERROR ,
2459
- (errcode (ERRCODE_UNDEFINED_TABLE ),
2460
- errmsg ("invalid reference to FROM-clause entry for table \"%s\"" ,
2461
- relation -> relname ),
2462
- (badAlias ?
2463
- errhint ("Perhaps you meant to reference the table alias \"%s\"." ,
2464
- badAlias ) :
2465
- errhint ("There is an entry for table \"%s\", but it cannot be referenced from this part of the query." ,
2466
- rte -> eref -> aliasname )),
2467
- parser_errposition (pstate , relation -> location )));
2468
- else
2469
- ereport (ERROR ,
2470
- (errcode (ERRCODE_UNDEFINED_TABLE ),
2471
- errmsg ("missing FROM-clause entry for table \"%s\"" ,
2472
- relation -> relname ),
2473
- parser_errposition (pstate , relation -> location )));
2474
- }
2475
- else
2476
- {
2477
- /* just issue a warning */
2478
- ereport (NOTICE ,
2408
+ if (rte )
2409
+ ereport (ERROR ,
2479
2410
(errcode (ERRCODE_UNDEFINED_TABLE ),
2480
- errmsg ("adding missing FROM-clause entry for table \"%s\"" ,
2411
+ errmsg ("invalid reference to FROM-clause entry for table \"%s\"" ,
2481
2412
relation -> relname ),
2482
2413
(badAlias ?
2483
- errhint ("Perhaps you meant to reference the table alias \"%s\"." ,
2484
- badAlias ) :
2485
- (rte ?
2486
- errhint ("There is an entry for table \"%s\", but it cannot be referenced from this part of the query." ,
2487
- rte -> eref -> aliasname ) : 0 )),
2414
+ errhint ("Perhaps you meant to reference the table alias \"%s\"." ,
2415
+ badAlias ) :
2416
+ errhint ("There is an entry for table \"%s\", but it cannot be referenced from this part of the query." ,
2417
+ rte -> eref -> aliasname )),
2418
+ parser_errposition (pstate , relation -> location )));
2419
+ else
2420
+ ereport (ERROR ,
2421
+ (errcode (ERRCODE_UNDEFINED_TABLE ),
2422
+ errmsg ("missing FROM-clause entry for table \"%s\"" ,
2423
+ relation -> relname ),
2488
2424
parser_errposition (pstate , relation -> location )));
2489
- }
2490
2425
}
0 commit comments