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

SQL base source error when query starts with 'with' and doesn't return data #870

Open
angelika233 opened this issue Mar 19, 2024 · 3 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@angelika233
Copy link
Contributor

What:
SQL class gives an error when query that is starting with with (or select) doesn't return data - for example when after with there is insert into statement.

Error:
Error during execution of task: ProgrammingError('No results. Previous SQL was not a query.')

Code causing error:

base.py
SQL class

if query_sanitized.startswith("SELECT") or query_sanitized.startswith("WITH"): 
            result = cursor.fetchall()
        else:
            result = True

Example:

with 

    base as (
        select 
           name
           ,age
         from sandbox.my_table
    )

    insert into sandbox.new_table 
    select * from base
    ;

Possible solution:
try except block?

@angelika233 angelika233 added bug Something isn't working good first issue Good for newcomers labels Mar 19, 2024
@trymzet
Copy link
Contributor

trymzet commented Sep 30, 2024

Isn't this because you were running multiple queries, including DML? run is only for running one query at a time. So only a WITH, only an INSERT, or only a SELECT.

@trymzet trymzet closed this as completed Sep 30, 2024
@trymzet trymzet reopened this Sep 30, 2024
@angelika233
Copy link
Contributor Author

You're right but this class doesn't handle insert + wouldn't it be better if option above doesn't cause an error? Maybe it's not a default query that we're running but there are also cases when this is needed

@trymzet
Copy link
Contributor

trymzet commented Oct 1, 2024

It does handle inserts already in the run() method - just specify an INSERT query as the query arg.

But if you need to insert from a CTE specifically then yes, feel free to add this. I think the try/except on fetchall() might be the generic solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants