Skip to content

Notion

Notion databases, pages and blocks as typed SQL tables, with filter pushdown and Markdown export

Connector software
Free and open source
Service credentials
Required
Use with an agent

Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.

npx skills add Query-farm/vgi-skills --skill orchard

Copy this request into your coding agent to get started.

Use https://query.farm/products/orchard/connectors/notion/index.md to help me query Notion with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.

Find recently edited roadmap pages

Uses your connected account. Set up the connector and credentials to run it with your data.

SELECT title, url, last_edited_time
FROM notion.main.search(query := 'roadmap')
WHERE object = 'page'
ORDER BY last_edited_time DESC
LIMIT 10

Quick start

Choose where to run Notion, then follow the steps below.

The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.

1. Install the vgi extension

Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.

setup.sql
SET allow_extension_repositories = 'allowed';

CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
    WITH PREFIX 'https://duckdb-extensions.query.farm';

INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;

2. Attach the connector

Attach the release directly

Downloads the latest release for your platform and caches it locally.

ATTACH 'notion' AS notion (
  TYPE vgi,
  LOCATION 'github-auto://Query-farm/vgi-notion'
);

3. Add service credentials

After attaching, create the secret for the service you want to query in the same SQL session. Replace the placeholders with your service settings.

notion credentials

Notion integration token (internal integration secret or OAuth access token)

Get these credentials →
secret.sql
CREATE SECRET notion (
    TYPE notion,
    token               '<NOTION_TOKEN>',  -- secret
    oauth_access_token  '<OAUTH_ACCESS_TOKEN>',  -- secret
    base_url            '<base_url>',
    notion_version      '<notion_version>',
    requests_per_second '<requests_per_second>'
);
Credential fields and requirements →

4. Run a query

query.sql
SELECT title, url, last_edited_time
FROM notion.main.search(query := 'roadmap')
WHERE object = 'page'
ORDER BY last_edited_time DESC
LIMIT 10
More example queries →
Technical details
Verified connector release
v0.2.0
Engine
2.0.1
VGI protocol
3.4.0
Verified on
December 1, 2026
Release notes on GitHub
Pin a version for production

When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.

Attach the release directly

Uses the verified release each time you attach the connector.

ATTACH 'notion' AS notion (
  TYPE vgi,
  LOCATION 'github-auto://Query-farm/[email protected]'
);

Overview

Notion workspaces as SQL: search, databases and their data sources as typed tables, page properties, block trees, Markdown export, comments and users. Read-only, with filter pushdown.

Catalog

Everything notion exposes once attached — read straight from the worker's released build.

notion 1 schema
main 3 tables · 10 functions

Read-only SQL over the Notion pages, databases, content, comments and people an integration can see.

Schema examples (17)
Examples (17)

The ten most recently edited pages whose title mentions 'roadmap'

SELECT title, url, last_edited_time
FROM notion.main.search(query := 'roadmap')
WHERE object = 'page'
ORDER BY last_edited_time DESC
LIMIT 10;

How many pages and data sources the integration can see

SELECT object, count(*) AS n
FROM notion.main.search()
GROUP BY object
ORDER BY object;

The columns query_data_source will return for a data source

SELECT property, type, column_name, sql_type
FROM notion.main.data_source_schema('1a2b3c4d-0000-4000-8000-00000000d501')
ORDER BY position;

Every select and status option, to know which values to filter on

SELECT property, unnest(options).name AS option
FROM notion.main.data_source_schema('1a2b3c4d-0000-4000-8000-00000000d501')
WHERE type IN ('select', 'status')
ORDER BY property, option;
13 more examples

Open tasks due from November on, with the status and date filters pushed into Notion

SELECT "Name", "Status", "Due".start AS due
FROM notion.main.query_data_source('1a2b3c4d-0000-4000-8000-00000000d501')
WHERE "Status" <> 'Done' AND "Due".start >= TIMESTAMPTZ '2026-11-01 00:00:00+00'
ORDER BY due;

Task count and estimate total per status

SELECT "Status", count(*) AS tasks, sum("Estimate") AS points
FROM notion.main.query_data_source('1a2b3c4d-0000-4000-8000-00000000d501')
GROUP BY "Status"
ORDER BY tasks DESC;

Tasks tagged 'search', addressing the database by its URL

SELECT "Name", "Tags"
FROM notion.main.query_database('https://www.notion.so/acme/Tasks-1a2b3c4d00004000800000000000d001')
WHERE list_contains("Tags", 'search')
ORDER BY "Name";

Where a page lives and when it last changed

SELECT title, parent_type, data_source_id, last_edited_time
FROM notion.main.page('1a2b3c4d-0000-4000-8000-00000000a001');

A page's non-empty properties as name / value pairs

SELECT property, type, text
FROM notion.main.page_properties('1a2b3c4d-0000-4000-8000-00000000a001')
WHERE text IS NOT NULL
ORDER BY position;

A page's outline: its headings in document order

SELECT depth, type, text
FROM notion.main.blocks('1a2b3c4d-0000-4000-8000-00000000a001')
WHERE type LIKE 'heading_%'
ORDER BY path;

How many to-do items on a page are ticked

SELECT count(*) FILTER (WHERE checked) AS done, count(*) AS total
FROM notion.main.blocks('1a2b3c4d-0000-4000-8000-00000000a001')
WHERE type = 'to_do';

Render a page to Markdown and measure it

SELECT title, length(markdown) AS chars
FROM notion.main.page_markdown('1a2b3c4d-0000-4000-8000-00000000a001');

A page's plain text split into words, if it mentions a launch

SELECT title, regexp_split_to_array(text, '\s+') AS words
FROM notion.main.page_text('1a2b3c4d-0000-4000-8000-00000000a001')
WHERE text ILIKE '%launch%';

The discussion on a page, oldest first

SELECT display_name, text, created_time
FROM notion.main.comments('1a2b3c4d-0000-4000-8000-00000000a001')
ORDER BY created_time;

Every data source the integration can query, most recently edited first

SELECT title, property_count, database_id
FROM notion.main.data_sources
ORDER BY last_edited_time DESC;

Databases and how many data sources each holds

SELECT title, len(data_source_ids) AS sources, is_inline
FROM notion.main.databases
ORDER BY title;

People versus bots in the workspace

SELECT type, count(*) AS n
FROM notion.main.users
GROUP BY type
ORDER BY type;
Tables
data_sources 1 example13 cols

Every Notion data source (the row collections inside databases) shared with the integration

Columns
idnot null VARCHAR
Data source id: pass it to query_data_source / data_source_schema.
title VARCHAR
Data source name.
description VARCHAR
Data source description (plain text).
database_id VARCHAR
The database (container) this data source belongs to.
database_parent_type VARCHAR
Where the database lives: page_id, block_id or workspace.
database_parent_id VARCHAR
Id of the page / block holding the database.
property_count INTEGER
Number of properties (columns).
property_names VARCHAR[]
Property names in schema order.
url VARCHAR
URL in the Notion app.
created_time TIMESTAMP WITH TIME ZONE
When it was created.
last_edited_time TIMESTAMP WITH TIME ZONE
When its schema or rows were last edited.
in_trash BOOLEAN
true when it is in the trash.
icon VARCHAR
Icon: an emoji or an image URL.
ConstraintsPRIMARY KEY (id) · FOREIGN KEY (database_id) REFERENCES databases(id)
Example

Every data source the integration can query, most recently edited first

SELECT title, property_count, database_id
FROM notion.main.data_sources
ORDER BY last_edited_time DESC;
Link
databases 1 example15 cols

Notion databases (containers of one or more data sources) shared with the integration

Columns
idnot null VARCHAR
Database id (from its URL).
title VARCHAR
Database title.
description VARCHAR
Database description (plain text).
url VARCHAR
URL in the Notion app.
public_url VARCHAR
Public URL when published to the web.
is_inline BOOLEAN
true for an inline database (inside a page's content).
is_locked BOOLEAN
true when the database is locked against edits.
parent_type VARCHAR
Where it lives: page_id, block_id or workspace.
parent_id VARCHAR
Id of the parent page or block.
data_source_ids VARCHAR[]
Ids of its data sources.
data_sources STRUCT(id VARCHAR, "name" VARCHAR)[]
Its data sources (id, name).
created_time TIMESTAMP WITH TIME ZONE
When it was created.
last_edited_time TIMESTAMP WITH TIME ZONE
When it was last edited.
in_trash BOOLEAN
true when it is in the trash.
icon VARCHAR
Icon: an emoji or an image URL.
ConstraintsPRIMARY KEY (id)
Example

Databases and how many data sources each holds

SELECT title, len(data_source_ids) AS sources, is_inline
FROM notion.main.databases
ORDER BY title;
Link
users 1 example7 cols

People and bots in the Notion workspace

Columns
idnot null VARCHAR
User id (what people / created_by columns hold).
type VARCHAR
'person' or 'bot'.
name VARCHAR
Display name.
avatar_url VARCHAR
Avatar image URL.
email VARCHAR
Email address; only returned when the integration has the 'read user information including email' capability.
bot_owner_type VARCHAR
Bots: 'workspace' or 'user'.
bot_workspace_name VARCHAR
Bots: the workspace name.
ConstraintsPRIMARY KEY (id)
Example

People versus bots in the workspace

SELECT type, count(*) AS n
FROM notion.main.users
GROUP BY type
ORDER BY type;
Link
Table functions
blocks (block_id VARCHAR, include_child_pages := BOOLEAN, max_depth := INTEGER) 2 examples

The block tree of a Notion page or block as rows, with plain text, type and nesting depth

Positional arguments
block_id VARCHAR
Page or block id (or notion.so URL) whose children to list.
Named arguments
include_child_pages := BOOLEAN
Also walk into sub-pages (child_page blocks); off by default. · default false
max_depth := INTEGER
How deep to recurse: 1 = direct children only (default 10, at most 50). · default 10
Returns columns
id VARCHAR
Block id.
parent_id VARCHAR
Id of the page or block this block is a child of.
root_id VARCHAR
The block_id argument (normalized), the root of the walk.
depth INTEGER
Nesting depth: 1 for the root's direct children.
position INTEGER
0-based position among its siblings.
path VARCHAR
Sortable document-order key: zero-padded positions joined by '.'.
type VARCHAR
Block type: paragraph, heading_1, bulleted_list_item, to_do, code, table_row, child_page, …
text VARCHAR
Plain text of the block (table rows: cells tab-separated; child pages: the title).
rich_text JSON
Raw rich text array (annotations, links, mentions), when the block has one.
has_children BOOLEAN
true when the block has nested children.
checked BOOLEAN
to_do blocks: whether the box is ticked.
language VARCHAR
code blocks: the language.
url VARCHAR
Media, file, bookmark and embed blocks: the URL (Notion-hosted file URLs expire).
created_time TIMESTAMP WITH TIME ZONE
When the block was created.
last_edited_time TIMESTAMP WITH TIME ZONE
When the block was last edited.
created_by VARCHAR
User id of the block's creator.
last_edited_by VARCHAR
User id of the block's last editor.
in_trash BOOLEAN
true when the block is in the trash.
content JSON
The block's type-specific payload as JSON (e.g. the table width, an image's file object).
Examples (2)

