-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmysql_fdw.sql
More file actions
23 lines (18 loc) · 916 Bytes
/
Copy pathmysql_fdw.sql
File metadata and controls
23 lines (18 loc) · 916 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
-- =============================================================================
-- Example: mysql_fdw (query a MySQL / MariaDB server)
-- =============================================================================
CREATE SERVER IF NOT EXISTS remote_mysql
FOREIGN DATA WRAPPER mysql_fdw
OPTIONS (host 'remote-mysql.example.com', port '3306');
CREATE USER MAPPING IF NOT EXISTS FOR CURRENT_USER
SERVER remote_mysql
OPTIONS (username 'mysql_user', password 'mysql_password');
-- Declare a foreign table mapping a MySQL table.
-- CREATE FOREIGN TABLE mysql_orders (
-- id int,
-- total numeric(12,2),
-- status varchar(32)
-- ) SERVER remote_mysql OPTIONS (dbname 'shop', table_name 'orders');
-- SELECT * FROM mysql_orders WHERE status = 'paid' LIMIT 10;
-- Tip: mysql_fdw supports IMPORT FOREIGN SCHEMA too:
-- IMPORT FOREIGN SCHEMA shop FROM SERVER remote_mysql INTO public;