1

I recently switched from PostgreSQL to trino, and I run into the problem, that I obviously can't write any WITH statement properly to make it run. I tried to research it but only problem I found is here, and it was a typo in the query.

My query is basically the same, but without the typo, and I still have the same problem:

WITH tab1 as (
    select 
     id,
     (case when col2 > 0 then 'a' else 'b' end) as cathegory
    from work_schema.generic_table
)

select 
 tab1.id
 -- id     # just to demonstrate I tried both, none of them works
from tab1

This query triggers very generic error that I just cannot find anything about in documentation (anything helpful), nor here or anywhere else.

SQL Error [57]: Query failed (#20250120_133332_03607_ritng): line 3:6: Schema must be specified when session schema is not set

The query inside WITH statement alone works, I just don't understand why similar definitions work when I copy them into trino.

Can you guys explain any of these?

2 Answers 2

0

Can you try setting the schema or catalog.schema in your session as the error mentions about session schema. something like this

USE work_catalog.work_schema;
--your query

OR

USE work_schema;
-- your query

This is from documentation

Update the session to use the specified catalog and schema.

Sign up to request clarification or add additional context in comments.

Comments

0

For anyone looking for an answer - it is very prosaic and I was able to identify the problem.

The problem is empty line in the middle of the query, which is interpreted as end of query by DBeaver.

So easy fix is:

  • learn to write queries without them.

Harder fix:

  • set interpretation rules so empty line is not interpreted as end of query (behavior is similar to “;”)

Viva la long night, but finally I know why this was happening.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.