Skip to main content

Raw SQL

Raw SQL fields execute custom PostgreSQL queries to produce computed values directly from the database.

View all settings
SettingDescription
Field NameText input, required. Unique identifier for the field.
Input TypeDropdown, required. Choose Single, Array, Object, or Object Array.
Display LabelText input. Human-readable label shown in forms.
Sort OrderNumber input, defaults to 0. Position in field lists.
IconIcon picker. Visual identifier.
Raw SQLCode editor, required. PostgreSQL query to execute.
StatusToggle, defaults to true. Enable or disable the field.
RequiredCheckbox. Make the field mandatory.
DescriptionText 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