

<a id="confluent-flink-query"></a>

# confluent flink query

## Description

Run a bounded Flink SQL query, wait for completion, and print the results.

Provide the SQL statement with `--sql`, or use `--file` to read the statement from a file.

Unlike creating a statement, which returns a handle as soon as it is submitted (or optionally waits until it starts or fails when using `--wait`) and never returns the rows, this command always waits for every result page and prints the complete result set, exiting with a non-zero if the statement fails. Use this command for scripts and one-time queries against a bounded, point-in-time result set.

With `-o json` or `-o yaml`, output defaults to an envelope that includes the column schema and rows. Rows alone don’t include type information. Use `--raw` to return a bare array of row objects.

```none
confluent flink query [flags]
```

## Flags

```none
    --sql string               Flink SQL statement. Alternatively, use "--file" or "-f".
-f, --file string              Path to a file that contains the Flink SQL statement. Alternatively, use --sql.
    --compute-pool string      Flink compute pool ID.
    --service-account string   Service account ID.
    --database string          The database which will be used as the default database. When using Kafka, this is the cluster ID.
    --property strings         Properties for the Flink statement in key=value format.
    --timeout duration         Maximum time to wait for the query to finish. (default 10m0s)
    --max-rows int             Maximum number of rows to fetch. Use 0 to fetch every row. This limit is client-side only; the query still produces rows after the limit is reached.
    --raw                      Return rows as a bare array without an envelope. Requires "-o json" or "-o yaml".
    --environment string       Environment ID.
    --context string           CLI context name.
-o, --output string            Specify the output format as "human", "json", or "yaml". (default "human")
    --cloud string             Specify the cloud provider as "aws", "azure", or "gcp".
    --region string            Cloud region for Flink (use "confluent flink region list" to see all).
```

## Global Flags

```none
-h, --help            Show help for this command.
    --unsafe-trace    Equivalent to -vvvv, but also log HTTP requests and responses which might contain plaintext secrets.
-v, --verbose count   Increase verbosity (-v for warn, -vv for info, -vvv for debug, -vvvv for trace).
```

## Examples

Run a bounded query in the current compute pool and print the rows as a table.

```none
confluent flink query --sql "SELECT * FROM orders LIMIT 10;"
```

Run a bounded query against Kafka cluster “my-cluster” and return JSON for a script.

```none
confluent flink query --sql "SELECT status, COUNT(*) FROM orders GROUP BY status;" --compute-pool lfcp-123456 --database my-cluster --output json
```

Return a bare JSON array of rows, without an envelope, for a script that only wants the data.

```none
confluent flink query --sql "SELECT * FROM orders LIMIT 10;" --output json --raw
```

## See Also

* [confluent flink](index.md#confluent-flink) - Manage Apache Flink.
