@@ -499,28 +499,44 @@ RangeVarGetRelidExtended(const RangeVar *relation, LOCKMODE lockmode,
499
499
*/
500
500
if (relation -> relpersistence == RELPERSISTENCE_TEMP )
501
501
{
502
- if (!OidIsValid (myTempNamespace ))
503
- relId = InvalidOid ; /* this probably can't happen? */
504
- else
505
- {
506
- if (relation -> schemaname )
507
- {
508
- Oid namespaceId ;
502
+ Oid namespaceId ;
509
503
510
- namespaceId = LookupExplicitNamespace (relation -> schemaname , missing_ok );
504
+ if (relation -> schemaname )
505
+ {
506
+ namespaceId = LookupExplicitNamespace (relation -> schemaname , missing_ok );
511
507
508
+ /*
509
+ * If the user has specified an existing temporary schema
510
+ * owned by another user.
511
+ */
512
+ if (OidIsValid (namespaceId ) && namespaceId != myTempNamespace )
513
+ {
512
514
/*
513
- * For missing_ok, allow a non-existent schema name to
514
- * return InvalidOid .
515
+ * We don't allow users to access temp tables of other
516
+ * sessions except for the case of dropping tables .
515
517
*/
516
- if (namespaceId != myTempNamespace )
518
+ if (!( flags & RVR_OTHER_TEMP_OK ) )
517
519
ereport (ERROR ,
518
- (errcode (ERRCODE_INVALID_TABLE_DEFINITION ),
519
- errmsg ("temporary tables cannot specify a schema name " )));
520
+ (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
521
+ errmsg ("could not access temporary relations of other sessions " )));
520
522
}
523
+ }
524
+ else
525
+ {
526
+ namespaceId = myTempNamespace ;
521
527
522
- relId = get_relname_relid (relation -> relname , myTempNamespace );
528
+ /*
529
+ * If this table was recognized as temporary, it means that we
530
+ * found it because backend's temporary namespace was specified
531
+ * in search_path. Thus, MyTempNamespace must contain valid oid.
532
+ */
533
+ Assert (OidIsValid (namespaceId ));
523
534
}
535
+
536
+ if (missing_ok && !OidIsValid (namespaceId ))
537
+ relId = InvalidOid ;
538
+ else
539
+ relId = get_relname_relid (relation -> relname , namespaceId );
524
540
}
525
541
else if (relation -> schemaname )
526
542
{
@@ -3553,21 +3569,19 @@ get_namespace_oid(const char *nspname, bool missing_ok)
3553
3569
RangeVar *
3554
3570
makeRangeVarFromNameList (const List * names )
3555
3571
{
3556
- RangeVar * rel = makeRangeVar ( NULL , NULL , -1 ) ;
3572
+ RangeVar * rel ;
3557
3573
3558
3574
switch (list_length (names ))
3559
3575
{
3560
3576
case 1 :
3561
- rel -> relname = strVal (linitial (names ));
3577
+ rel = makeRangeVar ( NULL , strVal (linitial (names )), -1 );
3562
3578
break ;
3563
3579
case 2 :
3564
- rel -> schemaname = strVal (linitial (names ));
3565
- rel -> relname = strVal (lsecond (names ));
3580
+ rel = makeRangeVar (strVal (linitial (names )), strVal (lsecond (names )), -1 );
3566
3581
break ;
3567
3582
case 3 :
3583
+ rel = makeRangeVar (strVal (lsecond (names )), strVal (lthird (names )), -1 );
3568
3584
rel -> catalogname = strVal (linitial (names ));
3569
- rel -> schemaname = strVal (lsecond (names ));
3570
- rel -> relname = strVal (lthird (names ));
3571
3585
break ;
3572
3586
default :
3573
3587
ereport (ERROR ,
@@ -3774,6 +3788,8 @@ GetTempNamespaceProcNumber(Oid namespaceId)
3774
3788
return INVALID_PROC_NUMBER ; /* no such namespace? */
3775
3789
if (strncmp (nspname , "pg_temp_" , 8 ) == 0 )
3776
3790
result = atoi (nspname + 8 );
3791
+ else if (strcmp (nspname , "pg_temp" ) == 0 )
3792
+ result = MyProcNumber ;
3777
3793
else if (strncmp (nspname , "pg_toast_temp_" , 14 ) == 0 )
3778
3794
result = atoi (nspname + 14 );
3779
3795
else
0 commit comments