File: 2-inherit.sql

package info (click to toggle)
pgcopydb 0.17-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 30,636 kB
  • sloc: ansic: 217,474; sql: 1,654; sh: 812; makefile: 365; python: 94
file content (48 lines) | stat: -rw-r--r-- 1,227 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
DROP TABLE IF EXISTS public.parent_model CASCADE;

CREATE TABLE IF NOT EXISTS public.parent_model
 (
    id integer NOT NULL,
     a integer NOT NULL,
     b boolean NOT NULL,
    CONSTRAINT pk_parent_model PRIMARY KEY (id)
 );

CREATE TABLE IF NOT EXISTS public.child_model_1
 (
    -- Inherited from table public.parent_model: id integer NOT NULL,
    -- Inherited from table public.parent_model: a integer NOT NULL,
    -- Inherited from table public.parent_model: b boolean NOT NULL,
    c jsonb NOT NULL,
    CONSTRAINT pk_child_model_1 PRIMARY KEY (id)
 )
INHERITS (public.parent_model);

CREATE TABLE IF NOT EXISTS public.child_model_2
 (
    -- Inherited from table public.parent_model: id integer NOT NULL,
    -- Inherited from table public.parent_model: a integer NOT NULL,
    -- Inherited from table public.parent_model: b boolean NOT NULL,
    d integer NOT NULL,
    CONSTRAINT pk_child_model_2 PRIMARY KEY (id)
 )
INHERITS (public.parent_model);

INSERT INTO child_model_1 (id, a, b, c)
SELECT
    10000 + s,
    1,
    false,
    '[1, 2, 3, 4]'
FROM
    generate_series(1, 1000) s;


INSERT INTO child_model_2 (id, a, b, d)
SELECT
    20000 + s,
    1,
    false,
    1313
FROM
    generate_series(1, 1000) s;