Subject: Postgres and Polymorphism

From: Mike Krus <[email-masked]>
Date: Wed, 03 Feb 93 19:12:41 -0500

Hi,

there's something I'd like to submit to the wisdom of the net.

Suppose you have classes in the following hierarchy :

		B
	       / \
	     C1	  C2

and you want to test elements of the hierarchy (retrieve ... B*) but that
the conditions for the test to succeed are different for C1 and C2.
The problem is that by selecting elements of B*, you don't know whether
they come from C1 or C2 (supposing B is empty).

The ideal solution would be to use what C++ calls polymorphism (through
the use of virtual methods) but Postgres doesn't support that.

The only solution I found is to check which class (C1 or C2) a particular
object comes from (using a retrieve with the oid on C1 and C2) and
then calling methods on those object (with different names since Postgres
method names are global :-( ).

But this inefficient as extra retrieves are needed. So my question is :
Is there a way to know which subclass an object comes from without doing
the extra selects? Or is there a way to achieve polymorphism?

I also have a related questions : when you do a retrieve on B*, the
result is a set of objects of type B, i.e. all the objects of type C1
and C2 are casted into type B by the operation. Is there a way to
preven that? The retrieve would them give me all the objects in all
the subclasses each with all their attributs...
If this could be done (and I could know which class an object belongs
to), I could write a method in the base class to do all my testing.

Thanks in advance,

--------
Michael Krus.					 Email : [email-masked]
Concordia University				Universite d'Orsay - Paris XI
Montreal, Canada					        Paris, France
"Western civilisation? It would be a good idea!" -- Gandhi

---

From: <[email-masked]>
Date: Wed, 03 Feb 93 17:10:53 PST

> the extra selects? Or is there a way to achieve polymorphism?

no, but enough people are interested in this that we may add it to
a future release of the system.

> to), I could write a method in the base class to do all my testing.

this is a bug, and will be fixed in a future release of the system.