选择“删除”列名称。在DBT查询中以创建视图

发布于 2025-02-08 08:59:05 字数 272 浏览 2 评论 0原文

我正在尝试在DBT中创建视图。源表有一个名为delete的列。如何在DBT中的选择查询中选择此列?

我尝试过:

select id, delete from src_table;
select id, "delete" from src_table;
select id, "DELETE" from src_table;
select id, DELETE from src_table;

但是他们俩都没有工作。请指教。

I am trying to create a VIEW in dbt. The source table has a column named delete. How do I select this column in the select query in DBT?

I tried :

select id, delete from src_table;
select id, "delete" from src_table;
select id, "DELETE" from src_table;
select id, DELETE from src_table;

but neither of them worked. Please advise.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烧了回忆取暖 2025-02-15 08:59:05

我怀疑您的列实际上并未完全命名delete。如果是,那么您将使用选择“删除”选择它。

为了证明这一点,我只是试图重现您的问题,但无法使用此查询:

create table if not exists delete_test as (
    select 1 as id, FALSE as "DELETE"
    union all
    select 2 as id, TRUE as "DELETE" 
)
;
-- this works
select id, "DELETE" from delete_test;

要准确找出您要选择的列的名称,您可以使用show列

show columns in table delete_test;

然后,您可以选择看起来像delete的值,然后将其复制到剪贴板(这显示了SnowSight UI):

“在此处输入映像说明”

我怀疑当您时会发现一些空间将该值粘贴到文本编辑器中。

I suspect your column is not actually named exactly DELETE. If it were, then you would select it with select "DELETE".

To prove that point, I just tried to reproduce your issue, but couldn't with this query:

create table if not exists delete_test as (
    select 1 as id, FALSE as "DELETE"
    union all
    select 2 as id, TRUE as "DELETE" 
)
;
-- this works
select id, "DELETE" from delete_test;

To find out exactly the name of the column you're trying to select, you could use show columns:

show columns in table delete_test;

You can then select the value that looks like DELETE and copy it to your clipboard (this is showing the snowsight UI):

enter image description here

I suspect you'll find some whitespace when you paste that value into a text editor.

寂寞花火° 2025-02-15 08:59:05

一位同事帮助解决了这个问题。除了将双引号删除外,还需要具有以下模型yaml:

version: 2

models:
  - name: model_name
    columns:
      - name: delete
        quote: true

一旦创建了此yaml定义,选择ID,从src_table中可以使用。

A colleague helped figure this out. In addition to having the delete in double quotes, need to have a model YAML as following:

version: 2

models:
  - name: model_name
    columns:
      - name: delete
        quote: true

once this yaml definition is created, select id, "delete" from src_table should work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文