Skip to main content

Offset

Definition

The offset method allows you to add the OFFSET clause to the query.

Available methods

1. offset(int count)

  • count: an int value which will be added to OFFSET clause.

2. offset(long count)

  • count: a long value which will be added to OFFSET clause.

3. offset(KOptionalLong kOptionalLong)

  • kOptionalLong: a long value which will be added to OFFSET clause.

Method hierarchy

The offset method can be used right after the following methods:

and the subsequent methods that can be called are:

Example: int

Java code:

k
.select(
APP_USER.FIRST_NAME
)
.from(APP_USER)
.offset(10)
.multiple();

SQL generated:

SELECT au.first_name
FROM app_user au
OFFSET 10

Parameters:

  • None

Example: KOptionalLong (null value)

Java code:

final Long nullLong = null;

k
.select(
APP_USER.FIRST_NAME
)
.from(APP_USER)
.offset(optional(nullLong))
.multiple();

SQL generated:

SELECT au.first_name
FROM app_user au

Parameters:

  • None

Example: KOptionalLong (not null value)

Java code:

final Long nullLong = 10;

k
.select(
APP_USER.FIRST_NAME
)
.from(APP_USER)
.offset(optional(nullLong))
.multiple();

SQL generated:

SELECT au.first_name
FROM app_user au
OFFSET 10

Parameters:

  • None

Example: long [calculateOffset]

tip

The first page is always number 1.

Java code:

final Long page = 1L;
final Long limit = 50L;

k
.select(
APP_USER.FIRST_NAME
)
.from(APP_USER)
.limit(limit)
.offset(calculateOffset(page, limit))
.multiple();

SQL generated:

SELECT au.first_name
FROM auth.app_user au
LIMIT 50
OFFSET 0

Parameters:

  • None