---
title: "Executing queries"
description: "Run queries built with the query DSL using query(), or raw SurrealQL with bound parameters using queryRaw(), and read the per-statement RPCQueryResult values in the Swift SDK."
canonical_url: "https://surrealdb.com/docs/reference/swift/concepts/executing-queries"
sdk: "Swift SDK"
surrealdb_version: "4.x"
last_modified: "2026-11-24T05:29:47Z"
---

> Full SurrealDB documentation index: https://surrealdb.com/docs/llms.txt

# Executing queries

Run queries built with the query DSL using query(), or raw SurrealQL with bound parameters using queryRaw(), and read the per-statement RPCQueryResult values in the Swift SDK.

The methods below run queries against the database. `query()` runs a query built with the [query DSL](/docs/reference/swift/concepts/query-dsl.md), and `queryRaw()` runs a raw SurrealQL string with bound parameters. To read and write records with a method for each operation, see [data manipulation](/docs/reference/swift/concepts/data-manipulation.md).

<table>
	<thead>
		<tr>
			<th scope="col">Method</th>
			<th scope="col">Description</th>
		</tr>
	</thead>
	<tbody>
		<tr>
			<td scope="row" data-label="Method"><a href="#query"> <code> client.query(query) </code></a></td>
			<td scope="row" data-label="Description">Runs a query built with the query DSL or macros</td>
		</tr>
		<tr>
			<td scope="row" data-label="Method"><a href="#query-raw"> <code> client.queryRaw(sql, bindings) </code></a></td>
			<td scope="row" data-label="Description">Runs a raw SurrealQL query with bound parameters</td>
		</tr>
	</tbody>
</table>

## `.query()` {#query}

Runs a query built with the query DSL, either a query macro such as `#select` or a `SurrealDSL` builder call.

```swift title="Method Syntax"
try await client.query(query)
```

### Arguments

| Argument | Description |
| --- | --- |
| `query` (required) | A query produced by a query macro or a `SurrealDSL` builder call. |

### Example usage

```swift
// Using a query macro
let selectQuery = #select(Person.self, where: Person.Fields.age > 18, limit: 10)
let people = try await client.query(selectQuery)

// Using the SurrealDSL builder
let query = SurrealDSL.select(Person.self, where: Person.Fields.age >= 21, limit: 50)
let result = try await client.query(query)
```

## `.queryRaw()` {#query-raw}

Executes a raw SurrealQL string with bound parameters and returns one `RPCQueryResult` per statement. Use it for arbitrary SurrealQL that the DSL does not model.

```swift title="Method Syntax"
try await client.queryRaw(sql, bindings: bindings)
```

### Arguments

| Argument | Description |
| --- | --- |
| `sql` (required) | The raw SurrealQL query to execute. |
| `bindings` (optional) | A dictionary of [`SurrealValue`](/docs/reference/swift/concepts/value-types.md#surrealvalue) parameters referenced in the query. |

### Example usage

```swift
let results: [RPCQueryResult] = try await client.queryRaw(
    "SELECT * FROM person WHERE age > $minAge LIMIT $limit;",
    bindings: [
        "minAge": .int(18),
        "limit": .int(50)
    ]
)

for row in results {
    if row.status == .ok {
        print(row.result)
    }
}
```
