Tag Info

New answers tagged

0

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 NULL, constraint testpk PRIMARY KEY (id) ) CREATE OR REPLACE FUNCTION inheritance_constraint() RETURNS trigger AS $BODY$ DECLARE ...


1

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 keys referring to this table: CREATE TABLE parent ( id integer PRIMARY KEY REFERENCES common (id), ... ); Similarly, any table referring to ...


2

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 you cannot create a key on the entire structure. It is only possible to reference individual tables. What you can do, however, is to write a trigger ensuring ...


1

This is straight from Stack Overflow As it was pointed out by @a_horse_with_no_name and @Jack Douglas, currval works only with the current session. So if you are ok with the fact that the result might be affected by an uncommitted transaction of another session, and you still want something that will work across sessions, you can use this: SELECT ...



Top 50 recent answers are included