Use RELATION_IS_OTHER_TEMP where possible

Junwang Zhao <zhjwpku@gmail.com>

From: Junwang Zhao <zhjwpku@gmail.com>
To: pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2025-06-10T16:07:35Z
Lists: pgsql-hackers

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Make more use of RELATION_IS_OTHER_TEMP().

Hi hackers,

While reviewing the Merge/Split partitions patch[0], I found
some places in tablecmds.c where RELATION_IS_OTHER_TEMP
can be used but not, such as:

/* If the parent is temp, it must belong to this session */
if (rel->rd_rel->relpersistence == RELPERSISTENCE_TEMP &&
!rel->rd_islocaltemp)
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("cannot attach as partition of temporary relation of another session")));

/* Ditto for the partition */
if (attachrel->rd_rel->relpersistence == RELPERSISTENCE_TEMP &&
!attachrel->rd_islocaltemp)
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("cannot attach temporary relation of another session as partition")));

All other files perform this check using RELATION_IS_OTHER_TEMP.
Should we update tablecmds.c to do the same for consistency?

[0] https://www.postgresql.org/message-id/884bcf9e-d6e3-4b0c-8dcb-7f2110070ac9@postgrespro.ru

-- 
Regards
Junwang Zhao