DEV Community

Cover image for Zero-ETL Read/Write to Microsoft Fabric OneLake from Azure Database for PostgreSQL with pg_duckdb
Franck Pachot
Franck Pachot

Posted on Edited on

Zero-ETL Read/Write to Microsoft Fabric OneLake from Azure Database for PostgreSQL with pg_duckdb

By Zero-ETL here, I mean that PostgreSQL can access the OneLake files directly, without first copying or ingesting them into PostgreSQL or exposing them through a Fabric SQL endpoint. DuckDB already has a community "onelake" extension. It integrates with Fabric workspaces and lakehouses, supports Delta and Iceberg reads, and provides Delta write operations. Its repository describes it as experimental. In standalone DuckDB, the installation starts with:

INSTALL onelake FROM community;
LOAD onelake;
Enter fullscreen mode Exit fullscreen mode

There is also a PostgreSQL route inside Fabric: Microsoft Fabric HorizonDB, currently in public preview, provides service-managed, serverless-style compute and SQL federation through the pg_fabric_fdw Foreign Data Wrapper.

From an existing Azure Database for PostgreSQL Flexible Server with pg_duckdb, can I read and write a OneLake file directly, without installing another extension or querying through a Fabric SQL endpoint?

In the previous post, we saw a restriction: the tested managed server allowed az:// paths, but not abfss://. The obvious OneLake paths use HTTPS or abfss://. To access OneLake from pg_duckdb we need to distinguish the client URI scheme from the storage API.

In this blog post, I'll show the URLs that fail, the Blob endpoint that works, then filtering, a PostgreSQL join, and exports to Parquet and CSV.

A file in a Fabric lakehouse

OneLake is Microsoft Fabric's logical data lake. A workspace contains Fabric items. A lakehouse is one type of item. Within a lakehouse, Files holds files and folders, while Tables holds managed Delta tables.

My example is a Parquet file under this location in the Lakehouse explorer, created from the sample dataset:

My workspace
  Lakehouse_1
    Files
      sample_datasets
        public_holidays.parquet
Enter fullscreen mode Exit fullscreen mode

This is a file under Files, not a registered Delta table under Tables. We are not connecting to the lakehouse's SQL analytics endpoint: that endpoint exposes Delta tables, not arbitrary Parquet files under Files.

To find your own path, open the lakehouse in Fabric and use the file's context menu. Microsoft documents Copy ABFS path in the lakehouse notebook guide. The file's Properties pane also helps identify its OneLake location.

Here are the HTTPS and ABFS paths for my file:

  • https://msit-onelake.dfs.fabric.microsoft.com/c8d766ad-bdc3-453e-bb67-0e181d2d14c8/33422e73-88cd-4056-a0fa-8f74baa13ce1/Files/sample_datasets/public_holidays.parquet

  • abfss://c8d766ad-bdc3-453e-bb67-0e181d2d14c8@msit-onelake.dfs.fabric.microsoft.com/33422e73-88cd-4056-a0fa-8f74baa13ce1/Files/sample_datasets/public_holidays.parquet

The first GUID identifies the workspace. The second identifies the lakehouse item. You can also find them in the Fabric browser URL: https://msit.fabric.microsoft.com/groups/<workspace-id>/lakehouses/<lakehouse-id>

That browser URL opens Fabric's user interface. It is not the URL to pass to read_parquet(), but provides all identifiers I need.

The msit-onelake hostname is the one supplied by my environment. Microsoft's general examples use onelake.dfs.fabric.microsoft.com. Start from your own file's location rather than copying my hostname.

First, confirm the restriction

I tested on a small Flexible Server with PostgreSQL 18.6, pg_duckdb 1.1.0, and DuckDB v1.4.3. The extension setup is the same as before: allow-list pg_duckdb, add it to shared_preload_libraries, restart, and create the extension in the database.


postgres=> \dx
                          List of installed extensions
  Name   | Version | Default version |   Schema   |         Description          
