Subject: Using "object orientated" tables?

From: Simon Connah <[email-masked]>
Date: Wed, 11 May 2022 01:33:20 +0000

Hi,

I was wondering what the community thought of using table inheritance in PostgreSQL? Is it considered bad practice these days?

Basically, I have a users table and every user has a unique, not null UUID which is used as the primary key. There are only three columns on the table. User ID, Username, Email.

Having said that I'll have to store data about them which I don't want to do in one massive table as it would be ugly as hell. So what I want is my main user's table to stick to three columns and then sub-tables which inherit from it to add their own column? So for instance I might want to store an account balance for people making money on my site.

Hopefully, I've managed to explain what I mean properly. If you need any extra information then let me.

Simon.

---

From: "David G. Johnston" <[email-masked]>
Date: Tue, 10 May 2022 18:43:08 -0700

On Tue, May 10, 2022 at 6:33 PM Simon Connah <[email-masked]>
wrote:

> Hi,
>
> I was wondering what the community thought of using table inheritance in
> PostgreSQL? Is it considered bad practice these days?
>
> Basically, I have a users table and every user has a unique, not null UUID
> which is used as the primary key. There are only three columns on the
> table. User ID, Username, Email.
>
> Having said that I'll have to store data about them which I don't want to
> do in one massive table as it would be ugly as hell. So what I want is my
> main user's table to stick to three columns and then sub-tables which
> inherit from it to add their own column? So for instance I might want to
> store an account balance for people making money on my site.
>
I wouldn't use inheritance, especially since I do not want to carry around
copies of Username and Email.  Having a "core data" users table then adding
additional one-to-one related tables based upon application needs is quite
common.

David J.

---

From: Tom Lane <[email-masked]>
Date: Tue, 10 May 2022 21:50:03 -0400

> I was wondering what the community thought of using table inheritance in PostgreSQL? Is it considered bad practice these days?

Mmm ... not if the various caveats[1] don't bother you.  The biggest
stumbling block for most people, I think, is that you can't have
foreign keys that reference the whole inheritance hierarchy.

			regards, tom lane

[1] https://www.postgresql.org/docs/current/ddl-inherit.html#DDL-INHERIT-CAVEATS

---

From: Simon Connah <[email-masked]>
Date: Wed, 11 May 2022 01:51:49 +0000

------- Original Message -------On Wednesday, May 11th, 2022 at 02:43, David G. Johnston <[email-masked]> wrote:

> On Tue, May 10, 2022 at 6:33 PM Simon Connah <[email-masked]> wrote:
> 

> I wouldn't use inheritance, especially since I do not want to carry around copies of Username and Email. Having a "core data" users table then adding additional one-to-one related tables based upon application needs is quite common.
> David J.

Thank you for your reply. That makes more sense. I'll eventually get the hang of things!
Simon.

---

From: Simon Connah <[email-masked]>
Date: Wed, 11 May 2022 01:52:59 +0000

------- Original Message -------
On Wednesday, May 11th, 2022 at 02:50, Tom Lane <[email-masked]> wrote:

> Simon Connah [email-masked] writes:
> 

> [1] https://www.postgresql.org/docs/current/ddl-inherit.html#DDL-INHERIT-CAVEATS

Thank you. I'll be sure to read that.

Simon.

---

From: Stephen Froehlich <[email-masked]>
Date: Wed, 11 May 2022 16:03:38 +0000

Just to pile on, this sounds like a normalization problem ...

https://docs.microsoft.com/en-us/office/troubleshoot/access/database-normalization-description
https://en.wikipedia.org/wiki/Database_normalization

-----Original Message-----
From: Simon Connah <[email-masked]> 
Sent: Tuesday, May 10, 2022 19:33
To: [email-masked]
Subject: Using "object orientated" tables?

Hi,

Simon.