Skip to content
odbc_fdw

odbc_fdw

odbc_fdw : Foreign data wrapper for accessing remote databases using ODBC

Overview

ID Extension Package Version Category License Language
8520
odbc_fdw
odbc_fdw
0.5.2
FDW
PostgreSQL
C
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
--s-d-r
No
Yes
No
Yes
yes
no
Relationships
See Also
wrappers
multicorn
jdbc_fdw
mysql_fdw
oracle_fdw
tds_fdw
db2_fdw
postgres_fdw

Package/source version 0.6.1; SQL extension version 0.5.2. Live queries require an installed ODBC driver and configured DSN.

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
EXT
MIXED
0.5.2
18
17
16
15
14
odbc_fdw -
RPM
PGDG
0.6.1
18
17
16
15
14
odbc_fdw_$v unixODBC
DEB
PIGSTY
0.6.1
18
17
16
15
14
postgresql-$v-odbc-fdw libodbc2
Linux / PG PG18 PG17 PG16 PG15 PG14
el8.x86_64
PGDG 0.6.1
PGDG 0.6.1
PGDG 0.6.1
PGDG 0.6.1
PGDG 0.6.1
el8.aarch64
PGDG 0.6.1
PGDG 0.6.1
PGDG 0.6.1
PGDG 0.6.1
PGDG 0.6.1
el9.x86_64
PGDG 0.6.1
PGDG 0.6.1
PGDG 0.6.1
PGDG 0.6.1
PGDG 0.6.1
el9.aarch64
PGDG 0.6.1
PGDG 0.6.1
PGDG 0.6.1
PGDG 0.6.1
PGDG 0.6.1
el10.x86_64
PGDG 0.6.1
PGDG 0.6.1
PGDG 0.6.1
PGDG 0.6.1
PGDG 0.6.1
el10.aarch64
PGDG 0.6.1
PGDG 0.6.1
PGDG 0.6.1
PGDG 0.6.1
PGDG 0.6.1
d12.x86_64
PIGSTY 0.6.1
PIGSTY 0.6.1
PIGSTY 0.6.1
PIGSTY 0.6.1
PIGSTY 0.6.1
d12.aarch64
PIGSTY 0.6.1
PIGSTY 0.6.1
PIGSTY 0.6.1
PIGSTY 0.6.1
PIGSTY 0.6.1
d13.x86_64
PIGSTY 0.6.1
PIGSTY 0.6.1
PIGSTY 0.6.1
PIGSTY 0.6.1
PIGSTY 0.6.1
d13.aarch64
PIGSTY 0.6.1
PIGSTY 0.6.1
PIGSTY 0.6.1
PIGSTY 0.6.1
PIGSTY 0.6.1
u22.x86_64
PIGSTY 0.6.1
PIGSTY 0.6.1
PIGSTY 0.6.1
PIGSTY 0.6.1
PIGSTY 0.6.1
u22.aarch64
PIGSTY 0.6.1
PIGSTY 0.6.1
PIGSTY 0.6.1
PIGSTY 0.6.1
PIGSTY 0.6.1
u24.x86_64
PIGSTY 0.6.1
PIGSTY 0.6.1
PIGSTY 0.6.1
PIGSTY 0.6.1
PIGSTY 0.6.1
u24.aarch64
PIGSTY 0.6.1
PIGSTY 0.6.1
PIGSTY 0.6.1
PIGSTY 0.6.1
PIGSTY 0.6.1
u26.x86_64
PIGSTY 0.6.1
PIGSTY 0.6.1
PIGSTY 0.6.1
PIGSTY 0.6.1
PIGSTY 0.6.1
u26.aarch64
PIGSTY 0.6.1
PIGSTY 0.6.1
PIGSTY 0.6.1
PIGSTY 0.6.1
PIGSTY 0.6.1
Package Version OS ORG SIZE File URL
odbc_fdw_18 0.6.1 el8.x86_64 pgdg 28.9 KiB odbc_fdw_18-0.6.1-1PGDG.rhel8.10.x86_64.rpm
odbc_fdw_18 0.6.1 el8.aarch64 pgdg 28.1 KiB odbc_fdw_18-0.6.1-1PGDG.rhel8.10.aarch64.rpm
odbc_fdw_18 0.6.1 el9.x86_64 pgdg 29.0 KiB odbc_fdw_18-0.6.1-1PGDG.rhel9.8.x86_64.rpm
odbc_fdw_18 0.6.1 el9.aarch64 pgdg 28.4 KiB odbc_fdw_18-0.6.1-1PGDG.rhel9.8.aarch64.rpm
odbc_fdw_18 0.6.1 el10.x86_64 pgdg 30.0 KiB odbc_fdw_18-0.6.1-1PGDG.rhel10.2.x86_64.rpm
odbc_fdw_18 0.6.1 el10.aarch64 pgdg 28.8 KiB odbc_fdw_18-0.6.1-1PGDG.rhel10.2.aarch64.rpm
postgresql-18-odbc-fdw 0.6.1 d12.x86_64 pigsty 48.7 KiB postgresql-18-odbc-fdw_0.6.1-1PIGSTY~bookworm_amd64.deb
postgresql-18-odbc-fdw 0.6.1 d12.aarch64 pigsty 47.9 KiB postgresql-18-odbc-fdw_0.6.1-1PIGSTY~bookworm_arm64.deb
postgresql-18-odbc-fdw 0.6.1 d13.x86_64 pigsty 49.0 KiB postgresql-18-odbc-fdw_0.6.1-1PIGSTY~trixie_amd64.deb
postgresql-18-odbc-fdw 0.6.1 d13.aarch64 pigsty 47.8 KiB postgresql-18-odbc-fdw_0.6.1-1PIGSTY~trixie_arm64.deb
postgresql-18-odbc-fdw 0.6.1 u22.x86_64 pigsty 53.1 KiB postgresql-18-odbc-fdw_0.6.1-1PIGSTY~jammy_amd64.deb
postgresql-18-odbc-fdw 0.6.1 u22.aarch64 pigsty 52.5 KiB postgresql-18-odbc-fdw_0.6.1-1PIGSTY~jammy_arm64.deb
postgresql-18-odbc-fdw 0.6.1 u24.x86_64 pigsty 51.1 KiB postgresql-18-odbc-fdw_0.6.1-1PIGSTY~noble_amd64.deb
postgresql-18-odbc-fdw 0.6.1 u24.aarch64 pigsty 50.7 KiB postgresql-18-odbc-fdw_0.6.1-1PIGSTY~noble_arm64.deb
postgresql-18-odbc-fdw 0.6.1 u26.x86_64 pigsty 50.8 KiB postgresql-18-odbc-fdw_0.6.1-1PIGSTY~resolute_amd64.deb
postgresql-18-odbc-fdw 0.6.1 u26.aarch64 pigsty 50.3 KiB postgresql-18-odbc-fdw_0.6.1-1PIGSTY~resolute_arm64.deb

Source

pig build pkg odbc_fdw;		# build deb

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install this extension with pig:

pig install odbc_fdw;		# install via package name, for the active PG version

pig install odbc_fdw -v 18;   # install for PG 18
pig install odbc_fdw -v 17;   # install for PG 17
pig install odbc_fdw -v 16;   # install for PG 16
pig install odbc_fdw -v 15;   # install for PG 15
pig install odbc_fdw -v 14;   # install for PG 14

Create this extension with:

CREATE EXTENSION odbc_fdw;

Usage

Sources:

odbc_fdw exposes tables or driver-specific queries from an ODBC data source as PostgreSQL foreign tables. It is primarily a read/query bridge across heterogeneous systems; validate data-type conversions and remote-driver behavior before relying on it for production queries.

Core Workflow

CREATE EXTENSION odbc_fdw;

-- In 0.6.1 a superuser must set the server-level dsn or driver option.
CREATE SERVER warehouse_odbc
  FOREIGN DATA WRAPPER odbc_fdw
  OPTIONS (dsn 'warehouse');

CREATE USER MAPPING FOR analyst
  SERVER warehouse_odbc
  OPTIONS (odbc_UID 'reporter', odbc_PWD 'secret');

CREATE FOREIGN TABLE remote_customer (
  id bigint,
  name text,
  created_at timestamp
) SERVER warehouse_odbc
  OPTIONS (schema 'sales', table 'customer');

SELECT * FROM remote_customer WHERE id = 42;

Use driver instead of dsn for a DSN-less connection. Other driver attributes use the odbc_ prefix and may be placed on the server, user mapping, or foreign table. Put credentials in a user mapping. Quote case-sensitive attribute names, and wrap values containing = or ; in braces as required by the driver.

Queries and Import

sql_query overrides table; pair it with sql_count when the FDW needs an explicit row-count query:

CREATE FOREIGN TABLE active_customer (
  id bigint,
  name text
) SERVER warehouse_odbc
  OPTIONS (
    sql_query 'SELECT id, name FROM sales.customer WHERE active = 1',
    sql_count 'SELECT count(*) FROM sales.customer WHERE active = 1'
  );

IMPORT FOREIGN SCHEMA sales
  FROM SERVER warehouse_odbc
  INTO imported
  OPTIONS (prefix 'odbc_');

Important Objects and Options

  • dsn or driver selects the ODBC data source; 0.6.1 restricts these server options to superusers because the driver manager loads shared libraries.
  • schema, table, sql_query, and sql_count select the remote relation or query.
  • prefix changes local names created by IMPORT FOREIGN SCHEMA.
  • ODBCTablesList(server_name, ...) lists visible remote tables.
  • ODBCTableSize(server_name, table_name) and ODBCQuerySize(server_name, query) return remote row counts.

Version 0.6.0 restores compatibility and fixes crashes on recent PostgreSQL releases. Version 0.6.1 escapes remote literals and identifiers to prevent SQL injection, restricts driver selection, and redacts common credential attributes in debug connection strings. Upgrade before allowing delegated FDW use, while retaining normal server ownership and user-mapping controls.

Only the ODBC types listed by the upstream README are fully supported. Identifier length, driver SQL dialect, encodings, null handling, and binary values can vary. The source/package release is 0.6.1, while the control file and install SQL continue to declare extension version 0.5.2.

Last updated on