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 syntax error when aliasing outcome of a relational division #2086

Closed
lukaseder opened this issue Jan 4, 2013 · 0 comments
Closed

SQL syntax error when aliasing outcome of a relational division #2086

lukaseder opened this issue Jan 4, 2013 · 0 comments

Comments

@lukaseder
Copy link
Member

The following query generates a SQL syntax error in most databases:

        create().select()
                .from(TBookToBookStore()
                .divideBy(TBookStore())
                .on(TBookToBookStore_BOOK_STORE_NAME().equal(TBookStore_NAME()))
                .returning(TBookToBookStore_BOOK_ID())
                .as("x")) // Aliasing is not possible
                .fetchOne(0, Integer.class);

... which renders as such

select *
from ((
  select distinct "dividend"."book_id"
  from "public"."t_book_to_book_store" as "dividend"
  where not exists (
    select 1
    from "public"."t_book_store"
    where not exists (
      select 1
      from "public"."t_book_to_book_store"
      where (
        "dividend"."book_id" = "public"."t_book_to_book_store"."book_id"
        and "public"."t_book_to_book_store"."book_store_name" = "public"."t_book_store"."name"
      )
    )
  )
) as "alias_40930429") as "x"

The error obtained is this:

Caused by: org.postgresql.util.PSQLException: FEHLER: Syntaxfehler bei »)«

The reason is that in most SQL dialects, it is not allowed to doubly-nest derived tables with aliases

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

No branches or pull requests

1 participant