SAP HANA Export Statement - stored-procedures

In the SAP Documentation is an EXPORT statement described.
Unfortunately I have the following error in a stored procedure:
Syntax error in procedure object: incorrect syntax near '#': line 18 col 8 (at pos 487)
Line 18 is:
EXPORT #MY_EXPORT AS CSV INTO '/path/filename' with replace;
How to fix this?
Full SQL
PROCEDURE "MY_SCHEMA"."my.package::EXPORTCVINTOCSV" ( )
LANGUAGE SQLSCRIPT
SQL SECURITY INVOKER
DEFAULT SCHEMA MY_SCHEMA
AS
BEGIN
--create local temporary table #MY_EXPORT as (
create table MY_EXPORT as (
SELECT a.*
FROM "_SYS_BIC"."my.package/myView" a
JOIN "_SYS_BIC"."my.package/myOtherView" b
ON a."CheckID" = b."CheckID"
WHERE a."SchedulingID" IS NOT NULL
);
EXPORT MY_EXPORT AS CSV INTO '/my/export/path' with replace;
END;

for unknown reasons IMPORT & EXPORT are not supported as procedure body, but as workaround you can wrap them into exec, .e.g.
EXEC 'EXPORT MY_EXPORT AS CSV INTO ''/my/export/path'' with replace';

the error message is confusing, but export of local temporary tables is anyway not supported.
If you try such statement outside the procedure you get:
SQL Error [7] [HY000]: SAP DBTech JDBC: [7]: feature not supported: cannot export local temporary table #MY_EXPORT

Related

new to dbt and trying to learn how to execute procedure using dbt but getting error

create or replace procedure output_message(message varchar)
returns varchar not null
language sql
as
begin
return message;
end;
call output_message('Hello World');
error I'm getting:
Database Error in model my_first_dbt_model (models/example/my_first_dbt_model.sql)
001003 (42000): SQL compilation error:
syntax error line 2 at position 7 unexpected 'create'.
syntax error line 3 at position 0 unexpected 'returns'.
compiled SQL at target/run/dbt_project/example/my_first_dbt_model.sql
You cannot put code for a stored procedure in a model file (any .sql file in your models directory). dbt assumes that a model file contains a single select statement; it then wraps that select statement in DDL (usually a create table my_model as (...) statement), depending on your materialization config for that model.
Macros are more flexible. Generally, Stored Procedures aren't part of the dbt workflow, but there are some valid use-cases for them (along with UDFs).
You can create a output_message.sql file in your macros directory, and use the code you provided, wrapping it in a macro definition, like:
{% macro output_message(msg) %}
create or replace procedure output_message(message varchar)
returns varchar not null
language sql
as
begin
return message;
end;
call output_message(msg);
{% endmacro %}
You can then call that macro in a post-hook or by using run-operation:
dbt run-operation output_message --args "{'msg': 'Hello World!'}"
You can customize your code using materialization link and I have followed a link to create ddl objects. You need to write macros for that.

Can I call a postgres "Procedure" (not "function") from java using the postgres JDBC driver?

I'm new to postgres but am attempting to call a procedure in Postgres 11 (new "procedure" not a "function"), calling from java as a spring SimpleJDBCCall (using Postgresql-42.2.5 jdbc driver). However, when I execute the procedure I am encountering the following exception:
org.springframework.jdbc.BadSqlGrammarException:
CallableStatementCallback; bad SQL grammar [{call
pa_test_schema.pr_dosomething(?)}]; nested exception is
org.postgresql.util.PSQLException: ERROR:
pa_test_schema.pr_dosomething(bigint) is a procedure Hint: To call a
procedure, use CALL. Position: 15 at
org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:101)
at
org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
at
org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
at
org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
at
org.springframework.jdbc.core.JdbcTemplate.translateException(JdbcTemplate.java:1402)
at
org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:1065)
at
org.springframework.jdbc.core.JdbcTemplate.call(JdbcTemplate.java:1104)
at
org.springframework.jdbc.core.simple.AbstractJdbcCall.executeCallInternal(AbstractJdbcCall.java:414)
at
org.springframework.jdbc.core.simple.AbstractJdbcCall.doExecute(AbstractJdbcCall.java:397)
at
org.springframework.jdbc.core.simple.SimpleJdbcCall.execute(SimpleJdbcCall.java:193)
My procedure code:
CREATE PROCEDURE pa_test_schema.pr_DoSomething
( P_input_ID IN inputs.input_ID%TYPE
) AS $$
BEGIN
-- do something
END;
$$ LANGUAGE plpgsql;
My java code:
SimpleJdbcCallOperations pr_DoSomething = new SimpleJdbcCall(jdbcTemplate)
.withSchemaName("pa_test_schema")
.withProcedureName("pr_DoSomething");
Map<String, Object> inputs = Maps.newHashMap();
inputs.put("p_input_id", 123456);
pr_DoSomething.execute(inputs);
When I step through the code I can see the driver is modifying the sql of the callable statement to the syntax required for calling a postgres function:
select * from pa_test_schema.pr_dosomething(?) as result
This is the method in the driver that is doing this conversion:
https://github.com/pgjdbc/pgjdbc/blob/faab499853c56f67cb70fb242f75b918452f2a6f/pgjdbc/src/main/java/org/postgresql/core/Parser.java#L766
I understand procedures were only introduced in Postgres 11 (previously one would have used void-returning functions) and have read through the postgres driver documentation but don't see any reference to calling procedures rather than functions.
Does this mean that the current postgres driver does not yet support this or is there another approach I should be using? Should I just be using postgres functions instead?
Currently (as of Postgres 11.1 and driver version 42.2.5) the standard JDBC approach using a CallableStatement cannot be used to call a stored procedure.
I don't really use Spring JDBC Template, but the following code works in plain JDBC and should be adaptable to Spring JDBC Tempalte:
Connection con = DriverManager.getConnection(...);
PreparedStatement pstmt = con.prepareStatement("call pa_test_schema.pr_DoSomething(?)");
pstmt.setInt(1, 42);
pstmt.execute();
Note that this uses Postgres' call command. Do not confuse this with the "{call ...}" syntax for a CallableStatement.
Some more details on why currently a CallableStatement does not work can be found in the JDBC mailing list here and here

