Notion
Notion provides a versatile, ready-to-use solution for managing your data.
The Notion Wrapper allows you to read data from your Notion workspace for use within your Postgres database. Only the users endpoint is supported at the moment.
Warning
Restoring a logical backup of a database with a materialized view using a foreign table can fail. For this reason, either do not use foreign tables in materialized views or use them in databases with physical backups enabled.
Preparation
Before you get started, make sure the wrappers
extension is installed on your database:
1 |
|
Then, create the foreign data wrapper:
1 2 3 |
|
Secure your credentials (optional)
By default, Postgres stores FDW credentials in plain text within the pg_catalog.pg_foreign_server
table, making them visible to anyone with access to this table. To enhance security, it is advisable to use Vault for credential storage. Vault integrates seamlessly with Wrappers to provide a secure storage solution for sensitive information. We strongly recommend utilizing Vault to safeguard your credentials.
1 2 3 4 5 6 7 |
|
Connecting to Notion
We need to provide Postgres with the credentials to connect to Notion, and any additional options. We can do this using the CREATE SERVER
command:
- With Vault (recommended)
1 2 3 4 5 6 7 |
|
- Without Vault
1 2 3 4 5 6 7 |
|
Creating Foreign Tables
The Notion Wrapper supports data reads from the Notion API.
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
Users | ✅ | ❌ | ❌ | ❌ | ❌ |
For example:
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Query Pushdown Support
This FDW supports where
clause pushdown. You can specify a filter in where
clause and it will be passed to Notion API call.
For example, this query
1 |
|
will be translated Notion API call: https://api.notion.com/v1/users/xxx
.
Examples
Some examples on how to use Notion foreign tables.
Users foreign table
The following command creates a "foreign table" in your Postgres database named notion_users
:
1 2 3 4 5 6 7 8 9 10 11 |
|
You can now fetch your Notion data from within your Postgres database:
1 |
|
You can also query with filters:
1 |
|