Code Editor & Querying

GluonDB's code editor lets you write and execute SQL queries across all your connected datasources. Switch between databases instantly or use our smart prefix syntax to target specific datasources inline.

Multiple Datasources

Each project can have multiple datasources connected — production databases, analytics warehouses, staging environments, and more. The code editor makes it easy to query any of them.

Selecting a Datasource

Option 1: Use the Datasource Selector

The editor toolbar includes a datasource dropdown. Select your target database, and all queries in the editor will execute against it.

This is the simplest approach when you're working with a single datasource at a time.

Option 2: Prefix Syntax (Smart Routing)

For more flexibility, use the datasource name as a prefix in your SQL:

sql
SELECT * FROM production.public.users LIMIT 10;

The format is:

text
datasource_name.schema.table

GluonDB automatically detects the prefix and routes the query to the correct datasource — even if a different one is selected in the dropdown.

Prefix Syntax Examples

Query from a specific datasource

sql
-- Query the "analytics" datasource SELECT DATE(created_at) as date, COUNT(*) as signups FROM analytics.public.users GROUP BY DATE(created_at) ORDER BY date DESC;

Join across the same datasource

sql
-- Both tables from "production" datasource SELECT u.name, o.total FROM production.public.users u JOIN production.public.orders o ON o.user_id = u.id WHERE o.created_at > NOW() - INTERVAL '30 days';

Compare data across datasources

Run separate queries against different datasources to compare data:

sql
-- First query: production SELECT COUNT(*) as count FROM production.public.orders; -- Second query: staging SELECT COUNT(*) as count FROM staging.public.orders;

How It Works

  1. Prefix Detection — GluonDB parses your SQL and looks for known datasource names as prefixes
  2. Smart Routing — If a prefix is found, the query is routed to that datasource
  3. Prefix Removal — The prefix is stripped before execution (your database sees public.users, not production.public.users)
  4. Fallback — If no prefix is detected, the query runs against the datasource selected in the dropdown

Datasource Names

Datasource names are case-insensitive. These all work the same:

sql
SELECT * FROM Production.public.users; SELECT * FROM production.public.users; SELECT * FROM PRODUCTION.public.users;

> Tip: Use lowercase for consistency and readability.

When to Use Each Method

MethodBest For
Dropdown selectorWorking with one datasource for an extended period
Prefix syntaxQuick queries across multiple datasources, comparing environments

Tips

  • Name datasources clearly — Use descriptive names like production, staging, analytics so your queries are self-documenting
  • Check the active datasource — The dropdown always shows which datasource will receive queries without prefixes
  • Use prefixes in shared queries — When sharing SQL with teammates, prefixes make it clear which database the query targets