A page's outline: its headings in document order

SELECT depth, type, text
FROM notion.main.blocks('1a2b3c4d-0000-4000-8000-00000000a001')
WHERE type LIKE 'heading_%'
ORDER BY path;

How many to-do items on a page are ticked

SELECT count(*) FILTER (WHERE checked) AS done, count(*) AS total
FROM notion.main.blocks('1a2b3c4d-0000-4000-8000-00000000a001')
WHERE type = 'to_do';
Link
comments (block_id VARCHAR) 1 example

Open (unresolved) comments on a Notion page or block

Arguments
block_id VARCHAR
Page or block id (or notion.so URL). A page id returns page-level comments.
Returns columns
id VARCHAR
Comment id.
discussion_id VARCHAR
Thread id: comments in one discussion share it.
parent_type VARCHAR
'page_id' or 'block_id'.
parent_id VARCHAR
The page or block commented on.
created_time TIMESTAMP WITH TIME ZONE
When it was posted.
last_edited_time TIMESTAMP WITH TIME ZONE
When it was last edited.
created_by VARCHAR
User id of the author.
display_name VARCHAR
Author name as shown in Notion (custom names for integrations).
text VARCHAR
Comment text (plain).
rich_text JSON
Raw rich text (mentions, links).
attachments STRUCT of 3 fields[]
Attached files: category (image, pdf, …), URL (expiring) and expiry time.
STRUCT[] 3 fields
  • categoryVARCHAR
  • urlVARCHAR
  • expiry_timeTIMESTAMP WITH TIME ZONE
Example

The discussion on a page, oldest first

SELECT display_name, text, created_time
FROM notion.main.comments('1a2b3c4d-0000-4000-8000-00000000a001')
ORDER BY created_time;
Link
data_source_schema (data_source_id VARCHAR, rich_text_json := BOOLEAN) 2 examples

The properties of a Notion data source and the SQL column each becomes in query_data_source

Positional arguments
data_source_id VARCHAR
Data source id or URL (a database id works when the database has one data source).
Named arguments
rich_text_json := BOOLEAN
Match query_data_source's rich_text_json setting when computing json_column. · default true
Returns columns
data_source_id VARCHAR
The resolved data source id.
data_source_title VARCHAR
The data source's name.
position INTEGER
0-based position in the schema.
property VARCHAR
Property name in Notion.
property_id VARCHAR
Property id (stable across renames).
type VARCHAR
Notion property type (title, rich_text, number, select, status, date, relation, formula, …).
column_name VARCHAR
The query_data_source column holding it (NULL for buttons, which have no value).
sql_type VARCHAR
That column's DuckDB type.
json_column VARCHAR
The `__json` raw rich text sibling column, for title / rich_text properties.
description VARCHAR
Property description.
options STRUCT of 4 fields[]
select / multi_select / status options (status options name their group: To-do, In progress, Complete).
STRUCT[] 4 fields
  • idVARCHAR
  • nameVARCHAR
  • colorVARCHAR
  • groupVARCHAR
number_format VARCHAR
number: the display format (number, percent, dollar, …).
relation_data_source_id VARCHAR
relation: the related data source.
formula_expression VARCHAR
formula: the expression.
rollup_function VARCHAR
rollup: the aggregation (count, sum, show_original, latest_date, …).
rollup_relation_property VARCHAR
rollup: the relation property it rolls up through.
rollup_property VARCHAR
rollup: the property it aggregates on the related pages.
unique_id_prefix VARCHAR
unique_id: the prefix shown before the number (e.g. 'TASK').
config JSON
The type-specific configuration as Notion returns it.
Examples (2)

The columns query_data_source will return for a data source

SELECT property, type, column_name, sql_type
FROM notion.main.data_source_schema('1a2b3c4d-0000-4000-8000-00000000d501')
ORDER BY position;

Every select and status option, to know which values to filter on

SELECT property, unnest(options).name AS option
FROM notion.main.data_source_schema('1a2b3c4d-0000-4000-8000-00000000d501')
WHERE type IN ('select', 'status')
ORDER BY property, option;
Link
page (page_id VARCHAR) 1 example

