no viable alternative at input 'is false' - hiveql

trying to query database in aws athena but got this error:
WHERE
"fo0"."date" > date'2014-08-03'
AND "re0"."rating" IS NOT NULL
AND "fi0"."is_side" is FALSE
GROUP BY "Name"
HAVING COUNT(DISTINCT "re0"."id") > 10
ORDER BY "% More Loves than Dislikes" DESC
;
I am pretty new to athena. Any resolve is helpful.

It looks like you may need to change this line:
AND "fi0"."is_side" is FALSE
to:
AND "fi0"."is_side" = FALSE
Since it sounds like your is_side datatype is a tinyint, try the following:
ND "fi0"."is_side" = 0

Related

User defined variable in postgresql query not working

Please can anyone help to solve the problem of the PostgreSQL query? It's expected to return the result in the image but it returns nothing:
Query:
SET foo.date_1 = '2021-01-04';
select interface_name, max(time_stamp) as date, message,api_request from central
where application = 'OMS to DW'
and time_stamp like ''''||'%' || current_setting('foo.date_1')||'%'||''''
and message not like 'succe%'
group by interface_name,message,api_request
Expecting:
Thank you all for trying to help. The problem now it's solved, the correct code should be:
SET foo.date_1 = '2021-01-04';
select interface_name, max(time_stamp) as date, message,api_request from central
where application = 'OMS to DW'
and time_stamp like '%' || current_setting('foo.date_1')||'%'
and message not like 'succe%'
group by interface_name,message,api_request

Postgresql: deleting duplicate records by CompanyID and CustomerID

