CREATE OR REPLACE FUNCTION insert_turn (
  integer,   -- testid
  time,      -- elapsedtime
  integer,   -- holeposition
  integer    -- blockid
) RETURNS integer AS $$
DECLARE
  par_testid       ALIAS FOR $1;
  par_elapsedtime  ALIAS FOR $2;
  par_holeposition ALIAS FOR $3;
  par_blockid      ALIAS FOR $4;

  var_turnid       integer;
BEGIN
  INSERT INTO tbl_turn (
    testid,
    elapsedtime,
    holeposition,
    blockid
  ) VALUES (
    par_testid,
    par_elapsedtime,
    par_holeposition,
    par_blockid
  );

  SELECT INTO var_turnid seq_turn.last_value;

  RETURN var_turnid;
END;
$$ LANGUAGE plpgsql;