2017-05-30 92 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