Postgres calling function throwing error when executed through ssis execute sql task - ssis-2012

I am trying to call this function through execute sql task. But getting this error
select spf (?,?,?,?,?,?,?)
[Execute SQL Task] Error: Executing the query " select spf (?,?,?,?,?,?,?)" failed with the following error: "ERROR [42883] ERROR: function spf(unknown, unknown, unknown, bigint, bigint, bigint, unknown) does not exist;
Error while executing the query". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
direct call from postgresql pgadmin is working, which means it's able to insert the values using the below command.
select spf ('POSTG-I0001','2019-02-16 00:00:34','2019-02-16 00:00:00',3,3,3,'Success')
adding schema name already tried.
create or replace function spf (varchar(100),varchar(50),varchar(50),integer,int,int,varchar(50))
RETURNS Table (
splog_interfaceid varchar(100),
splog_starttime varchar(50),
splog_endtime varchar(50),
splog_deliveredrowcount integer,
splog_processedrowcount int,
splog_sourcerowcount int,
splog_jobstatus varchar(50)
) As $$
Begin
insert into public.splog (interfaceid,starttime,endtime,deliveredrowcount,processedrowcount,sourcerowcount,jobstatus) values ($1,$2,$3,$4,$5,$6,$7);
Return Query Select * from splog;
END; $$

Related

Teradata - SQLSTATE equivalent in Big Query

I'm trying to find a equivalent to the below queries in BIGQUERY.
We are working on a Teradata to Big Query conversion. We want to know the equivalent query or how to write in big query.
DECLARE a CONDITION FOR SQLSTATE '50000';
DECLARE b CONDITION FOR SQLSTATE '50001';
DECLARE EXIT HANDLER
FOR a , b
INSERT INTO Proc_Error ('50000 & 50001',
'updateSalesData', 'CONDITION HANDLER');
DECLARE EXIT HANDLER
FOR NOT FOUND
INSERT INTO Proc_Error ('NOT FOUND',
'updateSalesData', 'Generic no data found handler performed');
DECLARE EXIT HANDLER
FOR SQLWARNING
INSERT INTO Proc_Error ('SQLWARNING',
'updateSalesData', 'Generic exit warning handler performed');
DECLARE EXIT HANDLER
FOR SQLEXCEPTION
INSERT INTO Proc_Error ('SQLEXCEPTION',
'updateSalesData', 'Generic exit handler performed');
DECLARE CONTINUE HANDLER
FOR SQLEXCEPTION
INSERT INTO Proc_Error ('SQLEXCEPTION',
'updateSalesData', 'Generic continue handler performed');

how to get the output of a stored procedure as task output in snowflake

I created a stored procedure where it returns the string with a successful message and the number of rows inserted or error messages like file not found or data did not load when executed manually. when I called the same stored procedure with task it shows(task_history) as succeed. and cant find if the data has been loaded or not. it has to be checked manually.
when I referred the following question Snowflake a working procedure is not being successfully executed when calling it within a scheduled task
the procedure and the task has the same owner(owner has global execute task privilege).
but data is being updated both the times during manual and task call of procedure.
how to make the return value appear in task and make the task not executing the successor task if the stored procedure return a error.
You can use SYSTEM$SET_RETURN_VALUE to set a return value in you first task.
In a tree of tasks, a task can call this function to set a return value. Another task that identifies this task as the predecessor task (using the AFTER keyword in the task definition) can retrieve the return value set by the predecessor task.
You can then use SYSTEM$GET_PREDECESSOR_RETURN_VALUE in your next task to condition your actions (for example doing nothing if the return_value contains an error).
The return value will appear for monitoring in TASK_HISTORY.
There are 2 parts to get the return value from stored procedure to save to task history.
The stored procedure should "EXECUTE AS CALLER"
You need to call system$set_return_value with the return value
Example
CREATE OR REPLACE PROCEDURE MySchema.MyStoredProcedure()
RETURNS VARIANT
LANGUAGE JAVASCRIPT
EXECUTE AS CALLER
AS $$
let command1 = = `DELETE FROM MySchema.MyTable WHERE rownum > 10;`;
let stmt1 = snowflake.createStatement({sqlText: command1});
let rs = stmt1.execute();
rs.next();
let deleted = rs.getColumnValue(1);
//This requires the SP to be run as CALLER - This return value is logged in Task History
stmt1 = snowflake.createStatement({sqlText:`call system$set_return_value(' { "RowsDeleted": ${deleted} }');`});
rs = stmt1.execute();
return { "RowsDeleted": deleted };
$$;

Error: Incorrect syntax near '#variable' in stored procedure in azure sql database

