Update Non key columns Query Pheonix JDBC

94 views Asked by At

I have problem with updating values in apache phoenix . The below query is throwing JDBC exception. I am new to Pheonix JDBC and confusing with upsert query usage for updating non primary key field values.

String sql = UPSERT INTO mytable (serverName,SationName, product) SELECT serverName,stationName ‘sampleProduct’ FROM mytable WHERE product = ‘sampleProduct’;   

The primary key of "myTable" is combination of "serverName" and "StationName". I would like to update value of product column from 'sampleProduct' to 'TestProduct'.

2

There are 2 answers

0
Rick James On

"The primary key of "myTable" is combination of "serverName" and "StationName". I would like to update value of product column from 'sampleProduct' to 'TestProduct'."

You say nothing about "inserting if the row does not already exist, so I don't see UPSERT as being appropriate. The MySQL code is

UPDATE myTable
    SET product = 'sampleProduct'
    WHERE serverName = '...'
      AND sampleProduct = '...';

(I don't know what values are needed for '...'.)

2
Faizan Younus On

Update the sql query with following line. Hope it will help.

String sql = "REPLACE INTO mytable (serverName,SationName, product)
         SELECT serverName,stationName , 'sampleProduct'
            FROM mytable WHERE product = 'sampleProduct'";