Michael Wood
Michael Wood

Reputation: 25

Postgresql Syntax error at or near "where"

I am getting the error

syntax error at or near "where" LINE 5: where zip in (select zipcode from zips where city = 'Sacra

when I try to run this code.

update listings
set price = CASE WHEN (listings.price IS NOT NULL) THEN (price * 
(((100+(select price_change from zips where zips.zipcode=listings.zip))/100)))
where zip in (select zipcode from zips where city = 'Sacramento');

Does anybody see any easy to fix errors? or did I come up with some garbage code?

Upvotes: 0

Views: 5318

Answers (3)

Vivek S.
Vivek S.

Reputation: 21945

Add an end keyword just before where clause

update listings
set price = CASE WHEN (listings.price IS NOT NULL) THEN (price * 
(((100+(select price_change from zips where zips.zipcode=listings.zip))/100))) END
where zip in (select zipcode from zips where city = 'Sacramento');

As per @a_horse_with_no_name's Comment

update listings 
set price = (price * (((100+(select price_change from zips where zips.zipcode=listings.zip))/100))) 
where zip in (select zipcode from zips where city = 'Sacramento') and listings.price IS NOT NULL

Upvotes: 0

Mike T
Mike T

Reputation: 43722

An SQL CASE expression needs to be ended with END keyword.

Upvotes: 1

Almin Islamovic
Almin Islamovic

Reputation: 278

update listings
set price = CASE WHEN (listings.price IS NOT NULL) THEN (price * 
(((100+(select price_change from zips where zips.zipcode=listings.zip))/100)))
where zip in (select zipcode from zips where city = 'Sacramento')

remove ; try again

Upvotes: 0

Related Questions