20.
PL/pgSQL
CREATE OR REPLACE FUNCTION fnc_test() RETURNS int AS $$
DECLARE
cs CURSOR FOR SELECT * FROM t_test;
rec record;
dum char;
BEGIN
OPEN cs;
LOOP
FETCH cs INTO rec;
IF NOT FOUND THEN
EXIT;
END IF;
RAISE NOTICE 'record is %', rec;
END LOOP;
CLOSE cs;
RETURN 0;
END;
$$ LANGUAGE plpgsql;
21.
PL/pgSQL
CREATE OR REPLACE FUNCTION fnc_test() RETURNS int AS $$
DECLARE
cs CURSOR FOR SELECT * FROM t_test;
rec record;
dum char;
BEGIN
OPEN cs;
LOOP
FETCH cs INTO rec;
IF NOT FOUND THEN
EXIT;
END IF;
RAISE NOTICE 'record is %', rec;
END LOOP;
CLOSE cs;
RETURN 0;
END;
$$ LANGUAGE plpgsql;
ループのスコープがわかりにくい
22.
PL/pgSQL
CREATE OR REPLACE FUNCTION fnc_test() RETURNS int AS $$
DECLARE
cs CURSOR FOR SELECT * FROM t_test;
rec record;
dum char;
BEGIN
OPEN cs;
LOOP
FETCH cs INTO rec;
IF NOT FOUND THEN
EXIT;
END IF;
RAISE NOTICE 'record is %', rec;
END LOOP;
CLOSE cs;
RETURN 0;
END;
$$ LANGUAGE plpgsql;
ループのスコープがわかりにくい
IFが直感的ではない
26.
PL/Python
CREATE OR REPLACE FUNCTION fnc_test()
RETURNS SETOF int AS $$
import plpy
cs = plpy.execute("SELECT * FROM t_test")
for record in cs:
yield record['text']
$$ LANGUAGE plpython2u;
27.
PL/Python
CREATE OR REPLACE FUNCTION fnc_test()
RETURNS SETOF int AS $$
import plpy
cs = plpy.execute("SELECT * FROM t_test")
for record in cs:
yield record['text']
$$ LANGUAGE plpython2u;
もちろんPython3も使える
28.
PL/Python
CREATE OR REPLACE FUNCTION fnc_test()
RETURNS SETOF int AS $$
import plpy
cs = plpy.execute("SELECT * FROM t_test")
for record in cs:
yield record['text']
$$ LANGUAGE plpython2u;
もちろんPython3も使える
既存のLibraryを再利用できる
Clipping is a handy way to collect and organize the most important slides from a presentation. You can keep your great finds in clipboards organized around topics.
Be the first to comment