FOREIGN DATA WRAPPER (FDW)
FOREIGN DATA WRAPPER (FDW) is a SQL statement in the PostgreSQL Specific category. PostgreSQL: connects to external data sources (other databases, CSV files, APIs) as if they were local tables. The syntax is CREATE FOREIGN TABLE local_name ... SERVER remote_server OPTIONS (...);. It returns foreign table. A typical example: CREATE EXTENSION postgres_fdw; CREATE SERVER remote_pg FOREIGN DATA WRAPPER postgres_fdw OPTIONS (host '10.0.0.5', dbname 'sales', port '5432'); CREATE USER MAPPING FOR current_user SERVER remote_pg OPTIONS (user 'readonly', password 'secret'); CREATE FOREIGN TABLE remote_orders ( id INT, product TEXT, amount DECIMAL ) SERVER remote_pg OPTIONS (schema_name 'public', table_name 'orders'); -- Now query remote data as local: SELECT * FROM remote_orders; A close relative is SERIAL, which postgreSQL auto-increment type. Creates an INTEGER column with a sequence. Equivalent to AUTO_INCREMENT in MySQL. A close relative is RETURNING, which postgreSQL extension that returns values from INSERT/UPDATE/DELETE statements (like OUTPUT in SQL Server).