SQL Basics
rawquery uses DuckDB SQL - standard SQL with some nice extras.
Table Naming
Tables are namespaced by connection name:
sql
-- Format: connection_name.table_name-- The schema is the name YOU gave the connection
SELECT * FROM my_stripe.customers;SELECT * FROM prod_db.users;SELECT * FROM crm.contacts;SELECT * FROM sf.Account;SELECT * FROM shop.orders;-- Format: connection_name.table_name-- The schema is the name YOU gave the connection
SELECT * FROM my_stripe.customers;SELECT * FROM prod_db.users;SELECT * FROM crm.contacts;SELECT * FROM sf.Account;SELECT * FROM shop.orders;Basic Queries
SELECT
sql
-- All columnsSELECT * FROM my_stripe.customers LIMIT 10;
-- Specific columnsSELECT id, email, name FROM my_stripe.customers;
-- With aliasSELECT email AS customer_email, created AS signup_dateFROM my_stripe.customers;-- All columnsSELECT * FROM my_stripe.customers LIMIT 10;
-- Specific columnsSELECT id, email, name FROM my_stripe.customers;
-- With aliasSELECT email AS customer_email, created AS signup_dateFROM my_stripe.customers;WHERE
sql
-- EqualitySELECT * FROM my_stripe.charges WHERE status = 'succeeded';
-- ComparisonSELECT * FROM my_stripe.charges WHERE amount > 10000;
-- Multiple conditionsSELECT * FROM my_stripe.chargesWHERE status = 'succeeded' AND amount > 10000 AND created > '2024-01-01';
-- INSELECT * FROM my_stripe.customersWHERE country IN ('US', 'CA', 'UK');
-- LIKESELECT * FROM crm.contactsWHERE email LIKE '%@company.com';-- EqualitySELECT * FROM my_stripe.charges WHERE status = 'succeeded';
-- ComparisonSELECT * FROM my_stripe.charges WHERE amount > 10000;
-- Multiple conditionsSELECT * FROM my_stripe.chargesWHERE status = 'succeeded' AND amount > 10000 AND created > '2024-01-01';
-- INSELECT * FROM my_stripe.customersWHERE country IN ('US', 'CA', 'UK');
-- LIKESELECT * FROM crm.contactsWHERE email LIKE '%@company.com';GROUP BY
sql
-- Count by statusSELECT status, COUNT(*) AS countFROM my_stripe.chargesGROUP BY status;
-- Sum by monthSELECT DATE_TRUNC('month', created) AS month, SUM(amount) / 100.0 AS revenueFROM my_stripe.chargesWHERE status = 'succeeded'GROUP BY 1ORDER BY 1;-- Count by statusSELECT status, COUNT(*) AS countFROM my_stripe.chargesGROUP BY status;
-- Sum by monthSELECT DATE_TRUNC('month', created) AS month, SUM(amount) / 100.0 AS revenueFROM my_stripe.chargesWHERE status = 'succeeded'GROUP BY 1ORDER BY 1;ORDER BY
sql
-- Ascending (default)SELECT * FROM my_stripe.customers ORDER BY created;
-- DescendingSELECT * FROM my_stripe.customers ORDER BY created DESC;
-- Multiple columnsSELECT * FROM my_stripe.chargesORDER BY amount DESC, created DESC;-- Ascending (default)SELECT * FROM my_stripe.customers ORDER BY created;
-- DescendingSELECT * FROM my_stripe.customers ORDER BY created DESC;
-- Multiple columnsSELECT * FROM my_stripe.chargesORDER BY amount DESC, created DESC;Aggregation Functions
| Function | Description |
|---|---|
| COUNT(*) | Count rows |
| COUNT(DISTINCT col) | Count unique values |
| SUM(col) | Sum values |
| AVG(col) | Average value |
| MIN(col) | Minimum value |
| MAX(col) | Maximum value |
Time Travel
rawquery stores your data as Iceberg tables, which keep a history of snapshots.
You can query data as it was at any point in time using the FOR SYSTEM_TIME AS OF clause.
sql
-- Query data as of a specific dateSELECT * FROM my_stripe.charges FOR SYSTEM_TIME AS OF '2024-01-15';
-- Full ISO 8601 timestampSELECT * FROM my_stripe.charges FOR SYSTEM_TIME AS OF '2024-01-15T14:30:00';
-- With timezoneSELECT * FROM my_stripe.charges FOR SYSTEM_TIME AS OF '2024-01-15T14:30:00+02:00';
-- Compare current vs historical dataSELECT 'now' AS snapshot, COUNT(*) AS totalFROM my_stripe.customers
UNION ALL
SELECT 'jan-2024' AS snapshot, COUNT(*) AS totalFROM my_stripe.customers FOR SYSTEM_TIME AS OF '2024-01-01';-- Query data as of a specific dateSELECT * FROM my_stripe.charges FOR SYSTEM_TIME AS OF '2024-01-15';
-- Full ISO 8601 timestampSELECT * FROM my_stripe.charges FOR SYSTEM_TIME AS OF '2024-01-15T14:30:00';
-- With timezoneSELECT * FROM my_stripe.charges FOR SYSTEM_TIME AS OF '2024-01-15T14:30:00+02:00';
-- Compare current vs historical dataSELECT 'now' AS snapshot, COUNT(*) AS totalFROM my_stripe.customers
UNION ALL
SELECT 'jan-2024' AS snapshot, COUNT(*) AS totalFROM my_stripe.customers FOR SYSTEM_TIME AS OF '2024-01-01';Time travel only works with synced (Iceberg) tables, not live connections. The available history depends on how long your data has been syncing.
Query History
The query editor automatically saves your last 50 queries to your browser's local storage. Each entry records the SQL, timestamp, row count, and execution time.
- Click History in the toolbar to open the history dropdown
- Click any entry to load it back into the editor
- Failed queries are marked with an error badge
- Use Clear all to remove all saved history
History is stored per browser. It is not synced across devices or shared with other workspace members.