One Notion page's metadata: title, parent, data source, times, raw properties

Arguments
page_id VARCHAR
Page id or notion.so URL.
Returns columns
id VARCHAR
Page id.
title VARCHAR
Page title.
url VARCHAR
URL in the Notion app.
public_url VARCHAR
Public URL when published to the web.
parent_type VARCHAR
Parent kind: workspace, page_id, block_id or data_source_id.
parent_id VARCHAR
Id of the parent.
data_source_id VARCHAR
Data source the page is a row of, if any.
database_id VARCHAR
Database the page is a row of, if any.
created_time TIMESTAMP WITH TIME ZONE
When it was created.
last_edited_time TIMESTAMP WITH TIME ZONE
When it was last edited.
created_by VARCHAR
User id of the creator.
last_edited_by VARCHAR
User id of the last editor.
in_trash BOOLEAN
true when it is in the trash.
is_locked BOOLEAN
true when the page is locked against edits.
icon VARCHAR
Icon: an emoji or an image URL.
cover VARCHAR
Cover image URL.
properties JSON
All property values as Notion returns them (JSON object keyed by name).
Example

Where a page lives and when it last changed

SELECT title, parent_type, data_source_id, last_edited_time
FROM notion.main.page('1a2b3c4d-0000-4000-8000-00000000a001');
Link
page_markdown (page_id VARCHAR, include_child_pages := BOOLEAN, include_title := BOOLEAN, max_depth := INTEGER) 1 example

A Notion page rendered to Markdown (headings, lists, to-dos, code, tables, links), one row

Positional arguments
page_id VARCHAR
Page id or notion.so URL.
Named arguments
include_child_pages := BOOLEAN
Also inline the content of sub-pages (default false: a sub-page shows as its title). · default false
include_title := BOOLEAN
Start with '# <page title>' (default true). · default true
max_depth := INTEGER
How deep to follow nested blocks (default 25, at most 50). · default 25
Returns columns
page_id VARCHAR
The page id (normalized).
title VARCHAR
The page title.
url VARCHAR
The page URL in the Notion app.
markdown VARCHAR
The page content as GitHub-flavoured Markdown.
block_count INTEGER
Number of blocks rendered.
truncated BOOLEAN
true when max_depth or the 20,000-block limit cut the page short.
Example

Render a page to Markdown and measure it

SELECT title, length(markdown) AS chars
FROM notion.main.page_markdown('1a2b3c4d-0000-4000-8000-00000000a001');
Link
page_properties (page_id VARCHAR) 1 example

One Notion page's property values in long form: one row per property with text and JSON

Arguments
page_id VARCHAR
Page id or notion.so URL.
Returns columns
page_id VARCHAR
The page id.
position INTEGER
0-based property position in the page object.
property VARCHAR
Property name.
property_id VARCHAR
Property id (stable across renames).
type VARCHAR
Notion property type.
text VARCHAR
The value as readable text (lists comma-separated, dates 'start → end'); NULL when empty.
value JSON
The value as Notion returns it (the type-specific payload).
Example

A page's non-empty properties as name / value pairs

SELECT property, type, text
FROM notion.main.page_properties('1a2b3c4d-0000-4000-8000-00000000a001')
WHERE text IS NOT NULL
ORDER BY position;
Link
page_text (page_id VARCHAR, include_child_pages := BOOLEAN, include_title := BOOLEAN, max_depth := INTEGER) 1 example

A Notion page's content as plain text, one row

Positional arguments
page_id VARCHAR
Page id or notion.so URL.
Named arguments
include_child_pages := BOOLEAN
Also inline the content of sub-pages (default false: a sub-page shows as its title). · default false
include_title := BOOLEAN
Start with the page title line (default true). · default true
max_depth := INTEGER
How deep to follow nested blocks (default 25, at most 50). · default 25
Returns columns
page_id VARCHAR
The page id (normalized).
title VARCHAR
The page title.
url VARCHAR
The page URL in the Notion app.
text VARCHAR
The page content as plain text.
block_count INTEGER
Number of blocks rendered.
truncated BOOLEAN
true when max_depth or the 20,000-block limit cut the page short.
Example

A page's plain text split into words, if it mentions a launch

SELECT title, regexp_split_to_array(text, '\s+') AS words
FROM notion.main.page_text('1a2b3c4d-0000-4000-8000-00000000a001')
WHERE text ILIKE '%launch%';
Link
query_data_source (data_source_id VARCHAR, notion_filter := VARCHAR, notion_sorts := VARCHAR, rich_text_json := BOOLEAN) 2 examples

Rows of a Notion data source as a typed table, one column per property

