PostgreSQL/Inheritance/Insert Data Children — различия между версиями

Материал из SQL эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Версия 13:45, 26 мая 2010

Insert data to children table

postgres=#
postgres=# -- Creating a child table
postgres=#
postgres=# CREATE TABLE "authors" (
postgres(#      "id" integer NOT NULL,
postgres(#      "last_name" text,
postgres(#      "first_name" text,
postgres(#      Constraint "authors_pkey" Primary Key ("id")
postgres(# );
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "authors_pkey" for table "authors"
CREATE TABLE
postgres=#
postgres=#
postgres=# CREATE TABLE distinguished_authors (award text)
postgres-#               INHERITS (authors);
CREATE TABLE
postgres=#
postgres=# INSERT INTO distinguished_authors
postgres-#              VALUES (1,
postgres(#              "Simon", "Neil", "Pulitzer Prize");
INSERT 0 1
postgres=#
postgres=# select * from authors;
 id | last_name | first_name
----+-----------+------------
  1 | Simon     | Neil
(1 row)
postgres=#
postgres=# select * from distinguished_authors;
 id | last_name | first_name |     award
----+-----------+------------+----------------
  1 | Simon     | Neil       | Pulitzer Prize
(1 row)
postgres=#
postgres=# drop table distinguished_authors;
DROP TABLE
postgres=# drop table authors;
DROP TABLE
postgres=#
postgres=#
postgres=#