Re: Design database - Mailing list pgsql-admin

From hubert depesz lubaczewski
Subject Re: Design database
Date
Msg-id 20210203164459.GA17357@depesz.com
Whole thread Raw
In response to Re: Design database  ("David G. Johnston" <david.g.johnston@gmail.com>)
Responses Re: Design database  (Mai Peng <maily.peng@webedia-group.com>)
List pgsql-admin
On Wed, Feb 03, 2021 at 08:35:41AM -0700, David G. Johnston wrote:
> On Wed, Feb 3, 2021 at 8:23 AM Mai Peng <[1]maily.peng@webedia-group.com> wrote:
> 
>   Hello,
> 
>   I’ve got a table name publication, and another table named publication_item.
>   Each publication_item is linked to a publication by publication_id.
>   How could I add a constraint that check each publication has one or more publication_item when a tuple is inserted
?
>   I don’t want to store items in the same table as publication because we could have 1-> n items.
> 
> [2]https://www.postgresql.org/docs/current/tutorial-fk.html

I don't think it helps. Fkey can check that publication_item contains
valid publication_id, but doesn't ensure that every publication has at
least one item.

As for the problem of OP, I think this describes working solution:
https://www.depesz.com/2017/07/03/how-to-make-sure-there-is-always-at-least-one-sub-record/

Best regards,

depesz




pgsql-admin by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: pg_wal keeps growing
Next
From: dbatoCloud Solution
Date:
Subject: Partitioning existing table issue - Help needed!