Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions postgres/drafts/11_update_dataviews.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
BEGIN ;

CREATE OR REPLACE VIEW layer0.recordview AS
SELECT
r.pgc
, r.id AS record_id
, r.modification_time

, r.table_id
, t.table_name
, t.datatype
, t.status

, t.bib
, b.code
, b.year
, b.author
, b.title
FROM
layer0.records AS r
LEFT JOIN layer0.tables AS t ON (r.table_id = t.id)
LEFT JOIN common.bib AS b ON (t.bib = b.id)
;


ALTER TABLE designation.data DROP COLUMN IF EXISTS modification_time cascade ;

CREATE OR REPLACE VIEW designation.dataview AS
SELECT
d.design
, r.*
FROM
designation.data AS d
LEFT JOIN layer0.recordview AS r USING (record_id)
;


ALTER TABLE icrs.data DROP COLUMN IF EXISTS modification_time cascade ;

CREATE OR REPLACE VIEW icrs.dataview AS
SELECT
d.ra
, d.dec
, d.e_ra
, d.e_dec
, r.*
FROM
icrs.data AS d
LEFT JOIN layer0.recordview AS r USING (record_id)
;


CREATE OR REPLACE VIEW nature.dataview AS
SELECT
d.type_name
, r.*
FROM
nature.data AS d
LEFT JOIN layer0.recordview AS r USING (record_id)
;


CREATE OR REPLACE VIEW layer2.designations AS
SELECT
r.pgc
, d.design
, r.bib
, r.code
, r.year
, r.author
, r.title
FROM
designation.data AS d
LEFT JOIN layer0.recordview AS r USING (record_id)
WHERE
r.pgc IS NOT NULL
;

COMMIT ;
Loading