I can't get the following query to work. It will work if I remove the last line of the query. Any suggestions are greatly appreciated.
DELETE FROM "ProjectMaster"
USING "ProjectMaster" ua2
WHERE "ProjectMaster"."EngagementName" = ua2."EngagementName"
AND "ProjectMaster"."ProjectMasterID" < ua2."ProjectMasterID"
AND "CompanyID" = 490 and "ClientID" = 11125
When I run your query in a fiddle, it gives me :
error: relation "ProjectMaster" does not exist
Here are a few changes that can be done to avoid this error, without altering the logic (that you did not actually explain) :
alias the table that you insert to (ua1)
prefix the fields in the last line with the table they belong to (ua1 or ua2 ?)
get rid of these noisy quotes
This runs without syntax error :
DELETE FROM ProjectMaster ua1
USING ProjectMaster ua2
WHERE
ua1.EngagementName = ua2.EngagementName
AND ua1.ClientID = ua2.ClientID
AND ua1.ProjectMasterID < ua2.ProjectMasterID
AND ua1.CompanyID = 490 and ua1.ClientID = 11125;
I'm thinking something like this:
DELETE FROM "ProjectMaster"
WHERE "CompanyID" = 490 and "ClientID" = 11125 AND
"ProjectMasterID" < (SELECT MAX(pm2."ProjectMasterID"
FROM "ProjectMaster" pm2
WHERE pm2."CompanyID" = "ProjectMaster"."CompanyID" AND
pm2."ClientID" = "ProjectMaster"."ClientID"
);
That is, the correlation is to the company and client, not to something called engagement. This is based on my interpretation of the title of your question.

PostgreSQL: return message after count = 0

I have maybe easy question, but I'm completely stucked.
I have script
SELECT COALESCE(COUNT(id), 0) as MyFiels from table
It works fine and when I have zero value it shows 0.
But I want that instead of 0, I can see one line = "NO RESULTS" for example.
I tried:
SELECT COALESCE(to_char(COUNT(id), 'NO RESULT')) as MyFiels from table
And PostgreSQL shows error message:
ERROR: "E" is not supported
SQL state: 0A000
Where I'm incorrect? Any ideas?
I see what is the error, you are trying to use coalesce to convert 0 to string, and coalesce convert null to something. You need use a CASE
SELECT CASE WHEN COUNT(*) = 0 THEN 'NO RESULT'
ELSE CAST(COUNT(*) as TEXT)
END as field
FROM Table

how to add date in Teradata?

Hi i want to add 01/01/1970 to a column ,datatype of last_hit_time_gmt is bigint ,when i run the below query i am getting data type
last_hit_gmmt
does not match a defined datatype name.
select
distinct STG.OMN_APND_KEY,
STG.last_hit_time_gmt,
IIF(STG.last_hit_time_gmt <>0,ADD_TO_DATE(TO_DATE('01/01/1970', 'DD/MM/YYYY'),'SS',cast(STG.last_hit_time_gmt as DATE ),NULL)
from EDW_STAGE_CDM_SRC.STG_OMNITUREDATA STG
WHERE
UPPER(STG_OMNITUREDATA.EVAR41) IN
('CONS_SUPP: CONSUMER','STORE','PURCHASE') and
STG.OMN_APND_KEY='61855975'
please help me..
The query and data type is incompatible with Teradata.
As stated in the comments you may want to use "CASE" instead of "IFF". The general format is
CASE WHEN *condition* THEN *result_if_true*
ELSE *result_if_false*
END as *ColumnName*
editing based on comment response
So in your query example the case statement can be used like...
select distinct STG.OMN_APND_KEY
,STG.last_hit_time_gmt
,CASE WHEN STG.last_hit_time_gmt = 0 THEN NULL
ELSE DATE '1970-01-01'
END AS YourColName
FROM EDW_STAGE_CDM_SRC.STG_OMNITUREDATA STG
WHERE UPPER(STG_OMNITUREDATA.EVAR41) IN
('CONS_SUPP: CONSUMER','STORE','PURCHASE') and
STG.OMN_APND_KEY='61855975'
Also, if you are merely just trying to update the field STG.last_hit_time_gmt, why not just use two simple UPDATE statements?
UPDATE EDW_STAGE_CDM_SRC.STG_OMNITUREDATA
SET STG.last_hit_time_gmt = DATE '1970-01-01'
WHERE STG.last_hit_time_gmt <> 0
AND UPPER(STG_OMNITUREDATA.EVAR41) IN
('CONS_SUPP: CONSUMER','STORE','PURCHASE')
AND STG.OMN_APND_KEY='61855975';
UPDATE EDW_STAGE_CDM_SRC.STG_OMNITUREDATA
SET STG.last_hit_time_gmt = NULL
WHERE STG.last_hit_time_gmt = 0
AND UPPER(STG_OMNITUREDATA.EVAR41) IN
('CONS_SUPP: CONSUMER','STORE','PURCHASE')
AND STG.OMN_APND_KEY='61855975';

DB2 Merge using multiple columns in ON statement

I have a megre statement that does something like the following:
MERGE INTO TABLE_NAME1 tgt
USING (SELECT CONTRACTOR, TRACTOR, COL1, COL2 FROM TABLE_NAME2) src
ON src.CONTRACTOR = tgt.CONTRACTOR AND src.TRACTOR = tgt.TRACTOR
This is because a contractor can have multiple tractors. The table key is not used because it is an identity key only - auto number on insert.
The Merge runs OK when the table is empty, but when running it again it duplicates the rows where the tractor is null. So I tried:
ON ((src.CONTRACTOR = tgt.CONTRACTOR AND src.TRACTOR = tgt.TRACTOR)
OR (src.CONTRACTOR = tgt.CONTRACTOR AND tgt.TRACTOR IS NULL))
But this causes it to hang. Does DB2 have an issue comparing NULL to NULL?
"Does DB2 have an issue comparing NULL to NULL?" No, it does not. However, the result of such a comparison is unknown, in other words, it is neither true nor false:
$ db2 "select * from sysibm.sysdummy1"
IBMREQD
-------
Y
1 record(s) selected.
$ db2 "select * from sysibm.sysdummy1 where null = null"
IBMREQD
-------
0 record(s) selected.
$ db2 "select * from sysibm.sysdummy1 where null != null"
IBMREQD
-------
0 record(s) selected.
Without seeing your complete statement and sample data it's hard to provide a definite answer, but you may want to try instead:
...ON ((src.CONTRACTOR = tgt.CONTRACTOR AND src.TRACTOR = tgt.TRACTOR
AND tgt.TRACTOR IS NOT NULL))