Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Table1:
- column_name | data_type
- ---------------------------+-----------------------------
- id | integer
- name | text
- account_id | integer
- tags | ARRAY {tag1,tag_2,'tag 3',...}
- -- Table2:
- column_name | data_type
- ---------------------------+-----------------------------
- id | integer
- name | text
- account_id | integer
- tags | ARRAY {tag1,tag_2,'tag 3',...}
- -- Tags:
- column_name | data_type
- ---------------------------+-----------------------------
- id | integer
- name | text
- account_id | integer
- source | enum (either 'table1' or 'table2')
- CREATE table tags
- AS
- SELECT
- DISTINCT(UNNEST(table1.tags)) AS name,
- table1.account_id AS account_id,
- 'table1' as source FROM table1
- UNION
- SELECT
- DISTINCT(UNNEST(table2.tags)) AS name,
- table2.account_id AS account_id,
- 'table2' as source FROM table2;
- ALTER TABLE tags ADD COLUMN id SERIAL PRIMARY KEY;
Add Comment
Please, Sign In to add comment