# AbstractQuery

abstract class AbstractQuery<T : AbstractQuery<T>>(targets: List<Table>) : Statement<ResultApi>

Base class representing an SQL query that returns a database result when executed.

## Constructors

AbstractQuery
Link copied to clipboard
constructor(targets: List<Table>)

## Types

CommentPosition
Link copied to clipboard
enum CommentPosition : Enum<AbstractQuery.CommentPosition>

Represents the position at which an SQL comment will be added in a `SELECT` query.

## Properties

comments
Link copied to clipboard
var comments: Map<AbstractQuery.CommentPosition, String>

The stored comments and their CommentPositions in this `SELECT` query.

distinct
Link copied to clipboard
var distinct: Boolean

Whether only distinct results should be retrieved by this `SELECT` query.

distinctOn
Link copied to clipboard
var distinctOn: List<Column<*>>?

List of columns on which the query should be distinct.

fetchSize
Link copied to clipboard
var fetchSize: Int?

The number of results that should be fetched when this query is executed.

groupedByColumns
Link copied to clipboard
var groupedByColumns: List<Expression<*>>

The stored list of columns for a `GROUP BY` clause in this `SELECT` query.

having
Link copied to clipboard
var having: Op<Boolean>?

The stored condition for a `HAVING` clause in this `SELECT` query.

limit
Link copied to clipboard
var limit: Int?

The stored value for a `LIMIT` clause in this query.

offset
Link copied to clipboard
var offset: Long

The stored value for an `OFFSET` clause in this query.

orderByExpressions
Link copied to clipboard
var orderByExpressions: List<Pair<Expression<*>, SortOrder>>

The stored list of columns and their SortOrder for an `ORDER BY` clause in this query.

set
Link copied to clipboard
abstract val set: FieldSet

The set of columns on which a query should be executed, contained by a ColumnSet.

targets
Link copied to clipboard
val targets: List<Table>
type
Link copied to clipboard
val type: StatementType
where
Link copied to clipboard
var where: Op<Boolean>?

The stored condition for a `WHERE` clause in this `SELECT` query.

## Functions

adjustComments
Link copied to clipboard
fun adjustComments(position: AbstractQuery.CommentPosition, content: String? = null): T

Changes the content of the comments field at the specified position in this query.

adjustHaving
Link copied to clipboard
fun adjustHaving(body: Op<Boolean>?.() -> Op<Boolean>): T

Changes the having field of this query.

arguments
Link copied to clipboard
open override fun arguments(): List<List<Pair<IColumnType<*>, Any?>>>

Returns all mappings of columns and expression types to their values needed to prepare an SQL statement.

comment
Link copied to clipboard
fun comment(content: String, position: AbstractQuery.CommentPosition = CommentPosition.FRONT): T

Appends an SQL comment, with content wrapped by `/* */`, at the specified CommentPosition in this `SELECT` query.

copyTo
Link copied to clipboard
open fun copyTo(other: T)

Copies all stored properties of this `SELECT` query into the properties of other.

fetchSize
Link copied to clipboard
fun fetchSize(n: Int): T

Modifies the number of results that should be fetched when this query is executed.

groupBy
Link copied to clipboard
fun groupBy(vararg columns: Expression<*>): T

Appends a `GROUP BY` clause with the specified columns to this `SELECT` query.

hasCustomForUpdateState
Link copied to clipboard
fun hasCustomForUpdateState(): Boolean

Whether this `SELECT` query already has a stored value option for performing locking reads.

having
Link copied to clipboard
fun having(op: () -> Op<Boolean>): T

Appends a `HAVING` clause with the specified op condition to this `SELECT` query.

isForUpdate
Link copied to clipboard
fun isForUpdate(): Boolean

Whether this `SELECT` query will perform a locking read.

prepareSQL
Link copied to clipboard
open fun prepareSQL(builder: QueryBuilder): String

Returns the string representation of an SQL query, generated by appending SQL expressions to a QueryBuilder.

open override fun prepareSQL(transaction: Transaction, prepared: Boolean = true): String

Returns the string representation of an SQL statement.

withDistinct
Link copied to clipboard
open fun withDistinct(value: Boolean = true): T

Modifies this query to retrieve only distinct results if value is set to `true`.

withDistinctOn
Link copied to clipboard
fun withDistinctOn(vararg columns: Column<*>): T

Specifies that the `SELECT` query should retrieve distinct results based on the given list of columns.