Endpoints
Table Operations
Fetch paginated table data with sorting and column metadata
POST
Overview
Retrieves paginated data from PostgreSQL tables and views with column metadata, sorting support, and primary key detection. Includes safety features like identifier validation and configurable page sizes.Request
PostgreSQL server hostname or IP address
PostgreSQL server port number
PostgreSQL username for authentication
PostgreSQL user password
Target database name
Schema name containing the table
Table or view name to fetch data from
Page number (1-indexed)Default:
1Number of rows per pageDefault:
50Range: 1-1000Column name to sort by (must exist in table)
Sort direction:
asc or descDefault: ascSSL connection mode (
disable, require, prefer)Response
Array of ColumnInfo objects describing table columns
Column name
PostgreSQL data type (e.g.,
integer, varchar, timestamp)Whether the column accepts NULL values
Default value expression (may be undefined)
Whether the column is part of the primary key
Array of row objects (key-value pairs)
Total number of rows in the table (for pagination)
Current page number (1-indexed)
Number of rows per page
Examples
Fetch First Page
Sorted by Column (Descending)
Specific Page
Error: Missing Required Fields
Error: Table Not Found
Error: Invalid Identifier
Column Metadata Query
The endpoint fetches column information including primary keys: From/app/api/table-data/route.ts:47-64:
Identifier Validation
To prevent SQL injection, table and column names are validated: From/app/api/table-data/route.ts:6-13:
Pagination Implementation
From/app/api/table-data/route.ts:102-108:
Pagination Constraints
- Minimum page size: 1 row
- Maximum page size: 1000 rows
- Default page size: 50 rows
- Minimum page number: 1
Sorting
Sort columns are validated against actual table columns: From/app/api/table-data/route.ts:88-94:
Invalid sort columns are silently ignored (no ORDER BY clause added). Only columns returned by the metadata query can be used for sorting.
TypeScript Interfaces
From/types/database.ts:21-27:
/types/database.ts:29-35:
Performance Considerations
Row Count Query
The endpoint executesCOUNT(*) for every request:
- Caching total counts
- Using estimated counts from
pg_class.reltuples - Implementing cursor-based pagination
Query Execution Order
- Column metadata (with primary key info)
- Total row count (COUNT query)
- Data fetch (LIMIT/OFFSET query)
Use Cases
- Table Data Viewer: Browse table contents with pagination
- Data Export: Fetch data in chunks for export
- Query Builder: Display sample data for tables
- Data Editor: Load rows for editing with primary key detection
Limitations
- No filtering/search support (use query execution endpoint)
- No column selection (always fetches all columns)
- Sort limited to single column
- Maximum 1000 rows per page