tds connection to mssql

This commit is contained in:
Paul Trowbridge 2023-08-22 20:06:56 +00:00
parent 8e8c7a4392
commit 1504fdb24c
1 changed files with 52 additions and 0 deletions

52
tds.md Normal file
View File

@ -0,0 +1,52 @@
install tds on ubuntu to connect to mssql from pgsql
https://github.com/tds-fdw/tds_fdw/blob/master/InstallUbuntu.md
copy and build tds_fdw:
```
export TDS_FDW_VERSION="2.0.3"
sudo apt-get install wget
wget https://github.com/tds-fdw/tds_fdw/archive/v${TDS_FDW_VERSION}.tar.gz
tar -xvzf v${TDS_FDW_VERSION}.tar.gz
cd tds_fdw-${TDS_FDW_VERSION}/
sudo chown ptrowbridge:ptrowbridge -R tds_fdw-2.0.3/
make USE_PGXS=1
sudo make USE_PGXS=1 install
```
create extension in postgres:
`CREATE EXTENSION tds_fdw;`
create foreign server:
```
CREATE SERVER mssql_svr
FOREIGN DATA WRAPPER tds_fdw
OPTIONS (servername '127.0.0.1', port '1433', database 'tds_fdw_test', tds_version '7.1');
```
`create server usmidsql01 foreign data wrapper tds_fdw options (servername 'usmidsql01', port '1433', database 'fanalysis', tds_version '7.1');`
create user mapping:
`CREATE USER MAPPING FOR ptrowbridge SERVER usmidsql01 OPTIONS (username 'Pricing', password '');`
to extract the schema into a single table that describes the schema do:
`IMPORT FOREIGN SCHEMA dbo FROM SERVER usmidsql01 INTO pricequote_dbo;`
and this will create a table call pricequote_dbo."UNCONTRAINED_COLUMNS"
create foreign table:
```
CREATE FOREIGN TABLE pricequote.pl (
quote integer
,billto text
,shipto text
,cdate timestamp
,value numeric(18,9)
,title text
,descr text
,comment text
,url text
,srce text
)
SERVER usmidsql01 OPTIONS (table_name 'fanalysis.rlarp.pl')
```