---------+---------+-----------------+------------+------------------------------
 plpgsql | 1.0     | 1.0             | pg_catalog | PL/pgSQL procedural language
(1 row)

postgres=> CREATE EXTENSION IF NOT EXISTS pg_duckdb;


NOTICE:  extension "pg_duckdb" already exists, skipping
WARNING:  sequence "extensions_table_seq" only supports USAGE, SELECT, and UPDATE privileges

CREATE EXTENSION

postgres=> SHOW duckdb.enable_external_access;

postgres=> \dx
                           List of installed extensions
   Name    | Version | Default version |   Schema   |         Description          
-----------+---------+-----------------+------------+------------------------------
 pg_duckdb | 1.1.0   | 1.1.0           | public     | DuckDB Embedded in Postgres
 plpgsql   | 1.0     | 1.0             | pg_catalog | PL/pgSQL procedural language
(2 rows)

 duckdb.enable_external_access 
-------------------------------
 off
(1 row)

postgres=> SHOW duckdb.allowed_directories;
 duckdb.allowed_directories 
----------------------------
 az://
(1 row)

postgres=> SHOW duckdb.allow_community_extensions;
 duckdb.allow_community_extensions 
-----------------------------------
 off
(1 row)

postgres=> 
Enter fullscreen mode Exit fullscreen mode

This shows that only az://'-prefixed are authorized, and that we cannot install the standalone community extension:

postgres=> SELECT * FROM duckdb.query($$
    SELECT extension_name, installed, loaded, description 
    FROM duckdb_extensions()
$$);


ERROR:  (PGDuckDB/Duckdb_ExecCustomScan_Cpp) Permission Error: File system LocalFileSystem has been disabled by configuration

postgres=> SELECT duckdb.raw_query('INSTALL onelake FROM community');

Permission Error: File system LocalFileSystem has been disabled by configuration

Enter fullscreen mode Exit fullscreen mode

Now try the HTTPS path:

postgres=> SELECT *
FROM read_parquet(
  'https://msit-onelake.dfs.fabric.microsoft.com/c8d766ad-bdc3-453e-bb67-0e181d2d14c8/33422e73-88cd-4056-a0fa-8f74baa13ce1/Files/sample_datasets/public_holidays.parquet'
)
LIMIT 3;

ERROR:  (PGDuckDB/CreatePlan) Prepared query returned an error: Permission Error: Cannot access file "https://msit-onelake.dfs.fabric.microsoft.com/c8d766ad-bdc3-453e-bb67-0e181d2d14c8/33422e73-88cd-4056-a0fa-8f74baa13ce1/Files/sample_datasets/public_holidays.parquet" - file system operations are disabled by configuration

Enter fullscreen mode Exit fullscreen mode

And the ABFS path:

postgres=> SELECT *
FROM read_parquet(
  'abfss://c8d766ad-bdc3-453e-bb67-0e181d2d14c8@msit-onelake.dfs.fabric.microsoft.com/33422e73-88cd-4056-a0fa-8f74baa13ce1/Files/sample_datasets/public_holidays.parquet'
)
LIMIT 3;


Permission Error: Cannot access file "..." - file system operations are disabled by configuration
ERROR:  (PGDuckDB/CreatePlan) Prepared query returned an error: Permission Error: Cannot access file "abfss://c8d766ad-bdc3-453e-bb67-0e181d2d14c8@msit-onelake.dfs.fabric.microsoft.com/33422e73-88cd-4056-a0fa-8f74baa13ce1/Files/sample_datasets/public_holidays.parquet

Enter fullscreen mode Exit fullscreen mode

The failure comes from the filesystem allow-list, before the file can be read. An HTTP bearer-token secret does not make the HTTPS path permitted. Attempting to add an HTTPS prefix to the setting also returned:

postgres=> SET duckdb.allowed_directories = 'az://,https://,abfss://';  

ERROR:  permission denied to set parameter "duckdb.allowed_directories"

