How can I define external API function in Postgresql? -
in project, need add external api function, example:
select c.name c,s checkresult(c.name); the function checkresults () returns ture or false, , in function need call thirty party api function. how can achieve in postgresql? thanks.
there 2 ways this.
one use procedure language. can use language want after installing language in question:
http://www.postgresql.org/docs/current/static/sql-createlanguage.html
postgres typically compiled perl , python languages. after installing e.g. plerlu (since need remote access functions), do:
create function funcname (argument-types) returns return-type $$ # pl/perl function body $$ language plperlu; http://www.postgresql.org/docs/current/interactive/plperl-funcs.html
the other way use foreign data wrapper:
http://wiki.postgresql.org/wiki/foreign_data_wrappers
these need(ed?) written in c. there multiple examples in above-referenced page. example pulls third party api, see twitter fdw instance:
select from_user, created_at, text twitter q = '#postgresql'; http://pgxn.org/dist/twitter_fdw/
https://github.com/umitanuki/twitter_fdw (so breaks link encoding _)
for more generic one, see www fdw:
select * www_fdw_geocoder_google address='1600 amphitheatre parkway,mountain view, ca'; https://github.com/cyga/www_fdw/ (so breaks link encoding _)
Comments
Post a Comment