I am experiencing unexpected behaviour on Postgres 9.0.4 using pl/pgsql relating to selecting from a function that returns a ROWTYPE into a ROWTYPE variable from within another function. In the example below I:
- Create a table, TESTTABLE and insert a row.
- Create a function FN_TEST_GET_ROW that returns a row of ROWTYPE TESTTABLE based on selection of a single row from TESTTABLE
- Create a test harness in the form of a function TESTX that calls FN_TEST_GET_ROW with ID=1
- Call the test harness
The error shown below is returned unexpectedly ERROR: invalid input syntax for integer: "(1,Fred)"
我只想把价值(1,Fred)归还,如果我执行的话,那就会出现这种情况。
SELECT fn_test_get_row(1);
directly.
编制表格:
CREATE TABLE testtable
(
id INTEGER,
name VARCHAR(10)
);
增加数据:
INSERT INTO testtable (id, name) VALUES (1, Fred );
建立职能:
CREATE OR REPLACE FUNCTION fn_test_get_row(a INTEGER)
RETURNS testtable AS $$
DECLARE
i_row testtable;
BEGIN
SELECT *
INTO i_row
FROM testtable
WHERE id = a;
-- Success
RETURN i_row;
END;
$$ LANGUAGE plpgsql;
建立测试功能:
CREATE OR REPLACE FUNCTION testx()
RETURNS testtable AS $$
DECLARE
i_row testtable;
BEGIN
SELECT fn_test_get_row(1)
INTO i_row;
-- Success
RETURN i_row;
END;
$$ LANGUAGE plpgsql;
Execute the test function:
select testx();
送回:
ERROR: invalid input syntax for integer: "(1,Fred)"
CONTEXT: PL/pgSQL function "testx" line 8 at SQL statement
********** Error **********
ERROR: invalid input syntax for integer: "(1,Fred)"
SQL state: 22P02
Context: PL/pgSQL function "testx" line 8 at SQL statement