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.6.1 | 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.6.1 | 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 |
Source
pig build pkg odbc_fdw; # build debInstall
Make sure PGDG and PIGSTY repo available:
pig repo add pgsql -u # add both repo and update cacheInstall 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 14Create this extension with:
CREATE EXTENSION odbc_fdw;Usage
odbc_fdw: Foreign data wrapper for accessing remote databases using ODBC
Create Server
Connect using a DSN defined in your ODBC configuration:
CREATE EXTENSION odbc_fdw;
CREATE SERVER odbc_server
FOREIGN DATA WRAPPER odbc_fdw
OPTIONS (dsn 'test');Or specify connection attributes directly without a DSN:
CREATE SERVER odbc_server
FOREIGN DATA WRAPPER odbc_fdw
OPTIONS (
odbc_DRIVER 'MySQL',
odbc_SERVER '192.168.1.17',
encoding 'iso88591'
);Server Options: dsn (ODBC data source name), driver (ODBC driver name, required if no DSN), odbc_* (driver-specific attributes), encoding (remote database character encoding).
Prefix driver-specific options with odbc_. Attributes DSN, DRIVER, UID, and PWD are automatically uppercased.
Create User Mapping
CREATE USER MAPPING FOR postgres
SERVER odbc_server
OPTIONS (odbc_UID 'root', odbc_PWD '');Create Foreign Table
CREATE FOREIGN TABLE odbc_table (
id integer,
name varchar(255),
description text,
users float4,
created timestamp
)
SERVER odbc_server
OPTIONS (
odbc_DATABASE 'mydb',
schema 'test',
sql_query 'SELECT id, name, description, created, users FROM test.mytable',
sql_count 'SELECT count(id) FROM test.mytable'
);
SELECT * FROM odbc_table;Table Options: schema (remote schema), table (remote table name), sql_query (custom SQL query, overrides table), sql_count (custom count SQL).
Import Foreign Schema
IMPORT FOREIGN SCHEMA test
FROM SERVER odbc_server
INTO public
OPTIONS (odbc_DATABASE 'mydb');