Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comment on the last line causes a syntax error for incremental tables #1075

Closed
mfrasco6 opened this issue Oct 17, 2018 · 1 comment
Closed

Comments

@mfrasco6
Copy link

Issue

Issue description

I got a syntax error when I ran dbt run on an incremental table. After spending some time debugging, I identified the source of the error. My sql file had an line comment at the end of the last line of my select statement. This caused the incremental table logic to fail.

Results

I expected my incremental table update to succeed. Instead, I got a syntax error.

The error message looked like

syntax error at or near "where"
where (updated_at >= (select max(t.updated_at) from...

System information

The output of dbt --version:

~: dbt --version
installed version: 0.11.1
   latest version: 0.11.1

Up to date!

The operating system you're running on: macOS Sierra Version 10.12.4

The python version you're using (probably the output of python --version): Python 3.6.5

Steps to reproduce

I have a .sql file that defines my incremental table that looks like this

{{
  config({
    "materialized" : "incremental",
    "sql_where" : "updated_at > (select max(updated_at) from {{ this }})",
    "unique_key": "id"
  })
}}

select ...
from table
where a = b -- This is a comment

If you try to run this table, look at the debugging output. It will look something like

create temporary table
    "xxx__dbt_incremental_tmp"
  as (
    select * from (
    select ...
    from table
    where a = b -- This is a comment) as dbt_incr_sbq
where updated_at > (select max(updated_at) from {{ this }})
);

However, because of the comment on the last line of my model, the ) as dbt_incr_sbq is ignored. And this causes the syntax error.

@drewbanin
Copy link
Contributor

Hey @mfrasco6 - thanks for the report! This is a dupe of #1018 which was fixed in #1019. This change will be going out in our next release of dbt, v0.12.0! Apologies for the trouble :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants