I am trying to UPDATE table2 using a certain condition, but getting the following error while using a MERGE statement in HIVE.
Someone please look into my error and provide a solution or correct me if any mistakes in the query.
MERGE INTO TABLE1 A1
USING TABLE2 A2
ON A1.PROJECT_ID=A2.PROJECT_ID
AND A1.GREENFIELD_STATUS_CODE=A2.GREENFIELD_STATUS_CODE
AND A1.COUNTRY_CODE=A2.COUNTRY_CODE
AND A1.PROJECT_NME=A2.PROJECT_NME
WHEN MATCHED THEN UPDATE SET A1.DATETIME_STAMP=A2.DATETIME_STAMP;
For the above query I am getting this error:
HiveServer2Error: Error while compiling statement: FAILED:
ParseException line 24:31 mismatched input '.' expecting = near 'A1'
in WHEN MATCHED THEN clause"
So here I am not able to get what the issue is
In your match statement remove A1 alias as Merge statement doesn't expect alias.
Try with this statement:
MERGE INTO TABLE1 A1
USING TABLE2 A2
ON A1.PROJECT_ID=A2.PROJECT_ID
AND A1.GREENFIELD_STATUS_CODE=A2.GREENFIELD_STATUS_CODE
AND A1.COUNTRY_CODE=A2.COUNTRY_CODE
AND A1.PROJECT_NME=A2.PROJECT_NME
WHEN MATCHED THEN UPDATE SET DATETIME_STAMP=A2.DATETIME_STAMP;
Refer to this article for more details regards to Hive-Merge Strategy.
Related
I am trying to query from a table within a copy command however, I have continually gotten errors. Here is the example SQL statement.
copy schema.table
from 's3://bucket/folder`
iam_role (select value from roles.iam where key = 'IAMRole');
The inner select statement on its own returns a value however, when I run the above, I get the following error:
SQL Error [500310] [42601]: [Amazon](500310) Invalid operation: syntax error at or near "("
The COPY command, as you must suspect, does not support embedded SQL.
If you want to do something like this, you can, but you'll need a procedure.
I was trying to follow the PostgreSQL guide to get children from an adjacency tree on PostgreSQL 9.6. For connivence I'll reproduce the command it suggests here:
WITH RECURSIVE tree AS (
SELECT id, ARRAY[]::INTEGER[] AS ancestors
FROM test WHERE parent_id IS NULL
UNION ALL
SELECT test.id, tree.ancestors || test.parent_id
FROM test, tree
WHERE test.parent_id = tree.id
) SELECT * FROM tree WHERE 3 = ANY(tree.ancestors);
My understanding was that you simply have to replace test with the name of the table you're trying to access, and parent_id with the name of the field that contains the parent id. So I did that for all instances. However, I am getting a super vague 'Syntax error at or near ")"' when trying to run this command.
What could be the possible causes of this?
This turned out to be a problem with my SQL client, DBeaver. When I run this command in psql, it worked exactly as expected.
When i try to execute Multiple Queries in tgreenplumRow component.
It is not allowing me Join and Filter queries.
Input Info
Source and target table both in greenplum only
Source table - Pointing the External source called HDFS
Target TABLE - regular table in greenplum database
Like this
SQL Transaction
Begin;
"insert into target_tbl (select S.* from source_tbl s "LEFT JOIN" target_tbl d ON s."PK"=d."PK" where d."PK" is null) ;
UPDATE target_tbl d
SET
"COL" = s."COL"
FROM source_tbl s
WHERE s."PK"=d."PK" and d."COL" != s."COL"
;
END;
Error I Get:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Syntax error on tokens, delete these tokens
Actual Data Flow is
tgreenplumconnection
|
tjdbcinput -->tmap -->thdfsoutput -->tgreenplumrow -->tgreenplumcommit
Q1: How to run multiple queries with Join and filter in txxxROW component.
Q2: Is that possible to Handle above Source and target file scenario in tmap ?
Any Help on this would be much appreciated ?
I like to break these queries into separate components. In your case you want to turn off auto commit on the connection.
So after that mapping you have 2 greenplumRows and 1 commit component.
I think this makes the code more easier to understand and debug, because right now you don't know whether insert or update throws an error.
Don't forget to escape the \ and double quotes with a \ character. I think that what is giving you trouble here.
t*row just simply passes the query that you write in to the database.
In tgreeenplumrow component, you have to simply have the queries in between double quotes like
"Begin;
insert into target_tbl (select S.* from source_tbl s LEFT JOIN target_tbl d ON s.PK=d.PK where d.PK is null) ;
UPDATE target_tbl d
SET
COL = s.COL
FROM source_tbl s
WHERE s.PK=d.PK and d.COL != s.COL;
END;"
Hope this would help you out.
I am trying to update a field in a table in Postgres called certificate_name by concatenating 3 fields from another table (first_name, middle_name, and last_name). I have tried several statements, but they all throw errors; my most recent attempt was the following:
update candidate_attributes ca
inner join "user" u on u.id=ca.candidate_user_id
set ca.certificate_name = concat(u.first_name, u.middle_name, u.last_name);
I'm getting an error that says:
syntax error at or near "inner"....
What am I doing wrong?
Your syntax isn't valid in Postgres. Resembles SQL Server syntax.
Read the manual on UPDATE and use instead:
UPDATE candidate_attributes ca
SET certificate_name = concat_ws(' ', u.first_name,u.middle_name,u.last_name)
FROM "user" u
WHERE u.id = ca.candidate_user_id;
I also threw in concat_ws() instead of concat(), assuming you want a space between each part of the name.
I try to update value from one table with another table by use IP_ID to compare 2 table by following sybtax
UPDATE EDWID02.CUSTOMER_MOBILE t1
SET T1.MOBILE = (
SELECT T2.MOBILE
FROM EDWID02.NEW_MOBILE t2
WHERE T1.IP_ID=T2.IP_ID)
The error I found was DB2 Database Error:
ERROR [21000] [IBM][DB2/AIX64] SQL0811N The result of a scalar fullselect,
SELECT INTO statement, or VALUES INTO statement is more than one row.
SQLSTATE=21000
even I change = to in it's told me another error DB2 Database Error:
ERROR [42601] [IBM][DB2/AIX64] SQL0104N An unexpected token "in" was found
following "t1 SET T1.MOBILE". Expected tokens may include: "=".
SQLSTATE=42601
I am coding in DB2.
your misunderstanding
'UPDATE t1 SET value=onevalue'
onevalue needs to be a single value. You may achieve this by (SELECT value FROM t2 WHERE t1.id = t2.id FETCH FIRST 1 ROW ONLY)