Considering the case in which we’ve got two tables, say: SubscriptionPayments
and OrderPayments
inherit the shared table Payments
.
Is there a way to find out within the table Payments
which table any record belongs to; in other words, is it possible to indicate whether a record in Payments
is a part of SubscriptionPayments
without joining?
Edit:
I’ve already thought of joining, casing, and even adding a discriminator column.
There must be some metadata relating inheriting tables to their base, so I thought there might be some metadata that indicates what record belongs to which table, something like a built-in discriminator.
2
Answers
If I understand your question correctly, you can use the discriminator column for this purpose
Yes, there’s
tableoid
system column, meant exactly for that:Demo:
All records in
Payments
do appear to be indistinguishable even though all columns were requested:That’s because by default, system columns are hidden unless explicitly listed, so you need to add
tableoid
to the list. It’s a (not very readable)oid
, but it can be converted to the actual table name by casting toregclass
: