• About Us
  • Privacy Policy
  • Disclaimer
  • Contact Us
AimactGrow
  • Home
  • Technology
  • AI
  • SEO
  • Coding
  • Gaming
  • Cybersecurity
  • Digital marketing
No Result
View All Result
  • Home
  • Technology
  • AI
  • SEO
  • Coding
  • Gaming
  • Cybersecurity
  • Digital marketing
No Result
View All Result
AimactGrow
No Result
View All Result

A Situation is a Subject – Java, SQL and jOOQ.

Admin by Admin
May 20, 2025
Home Coding
Share on FacebookShare on Twitter


Beginning with jOOQ 3.17, the Situation kind extends the Subject kind. As a result of, that’s what the SQL customary thinks it’s, in kinds:

<boolean worth expression> ::=
  <predicate>

The precise definition comprises intermediate guidelines, however you get the concept. A

(which is a Situation in jOOQ) can be utilized wherever a can be utilized, which once more can be utilized in projections, predicates, and elsewhere.

Not all SQL dialects work this manner, and in reality, earlier than SQL:1999 standardised on the BOOLEAN information kind, SQL itself didn’t work this manner. SQL-92, for instance, listed as a potential substitute for the solely, which is used for instance in , however not in any odd .

Therefore, whereas this works in PostgreSQL, which helps customary SQL BOOLEAN varieties:

SELECT id, id > 2 AS big_id
FROM guide
ORDER BY id

Producing:

|id |big_id|
|---|------|
|1  |false |
|2  |false |
|3  |true  |
|4  |true  |

It doesn’t work in Oracle, for instance, which delights us with the standard helpful error message:

SQL Error [923] [42000]: ORA-00923: FROM key phrase not discovered the place anticipated

How this used to work in jOOQ 3.16 or much less

jOOQ has at all times supported a manner to make use of Situation and Subject exchangeably. There are the 2 wrapper strategies:

  • DSL.subject(Situation) returns Subject
  • DSL.situation(Subject) returns Situation

That is documented right here. As such, the earlier question might have been written as follows:

Consequence> consequence =
ctx.choose(BOOK.ID, subject(BOOK.ID.gt(2)).as("big_id"))
//                  ^^^^^^^^^^^^^^^^^^^^ wrapping situation with subject()
   .from(BOOK)
   .orderBy(BOOK.ID)
   .fetch();

The generated SQL seems to be like this, for PostgreSQL:

SELECT
  guide.id,
  (guide.id > 2) AS big_id
FROM guide
ORDER BY guide.id

And for Oracle, that is the emulation of the characteristic:

SELECT
  guide.id,
  CASE
    WHEN guide.id > 2 THEN 1
    WHEN NOT (guide.id > 2) THEN 0
  END big_id
FROM guide
ORDER BY guide.id

The emulation preserves our beloved three valued logic, i.e. the BOOLEAN worth is NULL in case BOOK.ID is NULL.

How this works in jOOQ 3.17, now

Ranging from jOOQ 3.17 and #11969, this guide wrapping of subject(Situation) is now not crucial, and you may simply challenge the Situation straight:

Consequence> consequence =
ctx.choose(BOOK.ID, BOOK.ID.gt(2).as("big_id"))
   //               ^^^^^^^^^^^^^ no extra wrapping crucial
   .from(BOOK)
   .orderBy(BOOK.ID)
   .fetch();

The behaviour is precisely the identical as should you had wrapped the situation (together with the consequence kind), and the emulation nonetheless kicks in additionally for Oracle and different dialects that don’t assist BOOLEAN worth expressions. This implies you can too use Situation in different clauses that take Subject varieties, together with, e.g.:

  • GROUP BY or PARTITION BY
  • ORDER BY

Time to improve your jOOQ model!

Like this:

Like Loading…

Tags: ConditionFieldJavajOOQSQL
Admin

Admin

Next Post
Can Poochyena be shiny in Pokémon Go?

Can Poochyena be shiny in Pokémon Go?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recommended.

Google Adverts Lowers Buyer Lists Requirement For Goal Community On Search Campaigns

Google Adverts Lowers Buyer Lists Requirement For Goal Community On Search Campaigns

May 26, 2025
Stealing person credentials with evilginx – Sophos Information

Stealing person credentials with evilginx – Sophos Information

March 28, 2025

Trending.

Industrial-strength April Patch Tuesday covers 135 CVEs – Sophos Information

Industrial-strength April Patch Tuesday covers 135 CVEs – Sophos Information

April 10, 2025
Expedition 33 Guides, Codex, and Construct Planner

Expedition 33 Guides, Codex, and Construct Planner

April 26, 2025
How you can open the Antechamber and all lever places in Blue Prince

How you can open the Antechamber and all lever places in Blue Prince

April 14, 2025
Important SAP Exploit, AI-Powered Phishing, Main Breaches, New CVEs & Extra

Important SAP Exploit, AI-Powered Phishing, Main Breaches, New CVEs & Extra

April 28, 2025
Wormable AirPlay Flaws Allow Zero-Click on RCE on Apple Units by way of Public Wi-Fi

Wormable AirPlay Flaws Allow Zero-Click on RCE on Apple Units by way of Public Wi-Fi

May 5, 2025

AimactGrow

Welcome to AimactGrow, your ultimate source for all things technology! Our mission is to provide insightful, up-to-date content on the latest advancements in technology, coding, gaming, digital marketing, SEO, cybersecurity, and artificial intelligence (AI).

Categories

  • AI
  • Coding
  • Cybersecurity
  • Digital marketing
  • Gaming
  • SEO
  • Technology

Recent News

Borderlands 4 is a daring departure for the collection, however 2K could have carved off a few of its soul within the pursuit of killing cringe – preview

Borderlands 4 is a daring departure for the collection, however 2K could have carved off a few of its soul within the pursuit of killing cringe – preview

June 18, 2025
Coding a 3D Audio Visualizer with Three.js, GSAP & Internet Audio API

Coding a 3D Audio Visualizer with Three.js, GSAP & Internet Audio API

June 18, 2025
  • About Us
  • Privacy Policy
  • Disclaimer
  • Contact Us

© 2025 https://blog.aimactgrow.com/ - All Rights Reserved

No Result
View All Result
  • Home
  • Technology
  • AI
  • SEO
  • Coding
  • Gaming
  • Cybersecurity
  • Digital marketing

© 2025 https://blog.aimactgrow.com/ - All Rights Reserved