I am trying to create a stored procedure with parameters in an Azure SQL Database - Basic Managed Instance, through the Query Editor.
Any time I make reference to any parameter, I get a syntax error, independently of the rest of the SQL code.
I have been successful creating stored procedures without parameters.
Even the simplest code leads to an error:
CREATE PROCEDURE testProcedure
#masterPassword varchar(50)
AS
BEGIN
OPEN MASTER KEY DECRYPTION BY PASSWORD = #masterPassword;
END
I would not expect any errors. However, I still receive this error:
Failed to execute query. Error: Incorrect syntax near '#masterPassword'.
Try this -
CREATE OR ALTER PROCEDURE testProcedure
#masterPassword varchar(50)
AS
BEGIN
DECLARE #SELECT NVARCHAR(MAX);
SELECT #SELECT=N'OPEN MASTER KEY DECRYPTION BY PASSWORD = ''' + #masterPassword + ''' '; --Expecting String
EXEC (#SELECT);
END
--UNIT TESTING-
--error
select ''' + #in + '''
--corrected method
declare #a nvarchar(50),#in varchar(50);
set #in=cast('hi' as varchar(50));
select #a=' select ''' + #in + ''' ';
exec (#a)

How can I use Firebird's Execute Block with Delphi TSQLQuery?

Using dbExpress TSQLQuery, I can't execute a query with execute block command because that command requires ? notation for parameters, and Delphi uses : for parameters, then, if in the body of that block creates variables and uses them as
select data from table where .... into :var;
that ":var" is interpreted as a parameter by TSQLQuery.
Which is the way for executing an execute block statement with Delphi?
If I write:
execute block(param1 char(1)=:param1)
I can load a value for :param1 from Delphi, but when I execute it with Query.Open or Query.ExecSQL an error returns indicating absence of parameter so ? because in Firebird execute block is written:
execute block(param1 char(1)=?param1)
Is there any way to resolve this with TSQLQuery?
first you can disable the TSQLQuery property for
ParamCheck := False;
Then at the beginning of execute block, remove the parameter path..
execute block (param1 char (1) = :param1)
and your query is passed (%s) instead of :param1.
I did so in my problem and solved it !
":var" is interpreted as a parameter by TSQLQuery
You can turn that off by setting the ParamCheck property to False.
the only way that worked for me was not putting ":" for internal vars in the block.
Ex. select data from table into var; and that's work!, then, as this is a block, evaluate the var with an if!
if (var = 1)
do something;
else
do anotherthing;
and resolved business!

Handling error from one stored procedure into another in Sybase ASE 15.0

I need to execute a password reset on a Sybase ASE dataserver based on certain conditions:
if validations_here
begin
exec sp_password 'sso_passw', 'new_passw', #userid
end
sp_password might raise some errors, e.g. 10316 - "New password supplied is the same as the previous password". Although I couldn't find any documentation, I think they shouldn't be fatal errors and it should be possible to emulate them with raiserror.
Since it would be easier for the caller to handle it that way, I would like to get the error code and return it as part of a resultset, so I thought about SELECTing ##error. My code is as follows (I transcribed only those parts I think are relevant to the problem):
create procedure sp_desbloc_blanqueo_usr
#userid sysname,
#sso_pass varchar(20),
#new_pass varchar(20)
as
begin
declare #ret_code int
declare #ret_msg varchar(100)
declare #myerror int
select #ret_code = 0, #ret_msg = 'OK'
exec sp_password #sso_pass, #new_pass, #userid
set #myerror = ##error
if #myerror <> 0
begin
select #ret_code = #myerror, #ret_msg = 'Error occurred changing password'
-- It would be nice to have the actual error message as well
goto fin
end
fin:
select #ret_code as ret_code, #ret_msg as ret_msg
end
However, whenever I execute the stored procedure, I get 0 as ret_code and OK as ret_msg (even if parameters to sp_password are wrong).
How can I "catch" the error code of sp_password from my stored procedure?
Many "sp_" stored procedures set a nonzero return code when something goes wrong. Usually it is better to handle this return code than trying to catch errors raised inside the stored procedure. IIRC, this catching would not be possible with Transact-SQL; a 3rd generation language such as C would be required.
To get the return code of myproc stored procedure into variable #myvar, the syntax is
exec #myvar = myproc [arguments]
A simple example with sp_password:
declare #spreturn int
exec #spreturn = sp_password 'notmyoldpw', 'notmynewpw'
print "Return from sp_password is %1!", #spreturn
go
Server Message: Number 10315, Severity 14
Server 'SDSTRHA01_SY01', Procedure 'sp_password', Line 148:
Invalid caller's password specified, password left unchanged.
Server Message: Number 17720, Severity 16
Server 'SDSTRHA01_SY01', Procedure 'sp_password', Line 158:
Error: Unable to set the Password.
(1 row affected)
Return from sp_password is 1
(return status = 1)
The int variable #spreturn defined in the first line got sp_password return code, whose value was one as shown by (return status = 1) in the last message line. The reason why it was not zero is clear: there were two errors inside sp_password, 10315 and 17720. The point is to focus in this nonzero return code and ignore 10315 and 17720. In your stored proc, #spreturn ought to be checked against zero. If zero it ran OK, else something failed.

Resources