#! /usr/bin/env python print """ drop table foo; drop table codes; drop function check_code(int4, int2); create table codes ( c_table_field int4 not null, code int2 not null, primary key (c_table_field, code) ); insert into codes values (1, 0); create function check_code(int4, int2) returns bool as 'select count(code) = 1 as result from codes where c_table_field = $1 and code = $2 ' language 'sql' with (iscachable); create table foo ( id int4, status int2, t1 text, check (check_code(1, status)) ); COPY foo FROM stdin;""" for i in range(300000): print "%d\t0\t%s" % (i, 'abc0123456789') print "\\."