Issue with BigQuery WITH clause - google-bigquery

I'm trying to use BigQuery's WITH clause as described in the documentation. I'm getting an error when running the following query:
WITH subQ1 AS (SELECT "1"),
subQ2 AS (SELECT "2")
SELECT * FROM subQ1
UNION ALL
SELECT * FROM subQ2;
The thrown error is:
Error: Encountered " "WITH" "WITH "" at line 1, column 1. Was expecting: <EOF>
Anyone has any idea of what I'm doing wrong?

You should do Enabling Standard SQL
Rather than this - you should be good!
BigQuery Legacy SQL does not support WITH

Related

Bigquery job failed with error: Encountered " "FROM" "FROM ""

I'm calling a SQL query with a BigQuery API with Airflow. This query works perfectly fine in the BigQuery workspace but says I'm writing FROM FROM even though I'm not...
The logs say line 4, character 20 is where the error occurs which corresponds to:
, EXTRACT(DATE FROM event_time) AS session_date.
My overall query structure looks something like:
SELECT * FROM
((SELECT
fields_here
FROM table_name
LEFT JOIN UNNEST(sub_table) AS s
WHERE 1=1
UNION ALL
(SELECT
fields_here
FROM table_name
LEFT JOIN UNNEST(sub_table) AS s
WHERE 1=1
ORDER BY 1, 2))
ORDER BY 1, 2
I'm also using the LEAD() window function and COALESCE() but not sure if that matters. Really confused why this error is occurring...
Issue was not adding use_legacy_sql=False argument in Airflow

Google Cloud Big Query , Github Dataset Syntax Error

I am trying to make a query but google cloud gives a syntax error.
I had coppied this code which written in 2017 .
I have no idea about Sql
Syntax error: Unexpected "[" at [5:6]. If this is a table identifier, escape the name with `, e.g. `table.name` rather than [table.name].
The query is:
SELECT
f.repo_name,
f.path,
c.pkey
FROM
[bigquery-public-data:github_repos.files] f
JOIN (
SELECT
id,
You are probably using Standard SQL -- which is a good thing.
Try writing the table reference as:
FROM `bigquery-public-data.github_repos.files` f

Nested select statements in impala sql

I have the following SQL query in impala
SELECT currentdate,close
FROM ( SELECT * FROM spyprice)
Where currentdate between '2015-01-16' and '2016-06-17';
And it is giving me the error:
Starting Impala Shell without Kerberos authentication
ERROR: AnalysisException: Syntax error in line 15:
WHERE currentdate BETWEEN '2015-01-16' and '2016-06-17'
^
Encountered: WHERE
Expected: AS, DEFAULT, IDENTIFIER
CAUSED BY: Exception: Syntax error
Anyone knows what's going on?
Thanks in advance!
#James Xiang The right syntax of the query statement is :
SELECT a.currentdate, a.close FROM
(
SELECT * FROM spyprice
) a
Where a.currentdate between '2015-01-16' and '2016-06-17';

syntax error at or near $1 and also some exception sql grammar exception

I'm getting an error syntax error at or near $1 and also some exception sql grammar exception
"select t1.* from ( select * from employee_additional_attributes where stwid in :stwIdList )"
+ "as t1 join ( select stwid, max(employee_additional_attribute_id) as employee_additional_attribute_id from employee_additional_attributes"
+ "where stwid in :stwIdList and mis_attribute_id in (:attributeId) and start_time <= date(:date) group by stwid )"
+ "as t2 using ( stwid, employee_additional_attribute_id" )
PostgreSQL use the $<n> syntax for placeholders in parameterized queries (such as prepared statements in the underlying connection).
You have a syntax error in your first ($1) parameter:
(and of course some white-space syntax errors, which #Jens mentioned)
where stwid in :stwIdList
The right syntax for IN is <expression> IN (<expression>, ...). You cannot bind multiple values with a single parameter (with JDBC). If you can bind an array, you could use the <expression> = ANY (<array-expression>) syntax.
For hibernate see this related question (note the parenthesis around the query parameter).

Advantage Database 8.1 SQL IN clause

Using Advantage Database Server 8.1 I am having trouble executing a successful query. I am trying to do the following
SELECT * FROM Persons
WHERE LastName IN ('Hansen','Pettersen')
To check for multiple values in a column. But I get an error when I try to execute this query in Advantage.
Edit - Error
poQuery: Error 7200: AQE Error: State = 42000; NativeError = 2115; [iAnywhere Solutions][Advantage SQL Engine]Expected lexical element not found: ( There was a problem parsing the
WHERE clause in your SELECT statement. -- Location of error in the SQL statement is: 46
And here is the SQL i'm executing
select * from "Pat Visit" where
DIAG1 IN = ('43644', '43645', '43770', '43771', '43772', '43773', '43774',
'43842', '43843', '43845', '43846', '43847', '43848', '97804', '98961',
'98962', '99078')
Done
Does anyone have any Idea how I could do something similar in advantage that would be efficient as well?
Thanks
You have an extraneous = in the statement after the IN. It should be:
select * from "Pat Visit" where
DIAG1 IN ('43644', '43645', <snip> )