Skip to content

Instantly share code, notes, and snippets.

@jbq
Created August 16, 2011 16:43
Show Gist options
  • Save jbq/1149512 to your computer and use it in GitHub Desktop.
Save jbq/1149512 to your computer and use it in GitHub Desktop.
Test case for PLyMapping_ToTuple issue
CREATE OR REPLACE PROCEDURAL LANGUAGE plpythonu;
CREATE TABLE foo (
id integer not null primary key,
value integer not null
);
CREATE FUNCTION get_foo() RETURNS SETOF foo
LANGUAGE plpythonu
AS $$
r = plpy.execute("select * from foo limit 1 FOR UPDATE")
if len(r) == 0:
return
id = r[0]['id']
r = plpy.execute("update foo SET value = value + 1 WHERE id = %s RETURNING *" % id)
yield r[0]
$$;
COPY foo (id, value) FROM stdin;
1 1
\.
select * from get_foo();
alter table foo drop column value;
alter table foo add column value int;
update foo set value=1;
select * from get_foo();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment