Raw SQL
Raw SQL fields execute custom PostgreSQL queries to produce computed values directly from the database.
View all settings
| Setting | Description |
|---|---|
| Field Name | Text input, required. Unique identifier for the field. |
| Input Type | Dropdown, required. Choose Single, Array, Object, or Object Array. |
| Display Label | Text input. Human-readable label shown in forms. |
| Sort Order | Number input, defaults to 0. Position in field lists. |
| Icon | Icon picker. Visual identifier. |
| Raw SQL | Code editor, required. PostgreSQL query to execute. |
| Status | Toggle, defaults to true. Enable or disable the field. |
| Required | Checkbox. Make the field mandatory. |
| Description | Text area. Documents the field's purpose. |
Input Types
- Single — Returns a single scalar value
- Array — Returns an array of values
- Object — Returns a JSON object (single row)
- Object Array — Returns an array of JSON objects (multiple rows)
When to Use
Choose Raw SQL when:
- You need database-specific PostgreSQL functions
- Complex calculations not possible with Compute fields
- Window functions or advanced aggregations
- Subqueries and cross-collection joins
Settings
See Common Settings for shared options.
Not available: Default Value, Primary Key, Unique, Faker Type, Populate from Logged-In User, Use as Index, Form Visibility, DB Field Name
Raw SQL Editor (Basic Settings)
Code editor, required. Write PostgreSQL queries to compute the field value. The editor provides syntax highlighting for SQL.
SELECT * FROM users;
Advanced Settings
Only Description is available in Advanced Settings for this field type.
Example Expressions
-- Concatenate with formatting
CONCAT(first_name, ' ', last_name)
-- Date calculations
NOW() - created_at
-- Conditional logic
CASE WHEN status = 'active' THEN 1 ELSE 0 END
Use Cases
- Complex calculations not possible with Compute fields
- Database-specific PostgreSQL functions
- Advanced aggregations with window functions
- Subqueries and joins
Important Notes
- Raw SQL fields are read-only — no database column is created
- Use with caution — invalid SQL can cause query errors
Related
- Common Settings — Shared settings reference
- Compute — For simpler calculations