Skip to content
This repository
tree: fb0710c73f
Alex Sudakov November 01, 2011
file 27 lines (27 sloc) 1.131 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
DROP EXTENSION IF EXISTS www_fdw CASCADE;
CREATE EXTENSION www_fdw;
CREATE SERVER www_fdw_server_test FOREIGN DATA WRAPPER www_fdw OPTIONS (uri 'http://localhost:7777', response_type 'xml', response_deserialize_callback 'test_response_deserialize_callback');
CREATE USER MAPPING FOR current_user SERVER www_fdw_server_test;
CREATE FOREIGN TABLE www_fdw_test (
title text,
link text,
snippet text
) SERVER www_fdw_server_test;
CREATE OR REPLACE FUNCTION test_response_deserialize_callback(options WWWFdwOptions, response xml) RETURNS SETOF www_fdw_test AS $$
DECLARE
rows RECORD;
title text;
link text;
snippet text;
r RECORD;
BEGIN
RAISE DEBUG 'options parameter: %', options;
RAISE DEBUG 'response parameter: %', response;
FOR rows IN SELECT unnest(xpath('/doc/rows/row', response)) LOOP
title := (xpath('/row/title/text()', rows.unnest))[1];
link := (xpath('/row/link/text()', rows.unnest))[1];
snippet := (xpath('/row/snippet/text()', rows.unnest))[1];
r := ROW(title, link, snippet);
RETURN NEXT r;
END LOOP;
END; $$ LANGUAGE PLPGSQL;
Something went wrong with that request. Please try again.