Positional arguments
data_source_id VARCHAR
Data source id or URL (a database id also works when the database has one data source).
Named arguments
notion_filter := VARCHAR
Optional Notion filter object as JSON text, ANDed with what the WHERE clause pushes down (https://developers.notion.com/reference/filter-data-source-entries). · default null
notion_sorts := VARCHAR
Optional Notion sorts array as JSON text (https://developers.notion.com/reference/sort-data-source-entries); Notion orders the rows, so add ORDER BY in SQL to guarantee an order. · default null
rich_text_json := BOOLEAN
Add a `<property>__json` JSON column with the raw rich text of each title / rich_text property. · default true
Returns columns
id VARCHAR
Page id of the row.
<title / rich_text property> VARCHAR
Plain text.
<title / rich_text property>__json JSON
Raw rich text (marks, links, mentions).
<number property> DOUBLE
The number.
<checkbox property> BOOLEAN
Ticked or not.
<select / status property> VARCHAR
Option name.
<multi_select property> VARCHAR[]
Option names.
<people / relation property> VARCHAR[]
User ids / related page ids.
<date property> STRUCT of 4 fields
Date or range; all-day dates at 00:00 UTC.
STRUCT 4 fields
  • startTIMESTAMP WITH TIME ZONE
  • endTIMESTAMP WITH TIME ZONE
  • time_zoneVARCHAR
  • has_timeBOOLEAN
<created_time / last_edited_time property> TIMESTAMP WITH TIME ZONE
The instant.
<created_by / last_edited_by property> VARCHAR
User id.
<url / email / phone_number property> VARCHAR
The value.
<files property> STRUCT of 4 fields[]
Attached files.
STRUCT[] 4 fields
  • nameVARCHAR
  • typeVARCHAR
  • urlVARCHAR
  • expiry_timeTIMESTAMP WITH TIME ZONE
<unique_id property> BIGINT
The number (prefix in data_source_schema).
<formula property, text result> VARCHAR
Formula result.
<formula property, boolean result> BOOLEAN
Formula result.
<formula / rollup property, number result> DOUBLE
Result (rollups: count, sum, average, …).
<rollup property, show_original / show_unique> VARCHAR[]
The rolled-up values as text.
<formula / rollup property, date result> STRUCT of 4 fields
Date result.
STRUCT 4 fields
  • startTIMESTAMP WITH TIME ZONE
  • endTIMESTAMP WITH TIME ZONE
  • time_zoneVARCHAR
  • has_timeBOOLEAN
<other property types> JSON
Raw value.
url VARCHAR
Page URL in the Notion app.
created_time TIMESTAMP WITH TIME ZONE
When the page (row) was created.
last_edited_time TIMESTAMP WITH TIME ZONE
When the page was last edited (Notion rounds to the minute).
created_by VARCHAR
User id of the page's creator.
last_edited_by VARCHAR
User id of the last editor.
in_trash BOOLEAN
true when the page is in the trash.
Name VARCHAR
title: the task name.
Name__json JSON
Raw rich text of Name.
Status VARCHAR
status: Not started, In progress or Done.
Priority VARCHAR
select: High, Medium or Low.
Tags VARCHAR[]
multi_select option names.
Assignee VARCHAR[]
people: user ids.
Due STRUCT of 4 fields
date (or range).
STRUCT 4 fields
  • startTIMESTAMP WITH TIME ZONE
  • endTIMESTAMP WITH TIME ZONE
  • time_zoneVARCHAR
  • has_timeBOOLEAN
Estimate DOUBLE
number.
Blocked BOOLEAN
checkbox.
Project VARCHAR[]
relation: page ids in the Projects data source.
Notes VARCHAR
rich_text.
Notes__json JSON
Raw rich text of Notes.
URL_2 VARCHAR
url property 'URL' (renamed: it collides with the url column).
Owner email VARCHAR
email.
Attachments STRUCT of 4 fields[]
files.
STRUCT[] 4 fields
  • nameVARCHAR
  • typeVARCHAR
  • urlVARCHAR
  • expiry_timeTIMESTAMP WITH TIME ZONE
Task ID BIGINT
unique_id number (prefix TASK).
Created TIMESTAMP WITH TIME ZONE
created_time.
Edited by VARCHAR
last_edited_by user id.
Score DOUBLE
formula with a number result.
Label VARCHAR
formula with a text result.
Project count DOUBLE
rollup count of Project.
Project names VARCHAR[]
rollup show_original of the projects' names.
Returns columns · depends on the arguments
id VARCHAR
Page id of the row.
<title / rich_text property> VARCHAR
Plain text.
<title / rich_text property>__json JSON
Raw rich text (marks, links, mentions).
<number property> DOUBLE
The number.
<checkbox property> BOOLEAN
Ticked or not.
<select / status property> VARCHAR
Option name.
<multi_select property> VARCHAR[]
Option names.
<people / relation property> VARCHAR[]
User ids / related page ids.
<date property> STRUCT of 4 fields
Date or range; all-day dates at 00:00 UTC.
STRUCT 4 fields
  • startTIMESTAMP WITH TIME ZONE
  • endTIMESTAMP WITH TIME ZONE
  • time_zoneVARCHAR
  • has_timeBOOLEAN
<created_time / last_edited_time property> TIMESTAMP WITH TIME ZONE
The instant.
<created_by / last_edited_by property> VARCHAR
User id.
<url / email / phone_number property> VARCHAR
The value.
<files property> STRUCT of 4 fields[]
Attached files.
STRUCT[] 4 fields
  • nameVARCHAR
  • typeVARCHAR
  • urlVARCHAR
  • expiry_timeTIMESTAMP WITH TIME ZONE
<unique_id property> BIGINT
The number (prefix in data_source_schema).
<formula property, text result> VARCHAR
Formula result.
<formula property, boolean result> BOOLEAN
Formula result.
<formula / rollup property, number result> DOUBLE
Result (rollups: count, sum, average, …).
<rollup property, show_original / show_unique> VARCHAR[]
The rolled-up values as text.
<formula / rollup property, date result> STRUCT of 4 fields
Date result.
STRUCT 4 fields
  • startTIMESTAMP WITH TIME ZONE
  • endTIMESTAMP WITH TIME ZONE
  • time_zoneVARCHAR
  • has_timeBOOLEAN
<other property types> JSON
Raw value.
url VARCHAR
Page URL in the Notion app.
created_time TIMESTAMP WITH TIME ZONE
When the page (row) was created.
last_edited_time TIMESTAMP WITH TIME ZONE
When the page was last edited (Notion rounds to the minute).
created_by VARCHAR
User id of the page's creator.
last_edited_by VARCHAR
User id of the last editor.
in_trash BOOLEAN
true when the page is in the trash.
Name VARCHAR
title: the task name.
Name__json JSON
Raw rich text of Name.
Status VARCHAR
status: Not started, In progress or Done.
Priority VARCHAR
select: High, Medium or Low.
Tags VARCHAR[]
multi_select option names.
Assignee VARCHAR[]
people: user ids.
Due STRUCT of 4 fields
date (or range).
STRUCT 4 fields
  • startTIMESTAMP WITH TIME ZONE
  • endTIMESTAMP WITH TIME ZONE
  • time_zoneVARCHAR
  • has_timeBOOLEAN
Estimate DOUBLE
number.
Blocked BOOLEAN
checkbox.
Project VARCHAR[]
relation: page ids in the Projects data source.
Notes VARCHAR
rich_text.
Notes__json JSON
Raw rich text of Notes.
URL_2 VARCHAR
url property 'URL' (renamed: it collides with the url column).
Owner email VARCHAR
email.
Attachments STRUCT of 4 fields[]
files.
STRUCT[] 4 fields
  • nameVARCHAR
  • typeVARCHAR
  • urlVARCHAR
  • expiry_timeTIMESTAMP WITH TIME ZONE
Task ID BIGINT
unique_id number (prefix TASK).
Created TIMESTAMP WITH TIME ZONE
created_time.
Edited by VARCHAR
last_edited_by user id.
Score DOUBLE
formula with a number result.
Label VARCHAR
formula with a text result.
Project count DOUBLE
rollup count of Project.
Project names VARCHAR[]
rollup show_original of the projects' names.
Examples (2)

Open tasks due from November on, with the status and date filters pushed into Notion

SELECT "Name", "Status", "Due".start AS due
FROM notion.main.query_data_source('1a2b3c4d-0000-4000-8000-00000000d501')
WHERE "Status" <> 'Done' AND "Due".start >= TIMESTAMPTZ '2026-11-01 00:00:00+00'
ORDER BY due;

Task count and estimate total per status

SELECT "Status", count(*) AS tasks, sum("Estimate") AS points
FROM notion.main.query_data_source('1a2b3c4d-0000-4000-8000-00000000d501')
GROUP BY "Status"
ORDER BY tasks DESC;
Link
query_database (database_id VARCHAR, notion_filter := VARCHAR, notion_sorts := VARCHAR, rich_text_json := BOOLEAN) 1 example

Rows of a single-source Notion database (the database id from its URL) as a typed table

Positional arguments
database_id VARCHAR
Database id or notion.so URL; the database must hold exactly one data source.
Named arguments
notion_filter := VARCHAR
Optional Notion filter object as JSON text, ANDed with what the WHERE clause pushes down (https://developers.notion.com/reference/filter-data-source-entries). · default null
notion_sorts := VARCHAR
Optional Notion sorts array as JSON text (https://developers.notion.com/reference/sort-data-source-entries); Notion orders the rows, so add ORDER BY in SQL to guarantee an order. · default null
rich_text_json := BOOLEAN
Add a `<property>__json` JSON column with the raw rich text of each title / rich_text property. · default true
Returns columns
id VARCHAR
Page id of the row.
<title / rich_text property> VARCHAR
Plain text.
<title / rich_text property>__json JSON
Raw rich text (marks, links, mentions).
<number property> DOUBLE
The number.
<checkbox property> BOOLEAN
Ticked or not.
<select / status property> VARCHAR
Option name.
<multi_select property> VARCHAR[]
Option names.
<people / relation property> VARCHAR[]
User ids / related page ids.
<date property> STRUCT of 4 fields
Date or range; all-day dates at 00:00 UTC.
STRUCT 4 fields
  • startTIMESTAMP WITH TIME ZONE
  • endTIMESTAMP WITH TIME ZONE
  • time_zoneVARCHAR
  • has_timeBOOLEAN
<created_time / last_edited_time property> TIMESTAMP WITH TIME ZONE
The instant.
<created_by / last_edited_by property> VARCHAR
User id.
<url / email / phone_number property> VARCHAR
The value.
<files property> STRUCT of 4 fields[]
Attached files.
STRUCT[] 4 fields
  • nameVARCHAR
  • typeVARCHAR
  • urlVARCHAR
  • expiry_timeTIMESTAMP WITH TIME ZONE
<unique_id property> BIGINT
The number (prefix in data_source_schema).
<formula property, text result> VARCHAR
Formula result.
<formula property, boolean result> BOOLEAN
Formula result.
<formula / rollup property, number result> DOUBLE
Result (rollups: count, sum, average, …).
<rollup property, show_original / show_unique> VARCHAR[]
The rolled-up values as text.
<formula / rollup property, date result> STRUCT of 4 fields
Date result.
STRUCT 4 fields
  • startTIMESTAMP WITH TIME ZONE
  • endTIMESTAMP WITH TIME ZONE
  • time_zoneVARCHAR
  • has_timeBOOLEAN
<other property types> JSON
Raw value.
url VARCHAR
Page URL in the Notion app.
created_time TIMESTAMP WITH TIME ZONE
When the page (row) was created.
last_edited_time TIMESTAMP WITH TIME ZONE
When the page was last edited (Notion rounds to the minute).
created_by VARCHAR
User id of the page's creator.
last_edited_by VARCHAR
User id of the last editor.
in_trash BOOLEAN
true when the page is in the trash.
Name VARCHAR
title: the task name.
Name__json JSON
Raw rich text of Name.
Status VARCHAR
status: Not started, In progress or Done.
Priority VARCHAR
select: High, Medium or Low.
Tags VARCHAR[]
multi_select option names.
Assignee VARCHAR[]
people: user ids.
Due STRUCT of 4 fields
date (or range).
STRUCT 4 fields
  • startTIMESTAMP WITH TIME ZONE
  • endTIMESTAMP WITH TIME ZONE
  • time_zoneVARCHAR
  • has_timeBOOLEAN
Estimate DOUBLE
number.
Blocked BOOLEAN
checkbox.
Project VARCHAR[]
relation: page ids in the Projects data source.
Notes VARCHAR
rich_text.
Notes__json JSON
Raw rich text of Notes.
URL_2 VARCHAR
url property 'URL' (renamed: it collides with the url column).
Owner email VARCHAR
email.
Attachments STRUCT of 4 fields[]
files.
STRUCT[] 4 fields
  • nameVARCHAR
  • typeVARCHAR
  • urlVARCHAR
  • expiry_timeTIMESTAMP WITH TIME ZONE
Task ID BIGINT
unique_id number (prefix TASK).
Created TIMESTAMP WITH TIME ZONE
created_time.
Edited by VARCHAR
last_edited_by user id.
Score DOUBLE
formula with a number result.
Label VARCHAR
formula with a text result.
Project count DOUBLE
rollup count of Project.
Project names VARCHAR[]
rollup show_original of the projects' names.
Returns columns · depends on the arguments
id VARCHAR
Page id of the row.
<title / rich_text property> VARCHAR
Plain text.
<title / rich_text property>__json JSON
Raw rich text (marks, links, mentions).
<number property> DOUBLE
The number.
<checkbox property> BOOLEAN
Ticked or not.
<select / status property> VARCHAR
Option name.
<multi_select property> VARCHAR[]
Option names.
<people / relation property> VARCHAR[]
User ids / related page ids.
<date property> STRUCT of 4 fields
Date or range; all-day dates at 00:00 UTC.
STRUCT 4 fields
  • startTIMESTAMP WITH TIME ZONE
  • endTIMESTAMP WITH TIME ZONE
  • time_zoneVARCHAR
  • has_timeBOOLEAN
<created_time / last_edited_time property> TIMESTAMP WITH TIME ZONE
The instant.
<created_by / last_edited_by property> VARCHAR
User id.
<url / email / phone_number property> VARCHAR
The value.
<files property> STRUCT of 4 fields[]
Attached files.
STRUCT[] 4 fields
  • nameVARCHAR
  • typeVARCHAR
  • urlVARCHAR
  • expiry_timeTIMESTAMP WITH TIME ZONE
<unique_id property> BIGINT
The number (prefix in data_source_schema).
<formula property, text result> VARCHAR
Formula result.
<formula property, boolean result> BOOLEAN
Formula result.
<formula / rollup property, number result> DOUBLE
Result (rollups: count, sum, average, …).
<rollup property, show_original / show_unique> VARCHAR[]
The rolled-up values as text.
<formula / rollup property, date result> STRUCT of 4 fields
Date result.
STRUCT 4 fields
  • startTIMESTAMP WITH TIME ZONE
  • endTIMESTAMP WITH TIME ZONE
  • time_zoneVARCHAR
  • has_timeBOOLEAN
<other property types> JSON
Raw value.
url VARCHAR
Page URL in the Notion app.
created_time TIMESTAMP WITH TIME ZONE
When the page (row) was created.
last_edited_time TIMESTAMP WITH TIME ZONE
When the page was last edited (Notion rounds to the minute).
created_by VARCHAR
User id of the page's creator.
last_edited_by VARCHAR
User id of the last editor.
in_trash BOOLEAN
true when the page is in the trash.
Name VARCHAR
title: the task name.
Name__json JSON
Raw rich text of Name.
Status VARCHAR
status: Not started, In progress or Done.
Priority VARCHAR
select: High, Medium or Low.
Tags VARCHAR[]
multi_select option names.
Assignee VARCHAR[]
people: user ids.
Due STRUCT of 4 fields
date (or range).
STRUCT 4 fields
  • startTIMESTAMP WITH TIME ZONE
  • endTIMESTAMP WITH TIME ZONE
  • time_zoneVARCHAR
  • has_timeBOOLEAN
Estimate DOUBLE
number.
Blocked BOOLEAN
checkbox.
Project VARCHAR[]
relation: page ids in the Projects data source.
Notes VARCHAR
rich_text.
Notes__json JSON
Raw rich text of Notes.
URL_2 VARCHAR
url property 'URL' (renamed: it collides with the url column).
Owner email VARCHAR
email.
Attachments STRUCT of 4 fields[]
files.
STRUCT[] 4 fields
  • nameVARCHAR
  • typeVARCHAR
  • urlVARCHAR
  • expiry_timeTIMESTAMP WITH TIME ZONE
Task ID BIGINT
unique_id number (prefix TASK).
Created TIMESTAMP WITH TIME ZONE
created_time.
Edited by VARCHAR
last_edited_by user id.
Score DOUBLE
formula with a number result.
Label VARCHAR
formula with a text result.
Project count DOUBLE
rollup count of Project.
Project names VARCHAR[]
rollup show_original of the projects' names.
Example

Tasks tagged 'search', addressing the database by its URL

SELECT "Name", "Tags"
FROM notion.main.query_database('https://www.notion.so/acme/Tasks-1a2b3c4d00004000800000000000d001')
WHERE list_contains("Tags", 'search')
ORDER BY "Name";
Link

Credentials

The secret type notion declares, as reported by the worker itself.

notion

How to get these credentials

Notion integration token (internal integration secret or OAuth access token)

secret.sql
CREATE SECRET notion (
    TYPE notion,
    token               '<NOTION_TOKEN>',  -- secret
    oauth_access_token  '<OAUTH_ACCESS_TOKEN>',  -- secret
    base_url            '<base_url>',
    notion_version      '<notion_version>',
    requests_per_second '<requests_per_second>'
);
Key Type Required Description
token secret VARCHAR — Internal integration secret (ntn_… or secret_…) from notion.so/profile/integrations, sent as Bearer.
oauth_access_token secret VARCHAR — A public integration's OAuth 2.0 access token (sent as Bearer).
base_url VARCHAR — API base URL (default https://api.notion.com); http:// only for 127.0.0.1/localhost, e.g. a fixture server.
notion_version VARCHAR — Notion-Version header to send (default 2026-03-11).
requests_per_second VARCHAR — Client-side average request rate (default 3, Notion's documented limit).

The worker doesn't mark which keys are required.

Create the secret in the same session, after attaching notion — the worker registers its secret types at ATTACH. Keys marked secret are masked in duckdb_secrets(); angle-bracket values are placeholders. Read credentials from your environment or secret store in your application and pass them through your SQL client’s parameter bindings. Keep real values out of saved SQL and history. Native DuckDB and Haybarn do not provide a SQL getenv() function.

Try these queries

search_columns — The search() result columns (binds only; create a notion secret and drop LIMIT 0 for rows)

SELECT object, id, title, url, last_edited_time
FROM notion.main.search()
LIMIT 0;

Uses search

users_columns — The users table's columns (binds only; create a notion secret and drop LIMIT 0 for rows)

SELECT id, type, name, email FROM notion.main.users LIMIT 0;

Uses users

The columns query_data_source will return for a data source

SELECT property, type, column_name, sql_type
FROM notion.main.data_source_schema('1a2b3c4d-0000-4000-8000-00000000d501')
ORDER BY position

Uses data_source_schema

Open tasks due from November on, with the status and date filters pushed into Notion

SELECT "Name", "Status", "Due".start AS due
FROM notion.main.query_data_source('1a2b3c4d-0000-4000-8000-00000000d501')
WHERE "Status" <> 'Done' AND "Due".start >= TIMESTAMPTZ '2026-11-01 00:00:00+00'
ORDER BY due

Uses query_data_source

Tasks tagged 'search', addressing the database by its URL

SELECT "Name", "Tags"
FROM notion.main.query_database('https://www.notion.so/acme/Tasks-1a2b3c4d00004000800000000000d001')
WHERE list_contains("Tags", 'search')
ORDER BY "Name"

Uses query_database

Where a page lives and when it last changed

SELECT title, parent_type, data_source_id, last_edited_time
FROM notion.main.page('1a2b3c4d-0000-4000-8000-00000000a001')

Uses page

12 more examples in the Catalog, each listed under the table or function it uses.

Questions it can answer

Plain-English questions from the worker's agent test tasks. An AI agent with this catalog attached should answer each one with SQL.

  • Find the Notion page titled 'Product Roadmap' and give its URL.
  • Which Notion data sources can the integration see? Give their titles.
  • In the Notion 'Tasks' data source, which tasks are not Done? Give their names.
  • How many tasks are there in each status in the Notion Tasks data source?
  • Which Notion tasks are tagged 'search'?
  • What is the total Estimate of all Notion tasks that are In progress?

Notion is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.