Skip to content

Instantly share code, notes, and snippets.

@ppadron
Last active December 26, 2015 04:48
Show Gist options
  • Select an option

  • Save ppadron/7095522 to your computer and use it in GitHub Desktop.

Select an option

Save ppadron/7095522 to your computer and use it in GitHub Desktop.

Revisions

  1. ppadron revised this gist Oct 22, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions gistfile1.sql
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@ CREATE TABLE chefs (
    ) INHERITS (people);

    CREATE TABLE people_i_like (
    people_id integer references people(id),
    person_id integer references people(id),
    reason text
    );

    @@ -21,4 +21,4 @@ insert into chefs values (default, 'Bob', 'medium');

    insert into people_i_like values (1, 'taught me math');
    --ERROR: insert or update on table "people_i_like" violates foreign key constraint "people_i_like_people_id_fkey"
    --DETAIL: Key (people_id)=(1) is not present in table "people".
    --DETAIL: Key (person_id)=(1) is not present in table "people".
  2. ppadron created this gist Oct 22, 2013.
    24 changes: 24 additions & 0 deletions gistfile1.sql
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    CREATE TABLE people (
    id serial primary key,
    name text
    );

    CREATE TABLE scientists (
    university text
    ) INHERITS (people);

    CREATE TABLE chefs (
    hat_size text
    ) INHERITS (people);

    CREATE TABLE people_i_like (
    people_id integer references people(id),
    reason text
    );

    insert into scientists values (default, 'Alice', 'MIT');
    insert into chefs values (default, 'Bob', 'medium');

    insert into people_i_like values (1, 'taught me math');
    --ERROR: insert or update on table "people_i_like" violates foreign key constraint "people_i_like_people_id_fkey"
    --DETAIL: Key (people_id)=(1) is not present in table "people".