Neo4j apoc procedures impala configuration

1) Downloaded the impala drivers 2.5.37 from
https://www.cloudera.com/downloads/connectors/impala/jdbc/2-5-37.html
2) Executed:
call apoc.load.driver("com.cloudera.impala.jdbc4.Driver")
No errors.
3) Executed:
CALL apoc.load.jdbc("jdbc:impala://<URL>:21050/default;user=<username>;password=<password>",
'<database>.<table name>') YIELD row
RETURN row.account as account_num
Error :Failed to invoke procedure apoc.load.jdbc: Caused by:
java.lang.RuntimeException: Cannot execute SQL statement `SELECT *
FROM .. Error: [Simba]ImpalaJDBCDriver
Error setting/closing session: {0}.
Can you please help me out?
The second argument to apoc.load.jdbc must be a string that is either a table name or a SQL statement. Replace '.' with the appropriate value (in your case, probably the name of the table that contains the account column).

how to all Oracle Stored Proc in Package from Delphi

I have been given a stored procedure (developed by a 3rd party) to execute...
create or replace package body cux_ivr_task_assigupd_pkg is
-- Private type declarations
procedure cux_update_task_assgnments(
p_task_number in varchar2,
p_pressed_number in number,
x_err_code out varchar2,
x_err_message out varchar2) is
and trying to execute this procedure from a Delphi program. when trying to call with name cux_ivr_task_assigupd_pkg.cux_update_task_assgnments I get error
[Oracle][ODBC][Ora]ORA-06564: object
CUX_IVR_TASK_ASSIGUPD_PKG.CUX_UPDATE_TASK_ASSGNMENTS does not exist
ORA-06512: at "SYS.DBMS_DESCRIBE", line 117 ORA-06512: at line 1
and if I use name cux_update_task_assgnments then get error
[Oracle][ODBC][Ora]ORA-06550: line 1, column 7: PLS-00201: identifier
'CUX_UPDATE_TASK_ASSGNMENTS' must be declared ORA-06550: line 1,
column 7: PL/SQL: Statement ignored
I do not have access to the database itself - I am just a client that needs to be able to execute the procedure. I tried both names, as the people that manage the databases told me to try it one and then the other. So I not sure if it is permission related or ???
Ideally I would like to execute using an ADO command line
exec procedure-name(arg1, arg2, arg3, arg4)
but only error about incorrect syntax and the people responsible for the DB could not help?!?
Any clues about the above error?

Unable to retrieve destination column descriptions from the parameters of the SQL command

I am trying to upgrade an SSIS package from 2008 to 2012 and getting the below error.
Error: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has
occurred. Error code: 0x80004005.
An OLE DB record is available. Source: "Microsoft SQL Server Native
Client 11.0" Hresult: 0x80004005 Description: "The metadata could
not be determined because statement 'EXEC master.dbo.xp_logevent
#ErrorCode, #Message, error' in procedure 'DebugPrint' invokes an
extended stored procedure.".
Error: Unable to retrieve destination column descriptions from the
parameters of the SQL command.
Basically, we have an OLE DB Command to call a stored procedure which call several (nested) stored procedures and one of it is DebugPrint which call master.dbo.xp_logevent. Any idea to fix it? It works in SSIS 2008.
Thanks
You could try using 'with result sets' when calling your proc and setting your metadata there.
Example :
EXEC dbo.proc
WITH RESULT SETS (
ID INT
,Col2 VARCHAR)
I came across a similar error.
An OLE DB record is available. Source: "Microsoft SQL Server Native Client 11.0" Hresult: 0x80004005 Description: "The metadata could not be determined because statement '....' uses a temp table.".
Work around.
If SP uses a #table or ##table and it is used in the SP, then we need to specify the #table structure along with the EXEC.
The SP should be given along with the structure.
EXEC SP_TestTemp 1,2
it should be given like
EXEC SP_TestTemp 1,2 WITH RESULT SETS
(
(
id int,
Marks int
)
)
Note: the 'retain same connection = true' and 'validate external metadata' = false did not help/work here

Resources