PROBLEM:
I'm having issues with a function that I've created in Postgres (9.1) with plpgsql language. I'm coming from the world of SQL Server, so there's a bit of a language gap here.
My problem is that postgres doesn't seem to be assigning the parameters I'm passing in correctly.
Here's my function definition:
CREATE OR REPLACE FUNCTION func1 (
IN param1 character varying,
IN param2 character varying DEFAULT NULL::character varying,
IN param3 int DEFAULT NULL::int)
RETURNS void
AS $$
BEGIN
INSERT INTO table1
(
col1
, col2
, col3
)
VALUES
(
$1
, $2
, $3
)
END;
$$ LANGUAGE plpgsql;
The function itself works fine while testing in the database environment, but I'm currently trying to call it from C++ via ODBC connection.
Here's where I set the parameters:
pCmd->paramIn( "param1", (char *)name.getString().c_str() );
pCmd->paramIn( "param3", 100 );
In this case, I have not assigned param2 to any value. It's nullable - shouldn't be a problem.
The error I'm getting is:
ERROR: function func1(unknown, integer) does not exist;
From what I can see, the call is trying to assign the parameters in order, ignoring the parameter names.
QUESTION:
1 - How can I call this function to make this work? Do I have to pass "NULL" in as the missing parameters, and make sure that they're all in order?
2 - If I'm using an ODBC connection, which I most certainly am, should I call a SQL language function which, in turn, calls a PLPGSQL function? It's a bit convoluted, but I'd be open to trying it.
3 - (not a question) Please don't suggest, "Don't use ODBC." Also, please don't try changing the innards of the function, unless necessary. My primary concern right now is learning how to make a function call in postgres via ODBC.
Thank you all in advance for taking the time to read this, and a big thanks to anyone who answers.
UPDATE:
Here's the DboCommand:
DboCommand *cmd;
cmd = new DboCommand(dbConnection, "{call func1 (?) (?)}");
Which used to be this
cmd = new DboCommand(dbConnection, "func1");
Now, the error is:
the # of binded parameters < the # of parameter markers