> ## Documentation Index
> Fetch the complete documentation index at: https://docs.retab.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Query Table

Read a filtered, sorted, or windowed preview of a CSV table. This route is
read-only; table writes replace the whole CSV. Pass filter rules, sort rules,
and a window (`offset`/`limit`) to shape the returned rows.

<RequestExample>
  ```python Python theme={null}
  from retab import Retab
  from retab.types.tables import (
      WorkflowTableFilterOperator,
      WorkflowTableFilterRule,
      WorkflowTableSortRule,
  )

  client = Retab()

  rows = client.tables.query(
      table_id="workflow_table_123",
      filters=[
          WorkflowTableFilterRule(
              column="countrycode",
              operator=WorkflowTableFilterOperator.EQ,
              value="FR",
          ),
      ],
      sort=[WorkflowTableSortRule(column="countrycode")],
      limit=100,
  )
  print(rows)
  ```

  ```typescript TypeScript theme={null}
  import { Retab } from "@retab/node";

  const client = new Retab({ apiKey: process.env.RETAB_API_KEY });

  const rows = await client.tables.query("workflow_table_123", [
    { column: "countrycode", operator: "eq", value: "FR" },
  ]);
  console.log(rows);
  ```

  ```go Go theme={null}
  package main

  import (
  	"context"
  	"fmt"
  	"log"

  	retab "github.com/retab-dev/retab/clients/go"
  )

  func main() {
  	ctx := context.Background()

  	client, err := retab.NewClient("")
  	if err != nil {
  		log.Fatal(err)
  	}

  	rows, err := client.Tables.Query(ctx, "workflow_table_123", &retab.TablesQueryParams{
  		Body: map[string]any{
  			"filters": []map[string]any{
  				{"column": "countrycode", "operator": "eq", "value": "FR"},
  			},
  			"sort":  []map[string]any{{"column": "countrycode", "direction": "asc"}},
  			"limit": 100,
  		},
  	})
  	if err != nil {
  		log.Fatal(err)
  	}
  	fmt.Println(*rows)
  }
  ```

  ```ruby Ruby theme={null}
  require 'retab'

  client = Retab::Client.new(api_key: ENV['RETAB_API_KEY'])

  rows = client.tables.query(
    table_id: 'workflow_table_123',
    filters: [
      { 'column' => 'countrycode', 'operator' => 'eq', 'value' => 'FR' },
    ],
    sort: [{ 'column' => 'countrycode', 'direction' => 'asc' }],
    limit: 100,
  )
  puts rows
  ```

  ```rust Rust theme={null}
  use retab::Retab;
  use retab::enums::WorkflowTableFilterOperator;
  use retab::models::{QueryWorkflowTableRequest, WorkflowTableFilterRule, WorkflowTableSortRule};
  use retab::resources::tables::QueryParams;

  #[tokio::main]
  async fn main() -> Result<(), Box<dyn std::error::Error>> {
      let client = Retab::new(std::env::var("RETAB_API_KEY")?);

      let rows = client
          .tables()
          .query(
              "workflow_table_123",
              QueryParams {
                  body: Some(QueryWorkflowTableRequest {
                      filters: Some(vec![WorkflowTableFilterRule {
                          value: Some(serde_json::json!("FR")),
                          ..WorkflowTableFilterRule::new("countrycode", WorkflowTableFilterOperator::Eq)
                      }]),
                      sort: Some(vec![WorkflowTableSortRule::new("countrycode")]),
                      limit: Some(100),
                      ..Default::default()
                  }),
              },
          )
          .await?;
      println!("{:?}", rows);
      Ok(())
  }
  ```

  ```php PHP theme={null}
  <?php
  require 'vendor/autoload.php';

  use Retab\Client;
  use Retab\Resource\WorkflowTableFilterOperator;
  use Retab\Resource\WorkflowTableFilterRule;
  use Retab\Resource\WorkflowTableSortRule;

  $client = new Client(apiKey: getenv('RETAB_API_KEY'));

  $result = $client->tables()->query(
      tableId: 'workflow_table_123',
      filters: [
          new WorkflowTableFilterRule(
              column: 'countrycode',
              operator: WorkflowTableFilterOperator::Eq,
              value: 'FR',
          ),
      ],
      sort: [new WorkflowTableSortRule(column: 'countrycode')],
      limit: 100,
  );
  print_r($result);
  ```

  ```csharp C# theme={null}
  using Retab;
  using RetabClient = Retab.Retab;

  var apiKey = Environment.GetEnvironmentVariable("RETAB_API_KEY")!;
  var client = new RetabClient(apiKey);

  var result = await client.Tables.QueryAsync("workflow_table_123", new TablesQueryOptions());
  Console.WriteLine(result);
  ```

  ```java Java theme={null}
  import com.retab.RetabClient;

  public final class Example {
    public static void main(String[] args) throws Exception {
      RetabClient client = new RetabClient(System.getenv("RETAB_API_KEY"));

      var result = client.tables().query("workflow_table_123");
      System.out.println(result);
    }
  }
  ```

  ```bash cURL theme={null}
  curl -X POST https://api.retab.com/v1/tables/workflow_table_123/query \
    -H "Authorization: Bearer $RETAB_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{"filters":[{"column":"countrycode","operator":"eq","value":"FR"}],"sort":[{"column":"countrycode","direction":"asc"}],"limit":100}'
  ```
</RequestExample>


## OpenAPI

````yaml POST /v1/tables/{table_id}/query
openapi: 3.1.0
info:
  title: FastAPI
  version: 0.1.0
servers:
  - url: https://api.retab.com
security: []
paths:
  /v1/tables/{table_id}/query:
    post:
      tags:
        - Tables
      summary: Table.Query
      operationId: query_table
      parameters:
        - in: path
          name: table_id
          required: true
          schema:
            type: string
            title: Table Id
      requestBody:
        content:
          application/json:
            schema:
              anyOf:
                - $ref: '#/components/schemas/QueryWorkflowTableRequest'
                - type: 'null'
              title: Payload
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WorkflowTableRowsResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - HTTPBearer: []
components:
  schemas:
    QueryWorkflowTableRequest:
      properties:
        filters:
          items:
            $ref: '#/components/schemas/WorkflowTableFilterRule'
          type: array
          title: Filters
          default: []
        search:
          anyOf:
            - $ref: '#/components/schemas/WorkflowTableSearchRequest'
            - type: 'null'
        case_sensitive:
          type: boolean
          title: Case Sensitive
          default: false
        select:
          items:
            type: string
          type: array
          title: Select
          default: []
        distinct:
          anyOf:
            - $ref: '#/components/schemas/WorkflowTableDistinctRequest'
            - type: 'null'
        group_by:
          items:
            type: string
          type: array
          title: Group By
          default: []
        aggregations:
          items:
            $ref: '#/components/schemas/WorkflowTableAggregationRequest'
          type: array
          title: Aggregations
          default: []
        sort:
          items:
            $ref: '#/components/schemas/WorkflowTableSortRule'
          type: array
          title: Sort
          default: []
        sample:
          anyOf:
            - $ref: '#/components/schemas/WorkflowTableSampleRequest'
            - type: 'null'
        tail:
          anyOf:
            - $ref: '#/components/schemas/WorkflowTableTailRequest'
            - type: 'null'
        count_only:
          type: boolean
          title: Count Only
          default: false
        include_explain:
          type: boolean
          title: Include Explain
          default: false
        sort_column:
          anyOf:
            - type: string
            - type: 'null'
          title: Sort Column
        sort_direction:
          anyOf:
            - $ref: '#/components/schemas/WorkflowTableSortDirection'
            - type: 'null'
        viewer_mode:
          anyOf:
            - type: string
              const: windowed
            - type: 'null'
          title: Viewer Mode
        offset:
          type: integer
          minimum: 0
          title: Offset
          default: 0
        limit:
          anyOf:
            - type: integer
              maximum: 500
              minimum: 1
            - type: 'null'
          title: Limit
      type: object
      title: QueryWorkflowTableRequest
    WorkflowTableRowsResponse:
      properties:
        table_id:
          type: string
          title: Table Id
        columns:
          items:
            $ref: '#/components/schemas/WorkflowTableColumn'
          type: array
          title: Columns
          default: []
        rows:
          items:
            $ref: '#/components/schemas/WorkflowTableRow'
          type: array
          title: Rows
          default: []
        row_count:
          type: integer
          title: Row Count
        filtered_row_count:
          anyOf:
            - type: integer
            - type: 'null'
          title: Filtered Row Count
        offset:
          type: integer
          title: Offset
          default: 0
        limit:
          anyOf:
            - type: integer
            - type: 'null'
          title: Limit
        has_more:
          type: boolean
          title: Has More
          default: false
        next_cursor:
          anyOf:
            - type: string
            - type: 'null'
          title: Next Cursor
        previous_cursor:
          anyOf:
            - type: string
            - type: 'null'
          title: Previous Cursor
        explain:
          anyOf:
            - $ref: '#/components/schemas/WorkflowTableExplain'
            - type: 'null'
      type: object
      required:
        - row_count
        - table_id
      title: WorkflowTableRowsResponse
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
          default: []
      type: object
      title: HTTPValidationError
    WorkflowTableFilterRule:
      properties:
        column:
          type: string
          title: Column
        operator:
          $ref: '#/components/schemas/WorkflowTableFilterOperator'
        value:
          title: Value
          default: null
      type: object
      required:
        - column
        - operator
      title: WorkflowTableFilterRule
    WorkflowTableSearchRequest:
      properties:
        query:
          type: string
          title: Query
        columns:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Columns
      type: object
      required:
        - query
      title: WorkflowTableSearchRequest
    WorkflowTableDistinctRequest:
      properties:
        column:
          type: string
          title: Column
      type: object
      required:
        - column
      title: WorkflowTableDistinctRequest
    WorkflowTableAggregationRequest:
      properties:
        function:
          $ref: '#/components/schemas/WorkflowTableAggregationFunction'
        column:
          anyOf:
            - type: string
            - type: 'null'
          title: Column
        alias:
          anyOf:
            - type: string
            - type: 'null'
          title: Alias
      type: object
      required:
        - function
      title: WorkflowTableAggregationRequest
    WorkflowTableSortRule:
      properties:
        column:
          type: string
          title: Column
        direction:
          $ref: '#/components/schemas/WorkflowTableSortDirection'
          default: asc
      type: object
      required:
        - column
      title: WorkflowTableSortRule
    WorkflowTableSampleRequest:
      properties:
        size:
          type: integer
          maximum: 500
          minimum: 1
          title: Size
      type: object
      required:
        - size
      title: WorkflowTableSampleRequest
    WorkflowTableTailRequest:
      properties:
        size:
          type: integer
          maximum: 500
          minimum: 1
          title: Size
      type: object
      required:
        - size
      title: WorkflowTableTailRequest
    WorkflowTableSortDirection:
      type: string
      enum:
        - asc
        - desc
      title: WorkflowTableSortDirection
    WorkflowTableColumn:
      properties:
        name:
          type: string
          title: Name
        json_schema:
          additionalProperties: true
          type: object
          title: Json Schema
          default: {}
        sample_values:
          items:
            type: string
          type: array
          title: Sample Values
          default: []
        required:
          type: boolean
          title: Required
          default: false
        unique:
          type: boolean
          title: Unique
          default: false
      type: object
      required:
        - name
      title: WorkflowTableColumn
    WorkflowTableRow:
      properties:
        id:
          type: string
          title: Id
        data:
          additionalProperties: true
          type: object
          title: Data
          default: {}
        position:
          type: integer
          title: Position
      type: object
      required:
        - id
        - position
      title: WorkflowTableRow
    WorkflowTableExplain:
      properties:
        table_id:
          type: string
          title: Table Id
        snapshot_file_id:
          type: string
          title: Snapshot File Id
          default: ''
        selected_columns:
          items:
            type: string
          type: array
          title: Selected Columns
          default: []
        filters:
          items:
            $ref: '#/components/schemas/WorkflowTableFilterRule'
          type: array
          title: Filters
          default: []
        search:
          anyOf:
            - $ref: '#/components/schemas/WorkflowTableSearchRequest'
            - type: 'null'
        sort:
          items:
            $ref: '#/components/schemas/WorkflowTableSortRule'
          type: array
          title: Sort
          default: []
        offset:
          type: integer
          title: Offset
          default: 0
        limit:
          anyOf:
            - type: integer
            - type: 'null'
          title: Limit
        distinct:
          anyOf:
            - $ref: '#/components/schemas/WorkflowTableDistinctRequest'
            - type: 'null'
        group_by:
          items:
            type: string
          type: array
          title: Group By
          default: []
        aggregations:
          items:
            $ref: '#/components/schemas/WorkflowTableAggregationRequest'
          type: array
          title: Aggregations
          default: []
      type: object
      required:
        - table_id
      title: WorkflowTableExplain
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
          default: null
        ctx:
          type: object
          title: Context
          default: {}
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
    WorkflowTableFilterOperator:
      type: string
      enum:
        - eq
        - ne
        - gt
        - gte
        - lt
        - lte
        - contains
        - not_contains
        - starts_with
        - ends_with
        - in
        - not_in
        - between
        - is_empty
        - is_not_empty
        - is_null
        - is_not_null
      title: WorkflowTableFilterOperator
    WorkflowTableAggregationFunction:
      type: string
      enum:
        - count
        - count_distinct
        - min
        - max
        - sum
        - avg
      title: WorkflowTableAggregationFunction
  securitySchemes:
    HTTPBearer:
      type: http
      scheme: bearer

````