2017-05-30 55 views
0

有沒有辦法從PostgreSQL數據庫中的SQL腳本運行以下命令行語句?從SQL腳本調用.exe

raster2pgsql -s 4326 -I -C -M D:\postgresql\data\input.tif -F -t 100x100 public.demelevation > output.sql 

我發現了一些有前途的微軟SQL服務器here,但我無法找到PostgreSQL的類似的東西。

+0

有一個['plsh'語言處理(https://github.com/petere/plsh)基於UNIX OS-ES,但是,我不知道如果這可以在Windows上工作。無論如何,有幾個「不可信」的[語言變體](https://www.postgresql.org/docs/current/static/xplang.html)(即使對於contrib模塊),理論上它可以調用系統命令(例如' pltclu',['plperlu'](https://www.postgresql.org/docs/current/static/plperl-trusted.html)和['plpythonu'](https://www.postgresql.org/docs/ current/static/plpython.html)) – pozs

+0

如果.exe位於運行'psql'的同一臺計算機上,則可以使用SQL語句內的'\!'運行外部程序。 –

回答

1

you can useCOPY。想想如果從psql調用programm是個好主意。你也需要超級用戶權限。

例子:

t=# create table c (t text); 
t=# copy (select 1) to program $$echo "whatever" -v >/tmp/12$$; 
COPY 1 
t=# copy c from program 'echo "whatever" -v'; 
COPY 1 
t=# select * from c; 
     t 
------------- 
whatever -v 
(1 row) 

Time: 0.380 ms 
t=# !\ cat /tmp/12 
Invalid command \. Try \? for help. 
t-# \! cat /tmp/12 
whatever -v