Enter fullscreen mode Exit fullscreen mode

This confirms the restriction on this managed server, Azure Database for PostgreSQL (Flex). It does not mean that DuckDB generally cannot read HTTPS or ADLS paths, or that OneLake lacks a documented storage interface. OneLake exposes ADLS/Blob-compatible APIs, but a managed service must define some restrictions.

OneLake also exposes a Blob endpoint

The solution is in Microsoft's OneLake API parity documentation. OneLake implements both ADLS and Azure Blob Storage APIs. Its examples include a Blob request with this shape:

HEAD https://onelake.blob.fabric.microsoft.com/myWorkspace/myLakehouse.Lakehouse/Files/file.txt
Enter fullscreen mode Exit fullscreen mode

That is a OneLake endpoint, not a separately provisioned Azure Storage account.

DuckDB's Azure extension accepts fully qualified Blob paths. The endpoint is part of the filename. It is not restricted to blob.core.windows.net. The URL parser separates the account, endpoint, container, and remaining path.

Combining those two interfaces gives the following transformation for my environment:

  • OneLake DFS URL: https://msit-onelake.dfs.fabric.microsoft.com/<workspace-id>/<lakehouse-id>/Files/...

  • Corresponding OneLake Blob URL: https://msit-onelake.blob.fabric.microsoft.com/<workspace-id>/<lakehouse-id>/Files/...

  • DuckDB Azure Blob filename: az://msit-onelake.blob.fabric.microsoft.com/<workspace-id>/<lakehouse-id>/Files/...

Starting from the ABFS path, the workspace before @ becomes the first path segment after the hostname. The lakehouse ID and the rest of the path stay unchanged.

Microsoft's OneLake addressing guide explains the mapping:

  • Logical account: onelake.
  • Container or filesystem: the workspace.
  • Blob name or data path: the item followed by its folders and filename.

Here I use GUIDs for both the workspace and the item. With GUID addressing, there is no .lakehouse suffix on the item ID. With name-based addressing, the item type is part of the name, as in MyLakehouse.lakehouse.

The az:// prefix selects DuckDB's Azure Blob filesystem. Its requests still use HTTPS. It is client-side syntax, not another protocol that OneLake must expose. We are using the permitted filesystem, not changing the server's allow-list.

One detail matters: changing only https:// to az:// while retaining the DFS hostname did not work. With authentication configured, that test returned an SDK error containing map::at. The successful read used the Blob hostname.

Browse the same files with Azure Storage Explorer

This is also what "access OneLake from Azure tools" means: use the compatible storage APIs, not export the data into an Azure Storage account first.

Microsoft documents connecting Azure Storage Explorer to OneLake:

  1. Sign in with the account that has access to the Fabric data.
  2. Open the connect dialog and select ADLS Gen2 container or directory.
  3. Enter the OneLake HTTPS DFS URL for the workspace or lakehouse, then browse its folders.

Storage Explorer can use DFS here because it is not subject to the PostgreSQL server's DuckDB allow-list.

Authentication does not grant access by itself. The identity still needs permission to read the files in Fabric/OneLake, and the tenant must permit access from apps external to Fabric. Azure subscription access alone is not permission to read a Fabric lakehouse.

The PostgreSQL host and the two tokens

There are two connections involved: the client connects to PostgreSQL, then DuckDB, running inside PostgreSQL, accesses OneLake.

The PostgreSQL server hostname is available on the Flexible Server's Overview page in the Azure portal. This Azure CLI command prints it in Command Prompt, PowerShell, or Bash:


az postgres flexible-server show --resource-group "<resource-group>" --name "<flexible-server-name>" --query fullyQualifiedDomainName --output tsv

Enter fullscreen mode Exit fullscreen mode

Connect using your normal PostgreSQL authentication. For the test I used Microsoft Entra authentication. With an authorized Entra database role, the equivalent psql connection in Bash uses a PostgreSQL login token:

