Skip to content
Advertisement

Postgresql conditional script

I need to update the column (vendor_type) in the table depending on values in other columns.

Table name = “vendor”

Columns = “client_id”(varchar), “coach_id”(varchar), “exm_vendor”(boolean), “vendor_type”(varchar)

And this is what I want to do with postgresql:

Advertisement

Answer

Postgresql supports a number of ways to express conditional values, but perhaps the closest to your example is the CASE..WHEN expression

https://www.postgresql.org/docs/14/functions-conditional.html

you can put this into an update statement like this

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement