Get Sample Rows from Table
pg_sample_rowsRetrieve a sample of rows from a PostgreSQL table, applying optional filters, column selection, and ordering. Specify schema, limit, and output format as JSON or Markdown.
Instructions
Retrieve a sample of rows from a PostgreSQL table, with optional filtering and column selection.
Args:
table: Table name (required)
schema: Schema name (default: public)
limit: Number of rows to return, 1-500 (default: 10)
where_clause: Optional WHERE clause (without the WHERE keyword), e.g. "status = 'active'"
columns: Comma-separated column names to select (optional, default: all columns)
order_by: ORDER BY clause (without ORDER BY), e.g. "created_at DESC"
response_format: Output format
Returns: JSON: { table, schema, row_count, columns: string[], rows: object[] } Markdown: formatted table of results
Security: table and schema names are validated against actual database objects before use.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| table | Yes | Table name to sample | |
| schema | No | PostgreSQL schema name (default: public) | public |
| limit | No | Number of rows (default: 10, max: 500) | |
| where_clause | No | Optional WHERE condition without 'WHERE', e.g. "age > 18 AND active = true" | |
| columns | No | Comma-separated column names to return (default: all, e.g. 'id, name, email') | |
| order_by | No | ORDER BY clause without 'ORDER BY', e.g. 'created_at DESC' | |
| response_format | No | Output format: 'markdown' for human-readable, 'json' for machine-readable | markdown |