CREATE TABLE foo (
	foo_idx SERIAL PRIMARY KEY,
	foo INTEGER ) ;
CREATE TABLE bar (
	bar_idx SERIAL PRIMARY KEY,
	foo_idx INTEGER REFERENCES foo,
	bar INTEGER ) ;
INSERT INTO foo ( foo ) VALUES ( 111 ) ;
INSERT INTO foo ( foo ) VALUES ( 222 ) ;
INSERT INTO foo ( foo ) VALUES ( 333 ) ;

BEGIN WORK ;
SELECT foo_idx INTO TEMP v_idx FROM foo WHERE foo.foo = 222 ;
INSERT INTO bar ( foo_idx, bar ) VALUES ( v_idx.foo_idx, 888 ) ;
END WORK ;

DROP TABLE foo ;
DROP SEQUENCE foo_foo_idx_seq ;
DROP TABLE bar ;
DROP SEQUENCE bar_bar_idx_seq ;