pg_host="<server>.postgres.database.azure.com"
PGPASSWORD="$(az account get-access-token \
  --resource-type oss-rdbms \
  --query accessToken --output tsv)" \
psql "host=$pg_host dbname=postgres user=<your-Entra-database-role> sslmode=require"

Enter fullscreen mode Exit fullscreen mode

For OneLake, sign in to the Fabric tenant on the client and request a token for the Storage audience:

az login --tenant "<fabric-tenant-id>"

az account get-access-token --resource "https://storage.azure.com/" --query accessToken --output tsv

Enter fullscreen mode Exit fullscreen mode

Use the tenant containing the Fabric workspace. Its ID is available under Microsoft Entra ID > Properties > Tenant ID in the Azure portal (instructions). If your CLI is already signed in to the correct tenant, another login is unnecessary.

The resource matters: OneLake requires a Storage-audience token.

You can also get it from the cloud shell:

Use the returned value for <STORAGE_ACCESS_TOKEN> below. It is a credential: do not include the real value in published SQL, source control, screenshots, or query logs. An application should pass the secret-creation command through a bound parameter rather than hard-code the token.

Keep the secret across PostgreSQL connections

The Blob examples in the previous post used duckdb.create_azure_secret() with a connection string. On this server that helper accepts a connection string and an optional scope. DuckDB's Azure access_token provider accepts the externally obtained token. A native CREATE SECRET through duckdb.raw_query() works, but that secret belongs to the current backend's DuckDB instance and closing the PostgreSQL connection lose it.

For a demo that can be reopened from psql, I used pg_duckdb's PostgreSQL-backed secret configuration:

postgres=> CREATE SERVER onelake_blob TYPE 'azure'
FOREIGN DATA WRAPPER duckdb
OPTIONS (
    PROVIDER 'access_token',
    ACCOUNT_NAME 'onelake',
    SCOPE 'az://msit-onelake.blob.fabric.microsoft.com/c8d766ad-bdc3-453e-bb67-0e181d2d14c8/33422e73-88cd-4056-a0fa-8f74baa13ce1/Files/'
);

CREATE SERVER

postgres=> CREATE USER MAPPING FOR CURRENT_USER SERVER onelake_blob
OPTIONS (ACCESS_TOKEN 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1N...');

CREATE USER

Enter fullscreen mode Exit fullscreen mode

The test administrator had USAGE on the duckdb foreign data wrapper. Do not assume that every database role has this setup permission, or grant it broadly just to run a read query.

The server stores the non-sensitive configuration. The user mapping stores the token. pg_duckdb loads this metadata into each new backend's DuckDB secrets manager. This use of PostgreSQL's FDW catalogs is credential storage, not SQL federation to Fabric: we still read files with DuckDB's Azure filesystem.

The fully qualified path supplies the endpoint. SCOPE selects the secret for filenames under that prefix. It does not grant access. I scoped it to this lakehouse's Files area so the same secret can match the sample file and the separate export folder.

Now read the file:

postgres=> SELECT *
FROM read_parquet(
    'az://msit-onelake.blob.fabric.microsoft.com/c8d766ad-bdc3-453e-bb67-0e181d2d14c8/33422e73-88cd-4056-a0fa-8f74baa13ce1/Files/sample_datasets/public_holidays.parquet'
)
LIMIT 5;

 countryOrRegion |        holidayName         |    normalizeHolidayName    | isPaidTimeOff | countryRegionCode |        date         
-----------------+----------------------------+----------------------------+---------------+-------------------+---------------------
 Argentina       | Año Nuevo [New Year's Day] | Año Nuevo [New Year's Day] |               | AR                | 1970-01-01 00:00:00
 Australia       | New Year's Day             | New Year's Day             |               | AU                | 1970-01-01 00:00:00
 Austria         | Neujahr                    | Neujahr                    |               | AT                | 1970-01-01 00:00:00
 Belgium         | Nieuwjaarsdag              | Nieuwjaarsdag              |               | BE                | 1970-01-01 00:00:00
 Brazil          | Ano novo                   | Ano novo                   |               | BR                | 1970-01-01 00:00:00
(5 rows)

Enter fullscreen mode Exit fullscreen mode

Without a secret, the initial test returned Unauthorized for this same Blob path. With the token secret, the read succeeded. After configuring the server and user mapping, I disconnected and ran the read from a new psql process: it still worked.

The CLI login happens on the client, while DuckDB runs on the database server. Passing the token explicitly bridges those two environments. It does not assume that the managed server has access to the client's Azure CLI credentials.

Read the data, and look at the execution plan

A successful count(*) is useful, but Parquet can answer it from metadata. To confirm that the file's data can be decoded, I also serialized every row:

postgres=> SELECT *
FROM duckdb.query($duckdb$
SELECT count( * ) AS row_count,
       sum(length(to_json(r))) AS json_characters
FROM read_parquet(
    'az://msit-onelake.blob.fabric.microsoft.com/c8d766ad-bdc3-453e-bb67-0e181d2d14c8/33422e73-88cd-4056-a0fa-8f74baa13ce1/Files/sample_datasets/public_holidays.parquet'
) r
$duckdb$);


 row_count | json_characters 
-----------+-----------------
     69557 |        12527546
(1 row)

Enter fullscreen mode Exit fullscreen mode

The second value counts characters in the JSON serialization. Its purpose here is to make the query consume the rows and their columns, rather than count them from the Parquet footer.

I also downloaded the file through the HTTPS DFS and Blob endpoints with the same Storage token. Both returned 330,368 bytes with identical SHA-256 hashes. The Blob endpoint points to the same OneLake file. No staging copy was created. Those client-side downloads were an independent identity check, not an input to the PostgreSQL query.

An EXPLAIN ANALYZE shows where the data comes from:

QUERY PLAN
-----------------------------------------------------------------------

Custom Scan (DuckDBScan) (cost=0.00..0.00 rows=0 width=0)
  (actual time=0.002..0.003 rows=0.00 loops=1)

DuckDB Execution Plan:

┌──────────────────────────────────────────┐
│       Query Profiling Information        │
└──────────────────────────────────────────┘

EXPLAIN ANALYZE SELECT query.*
FROM system.main.query('
  SELECT
    count(*) AS row_count,
    sum(length(to_json(r))) AS json_characters
  FROM read_parquet(
    ''az://msit-onelake.blob.fabric.microsoft.com/c8d766ad-bdc3-453e-bb67-0e181d2d14c8/33422e73-88cd-4056-a0fa-8f74baa13ce1/Files/sample_datasets/public_holidays.parquet''
  ) r
'::text) query

┌──────────────────────────────────────────┐
│              Total Time: 0.236s          │
└──────────────────────────────────────────┘

┌─────────────────────────────┐
│            QUERY            │
└──────────────┬──────────────┘
               │
┌──────────────┴──────────────┐
│       EXPLAIN_ANALYZE        │
│─────────────────────────────│
│           0 rows            │
│          (0.00s)            │
└──────────────┬──────────────┘
               │
┌──────────────┴──────────────┐
│     UNGROUPED_AGGREGATE      │
│─────────────────────────────│
│ Aggregates:                 │
│ count_star()                │
│ sum(#0)                     │
│                             │
│           1 row             │
│          (0.00s)            │
└──────────────┬──────────────┘
               │
┌──────────────┴──────────────┐
│         PROJECTION          │
│─────────────────────────────│
│ length(CAST(to_json         │
│   (struct_pack              │
│    (countryOrRegion,        │
│     holidayName,            │
│     normalizeHolidayName,   │
│     isPaidTimeOff,          │
│     countryRegionCode,      │
│     date))                  │
│   AS VARCHAR))              │
│                             │
│        69,557 rows          │
│          (0.06s)            │
└──────────────┬──────────────┘
               │
┌──────────────┴──────────────┐
│         TABLE_SCAN          │
│─────────────────────────────│
│ Function:                   │
│ READ_PARQUET                │
│                             │
│ Projections:                │
│   countryOrRegion           │
│   holidayName               │
│   normalizeHolidayName      │
│   isPaidTimeOff             │
│   countryRegionCode         │
│   date                      │
│                             │
│ Total Files Read: 1         │
│                             │
│        69,557 rows          │
│          (0.00s)            │
└─────────────────────────────┘

Planning:
  Buffers: shared hit=1

Planning Time: 140.816 ms
Execution Time: 113.195 ms

(73 rows)

Enter fullscreen mode Exit fullscreen mode

For comparison, with only count(*), DuckDB can get the row count from Parquet metadata without scanning the projected column values: :

QUERY PLAN
-----------------------------------------------------------------------

Custom Scan (DuckDBScan) (cost=0.00..0.00 rows=0 width=0)
  (actual time=0.001..0.002 rows=0.00 loops=1)

DuckDB Execution Plan:

┌──────────────────────────────────────────┐
│       Query Profiling Information        │
└──────────────────────────────────────────┘

EXPLAIN ANALYZE SELECT query.*
FROM system.main.query('
  SELECT
    count(*) AS row_count
    -- , sum(length(to_json(r))) AS json_characters
  FROM read_parquet(
    ''az://msit-onelake.blob.fabric.microsoft.com/c8d766ad-bdc3-453e-bb67-0e181d2d14c8/33422e73-88cd-4056-a0fa-8f74baa13ce1/Files/sample_datasets/public_holidays.parquet''
  ) r
'::text) query

┌──────────────────────────────────────────┐
│              Total Time: 0.112s          │
└──────────────────────────────────────────┘

Planning:
  Buffers: shared hit=1

Planning Time: 133.965 ms
Execution Time: 115.394 ms

(20 rows)
Enter fullscreen mode Exit fullscreen mode

Filter and aggregate

The file is not limited to previewing rows. Here are the 2025 holidays for four countries:

postgres=> SELECT r['countryRegionCode'] AS country_code, count( * ) AS holidays
FROM read_parquet(
  'az://msit-onelake.blob.fabric.microsoft.com/c8d766ad-bdc3-453e-bb67-0e181d2d14c8/33422e73-88cd-4056-a0fa-8f74baa13ce1/Files/sample_datasets/public_holidays.parquet'
) r
WHERE r['countryRegionCode'] IN ('AU', 'DE', 'CH', 'FR')
  AND r['date'] >= DATE '2025-01-01'
  AND r['date'] < DATE '2026-01-01'
GROUP BY r['countryRegionCode']
ORDER BY 1;

 country_code | holidays 
--------------+----------
 AU           |        8
 CH           |        9
 DE           |        9
 FR           |       11
(4 rows)
Enter fullscreen mode Exit fullscreen mode

Join with PostgreSQL and materialize the result

The country selection can be an ordinary PostgreSQL table rather than a list embedded in the query:

postgres=> CREATE SCHEMA demo;


CREATE SCHEMA

postgres=> CREATE TABLE demo.country_selection (
    country_code text PRIMARY KEY,
    country_name text NOT NULL
);

CREATE TABLE

postgres=> INSERT INTO demo.country_selection VALUES
    ('AU', 'Australia'),
    ('BR', 'Brazil'),
    ('CH', 'Switzerland');

INSERT 0 3
Enter fullscreen mode Exit fullscreen mode

Join the local lookup to the OneLake file, and store the selected rows in PostgreSQL:

postgres=> CREATE TABLE demo.holidays_2025 AS
SELECT c.country_name,
       r['countryRegionCode']::text AS country_code,
       r['holidayName']::text AS holiday_name,
       r['date']::date AS holiday_date
FROM demo.country_selection c
JOIN read_parquet(
  'az://msit-onelake.blob.fabric.microsoft.com/c8d766ad-bdc3-453e-bb67-0e181d2d14c8/33422e73-88cd-4056-a0fa-8f74baa13ce1/Files/sample_datasets/public_holidays.parquet'
) r ON r['countryRegionCode'] = c.country_code
WHERE r['date'] >= DATE '2025-01-01'
  AND r['date'] < DATE '2026-01-01'
  ;

SELECT 30
Enter fullscreen mode Exit fullscreen mode

psql reports SELECT 30. This time we intentionally have a local copy: demo.holidays_2025 is a PostgreSQL table containing the selected result. The source file stays in OneLake.

Write the result back to OneLake

Reading worked with this identity. Writing is a separate capability and requires write permission in the lakehouse.

I created a separate folder, Files > pg_duckdb_demo_cb6711ea, for the exports. Create your own output folder in the Lakehouse explorer or Storage Explorer. Do not overwrite the source sample.

Export the PostgreSQL result as Parquet:

postgres=> SELECT duckdb.raw_query($duckdb$
COPY (
    SELECT * FROM pgduckdb.demo.holidays_2025
    ORDER BY country_code, holiday_date, holiday_name
) TO 'az://msit-onelake.blob.fabric.microsoft.com/c8d766ad-bdc3-453e-bb67-0e181d2d14c8/33422e73-88cd-4056-a0fa-8f74baa13ce1/Files/pg_duckdb_demo_cb6711ea/holidays_2025.parquet'
(FORMAT PARQUET)
$duckdb$);

NOTICE:  result: Count
BIGINT
[ Rows: 1]
30


 raw_query 
-----------

(1 row)
Enter fullscreen mode Exit fullscreen mode

The pgduckdb. prefix is DuckDB's catalog for the PostgreSQL tables. Keep SELECT duckdb.raw_query(...) around the native DuckDB COPY: as in the earlier export test, plain PostgreSQL file COPY is a different access path and is restricted on this service. The test login could execute duckdb.raw_query().

The same result can be exported as CSV:

postgres=> SELECT duckdb.raw_query($duckdb$
COPY (
    SELECT * FROM pgduckdb.demo.holidays_2025
    ORDER BY country_code, holiday_date, holiday_name
) TO 'az://msit-onelake.blob.fabric.microsoft.com/c8d766ad-bdc3-453e-bb67-0e181d2d14c8/33422e73-88cd-4056-a0fa-8f74baa13ce1/Files/pg_duckdb_demo_cb6711ea/holidays_2025.csv'
(FORMAT CSV, HEADER true)
$duckdb$);

NOTICE:  result: Count
BIGINT
[ Rows: 1]
30


 raw_query 
-----------

(1 row)
Enter fullscreen mode Exit fullscreen mode

Each COPY reported 30 rows. The files are visible under the lakehouse's Files area, not registered as tables under Tables.

Read both files back from OneLake:

postgres=> SELECT count(*) AS parquet_rows
FROM read_parquet(
  'az://msit-onelake.blob.fabric.microsoft.com/c8d766ad-bdc3-453e-bb67-0e181d2d14c8/33422e73-88cd-4056-a0fa-8f74baa13ce1/Files/pg_duckdb_demo_cb6711ea/holidays_2025.parquet'
);

 parquet_rows 
--------------
           30
(1 row)

postgres=> SELECT count(*) AS csv_rows
FROM read_csv(
  'az://msit-onelake.blob.fabric.microsoft.com/c8d766ad-bdc3-453e-bb67-0e181d2d14c8/33422e73-88cd-4056-a0fa-8f74baa13ce1/Files/pg_duckdb_demo_cb6711ea/holidays_2025.csv',
  header := true
);

 csv_rows 
----------
       30
(1 row)
Enter fullscreen mode Exit fullscreen mode

Both counts are 30.

I also compared the PostgreSQL rows and exported rows in both directions with EXCEPT ALL:

postgres=> SELECT *
FROM duckdb.query($duckdb$
WITH expected AS (
    SELECT * FROM pgduckdb.demo.holidays_2025
), actual AS (
    SELECT * FROM read_parquet(
      'az://msit-onelake.blob.fabric.microsoft.com/c8d766ad-bdc3-453e-bb67-0e181d2d14c8/33422e73-88cd-4056-a0fa-8f74baa13ce1/Files/pg_duckdb_demo_cb6711ea/holidays_2025.parquet'
    )
), differences AS (
    (SELECT * FROM expected EXCEPT ALL SELECT * FROM actual)
    UNION ALL
    (SELECT * FROM actual EXCEPT ALL SELECT * FROM expected)
)
SELECT count(*) AS parquet_differences FROM differences
$duckdb$);

 parquet_differences 
---------------------
                   0
(1 row)
Enter fullscreen mode Exit fullscreen mode

These are whole-file exports, with no in-place row updates to Parquet, Delta transaction-log maintenance, or Iceberg commits.

Persistent configuration is not a permanent token

The SERVER and USER MAPPING survive disconnecting from PostgreSQL. The bearer token still expires, and the Azure access_token provider does not refresh it automatically.

After obtaining a new Storage-audience token, update the mapping:

ALTER USER MAPPING FOR CURRENT_USER
SERVER onelake_blob
OPTIONS (SET ACCESS_TOKEN '<STORAGE_ACCESS_TOKEN>');
Enter fullscreen mode Exit fullscreen mode

pg_duckdb reloads modified secret metadata. A production application still needs an appropriate token lifecycle and secure handling. Storing an expiring token in PostgreSQL does not turn it into a long-lived credential.

What about Fabric HorizonDB and pg_fabric_fdw?

Microsoft Fabric HorizonDB is another option when the application belongs in Fabric. It provides managed PostgreSQL as a Fabric item, with service-managed compute scaling and, where enabled, idle pause and scale to zero. Reconnecting to the same endpoint resumes a paused database. This is the serverless compute model to distinguish from the provisioned Flexible Server used here.

For analytical access, its service-managed pg_fabric_fdw translates eligible PostgreSQL queries into T-SQL and sends them over TDS to a supported Fabric warehouse or SQL analytics endpoint. The foreign tables are read-only.

The two paths are different:

  • This test: Azure Database for PostgreSQL -> pg_duckdb -> Azure Blob API -> OneLake file

  • Fabric HorizonDB federation: PostgreSQL -> pg_fabric_fdw -> Fabric SQL endpoint -> exposed tables

Federation can be useful for joining PostgreSQL rows with tables already exposed through Fabric SQL. It does not make an arbitrary Parquet file under Files into a SQL-endpoint table.

Takeaways

  • DuckDB has an experimental OneLake community extension for richer table integration. This test needed neither that extension nor a Fabric SQL endpoint.
  • On the tested Flexible Server, the original HTTPS and abfss:// paths are blocked by configuration. That remains true even though the file is accessible with valid credentials outside PostgreSQL.
  • OneLake exposes both ADLS and Blob APIs. Use the Blob endpoint with DuckDB's allowed az:// filesystem, keeping the workspace, item, and file path.
  • The tests read Parquet from PostgreSQL, filtered, joined, and exported to Parquet and CSV.
  • PostgreSQL-backed secret metadata works across psql sessions. Its Entra Storage-audience token is separate from PostgreSQL authentication and still needs refreshing.
  • Fabric HorizonDB offers a separate serverless PostgreSQL and SQL-federation route. Here, pg_duckdb reads and writes the actual files through the storage API.

The az:// restriction didn't prevent direct OneLake access. OneLake already exposes a Blob-compatible API, and that API matches the Azure filesystem that managed pg_duckdb allows. PostgreSQL can therefore read and write OneLake files directly, without a Fabric SQL endpoint or an intermediate storage copy.

Top comments (0)