Quantcast
Channel: Can i have one foreign key to both parent and it's childs in postgresql? - Database Administrators Stack Exchange
Browsing all 4 articles
Browse latest View live

Answer by Ben for Can i have one foreign key to both parent and it's childs...

I have found a soultion with a help from this answer Can i have one foreign key to both parent and it's childs in postgresql? , here's a trigger: CREATE TABLE test ( id serial, foreign_id bigint NOT...

View Article



Answer by dezso for Can i have one foreign key to both parent and it's childs...

What you also could do is to set up a table where only the IDs are stored:CREATE TABLE common (id serial PRIMARY KEY);Then change both your parent and child so that their primary keys are also foreign...

View Article

Answer by Hans-Jürgen Schönig for Can i have one foreign key to both parent...

this is not possible out of the box. inheritance in PostgreSQL is based on individual tables, which are only logically connected through pg_inherit. Each table is still somewhat independent. Therefore...

View Article

Can i have one foreign key to both parent and it's childs in postgresql?

I want to have a foreign key to reference table and it's children. Here's how I tried and failed:CREATE TABLE parent ( id serial, CONSTRAINT parent_pk PRIMARY KEY(id));CREATE TABLE child ( val text,...

View Article
Browsing all 4 articles
Browse latest View live




Latest Images