Executing multiple SQL code in Pyspark SQL - apache-spark-sql

I am using python in Databricks. Is there any way to execute multiple SQL statements using spark.sql or any other method?

For executing "multiline" sql code in pyspark-sql Use """
spark.sql(""" select * from db.tbl """)
As far as my information you cannot write "multiple" sql statement in single spark.sql() .

Related

executing sql query in UiPath to extract data from snowflake

I am using execute query activity in Uipath studio and writing the sql query like this
"select * from SNOWFLAKE_SAMPLE_DATA where value=CALL_CENTER"
to extract the table values from snowflake.
where "SNOWFLAKE_SAMPLE_DATA" is the database and "CALL_CENTER" is the table which is present in the said database.
After I execute the query in uipath it gives the following error:
Execute Query: ERROR [42S02] SQL compilation error: Object
'SNOWFLAKE_SAMPLE_DATA' does not exist or not authorized.
Any help in this regard will be highly appreciated.
Thank You
You will need to update your SQL query.
The correct syntax is SELECT * FROM [database.table];
If you want to pull everything from the table, you will need to enter the line below (in double quotes) in the Sql property of the Execute Query activity:
SELECT * FROM SNOWFLAKE_SAMPLE_DATA.CALL_CENTER;
Lastly, the output will need to go to a data table.

SQL where clause parameterization

I am trying to parameterize certain where clauses to standardized my Postgres SQL scripts for DB monitoring. But have not found a solution that will allow me to have the following script run successfully
variablename = "2021-04-08 00:00:00"
select * from table1
where log_date > variablename;
select * from table2
where log_date > variablename;
Ideally, I would be able to run each script separately, but being able to find/replace the variable line would go a long way for productivity.
Edit: I am currently using DBeaver to run my scripts
To do this in DBeaver I figured out you can use Dynamic Parameter Bindings feature.
https://github.com/dbeaver/dbeaver/wiki/SQL-Execution#dynamic-parameter-bindings
Here is a quick visual demo of how to use it:
https://twitter.com/dbeaver_news/status/1085222860841512960?lang=en
select * from table1
where log_date > :variablename;
When executing the query DBeaver will prompt you for the value desired and remember it when running another query.

Collect list function in hive and impala

I am using
concat_ws(' ', collect_list(field1)) as field1,
but the query is not running in impala.
Does impala not support this function?
If not, what is an alternative for a similar operation in impala?
You can use group_concat() function in impala,
Plase refer https://www.cloudera.com/documentation/enterprise/5-5-x/topics/impala_group_concat.html

Vanilla Postgres, select from prepared statement

I would like to use a prepared statement in a subquery.
Simple example:
PREPARE get_series(int) AS SELECT * FROM generate_series(1,$1);
SELECT * FROM EXECUTE get_series(13);
But I am getting a syntax error.
As an alternative I could use a stored procedure, but the whole idea is to keep everything in the source code and prepared statements allow to invoke a parametrized query. Kind'a like UDP's but on the source code side.
Note: I'm using Postgres 10.2
EXECUTE is an SQL statement, not an expression that you can use in a FROM clause.
Try this:
EXECUTE get_series(13);
You cannot use EXECUTE in a subquery — only SELECT is allowed there.
I would say that you shouldn't use a prepared statement for this; maybe a set returning function is what you really need.
Actually it came to me that I can create as complex query as I want using CTEs.
CTEs will make it easier to read and they will be parametrized through prepare statement. In the end the query still stays in the source code and in the source code I can extract the reusable parts.

How to execute multiple Oracle sql queries from VBscript?

I have a database object called objdb. From this object it seems that I can only execute one sql query at a time. if I insert a semi-colon in the end,it gives me a
ORA-0911 invalid character error.
For example, if I run
objdb.executeSQl("select * from table1; select * from table2")
This gives me a error.
How can I run multiple queries from a single ExecuteSQl method ?