官术网_书友最值得收藏!

Connecting to SQL Server Spatial

First we need to create a server:

CREATE SERVER fdw_sqlserver_test 
FOREIGN DATA WRAPPER ogr_fdw
OPTIONS (
datasource 'MSSQL:server=CM_DOM\MSSQLSERVER12;database=hgis;UID=postgres_fdw;PWD=postgres_fdw',
format 'MSSQLSpatial');
You may have noticed I have created a postgres_fdw user with the same password.

If you're using Postgre SQL 9.5+, you can use the IMPORT SCHEMA command:

IMPORT FOREIGN SCHEMA "dbo.Wig100_skorowidz" 
FROM SERVER fdw_sqlserver_test INTO data_linked;

Otherwise you will have to specify the table schema explicitly:

CREATE FOREIGN TABLE data_linked.dbo_wig100_skorowidz 
(fid integer ,
geom public.geometry ,
oid integer ,
gid integer ,
version integer ,
godlo character varying ,
nazwa character varying ,
nazwa2 character varying ,
kalibracja character varying ,
pas real ,
slup real )
SERVER fdw_sqlserver_test
OPTIONS (layer 'dbo.Wig100_skorowidz');
By default, PgAdmin does not display foreign tables, so you may have to go to File | Options and tick the Foreign Tables checkbox in the Browser node. In PgAdmin 4, foreign tables seem to be visible by default.

At this stage, you should be able to query the foreign table as if it was local.

主站蜘蛛池模板: 包头市| 赤城县| 神农架林区| 嘉善县| 右玉县| 南开区| 简阳市| 安溪县| 沁阳市| 秀山| 文登市| 陈巴尔虎旗| 天峻县| 虹口区| 保靖县| 略阳县| 如东县| 剑川县| 鸡东县| 丹凤县| 五常市| 确山县| 独山县| 观塘区| 金山区| 普兰店市| 贺兰县| 高陵县| 永年县| 高碑店市| 泰州市| 淄博市| 九江市| 全椒县| 安福县| 广德县| 微山县| 忻州市| 桦南县| 广灵县| 宜兰市|