【发布时间】:2020-08-04 10:08:14
【问题描述】:
我正在尝试在 Redshift 中创建一个视图,以使我们能够查看每个表中的最新数据。 我们有更新各种时间表的数据集,每个表都有一个“更新”列,其中包含上次更新行的日期戳。
我想要实现的是底部的视图(来自这两个示例表):
other.bigtable
+-----+--------+------------------+
| id | stat | updated |
+-----+--------+------------------+
| A2 | rgerhg | 03/05/2020 05:00 |
| F5 | bdfb | 03/05/2020 05:00 |
| GF5 | bb | 03/05/2020 05:00 |
+-----+--------+------------------+
default.test
+----+------+------------------+
| id | name | updated |
+----+------+------------------+
| 1 | A | 02/02/2008 00:00 |
| 2 | B | 02/02/2008 00:00 |
| 3 | C | 02/02/2008 00:00 |
| 4 | F | 02/02/2008 00:00 |
| 5 | T | 02/02/2010 00:00 |
+----+------+------------------+
default.view_updates
+---------+------------+------------------+
| schema | table_name | max_update |
+---------+------------+------------------+
| default | test | 02/02/2010 00:00 |
| other | big_table | 03/05/2020 05:00 |
+---------+------------+------------------+
到目前为止,我正在获取表格和架构,但不知道从哪里开始日期。 Redshift 似乎有点受限。
编辑:
利用从网上窃取的一些代码,我希望用它来为额外的列创建表:
select t.table_schema,
t.table_name
from information_schema.tables t
inner join information_schema.columns c
on c.table_name = t.table_name
and c.table_schema = t.table_schema
where c.column_name = 'updated'
and t.table_schema not in ('information_schema', 'pg_catalog')
and t.table_type = 'BASE TABLE'
order by t.table_schema;
[来源:https://dataedo.com/kb/query/amazon-redshift/find-tables-with-specific-column-name]
【问题讨论】:
标签: amazon-redshift