Elijah Leis
Elijah Leis

Reputation: 415

PgAdmin4 keeps returning: ERROR: syntax error at or near "IN"

I have a query that updates all records inside my table and the values inside of each column should be in sync with my other table so i created this query:

UPDATE dashboard.event SET operation_start_time IN 
(SELECT operation_start FROM dashboard.inventory), operation_end_time IN 
(SELECT operation_end FROM dashboard.inventory) 
WHERE terminal_id IN (SELECT terminal_id FROM dashboard.inventory)

but the problem postgres keep returning me "ERROR: syntax error at or near "IN"" in which i don't get why. If i put "=" instead of "IN" it returns me the error:

ERROR: more than one row returned by a subquery used as an expression

For the logic of these query. I have an inventory table and in it has a column name operation_start and operation_end. I want the data in those columns to be updated or inserted in the event table for each terminal_id

Any help will be appreciated please. Thank you!

Upvotes: 0

Views: 502

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269973

If you want to update the columns in event from inventory for a given terminal_id, the the syntax would look like:

UPDATE dashboard.event e
    SET operation_start_time = e.operation_start,
        operation_end_time = e.operation_end
    FROM dashboard.inventory i
    WHERE e.terminal_id = i.terminal_id;

Upvotes: 1

Related Questions