NOT LIKE ANY query in Snowflake - sql-like

I am trying to run the following query in Snowflake:
SELECT * FROM chapters
WHERE
title NOT LIKE ANY ('Summary%', 'Appendix%')
but it errors out. I know Snowflake support LIKE ANY query syntax. But I am not sure why my query is not working.

It does seem like that syntax with NOT should work, and I'm not quite sure why it doesn't, but this works.
SELECT * FROM chapters
WHERE
NOT (title LIKE ANY ('Summary%', 'Appendix%'))
Extra parens are optional, but seems more clear to me when it's "worded" this way.

The query execution looks like this when we see the profile for the below query.
select cc_name from "SNOWFLAKE_SAMPLE_DATA"."TPCDS_SF100TCL"."CALL_CENTER"
where not(cc_name like any ('North%', 'Califor%'))

Related

Databricks SQL nondeterministic expressions using DELETE FROM

I am trying to execute the following SQL clause using Databricks SQL:
DELETE FROM prod_gbs_gpdi.bronze_data.sapex_ap_posted AS HISTORICAL_DATA
WHERE
HISTORICAL_DATA._JOB_SOURCE_FILE = (SELECT MAX(NEW_DATA._JOB_SOURCE_FILE) FROM temp_sapex_posted AS NEW_DATA)
The intention of the query is to delete a set of rows in a historical data table based on a value present in a column of new data table.
For reasons that I cannot understand it is raising an error like:
Error in SQL statement: AnalysisException: nondeterministic expressions are only allowed in
Project, Filter, Aggregate, Window, or Generate, but found:
(HISTORICAL_DATA._JOB_SOURCE_FILE IN (listquery()))
in operator DeleteCommandEdge
It seems it is not accepting a subquery inside the where clause. That's odd for me, as in the Databricks documentation Link it is acceptable.
I even tried other types of predicates, like:
(SELECT FIRST(NEW_DATA._JOB_SOURCE_FILE) FROM temp_sapex_posted AS NEW_DATA)
(SELECT DISTINCT NEW_DATA._JOB_SOURCE_FILE FROM temp_sapex_posted AS NEW_DATA)
IN (SELECT NEW_DATA._JOB_SOURCE_FILE FROM temp_sapex_posted AS NEW_DATA)
None of them seems to take effect in executing the query successfully.
What's even odd for me is that I was able to accomplish a similar case with a slightly different query, as it can be seen in this link.
I have created demo_table1 & demo_table2 for querying purpose. I have created the following query carrying the similar purpose. I haven’t considered double aliases and have given straight query using subquery, it also depends on data frame in usage use a normal pandas data frame. it works fine for me.
delete from demo_table1 as t1 where t1.age = (select min(t2.age) from demo_table2 as t2);

How to prevent SQL injection in InfluxDB for a user-supplied measurement

Say I have an InfluxDB query where the user supplies a measurement. In this case the user supplies the value "foo". Then I would construct the query:
SELECT * from "foo"
WHERE time > "2022-06-21T18:27:16.041Z"
What's the best way to prevent injection attacks here? I know InfluxDB supports bind parameters, but apparently that feature only works for the WHERE clause, so it wouldn't help me.
I was thinking of trying this:
const query = `
SELECT "value" FROM "${Influx.escape.measurement(key)}"
WHERE time > "2022-06-21T18:27:16.041Z"
`
...but based on my testing that function doesn't escape quotation marks, only spaces.
I'm using InfluxDB 1.x in Node.js via the influx npm package.
Before sending the value to the query try filtering chars like single and double quotes
Looking into docs, articles I can see that every subquery is in brackets, like:
select * from (select "value" from "measurement") <where_caluse>
So filtering for brackets beetwen "FROM" and "WHERE" should be enough.
Based on:
#1 https://www.influxdata.com/blog/tldr-influxdb-tech-tips-january-26-2017/
#2 https://docs.influxdata.com/influxdb/v1.7/query_language/data_exploration/#subqueries

Data factory SAP BW

I'm trying to use the Data Factory in Azure to export data from a SAP BW. The connection is working, and I'm able to get data. The problem is how I'm getting the data. The picture describes the issue pretty well.
Has anyone encountered something similar? Any tips on how to approach this issue? Any help is greatly appreciated!
Query like:
SELECT
[Measures].<<Measure>> ON COLUMNS,
NON EMPTY
{<<Dimension>>.MEMBERS,
<<Dimension>>.MEMBERS} ON ROWS
FROM <<Cube>>
Picture:
https://i.stack.imgur.com/9Gxfh.png
Best regards,
This is how your query should look like.
select Measures.Value on columns,
nonempty
(
DimPlan.Plan.Plan,
DimCategory.Category.Category,
DimProduct.Product.Product
)
on rows
from YourCube
Looks like you are getting the ALL members of each hierarchy coming through into the results.
Very similar to MoazRubs answer but avoiding needing to use the NonEmpty function - you can simply cross-join the hierarchies via the * operator:
SELECT
Measures.Value ON 0,
DimPlan.Plan.Plan.MEMBERS *
DimCategory.Category.Category.MEMBERS *
DimProduct.Product.Product.MEMBERS
ON 1
FROM YourCube;

Execute multiple SQL queries in one statement using Python

I am new to Python and I want to execute multiple SQL queries in one statement using python, but I am not able to find the appropriate way to do so.
I wrote following code but its throwing an error as " DatabaseError: ORA-00933: SQL command not properly ended."
import cx_Oracle;
SQLQuery = "select x from xyz where p= 'sn'; select * from abs where a ='qw';"
connection = cx_Oracle.connect('username', 'password', 'server')
cursor = connection.cursor()
cursor.execute(SQLQuery) #its throwing error here
It would be great if one can suggest me the appropriate function for executing the multiple queries in one call.
Appreciate your response. Thanks in advance.
What do you want to achieve with this?
Technically you could try to get rows from two tables or try to combine rows from different tables, but all this is directly done in SQL.
Remove ; (semicolon) at the end of query and it should run fine.

Can we run complex multi line SQL queries using Blueprism?

I am new to SQL stuff in blueprism, I am able to configure SQL object and execute simple queries, but I am facing trouble while trying to run multiline complex SQL queries.
when I was trying to execute the below query in blueprism, getting some error message, saying "Incorrect Syntax near Database2"
"select top 10 * from [Database1].[dbo].[Table1]
join [Database1].[dbo].[Table2] on [Database1].[dbo].[Table2].Fieldname1=[Database1].[dbo].[Table1].Fieldname2
join [Database2].[dbo].[Table1] on [Database2].[dbo].[Table1].Fieldname1=[Database1].[dbo].[Table2].Fieldname2"
Can somebody please help me, what was the wrong in the above query...
I found the answer myself, there should not be any additional white space characters in the query, entire query should be in continuous line. The beauty of blueprism is, it can execute any level of complex queries without any constraints, but need to modify the syntax accordingly. always we should mention the filename and table names in the following format - [databasename].[dbo].[tablename].[fieldname]

Resources