Stored procedure out parameter types
lewis.watson Jun 9, 2014 10:54 AMHello All,
I have a simple PostgreSQL stored procedure called delete_case which deletes rows from a table based on a primary key
CREATE OR REPLACE FUNCTION delete_case(integer) RETURNS void AS $BODY$DELETE FROM cases WHERE id=$1 $BODY$ LANGUAGE sql VOLATILE COST 100; ALTER FUNCTION delete_case(integer) OWNER TO postgres;
I can import into Teiid Designer easily enough. Note: "RETURNS void" has been interpreted as "returnValue: object"
I then wrap the source model in a view model
With the following transformation procedure
BEGIN SELECT Cases1.delete_case.returnValue FROM Cases1.delete_case WHERE Cases1.delete_case.id = Cases1_view.delete_case.id; END
However, when I preview the procedure I get the following errors:
SQL Results:
TEIID30504 Remote org.teiid.core.TeiidProcessingException: TEIID30504 Cases1: TEIID11004 Error executing statement(s): {?= call "public"."delete_case"(?)}
Server Console:
15:21:03,934 INFO [org.teiid.CONNECTOR] (Worker24_QueryProcessorQueue108) PostgreSQLExecutionFactory Commit=true;DatabaseProductName=PostgreSQL;DatabaseProductVersion=9.3.4;DriverMajorVersion=9;DriverMajorVersion=3;DriverName=PostgreSQL Native Driver;DriverVersion=PostgreSQL 9.3 JDBC4.1 (build 1101);IsolationLevel=2 15:21:03,958 WARN [org.teiid.CONNECTOR] (Worker24_QueryProcessorQueue108) Connector worker process failed for atomic-request=Ro8OcSrf7oSC.0.3.28: org.teiid.translator.TranslatorException: TEIID11004 Error executing statement(s): {?= call "public"."delete_case"(?)} at org.teiid.translator.jdbc.JDBCProcedureExecution.execute(JDBCProcedureExecution.java:70) at org.teiid.dqp.internal.datamgr.ConnectorWorkItem.execute(ConnectorWorkItem.java:312) [teiid-engine-8.4.1-redhat-7.jar:8.4.1-redhat-7] at org.teiid.dqp.internal.process.DataTierTupleSource.getResults(DataTierTupleSource.java:301) [teiid-engine-8.4.1-redhat-7.jar:8.4.1-redhat-7] at org.teiid.dqp.internal.process.DataTierTupleSource$1.call(DataTierTupleSource.java:113) [teiid-engine-8.4.1-redhat-7.jar:8.4.1-redhat-7] at org.teiid.dqp.internal.process.DataTierTupleSource$1.call(DataTierTupleSource.java:110) [teiid-engine-8.4.1-redhat-7.jar:8.4.1-redhat-7] at java.util.concurrent.FutureTask.run(FutureTask.java:262) [rt.jar:1.7.0_60] at org.teiid.dqp.internal.process.FutureWork.run(FutureWork.java:58) [teiid-engine-8.4.1-redhat-7.jar:8.4.1-redhat-7] at org.teiid.dqp.internal.process.DQPWorkContext.runInContext(DQPWorkContext.java:269) [teiid-engine-8.4.1-redhat-7.jar:8.4.1-redhat-7] at org.teiid.dqp.internal.process.ThreadReuseExecutor$RunnableWrapper.run(ThreadReuseExecutor.java:119) [teiid-engine-8.4.1-redhat-7.jar:8.4.1-redhat-7] at org.teiid.dqp.internal.process.ThreadReuseExecutor$3.run(ThreadReuseExecutor.java:214) [teiid-engine-8.4.1-redhat-7.jar:8.4.1-redhat-7] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_60] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_60] at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_60] Caused by: org.postgresql.util.PSQLException: A CallableStatement function was executed and the out parameter 1 was of type java.sql.Types=1111 however type java.sql.Types=2000 was registered. at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:468) at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:410) at org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.execute(WrappedPreparedStatement.java:404) at org.teiid.translator.jdbc.JDBCExecutionFactory.executeStoredProcedure(JDBCExecutionFactory.java:787) at org.teiid.translator.jdbc.JDBCProcedureExecution.execute(JDBCProcedureExecution.java:67) ... 12 more 15:21:03,961 WARN [org.teiid.PROCESSOR] (Worker23_QueryProcessorQueue109) TEIID30020 Processing exception for request Ro8OcSrf7oSC.0 'TEIID30504 Cases1: TEIID11004 Error executing statement(s): {?= call "public"."delete_case"(?)}'. Originally TeiidProcessingException 'A CallableStatement function was executed and the out parameter 1 was of type java.sql.Types=1111 however type java.sql.Types=2000 was registered.' AbstractJdbc2Statement.java:468. Enable more detailed logging to see the entire stacktrace
From what I can gather from the error the procedure is returning a value of type java.sql.Types=1111 (aka OTHER) whereas it was expecting java.sql.Types=2000 (aka JAVA_OBJECT). The PostgreSQL delete_case is returning void so I'm not sure why a return parameter is there in the first place. I've tried removing the parameter from both the source and the view model but then Teiid produces a "TEIID30492 Command must project at least one symbol " error. All I really want the virtual procedure to do is call the underlying PostgreSQL procedure and report any errors.
I've had a look at the procedure argument settings for both the view and the source models but nothing I've tried so far gets round the error. Am I on the right track or am I going about this in the wrong way?
My eventual goal with this is to create a model view table called "cases" which will have SELECT, INSERT, UPDATE, DELETE procedures that call appropriate PostgreSQL stored procedures.
Regards
Lewis