我可以在 redshift 中为外部 table 添加别名以删除架构名称吗?
Can I alias an external table in redshift to remove the schema name?
我们想将 table 迁移到 Spectrum,这需要定义外部架构
create external schema spectrum
from data catalog
database 'spectrumdb'
iam_role 'my_iam_role'
create external database if not exists;
我在 Redshift 中创建了一个外部 table,如下所示:
create external table spectrum.my_table(
id bigint,
accountId bigint,
state varchar(65535),
) stored as parquet
location 's3://some_bucket/my_table_files';
是否可以为 table 设置别名,以便在查询时可以将其命名为 my_table_alias
而不是 spectrum.my_table
?基本上,我们想让外部 table 的更改对我们的 Redshift 实例的客户端不透明(这意味着我们无法更改 table 名称)。非常感谢您的帮助!
Redshift 没有别名,最好的选择是创建一个视图。
创建视图时需要使用 WITH NO SCHEMA BINDING
选项,因为视图位于外部 table。
如果您不想指定架构名称或有这样的要求,请在 public 架构中创建视图或将用户默认架构设置为视图所在的架构
alter user .. set search_path to ..
使用视图访问外部 table 的其他好处是,您可以
- 重命名列以更加用户友好
- 添加或删除具有视图定义的列
- 更改数据类型 and/or date/time 格式
- 您将能够在不影响用户访问的情况下更改 name/structure 外部 table
如果这回答了您的问题,请告诉我。
我们想将 table 迁移到 Spectrum,这需要定义外部架构
create external schema spectrum
from data catalog
database 'spectrumdb'
iam_role 'my_iam_role'
create external database if not exists;
我在 Redshift 中创建了一个外部 table,如下所示:
create external table spectrum.my_table(
id bigint,
accountId bigint,
state varchar(65535),
) stored as parquet
location 's3://some_bucket/my_table_files';
是否可以为 table 设置别名,以便在查询时可以将其命名为 my_table_alias
而不是 spectrum.my_table
?基本上,我们想让外部 table 的更改对我们的 Redshift 实例的客户端不透明(这意味着我们无法更改 table 名称)。非常感谢您的帮助!
Redshift 没有别名,最好的选择是创建一个视图。
创建视图时需要使用 WITH NO SCHEMA BINDING
选项,因为视图位于外部 table。
如果您不想指定架构名称或有这样的要求,请在 public 架构中创建视图或将用户默认架构设置为视图所在的架构
alter user .. set search_path to ..
使用视图访问外部 table 的其他好处是,您可以
- 重命名列以更加用户友好
- 添加或删除具有视图定义的列
- 更改数据类型 and/or date/time 格式
- 您将能够在不影响用户访问的情况下更改 name/structure 外部 table
如果这回答了您的问题,请告诉我。