1

Running PostgreSQL 7.x (Yeah I'm upgrading)

The problem:

I have three to four fields that need to be set if no data is returned.

Was thinking of something like this

SELECT CASE
       WHEN default_field IS NULL THEN field_1 = 'blah', field_2 = 'foo', field_3 = 'bar'
       ELSE field_1,field_2,field_3
       END

Any thoughts on how I could do this?

so think an IF condition

IF this these other fields get these values, else leave the returned values intact

Phill Pafford
  • 83,471
  • 91
  • 263
  • 383

1 Answers1

1

I'd just spell out the 3 case statements independently.

SELECT CASE WHEN default_field IS NULL THEN 'blah' ELSE field_1 END AS field_1,
       CASE WHEN default_field IS NULL THEN 'foo' ELSE field_2 END AS field_2,
       CASE WHEN default_field IS NULL THEN 'bar' ELSE field_3 END AS field_3
...
Joe Stefanelli
  • 132,803
  • 19
  • 237
  • 235