使用where语句在DBT中的表中更新特定单元格

发布于 2025-02-13 05:43:36 字数 879 浏览 1 评论 0原文

嗨,我有下表销售

国家 /地区销售销售_DATE
US212-06-2022
JP215-06-2022

我必须编写一个SQL查询来更新DBT中的Paticular Cell。我想为我们更改sale_date。

现在我的查询是 -

UPDATE `sales`
SET 
    Sale_Date = '2022-06-16'
WHERE
    Country = 'US'

但是,在DBT中,我会得到以下错误,

Server error: Database Error in rpc request (from remote system)
Syntax error: Expected end of input but got keyword LIMIT at [4:1]

我缺少什么?我是DBT的新手。

Hi I have a following table Sales

CountrySalesSale_Date
US212-06-2022
JP215-06-2022

I have to write a SQL query to update the paticular cell in dbt. I want to change Sale_Date for US.

Now my query is-

UPDATE `sales`
SET 
    Sale_Date = '2022-06-16'
WHERE
    Country = 'US'

However, In dbt I get following error

Server error: Database Error in rpc request (from remote system)
Syntax error: Expected end of input but got keyword LIMIT at [4:1]

What am I missing? I am fairly new to dbt.

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

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

发布评论

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

评论(1

葬シ愛 2025-02-20 05:43:36

DBT被认为主要与选择语句一起使用。您可以找到更多上下文在这里

您可能要做的就是只使用选择语句进行以下操作

select
  [...],
  case when country = 'US' then '2022-06-16'::date else sale_date end as <new_column_name>
from {{ ref('your_staging_model') }}. -- or {{ source('your_schema', 'your_source_table')}}

。包含一个带有Update的列,类似于您需要的转换。

dbt is thought to mainly be used with SELECT statements. You can find a bit more context here.

What you might want to do is to just apply that transformation using a SELECT statement as follows:

select
  [...],
  case when country = 'US' then '2022-06-16'::date else sale_date end as <new_column_name>
from {{ ref('your_staging_model') }}. -- or {{ source('your_schema', 'your_source_table')}}

So now, you will have a dbt model materialized either as a view, a table, or whatever you prefer, that contains a column with the UPDATE-like transformation that you needed.

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