# Result Set Packets

MariaDB Server sends the following packets as part of a result set.

A result set consists of different packets:

* [Result set metadata](#ResultSet-metadata).
  * 1 [column count packet](#column-count-packet).
* If not (`MARIADB_CLIENT_CACHE_METADATA` capability set) `OR` (send metadata == 1):
  * For each column (for instance, `column_count` times):
    * [Column Definition packet](#column-definition-packet).
* If not (`CLIENT_DEPRECATE_EOF` capability set) [EOF\_Packet](/docs/server/reference/clientserver-protocol/4-server-response-packets/eof_packet.md).
* n [result set row](/docs/server/reference/clientserver-protocol/4-server-response-packets/resultset-row.md).
* If error:
  * [ERR\_Packet](/docs/server/reference/clientserver-protocol/4-server-response-packets/err_packet.md).
* Else:
  * If `CLIENT_DEPRECATE_EOF` capability:
    * [OK\_Packet](/docs/server/reference/clientserver-protocol/4-server-response-packets/ok_packet.md) with a `0xFE` header.
  * Else [EOF\_Packet](/docs/server/reference/clientserver-protocol/4-server-response-packets/eof_packet.md).

{% hint style="warning" %}
It is unsafe to assume that any packet with a `0xFE` header is an [OK packet (OK\_Packet)](/docs/server/reference/clientserver-protocol/4-server-response-packets/ok_packet.md) or an [EOF packet (EOF\_Packet)](/docs/server/reference/clientserver-protocol/4-server-response-packets/eof_packet.md), because [result set row packets (ResultsetRow)](/docs/server/reference/clientserver-protocol/4-server-response-packets/resultset-row.md) can also begin with `0xFE` when using the text protocol with a field length greater than `0xFFFFFF`.\
To safely confirm that a packet with a `0xFE` header is an [OK packet (OK\_Packet)](/docs/server/reference/clientserver-protocol/4-server-response-packets/ok_packet.md) or an [EOF packet (EOF\_Packet)](/docs/server/reference/clientserver-protocol/4-server-response-packets/eof_packet.md), you must also check that the packet length is less than `0xFFFFFF`.
{% endhint %}

## Column Count Packet

The column count packet describes the number of columns in the result set. It uses the following format:

* [int\<lenenc>](/docs/server/reference/clientserver-protocol/protocol-data-types.md#length-encoded-integers) column count.
* If (`MARIADB_CLIENT_CACHE_METADATA` capability set):
  * int<1> metadata follows (0 / 1).

The metadata indicator byte is only present if both the client and the server declare the `MARIADB_CLIENT_CACHE_METADATA` capability.

If the metadata byte is set to `1`, the normal metadata follows the column definitions. If the metadata byte is set to `0`, the Column Count Packet is immediately followed by the second [EOF packet (EOF\_Packet)](/docs/server/reference/clientserver-protocol/4-server-response-packets/eof_packet.md) or the result set rows if the `CLIENT_DEPRECATE_EOF` capability is set.

## Column Definition Packet

A column definition packet describes a column in the result set. It uses the following format:

* [string\<lenenc>](/docs/server/reference/clientserver-protocol/protocol-data-types.md#length-encoded-strings) catalog (always 'def').
* [string\<lenenc>](/docs/server/reference/clientserver-protocol/protocol-data-types.md#length-encoded-strings) schema.
* [string\<lenenc>](/docs/server/reference/clientserver-protocol/protocol-data-types.md#length-encoded-strings) table alias.
* [string\<lenenc>](/docs/server/reference/clientserver-protocol/protocol-data-types.md#length-encoded-strings) table.
* [string\<lenenc>](/docs/server/reference/clientserver-protocol/protocol-data-types.md#length-encoded-strings) column alias.
* [string\<lenenc>](/docs/server/reference/clientserver-protocol/protocol-data-types.md#length-encoded-strings) column.
* If extended type supported (see `MARIADB_CLIENT_EXTENDED_METADATA` ):
  * [string\<lenenc>](/docs/server/reference/clientserver-protocol/protocol-data-types.md#length-encoded-strings) [extended metadata](#extended-metadata).
* [int\<lenenc>](/docs/server/reference/clientserver-protocol/protocol-data-types.md#length-encoded-integers) length of fixed fields (=0xC).
* [int<2>](/docs/server/reference/clientserver-protocol/protocol-data-types.md#fixed-length-integers) character set number.
* [int<4>](/docs/server/reference/clientserver-protocol/protocol-data-types.md#fixed-length-integers) max. column size.
* [int<1>](/docs/server/reference/clientserver-protocol/protocol-data-types.md#fixed-length-integers) [Field types](#field-types).
* [int<2>](/docs/server/reference/clientserver-protocol/protocol-data-types.md#fixed-length-integers) [Field detail flag](#field-details-flag).
* [int<1>](/docs/server/reference/clientserver-protocol/protocol-data-types.md#fixed-length-integers) decimals.
* [int<2>](/docs/server/reference/clientserver-protocol/protocol-data-types.md#fixed-length-integers) - unused -

## Field Types

The column type field in the column definition packet describes the base type of the column. It also indicates how the values are encoded for `COM_STMT_EXECUTE` parameters and binary result set rows.

| Value | Protocol Column Type      | Encoding                                                                                                                                                                    |
| ----- | ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 0     | MYSQL\_TYPE\_DECIMAL      | [byte encoding](/docs/server/reference/clientserver-protocol/protocol-data-types.md#length-encoded-bytes)                                                                   |
| 1     | MYSQL\_TYPE\_TINY         | [TINYINT Binary encoding](/docs/server/reference/clientserver-protocol/4-server-response-packets/resultset-row.md#tinyint-binary-encoding)                                  |
| 2     | MYSQL\_TYPE\_SHORT        | [SMALLINT Binary encoding](/docs/server/reference/clientserver-protocol/4-server-response-packets/resultset-row.md#smallint-binary-encoding)                                |
| 3     | MYSQL\_TYPE\_LONG         | [INTEGER Binary encoding](/docs/server/reference/clientserver-protocol/4-server-response-packets/resultset-row.md#integer-binary-encoding)                                  |
| 4     | MYSQL\_TYPE\_FLOAT        | [FLOAT Binary encoding](/docs/server/reference/clientserver-protocol/4-server-response-packets/resultset-row.md#float-binary-encoding)                                      |
| 5     | MYSQL\_TYPE\_DOUBLE       | [DOUBLE Binary encoding](/docs/server/reference/clientserver-protocol/4-server-response-packets/resultset-row.md#double-binary-encoding)                                    |
| 6     | MYSQL\_TYPE\_NULL         | Not used, being NULL is indicated by the NULL-bitmap in the result                                                                                                          |
| 7     | MYSQL\_TYPE\_TIMESTAMP    | [TIMESTAMP Binary encoding](/docs/server/reference/clientserver-protocol/4-server-response-packets/resultset-row.md#timestamp-binary-encoding)                              |
| 8     | MYSQL\_TYPE\_LONGLONG     | [BIGINT Binary encoding](/docs/server/reference/clientserver-protocol/4-server-response-packets/resultset-row.md#bigint-binary-encoding)                                    |
| 9     | MYSQL\_TYPE\_INT24        | [INTEGER Binary encoding](/docs/server/reference/clientserver-protocol/4-server-response-packets/resultset-row.md#integer-binary-encoding)                                  |
| 10    | MYSQL\_TYPE\_DATE         | [TIMESTAMP Binary encoding](/docs/server/reference/clientserver-protocol/4-server-response-packets/resultset-row.md#timestamp-binary-encoding)                              |
| 11    | MYSQL\_TYPE\_TIME         | [TIME Binary encoding](/docs/server/reference/clientserver-protocol/4-server-response-packets/resultset-row.md#time-binary-encoding)                                        |
| 12    | MYSQL\_TYPE\_DATETIME     | [TIMESTAMP Binary encoding](/docs/server/reference/clientserver-protocol/4-server-response-packets/resultset-row.md#timestamp-binary-encoding)                              |
| 13    | MYSQL\_TYPE\_YEAR         | [SMALLINT Binary encoding](/docs/server/reference/clientserver-protocol/4-server-response-packets/resultset-row.md#smallint-binary-encoding)                                |
| 14    | MYSQL\_TYPE\_NEWDATE      | [byte encoding](/docs/server/reference/clientserver-protocol/protocol-data-types.md#length-encoded-bytes)                                                                   |
| 15    | MYSQL\_TYPE\_VARCHAR      | [byte encoding](/docs/server/reference/clientserver-protocol/protocol-data-types.md#length-encoded-bytes)                                                                   |
| 16    | MYSQL\_TYPE\_BIT          | [byte encoding](/docs/server/reference/clientserver-protocol/protocol-data-types.md#length-encoded-bytes)                                                                   |
| 17    | MYSQL\_TYPE\_TIMESTAMP2   | Used only in the replication protocol                                                                                                                                       |
| 18    | MYSQL\_TYPE\_DATETIME2    | Used only in the replication protocol                                                                                                                                       |
| 19    | MYSQL\_TYPE\_TIME2        | Used only in the replication protocol                                                                                                                                       |
| 245   | MYSQL\_TYPE\_JSON         | [byte encoding](/docs/server/reference/clientserver-protocol/protocol-data-types.md#length-encoded-bytes) (only used with MySQL, MariaDB uses MYSQL\_TYPE\_STRING for JSON) |
| 246   | MYSQL\_TYPE\_NEWDECIMAL   | [byte encoding](/docs/server/reference/clientserver-protocol/protocol-data-types.md#length-encoded-bytes)                                                                   |
| 247   | MYSQL\_TYPE\_ENUM         | [byte encoding](/docs/server/reference/clientserver-protocol/protocol-data-types.md#length-encoded-bytes)                                                                   |
| 248   | MYSQL\_TYPE\_SET          | [byte encoding](/docs/server/reference/clientserver-protocol/protocol-data-types.md#length-encoded-bytes)                                                                   |
| 249   | MYSQL\_TYPE\_TINY\_BLOB   | [byte encoding](/docs/server/reference/clientserver-protocol/protocol-data-types.md#length-encoded-bytes)                                                                   |
| 250   | MYSQL\_TYPE\_MEDIUM\_BLOB | [byte encoding](/docs/server/reference/clientserver-protocol/protocol-data-types.md#length-encoded-bytes)                                                                   |
| 251   | MYSQL\_TYPE\_LONG\_BLOB   | [byte encoding](/docs/server/reference/clientserver-protocol/protocol-data-types.md#length-encoded-bytes)                                                                   |
| 252   | MYSQL\_TYPE\_BLOB         | [byte encoding](/docs/server/reference/clientserver-protocol/protocol-data-types.md#length-encoded-bytes)                                                                   |
| 253   | MYSQL\_TYPE\_VAR\_STRING  | [byte encoding](/docs/server/reference/clientserver-protocol/protocol-data-types.md#length-encoded-bytes)                                                                   |
| 254   | MYSQL\_TYPE\_STRING       | [byte encoding](/docs/server/reference/clientserver-protocol/protocol-data-types.md#length-encoded-bytes)                                                                   |
| 255   | MYSQL\_TYPE\_GEOMETRY     | [byte encoding](/docs/server/reference/clientserver-protocol/protocol-data-types.md#length-encoded-bytes)                                                                   |

## Field Details Flag

The column details flag describes certain column attributes and whether certain column options are set.

It is a bitmask with the following flags:

| Flag Value | Flag Name                | Flag Description                          |
| ---------- | ------------------------ | ----------------------------------------- |
| 1          | NOT\_NULL                | field cannot be null                      |
| 2          | PRIMARY\_KEY             | field is a primary key                    |
| 4          | UNIQUE\_KEY              | field is unique                           |
| 8          | MULTIPLE\_KEY            | field is in a multiple key                |
| 16         | BLOB                     | is this field a Blob                      |
| 32         | UNSIGNED                 | is this field unsigned                    |
| 64         | ZEROFILL\_FLAG           | is this field a zerofill                  |
| 128        | BINARY\_COLLATION        | whether this field has a binary collation |
| 256        | ENUM                     | Field is an enumeration                   |
| 512        | AUTO\_INCREMENT          | field auto-increment                      |
| 1024       | TIMESTAMP                | field is a timestamp value                |
| 2048       | SET                      | field is a SET                            |
| 4096       | NO\_DEFAULT\_VALUE\_FLAG | field doesn't have default value          |
| 8192       | ON\_UPDATE\_NOW\_FLAG    | field is set to NOW on UPDATE             |
| 32768      | NUM\_FLAG                | field is num                              |

{% hint style="info" %}
The `BLOB` flag cannot be used to determine if a column has binary data, because [BINARY](/docs/server/reference/data-types/string-data-types/binary.md) and [VARBINARY](/docs/server/reference/data-types/string-data-types/varbinary.md) columns are treated as strings, instead of blobs.

The `BINARY_COLLATION` flag can be used to determine if a string column has binary data.
{% endhint %}

## Extended Metadata

This extended column type information can be used to find out more specific details about the column type:

* For a [POINT](/docs/server/reference/sql-statements/geometry-constructors/geometry-constructors/point.md) column, the column type field is `MYSQL_TYPE_GEOMETRY`, but the extended type indicates 'point'.
* For a [JSON](/docs/server/reference/data-types/string-data-types/json.md) column, the column type field is `MYSQL_TYPE_STRING`, but the extended type indicates 'json'.
* While string has data:
  * [int<1>](/docs/server/reference/clientserver-protocol/protocol-data-types.md#fixed-length-integers) data type: 0x00:type, 0x01: format.
  * [string\<lenenc>](/docs/server/reference/clientserver-protocol/protocol-data-types.md#length-encoded-strings) value.

<sub>*This page is licensed: CC BY-SA / Gnu FDL*</sub>

{% @marketo/form formId="4316" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mariadb.com/docs/server/reference/clientserver-protocol/4-server-response-packets/result-set-packets.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
