### jOOQ Example of PARTITION BY
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/window-functions/window-partition
Achieves the same result as the SQL example using jOOQ's DSL for the PARTITION BY clause.
```java
create.select(
BOOK.ID,
BOOK.AUTHOR_ID,
count().over(partitionBy(BOOK.AUTHOR_ID)))
.from(BOOK)
.fetch();
```
--------------------------------
### Set Catalog jOOQ Example
Source: https://www.jooq.org/doc/3.19/manual/sql-building/ddl-statements/set-statement/set-catalog-statement
A concise example demonstrating the jOOQ method for setting the catalog.
```java
setCatalog("c")
```
--------------------------------
### MockFileDatabase File Syntax Example
Source: https://www.jooq.org/doc/3.19/manual/sql-execution/mock-file-database
This example demonstrates the syntax for defining SQL statements, their results, and exceptions within a MockFileDatabase configuration file. Lines starting with '#' are comments, SQL statements are followed by '>' for results and '@ rows:' for row counts. Exceptions can also be specified.
```plaintext
# All lines with a leading hash are ignored. This is the MockFileDatabase comment syntax
-- SQL comments are parsed and passed to the SQL statement
/* The same is true for multi-line SQL comments */
select 'A';
> A
> -
> A
@ rows: 1
select 'A', 'B' union all 'C', 'D';
> A B
> - -
> A B
> C D
@ rows: 2
# Statements without result sets just leave that section empty
update t set x = 1;
@ rows: 3
# Statements producing specific exceptions can indicate them as such
select * from t;
@ exception: ACCESS TO TABLE T FORBIDDEN
```
--------------------------------
### Use ST_StartPoint with jOOQ
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/spatial-functions/st-startpoint-function
Demonstrates how to use the ST_StartPoint function with jOOQ to get the starting point of a linestring. Requires the jOOQ library and a configured DSLContext.
```java
create.select(stStartPoint(stGeomFromText("LINESTRING (0 0, 1 1, 2 0, 3 1)"))).fetch();
```
--------------------------------
### jOOQ LISTAGG DSL Example
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/aggregate-functions/listagg-function
Shows how to use the jOOQ DSL to achieve the same functionality as the SQL LISTAGG example.
```java
create.select(
listAgg(BOOK.ID).withinGroupOrderBy(BOOK.ID),
listAgg(BOOK.ID, "; ").withinGroupOrderBy(BOOK.ID))
.from(BOOK).fetch();
```
--------------------------------
### jOOQ BIT_OR_AGG DSL Example
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/aggregate-functions/bit-or-agg-function
Shows how to use the bitOrAgg function from the jOOQ DSL to achieve the same result as the SQL example.
```java
create.select(
bitOrAgg(BOOK.ID),
bitOrAgg(BOOK.AUTHOR_ID))
.from(BOOK)
```
--------------------------------
### ARRAY Constructor Example (jOOQ)
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/array-functions/array-constructor-subquery
A minimal jOOQ example demonstrating the `array()` function with a constant value.
```java
array(select(val(1)))
```
--------------------------------
### SQL CURRENT_CATALOG Example
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/system-functions/current-catalog-function
Standard SQL syntax to select the current catalog. This is a basic example showing the direct SQL usage.
```sql
SELECT current_catalog;
```
--------------------------------
### Example HTML Output
Source: https://www.jooq.org/doc/3.19/manual/sql-execution/exporting/exporting-html
This is an example of the HTML table generated by the `formatHTML()` method, representing fetched book data.
```html
| ID |
AUTHOR_ID |
TITLE |
| 1 |
1 |
1984 |
| 2 |
1 |
Animal Farm |
```
--------------------------------
### jOOQ FOR JSON AUTO, ROOT Example
Source: https://www.jooq.org/doc/3.19/manual/sql-building/sql-statements/select-statement/for-json-clause/for-json-root-directive
Shows how to achieve the same JSON output structure as the SQL example using jOOQ's DSL.
```java
create.select(BOOK.ID, BOOK.TITLE)
.from(BOOK)
.orderBy(BOOK.ID)
.forJSON().auto().root("result")
.fetch();
```
--------------------------------
### Current User Result Example
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/system-functions/current-user-function
An example of the output format when fetching the current user. This shows the typical tabular result.
```text
+--------------+
| current_user |
+--------------+
| sa |
+--------------+
```
--------------------------------
### SQL Example of PARTITION BY
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/window-functions/window-partition
Fetches all books and the total number of books per author using the SQL PARTITION BY clause.
```sql
SELECT
BOOK.ID,
BOOK.AUTHOR_ID,
count(*) OVER (PARTITION BY BOOK.AUTHOR_ID)
FROM
BOOK
```
--------------------------------
### Get DataType for an embedded DOMAIN
Source: https://www.jooq.org/doc/3.19/manual/sql-building/data-types/domain-data-types
Retrieve the `DataType` for an embedded domain type, which provides additional type safety. This example shows how to get a `DataType` for an `email` domain.
```java
DataType emailType = Domains.EMAIL.getDataType();
```
--------------------------------
### SQL CHR Function Example
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/string-functions/chr-function
Demonstrates the basic usage of the CHR function in standard SQL to get the character for ASCII code 64.
```sql
SELECT chr(64);
```
--------------------------------
### Configuration File Code Block Example
Source: https://www.jooq.org/doc/3.19/manual/getting-started/the-manual
Demonstrates a configuration file code block.
```properties
# A config file code block
org.jooq.property=value
```
--------------------------------
### SQL Server WITH Hint Example
Source: https://www.jooq.org/doc/3.19/manual/sql-building/hints/hints-sql-server/hints-sql-server-table
Demonstrates the SQL Server syntax for applying a WITH hint to a table.
```sql
SELECT *
FROM BOOK WITH (READUNCOMMITTED)
```
--------------------------------
### SQL LIKE Predicate Examples
Source: https://www.jooq.org/doc/3.19/manual/sql-building/conditional-expressions/like-predicate
Demonstrates SQL syntax for case-insensitive and case-sensitive LIKE predicates, including contains, starts with, and ends with patterns.
```sql
-- case insensitivity
LOWER(TITLE) LIKE LOWER('%abc%')
LOWER(TITLE) NOT LIKE LOWER('%abc%')
-- contains and similar methods
TITLE LIKE '%' || 'abc' || '%'
TITLE LIKE 'abc' || '%'
TITLE LIKE '%' || 'abc'
```
--------------------------------
### jOOQ XMLPARSE Example
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/xml-functions/xml-parse-function
A concise jOOQ API call for parsing an XML document, often used as a starting point for dialect-specific translations.
```java
xmlparseDocument("")
```
--------------------------------
### Fetching Records by Example using DSLContext Convenience API
Source: https://www.jooq.org/doc/3.19/manual/sql-building/conditional-expressions/query-by-example
Shows how to use the `DSLContext.fetchByExample()` convenience method to directly query records based on an example `TableRecord`. Requires a `configuration` object.
```java
// Using the convenience API on DSLContext
Result books2 = DSL.using(configuration).fetchByExample(book);
```
--------------------------------
### SQL PRODUCT() Function Output Example
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/aggregate-functions/product-function
Illustrates the expected output format and a sample result when using the PRODUCT() aggregate function.
```text
+---------+
| product |
+---------+
| 24 |
+---------+
```
--------------------------------
### ST_StartPoint Function Usage
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/spatial-functions/st-startpoint-function
Demonstrates how to use the ST_StartPoint function in jOOQ to get the starting point of a linestring. It also shows the expected output.
```APIDOC
## ST_StartPoint
### Description
This function returns the first point of a linestring.
### Method
N/A (This is a function, not an API endpoint)
### Endpoint
N/A
### Parameters
#### Path Parameters
N/A
#### Query Parameters
N/A
#### Request Body
N/A
### Request Example
```java
create.select(stStartPoint(stGeomFromText("LINESTRING (0 0, 1 1, 2 0, 3 1)"))).fetch();
```
### Response
#### Success Response (200)
- **POINT (0 0)** (string) - The starting point of the linestring.
#### Response Example
```
+---------------+
| ST_StartPoint |
+---------------+
| POINT (0 0) |
+---------------+
```
### Dialect Support
This example using jOOQ:
```java
stStartPoint(geometry)
```
Translates to the following dialect specific expressions:
### Aurora MySQL, Aurora Postgres, CockroachDB, DuckDB, MariaDB, MySQL, Postgres, Redshift, Snowflake
```sql
st_startpoint(geometry)
```
### Oracle
```sql
sdo_lrs.geom_segment_start_pt(geometry)
```
### SQLServer
```sql
geometry.STStartPoint()
```
### ASE, Access, BigQuery, ClickHouse, DB2, Databricks, Exasol, Firebird, H2, HSQLDB, Hana, Informix, MemSQL, SQLDataWarehouse, SQLite, Spanner, Sybase, Teradata, Trino, Vertica, YugabyteDB
```sql
/* UNSUPPORTED */
```
> Generated with jOOQ 3.22. Support in older jOOQ versions may differ. Translate your own SQL on our website
```
--------------------------------
### SQL Example for CONNECT_BY_ROOT
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/connect-by-functions/connect-by-root-operator
Demonstrates the usage of CONNECT_BY_ROOT and SYS_CONNECT_BY_PATH in SQL with a sample hierarchical dataset.
```sql
SELECT
child,
parent,
sys_connect_by_path(child, '/'),
connectByRoot(child)
FROM (
VALUES
(1, null),
(2, 1),
(3, null),
(4, 3)
) AS t (child, parent)
START WITH
parent IS NULL
CONNECT BY NOCYCLE
PRIOR child = parent;
```
--------------------------------
### JOIN USING Example Query
Source: https://www.jooq.org/doc/3.19/manual/reference/dont-do-this/dont-do-this-natural-join-or-using
Demonstrates a correct usage of JOIN .. USING with the defined schema to join actor, film_actor, and film tables.
```sql
SELECT *
FROM actor
JOIN film_actor USING (actor_id)
JOIN film USING (film_id);
```
--------------------------------
### Get SRID of a Geometry using jOOQ
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/spatial-functions/st-srid-function
Use the stSrid function to retrieve the SRID of a geometry. This example demonstrates its usage with stGeomFromText and fetches the result.
```java
create.select(stSrid(stGeomFromText("POINT (1 0)", 4326))).fetch();
```
--------------------------------
### jOOQ Example of LEAD Window Function
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/window-functions/window-lead
Shows how to implement the LEAD window function using jOOQ's DSL, including basic usage, offsets, and default values.
```java
create.select(
BOOK.ID,
lead(BOOK.ID).over(orderBy(BOOK.ID)),
lead(BOOK.ID, 2).over(orderBy(BOOK.ID)),
lead(BOOK.ID, 2, -1).over(orderBy(BOOK.ID)))
.from(BOOK)
.fetch();
```
--------------------------------
### ST_Length Function Usage
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/spatial-functions/st-length-function
Demonstrates how to use the ST_Length function in jOOQ to get the length of a geometry. Includes an example of creating a geometry from WKT and fetching its length.
```APIDOC
## ST_Length Function
### Description
This function returns the length of a geometry.
### Method
N/A (This is a function, not an API endpoint)
### Endpoint
N/A
### Parameters
#### Path Parameters
N/A
#### Query Parameters
N/A
#### Request Body
N/A
### Request Example
```java
create.select(stLength(stGeomFromText("LINESTRING (0 0, 0 1, 1 1, 1 2)"))).fetch();
```
### Response
#### Success Response (200)
- **ST_Length** (integer) - The length of the geometry.
#### Response Example
```json
{
"ST_Length": 3
}
```
### Dialect Support
This example using jOOQ:
```java
stLength(geometry)
```
Translates to the following dialect specific expressions:
### Aurora MySQL, Aurora Postgres, CockroachDB, DuckDB, MariaDB, MySQL, Postgres, Redshift, Snowflake
```sql
st_length(geometry)
```
### Oracle
```sql
sdo_geom.sdo_length(geometry, tol => null)
```
### SQLServer
```sql
geometry.STLength()
```
### ASE, Access, BigQuery, ClickHouse, DB2, Databricks, Exasol, Firebird, H2, HSQLDB, Hana, Informix, MemSQL, SQLDataWarehouse, SQLite, Spanner, Sybase, Teradata, Trino, Vertica, YugabyteDB
```sql
/* UNSUPPORTED */
```
> Generated with jOOQ 3.22. Support in older jOOQ versions may differ. Translate your own SQL on our website
```
--------------------------------
### SQL RATIO_TO_REPORT Example
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/window-functions/window-ratio-to-report
Demonstrates the basic SQL syntax for the RATIO_TO_REPORT window function, calculating the ratio of each ID to the total sum of IDs in the BOOK table.
```sql
SELECT
ID,
ratio_to_report(ID) OVER ()
FROM
BOOK;
```
--------------------------------
### CURRENT_LOCALTIME Function
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/datetime-functions/current-localtime-function
Demonstrates how to use the CURRENT_LOCALTIME function in jOOQ to get the current server time. It also shows the generated SQL and an example of the returned data.
```APIDOC
## CURRENT_LOCALTIME
### Description
Get the current server time as a SQL `TIME` type (represented by `java.time.LocalTime`). This function behaves like `CURRENT_TIME` but uses JSR-310 types for client-side representation.
### Method
N/A (This is a function call within jOOQ's DSL)
### Endpoint
N/A
### Parameters
N/A
### Request Example
```java
// Using jOOQ DSL
create.select(currentLocalTime()).fetch();
```
### Response
#### Success Response (200)
- **current_time** (TIME) - The current server time.
#### Response Example
```json
{
"current_time": "15:30:45"
}
```
### Dialect Support
This example using jOOQ:
```java
currentLocalTime()
```
Translates to the following dialect specific expressions:
#### Access
```sql
TIME()
```
#### ASE, Aurora MySQL, MariaDB, MemSQL, MySQL, Snowflake
```sql
current_time()
```
#### Aurora Postgres, CockroachDB, Firebird, Postgres, YugabyteDB
```sql
cast(CURRENT_TIME AS time)
```
#### BigQuery, DB2, H2, HSQLDB, Hana, Redshift, SQLite, Spanner, Teradata, Trino, Vertica
```sql
CURRENT_TIME
```
#### ClickHouse
```sql
current_timestamp()
```
#### Databricks, Exasol
```sql
current_timestamp
```
#### DuckDB
```sql
cast(current_time AS TIME)
```
#### Informix
```sql
CURRENT HOUR TO SECOND
```
#### Oracle
```sql
cast(current_timestamp AS timestamp)
```
#### SQLDataWarehouse, SQLServer
```sql
convert(TIME, current_timestamp)
```
#### Sybase
```sql
CURRENT TIME
```
> Generated with jOOQ 3.22. Support in older jOOQ versions may differ. Translate your own SQL on our website
```
--------------------------------
### SQL CREATE TABLE and INSERT statements
Source: https://www.jooq.org/doc/3.19/manual/sql-execution/logging-sql-exceptions
Example SQL statements demonstrating table creation and data insertion, including cases that violate constraints.
```sql
-- Depending on the dialect, use DECIMAL or NUMBER, instead
CREATE TABLE t (n1 numeric(3) NOT NULL, n2 numeric(3) NOT NULL);
INSERT INTO t (n1, n2) VALUES (123, null);
INSERT INTO t (n1, n2) VALUES (1234, 123);
```
--------------------------------
### CURRENT_DATE Function
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/datetime-functions/current-date-function
Demonstrates how to use the `currentDate()` function in jOOQ to get the current server date. Includes SQL and jOOQ code examples, and expected output.
```APIDOC
## CURRENT_DATE
### Description
Get the current server time as a SQL `DATE` type (represented by `java.sql.Date`).
### Method
`currentDate()`
### Endpoint
N/A (jOOQ function)
### Parameters
None
### Request Example
```java
// SQL equivalent
SELECT current_date;
// jOOQ DSL
create.select(currentDate()).fetch();
```
### Response
#### Success Response (200)
- **current_date** (DATE) - The current date from the server.
#### Response Example
```json
{
"current_date": "2020-02-03"
}
```
### Dialect Support
This example using jOOQ:
```java
currentDate()
```
Translates to the following dialect specific expressions:
#### Access
```sql
DATE()
```
#### ASE, Aurora MySQL, ClickHouse, MariaDB, MemSQL, MySQL, Snowflake
```sql
current_date()
```
#### Aurora Postgres, BigQuery, CockroachDB, DB2, Databricks, DuckDB, Exasol, Firebird, H2, HSQLDB, Hana, Postgres, Redshift, SQLite, Spanner, Teradata, Trino, Vertica, YugabyteDB
```sql
CURRENT_DATE
```
#### Informix
```sql
CURRENT YEAR TO DAY
```
#### Oracle
```sql
trunc(current_date)
```
#### SQLDataWarehouse, SQLServer
```sql
convert(DATE, current_timestamp)
```
#### Sybase
```sql
CURRENT DATE
```
> Generated with jOOQ 3.22. Support in older jOOQ versions may differ. Translate your own SQL on our website
```
--------------------------------
### jOOQ Example with PRIOR and CONNECT BY
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/connect-by-functions/prior-operator
Shows how to implement a hierarchical query using jOOQ's DSL, including the PRIOR operator and CONNECT BY clause. Requires importing jOOQ DSL fields and functions.
```java
Field child = field("child", INTEGER);
Field parent = field("parent", INTEGER);
ctx.select(
child,
parent,
sysConnectByPath(child, "/"))
.from(values(
row(val(1), val(null, INTEGER)),
row(2, 1),
row(3, 2)).as(table("t"), child, parent))
.startWith(parent.isNull())
.connectByNoCycle(prior(child).eq(parent))
.fetch();
```
--------------------------------
### SQL POSITION function example
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/string-functions/position-function
Demonstrates the usage of the SQL POSITION function to find the first occurrence of a character within a string, with an optional starting position.
```sql
SELECT
position('hello', 'e'),
position('hello', 'e', 4);
```
--------------------------------
### jOOQ RANK Function Example
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/window-functions/window-rank
Shows how to use the RANK() window function with jOOQ's DSL. It mirrors the SQL example, assigning ranks based on LANGUAGE_ID.
```java
create.select(
BOOK.LANGUAGE_ID,
rank().over(orderBy(BOOK.LANGUAGE_ID)))
.from(BOOK)
.fetch();
```
--------------------------------
### SQL Example for ISO_DAY_OF_WEEK
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/datetime-functions/iso-day-of-week-function
Demonstrates how to use the ISO_DAY_OF_WEEK function in plain SQL to get the day of the week for a specific date. The result is 7 for Monday, February 3rd, 2020.
```sql
SELECT iso_day_of_week(DATE '2020-02-03');
```
--------------------------------
### SQL CASE Expression Examples
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/case-expressions
Demonstrates both searched and simple CASE syntaxes in standard SQL.
```sql
SELECT
-- Searched case
CASE WHEN AUTHOR.FIRST_NAME = 'Paulo' THEN 'brazilian'
WHEN AUTHOR.FIRST_NAME = 'George' THEN 'english'
ELSE 'unknown'
END,
-- Simple case
CASE AUTHOR.FIRST_NAME WHEN 'Paulo' THEN 'brazilian'
WHEN 'George' THEN 'english'
ELSE 'unknown'
END
FROM AUTHOR
```
--------------------------------
### SQL Query from Example Book Record
Source: https://www.jooq.org/doc/3.19/manual/sql-building/conditional-expressions/query-by-example
This SQL query demonstrates how an example book record with specific attributes set translates into a WHERE clause with equality predicates.
```sql
-- example book record:
ID :
AUTHOR_ID : 1
TITLE :
PUBLISHED_IN: 1970
LANGUAGE_ID : 1
```
```sql
-- Corresponding query
SELECT *
FROM book
WHERE author_id = 1
AND published_in = 1970
AND language_id = 1
```
--------------------------------
### Generated Procedure Implementation Example
Source: https://www.jooq.org/doc/3.19/manual/code-generation/codegen-object-types/codegen-procedures
Illustrates the structure of a generated `org.jooq.Routine` implementation for a database procedure. Includes static members for parameters and methods for setting IN parameters and getting OUT parameters.
```java
public class AuthorExists extends AbstractRoutine {
// All IN, IN OUT, OUT parameters and function return values generate a static member
public static final Parameter AUTHOR_NAME = createParameter("AUTHOR_NAME", VARCHAR);
public static final Parameter RESULT = createParameter("RESULT", NUMERIC);
// A constructor for a new "empty" procedure call
public AuthorExists() {
super("AUTHOR_EXISTS", TEST);
addInParameter(AUTHOR_NAME);
addOutParameter(RESULT);
}
// Every IN and IN OUT parameter generates a setter
public void setAuthorName(String value) {
setValue(AUTHOR_NAME, value);
}
// Every IN OUT, OUT and RETURN_VALUE generates a getter
public BigDecimal getResult() {
return getValue(RESULT);
}
// [...]
}
```
--------------------------------
### SQL NULL Ordering Example
Source: https://www.jooq.org/doc/3.19/manual/sql-building/sql-statements/select-statement/order-by-clause/order-by-nulls-ordering
Demonstrates the standard SQL syntax for ordering by a column and specifying NULLS LAST.
```sql
SELECT
AUTHOR.FIRST_NAME,
AUTHOR.LAST_NAME
FROM AUTHOR
ORDER BY LAST_NAME ASC,
FIRST_NAME ASC NULLS LAST
```
--------------------------------
### Generated Book DAO Example
Source: https://www.jooq.org/doc/3.19/manual/code-generation/codegen-object-types/codegen-daos
This is an example of a generated DAO for a 'Book' table. It extends `DAOImpl` and includes constructors and fetch methods for common operations.
```java
public class BookDao extends DAOImpl {
// Generated constructors
public BookDao() {
super(BOOK, Book.class);
}
public BookDao(Configuration configuration) {
super(BOOK, Book.class, configuration);
}
// Every column generates at least one fetch method
public List fetchById(Integer... values) {
return fetch(BOOK.ID, values);
}
public Book fetchOneById(Integer value) {
return fetchOne(BOOK.ID, value);
}
public List fetchByAuthorId(Integer... values) {
return fetch(BOOK.AUTHOR_ID, values);
}
// [...]
}
```
--------------------------------
### SQL Examples for Parameter Types
Source: https://www.jooq.org/doc/3.19/manual/sql-building/dsl-context/custom-settings/settings-parameter-type
Illustrates the SQL output generated for different parameter type configurations: INDEXED, NAMED, NAMED_OR_INLINED, and INLINED.
```SQL
-- INDEXED
SELECT FIRST_NAME || ? FROM AUTHOR WHERE ID = ?
-- NAMED
SELECT FIRST_NAME || :1 FROM AUTHOR WHERE ID = :x
-- NAMED_OR_INLINED
SELECT FIRST_NAME || 'x' FROM AUTHOR WHERE ID = :x
-- INLINED
SELECT FIRST_NAME || 'x' FROM AUTHOR WHERE ID = 42
```
--------------------------------
### jOOQ UPDATE with ORDER BY and LIMIT
Source: https://www.jooq.org/doc/3.19/manual/sql-building/sql-statements/update-statement/update-order-by-limit
This is the jOOQ DSL example for updating a single record based on an order. It requires no specific setup beyond importing the necessary jOOQ classes.
```java
update(BOOK).set(BOOK.TITLE, "New Title").orderBy(BOOK.ID.asc()).limit(1)
```
--------------------------------
### Get Number of Points in Linestring Geometry with jOOQ
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/spatial-functions/st-numpoints-function
Use the `stNumPoints` function to retrieve the count of points within a linestring geometry. This example demonstrates its usage with `stGeomFromText` and fetching the result.
```java
create.select(stNumPoints(stGeomFromText("LINESTRING (0 0, 0 1, 1 1, 1 2)"))).fetch();
```
--------------------------------
### SQL OVERLAY function example
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/string-functions/overlay-function
Demonstrates the basic usage of the OVERLAY function in standard SQL.
```sql
SELECT overlay('abcdefg', 'xxx', 2);
```
--------------------------------
### Get Number of Geometries using jOOQ
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/spatial-functions/st-numgeometries-function
Use the stNumGeometries function in jOOQ to retrieve the number of interior rings in a polygon geometry. This example demonstrates its basic usage with a MULTIPOINT input.
```java
create.select(stNumGeometries(stGeomFromText("MULTIPOINT ((-1 -1), (1 -1), (1 1), (-1 1))"))).fetch();
```
--------------------------------
### SQL NULLIF Example
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/general-functions/nullif-function
Demonstrates the basic usage of the NULLIF function in SQL.
```sql
SELECT nullif(1, 1), nullif(1, 2);
```
--------------------------------
### EXTRACT Function Usage
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/datetime-functions/extract-function
Demonstrates how to use the EXTRACT function in jOOQ to get a specific date part from a datetime value. Includes SQL and jOOQ code examples, along with the expected output.
```APIDOC
## EXTRACT Function
### Description
Extract a `org.jooq.DatePart` from a datetime value.
### Method
N/A (This is a function, not an endpoint)
### Endpoint
N/A
### Parameters
#### Path Parameters
N/A
#### Query Parameters
N/A
#### Request Body
N/A
### Request Example
```sql
SELECT EXTRACT(MONTH FROM DATE '2020-02-03');
```
```java
create.select(extract(Date.valueOf("2020-02-03"), DatePart.MONTH)).fetch();
```
### Response
#### Success Response (200)
- **month** (integer) - The extracted month value.
#### Response Example
```json
{
"month": 2
}
```
### Dialect Support
This example using jOOQ:
```java
extract(Date.valueOf("2020-02-03"), DatePart.MONTH)
```
Translates to the following dialect specific expressions:
#### Access
```sql
datepart('m', #2020/02/03 00:00:00#)
```
#### ASE, Sybase
```sql
datepart(mm, '2020-02-03 00:00:00.0')
```
#### Aurora MySQL, Aurora Postgres, CockroachDB, Databricks, DuckDB, Exasol, Firebird, H2, HSQLDB, Hana, MariaDB, MySQL, Oracle, Postgres, Redshift, Snowflake, Spanner, Teradata, Trino, Vertica, YugabyteDB
```sql
extract(MONTH FROM TIMESTAMP '2020-02-03 00:00:00.0')
```
#### BigQuery
```sql
extract(MONTH FROM DATETIME '2020-02-03 00:00:00.0')
```
#### ClickHouse
```sql
extract(MONTH FROM TIMESTAMP '2020-02-03 00:00:00')
```
#### DB2
```sql
MONTH(TIMESTAMP '2020-02-03 00:00:00.0')
```
#### Informix
```sql
MONTH(DATETIME(2020-02-03 00:00:00.0) YEAR TO FRACTION)
```
#### MemSQL
```sql
extract(MONTH FROM {ts '2020-02-03 00:00:00.0'})
```
#### SQLDataWarehouse, SQLServer
```sql
datepart(mm, cast('2020-02-03 00:00:00.0' AS DATETIME2))
```
#### SQLite
```sql
cast(
strftime('%m', '2020-02-03 00:00:00.0')
AS int
)
```
> Generated with jOOQ 3.22. Support in older jOOQ versions may differ. Translate your own SQL on our website
```
--------------------------------
### jOOQ Example for CONNECT_BY_ROOT
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/connect-by-functions/connect-by-root-operator
Shows how to implement the CONNECT_BY_ROOT functionality using jOOQ's DSL, including SYS_CONNECT_BY_PATH and connectByRoot.
```java
Field child = field("child", INTEGER);
Field parent = field("parent", INTEGER);
create.select(
child,
parent,
sysConnectByPath(child, "/"),
connectByRoot(child))
.from(values(
row(val(1), val(null, INTEGER)),
row(2, 1),
row(val(3), val(null, INTEGER)),
row(4, 3)).as(table("t"), child, parent))
.startWith(parent.isNull())
.connectByNoCycle(prior(child).eq(parent))
.fetch();
```
--------------------------------
### jOOQ NTILE Example
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/window-functions/window-ntile
Shows how to implement the NTILE window function using the jOOQ API, partitioning data by ID.
```java
create.select(
BOOK.ID,
ntile(2).over(orderBy(BOOK.ID)))
.from(BOOK)
.fetch();
```
--------------------------------
### Get Number of Interior Rings of a Polygon with jOOQ
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/spatial-functions/st-numinteriorrings-function
Use the stNumInteriorRings function to count the interior rings of a polygon. This example demonstrates its usage with a WKT string representing a polygon with two interior rings.
```java
create.select(stNumInteriorRings(
stGeomFromText("""
POLYGON (
(-3 -3, 3 -3, 3 3, -3 3, -3 -3),
(-2 -2, 2 -2, 2 2, -2 2, -2 -2),
(-1 -1, 1 -1, 1 1, -1 1, -1 -1)
)
""")).fetch();
```
--------------------------------
### SQL Example for WITH TIES
Source: https://www.jooq.org/doc/3.19/manual/sql-building/sql-statements/select-statement/with-ties-clause
Demonstrates the SQL syntax for fetching rows with ties using the FETCH NEXT clause.
```sql
SELECT *
FROM book
ORDER BY author_id
FETCH NEXT 1 ROWS WITH TIES
```
--------------------------------
### Translate CREATE SEQUENCE to SQL Dialects
Source: https://www.jooq.org/doc/3.19/manual/sql-building/ddl-statements/create-statement/create-sequence-statement
This example shows how jOOQ translates a simple CREATE SEQUENCE statement into various SQL dialects. Note the dialect-specific options like BIT_REVERSED_POSITIVE for Spanner and START WITH 1 for SQLServer. Some dialects are marked as UNSUPPORTED.
```sql
CREATE SEQUENCE s
```
```sql
CREATE SEQUENCE s BIT_REVERSED_POSITIVE
```
```sql
CREATE SEQUENCE s START WITH 1
```
```sql
/* UNSUPPORTED */
```
--------------------------------
### SQL NTILE Example
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/window-functions/window-ntile
Demonstrates the basic usage of the NTILE window function in SQL to divide rows into two buckets based on the ID column.
```sql
SELECT
ID,
ntile(2) OVER (ORDER BY ID)
FROM
BOOK;
```
--------------------------------
### GOTO statement example with label in jOOQ
Source: https://www.jooq.org/doc/3.19/manual/sql-building/procedural-statements/procedural-goto
Illustrates a jOOQ example for a GOTO statement that jumps to a labeled block. This specific example is translated into various SQL dialects.
```java
begin(l.label(insertInto(BOOK).columns(BOOK.ID).values(1)), goto_(l))
```
--------------------------------
### SQL Derived Table Example
Source: https://www.jooq.org/doc/3.19/manual/sql-building/table-expressions/aliased-tables/unnamed-derived-tables
A basic SQL example of a derived table.
```sql
-- Derived table
(SELECT 1 AS a)
```
--------------------------------
### SQL WINDOW Clause Example
Source: https://www.jooq.org/doc/3.19/manual/sql-building/sql-statements/select-statement/window-clause
Demonstrates the SQL syntax for the WINDOW clause to define a window specification for reuse.
```sql
SELECT
LAG(first_name, 1) OVER w "prev",
first_name,
LEAD(first_name, 1) OVER w "next"
FROM author
WINDOW w AS (ORDER first_name)
ORDER BY first_name DESC
```
--------------------------------
### HQL Implicit JOIN Example
Source: https://www.jooq.org/doc/3.19/manual/coming-from-jpa/from-jpa-implicit-join
This is an example of how implicit JOINs are written in HQL.
```sql
from Book as book
where book.language.cd = 'en'
```
--------------------------------
### Ad-hoc SQL SELECT * Example
Source: https://www.jooq.org/doc/3.19/manual/reference/dont-do-this/dont-do-this-sql-select-all
Demonstrates the basic SQL syntax for selecting all columns from a table, useful for quick data inspection.
```sql
SELECT * FROM book
```
--------------------------------
### CARDINALITY Result Example
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/array-functions/cardinality-function
This is an example of the output format when using the CARDINALITY function in jOOQ.
```text
+-------------+
| cardinality |
+-------------+
| 2 |
+-------------+
```
--------------------------------
### SQL Example of LEAD Window Function
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/window-functions/window-lead
Demonstrates the basic usage of the LEAD function in SQL to fetch values from the next and second next rows, with and without a default value.
```sql
SELECT
ID,
lead(ID) OVER (ORDER BY ID),
lead(ID, 2) OVER (ORDER BY ID),
lead(ID, 2, -1) OVER (ORDER BY ID)
FROM
BOOK;
```
--------------------------------
### SQL XMLEXISTS Predicate Example
Source: https://www.jooq.org/doc/3.19/manual/sql-building/conditional-expressions/xml-exists-predicate
This is a basic SQL example demonstrating the usage of the XMLEXISTS predicate.
```sql
SELECT 1
WHERE xmlexists('/a/b' PASSING '')
```
--------------------------------
### SQL Example for Keyset Pagination
Source: https://www.jooq.org/doc/3.19/manual/sql-building/sql-statements/select-statement/seek-clause
This SQL query demonstrates how to fetch records strictly after a given boundary using a combination of value and ID comparison.
```sql
SELECT id, value
FROM t
WHERE (value, id) > (2, 533)
ORDER BY value, id
LIMIT 5
```
--------------------------------
### Quantified Comparison Predicate Examples
Source: https://www.jooq.org/doc/3.19/manual/sql-building/conditional-expressions/quantified-comparison-predicate
Demonstrates the syntax for TITLE = ANY and PUBLISHED_IN > ALL using string and integer literals.
```sql
TITLE = ANY('Animal Farm', '1982')
PUBLISHED_IN > ALL(1920, 1940)
```
--------------------------------
### JSON Data Example
Source: https://www.jooq.org/doc/3.19/manual/sql-execution/importing/importing-sources/importing-source-json
This is an example of JSON data structure that can be imported. It includes field definitions and records.
```json
{"fields" :[{"name":"ID","type":"INTEGER"},
{"name":"AUTHOR_ID","type":"INTEGER"},
{"name":"TITLE","type":"VARCHAR"}],
"records":[[1,1,"1984"],
[2,1,"Animal Farm"]]}
```
--------------------------------
### SQL Server OPTION Hint Example
Source: https://www.jooq.org/doc/3.19/manual/sql-building/hints/hints-sql-server/hints-sql-server-option
Demonstrates the SQL Server OPTION hint syntax in plain SQL. The OPTION keyword must be included manually when using jOOQ.
```sql
SELECT field1, field2
FROM table1
OPTION (OPTIMIZE FOR UNKNOWN)
```
--------------------------------
### COTH Function Usage and Examples
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/numeric-functions/coth-function
Demonstrates how to use the COTH function in jOOQ and provides a SQL example.
```APIDOC
## COTH Function
### Description
The `COTH()` function calculates the hyperbolic cotangent of a numeric value.
### Method
N/A (This is a function, not an API endpoint)
### Endpoint
N/A
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```sql
SELECT coth(1);
```
### Response
#### Success Response (200)
- **Result** (numeric) - The hyperbolic cotangent of the input value.
#### Response Example
```
+--------------+
| coth |
+--------------+
| 1.3130352855 |
+--------------+
```
### jOOQ Usage Example
```java
create.select(coth(1)).fetch();
```
### Dialect Support
This example using jOOQ:
```java
coth(x)
```
Translates to the following dialect specific expressions:
#### ASE, Access, Aurora MySQL, Aurora Postgres, DuckDB, HSQLDB, MariaDB, MemSQL, MySQL, Postgres, SQLDataWarehouse, SQLServer, Sybase, Vertica, YugabyteDB
```
((exp((x * 2)) + 1) / (exp((x * 2)) - 1))
```
#### BigQuery, ClickHouse, DB2, Databricks, Exasol, Firebird, H2, Hana, Informix, Oracle, SQLite, Snowflake, Spanner, Teradata, Trino
```
(1 / tanh(x))
```
#### CockroachDB
```
((exp(cast((
(x * 2)
AS decimal
)) + 1) / (exp(cast((
(x * 2)
AS decimal
)) - 1))
```
> Generated with jOOQ 3.22. Support in older jOOQ versions may differ. Translate your own SQL on our website
```
--------------------------------
### SQLDataWarehouse/SQLServer LocalDateTimeAdd Example
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/datetime-functions/localdatetimeadd-function
Provides an example of adding 3 days to a DATETIME2 value in SQLDataWarehouse and SQLServer.
```sql
dateadd(DAY, 3, cast('2020-02-03 15:30:45.0' AS DATETIME2))
```
--------------------------------
### Configuring SQL Parser Settings
Source: https://www.jooq.org/doc/3.19/manual/sql-building/dsl-context/custom-settings/settings-parser
Provides an example of how to configure various SQL parser settings using the `Settings` builder. This includes setting the dialect, meta lookup behavior, search path, and comment handling.
```java
Settings settings = new Settings()
.withParseDialect(SQLSERVER) // Defaults to DEFAULT
.withParseWithMetaLookups(THROW_ON_FAILURE) // Defaults to OFF
.withParseSearchPath(
new ParseSearchSchemata().withSchema("PUBLIC"),
new ParseSearchSchemata().withSchema("TEST"))
.withParseUnsupportedSyntax(FAIL) // Defaults to IGNORE
.withParseUnknownFunctions(IGNORE) // Defaults to FAIL
.withParseIgnoreComments(true) // Defaults to false
.withParseIgnoreCommentStart("") // Defaults to "[jooq ignore start]"
.withParseIgnoreCommentStop("") // Defaults to "[jooq ignore stop]"
```
--------------------------------
### SQL LPAD Example
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/string-functions/lpad-function
Demonstrates the standard SQL usage of the LPAD function to pad a string.
```sql
SELECT lpad('hello', 10, '.');
```
--------------------------------
### jOOQ BIT_XNOR_AGG Example
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/aggregate-functions/bit-xnor-agg-function
Shows how to use the bitXNorAgg function in jOOQ to achieve the same result as the SQL example.
```java
create.select(
bitXNorAgg(BOOK.ID),
bitXNorAgg(BOOK.AUTHOR_ID))
.from(BOOK)
```
--------------------------------
### Create DSLContext from Configuration
Source: https://www.jooq.org/doc/3.19/manual/sql-building/dsl-context
Instantiate a DSLContext using an existing Configuration object. This is useful when you have a pre-configured setup.
```java
DSLContext create = DSL.using(configuration);
```
--------------------------------
### Clone and run jbang example
Source: https://www.jooq.org/doc/3.19/manual/getting-started/tutorials/jooq-with-jbang
Clone the jbang-example repository and run the main example using jbang.
```shell
git clone https://github.com/jOOQ/jbang-example
cd jbang-example
jbang Example.java
```
--------------------------------
### SQL FIRST_VALUE Example
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/window-functions/window-first-value
Demonstrates the use of the SQL FIRST_VALUE window function with different window frame clauses on a BOOK table.
```sql
SELECT
ID,
first_value(ID) OVER (ORDER BY ID),
first_value(ID) OVER (ORDER BY ID ROWS 1 PRECEDING)
FROM
BOOK;
```
--------------------------------
### Get Sequence Properties
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/sequences-and-serials
Use these methods to get fields representing the CURRVAL and NEXTVAL properties of a sequence.
```java
// Get a field for the CURRVAL sequence property
Field currval();
// Get a field for the NEXTVAL sequence property
Field nextval();
```
--------------------------------
### RPAD SQL Example
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/string-functions/rpad-function
Demonstrates the usage of the RPAD function in standard SQL to pad a string.
```sql
SELECT rpad('hello', 10, '.');
```
--------------------------------
### SQL SELECT Clause Examples
Source: https://www.jooq.org/doc/3.19/manual/sql-building/sql-statements/select-statement/select-clause
Demonstrates basic SQL SELECT clauses for projecting columns and function results.
```sql
SELECT BOOK.ID, BOOK.TITLE
```
```sql
SELECT BOOK.ID, TRIM(BOOK.TITLE)
```
--------------------------------
### COT Function Usage and Examples
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/numeric-functions/cot-function
Demonstrates how to use the COT function in SQL and jOOQ, along with an example of its output.
```APIDOC
## COT Function
Supported by ✅ Open Source Edition ✅ Express Edition ✅ Professional Edition ✅ Enterprise Edition
The `COT()` function calculates the cotangent of a numeric value.
### SQL Example
```sql
SELECT cot(1.5707963268);
```
### jOOQ Example
```java
create.select(cot(1.5707963268)).fetch();
```
### Result Example
```
+-----+
| cot |
+-----+
| 0 |
+-----+
```
```
--------------------------------
### Full jOOQ Application Example
Source: https://www.jooq.org/doc/3.19/manual/getting-started/tutorials/jooq-in-7-steps/jooq-in-7-steps-step6
A complete Java program demonstrating jOOQ integration, including database connection, query execution, and result iteration. Static imports for generated tables and jOOQ functions are used for brevity.
```java
package test;
// For convenience, always static import your generated tables and
// jOOQ functions to decrease verbosity:
import static test.generated.Tables.*;
import static org.jooq.impl.DSL.*;
import java.sql.*;
import org.jooq.*;
import org.jooq.impl.*;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
String userName = "root";
String password = "";
String url = "jdbc:mysql://localhost:3306/library";
// Connection is the only JDBC resource that we need
// PreparedStatement and ResultSet are handled by jOOQ, internally
try (Connection conn = DriverManager.getConnection(url, userName, password)) {
DSLContext create = DSL.using(conn, SQLDialect.MYSQL);
Result result = create.select().from(AUTHOR).fetch();
for (Record r : result) {
Integer id = r.getValue(AUTHOR.ID);
String firstName = r.getValue(AUTHOR.FIRST_NAME);
String lastName = r.getValue(AUTHOR.LAST_NAME);
System.out.println("ID: " + id + " first name: " + firstName + " last name: " + lastName);
}
}
// For the sake of this tutorial, let's keep exception handling simple
catch (Exception e) {
e.printStackTrace();
}
}
}
```
--------------------------------
### jOOQ JSON_SET Dialect Example
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/json-functions/json-set-function
A specific jOOQ DSL example for JSON_SET, useful for understanding its direct translation.
```java
jsonSet(val(json("{\"a\":1}")), "$.a", 2)
```
--------------------------------
### jOOQ RATIO_TO_REPORT DSL Example
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/window-functions/window-ratio-to-report
Shows how to implement the RATIO_TO_REPORT window function using the jOOQ DSL, applying it to the ID column of the BOOK table.
```java
create.select(
BOOK.ID,
ratioToReport(BOOK.ID).over())
.from(BOOK)
.fetch();
```
--------------------------------
### jOOQ BIT_COUNT Java API Example
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/bitwise-functions/bit-count-function
Example of using the jOOQ API to call BIT_COUNT with a byte literal.
```java
bitCount((byte) 5)
```
--------------------------------
### jOOQ Window Frame Examples
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/window-functions/window-frame
Shows how to implement window frame clauses using the jOOQ API.
```java
create.select(
BOOK.ID,
BOOK.PUBLISHED_IN,
// The 2 preceding rows and the current row
count().over(orderBy(BOOK.PUBLISHED_IN).rowsPreceding(2)),
// The 42 preceding years and the current row
count().over(orderBy(BOOK.PUBLISHED_IN).rangePreceding(42)),
// The 1 preceding groups of years and the current row
trunc(BOOK.PUBLISHED_IN, -1),
count().over(orderBy(trunc(BOOK.PUBLISHED_IN, -1))
.groupsPreceding(1)))
.from(BOOK)
.orderBy(BOOK.PUBLISHED_IN)
.fetch();
```
--------------------------------
### jOOQ BIT_GET Example
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/bitwise-functions/bit-get-function
Shows how to use the jOOQ API to generate SQL for the BIT_GET function. Ensure the 'inline' and 'bitGet' functions are imported.
```java
create.select(
bitGet(inline(3), 0),
bitGet(inline(3), 2)).fetch();
```
--------------------------------
### jOOQ GROUP BY Example
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/aggregate-functions/aggregate-grouping
This jOOQ code performs the same aggregation as the SQL example, grouping by AUTHOR_ID and counting rows.
```java
create.select(BOOK.AUTHOR_ID, count())
.from(BOOK)
.groupBy(BOOK.AUTHOR_ID).fetch();
```
--------------------------------
### MonetaryAmountRecord Implementation Example
Source: https://www.jooq.org/doc/3.19/manual/code-generation/codegen-embeddable-types/codegen-embeddable-types-configuration
Example of an EmbeddableRecord implementation for monetary amounts. This record holds fields for amount and currency.
```java
public class MonetaryAmountRecord extends EmbeddableRecordImpl {
public MonetaryAmountRecord(BigDecimal amount, String currency) { /* ... */ }
// Getters, setters
}
```
--------------------------------
### SQL CHOOSE Function Example
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/general-functions/choose-function
Demonstrates the usage of the CHOOSE function in standard SQL to select an argument based on an integer index.
```sql
SELECT
choose(1, 'a', 'b'),
choose(2, 'a', 'b'),
choose(3, 'a', 'b');
```
--------------------------------
### jOOQ Derived Table Example
Source: https://www.jooq.org/doc/3.19/manual/sql-building/table-expressions/aliased-tables/unnamed-derived-tables
An example of creating a derived table using jOOQ's DSL API in Java.
```java
// Derived table
table(select(inline(1).as("a")));
```
--------------------------------
### ALTER TABLE ADD COLUMN AFTER - jOOQ Example
Source: https://www.jooq.org/doc/3.19/manual/sql-building/ddl-statements/alter-statement/alter-table-statement/alter-table-add-column-position
This is a jOOQ DSL example for adding a column after a specified existing column.
```java
alterTable("t").add("c", INTEGER).after("other")
```
--------------------------------
### jOOQ ROW_NUMBER() Example
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/window-functions/window-row-number
Shows how to implement the ROW_NUMBER window function using the jOOQ API, mirroring the SQL example.
```java
create.select(BOOK.LANGUAGE_ID, rowNumber().over(orderBy(BOOK.LANGUAGE_ID)).as("row_num"))
.from(BOOK)
.fetch();
```
--------------------------------
### SQL BIT_XOR Example
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/bitwise-functions/bit-xor-function
Demonstrates the usage of the BIT_XOR function in standard SQL.
```sql
SELECT bit_xor(5, 3);
```
--------------------------------
### SQL BIT_AND Example
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/bitwise-functions/bit-and-function
Demonstrates the usage of the BIT_AND function in a standard SQL SELECT statement.
```sql
SELECT bit_and(5, 4);
```
--------------------------------
### SQL XMLFOREST Example
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/xml-functions/xml-forest-function
Demonstrates the basic SQL syntax for the XMLFOREST function, creating XML elements from other elements.
```sql
SELECT xmlforest(
xmlelement(NAME e1) AS w1,
xmlelement(NAME e2) AS w2
)
```
--------------------------------
### SQL and jOOQ Execution Example
Source: https://www.jooq.org/doc/3.19/manual/getting-started/the-manual
Compares immediate SQL execution with jOOQ's fetch() or execute() calls.
```sql
SELECT 1 FROM DUAL
UPDATE t SET v = 1
```
```java
create.selectOne().fetch();
create.update(T).set(T.V, 1).execute();
```
--------------------------------
### jOOQ DSL Example for BIT_XOR_AGG
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/aggregate-functions/bit-xor-agg-function
Example of using the `bitXorAgg` function within the jOOQ DSL for building SQL queries.
```APIDOC
## jOOQ DSL Example for BIT_XOR_AGG
### Description
Demonstrates how to use the `bitXorAgg` function in jOOQ to achieve the same result as the SQL `BIT_XOR_AGG` function.
### Method
jOOQ DSL Query Construction
### Endpoint
N/A
### Parameters
None directly for the function call, but it operates on jOOQ `Field` objects.
### Request Example
```java
create.select(
bitXorAgg(BOOK.ID),
bitXorAgg(BOOK.AUTHOR_ID))
.from(BOOK)
```
### Response
N/A (This is a code example for query construction)
```
--------------------------------
### RPAD jOOQ DSL Example
Source: https://www.jooq.org/doc/3.19/manual/sql-building/column-expressions/string-functions/rpad-function
Shows how to use the RPAD function within the jOOQ DSL for programmatic SQL construction.
```java
create.select(rpad(val("hello"), 10, '.')).fetch();
```
--------------------------------
### Example Generated Interface Structure
Source: https://www.jooq.org/doc/3.19/manual/code-generation/codegen-object-types/codegen-interfaces
This is an example of an interface generated by jOOQ for a database table. It includes setters and getters for columns.
```java
public interface IBook extends java.io.Serializable {
// Every column generates a getter and a setter
public void setId(Integer value);
public Integer getId();
// [...]
}
```