1

I need analog of sql IS_NULL function. In postgres, for example, I can write like this

coalesce(field, 'Empty')

How I can implement this using Django?

m9_psy
  • 3,217
  • 5
  • 25
  • 38
  • You mean... http://stackoverflow.com/questions/844556/django-filter-how-do-i-go-about-filtering-for-empty-or-null-names-in-a-querys? – netcoder Nov 23 '13 at 13:53
  • Not exactly. I need replace all null values with deafult value. Not only detect them – m9_psy Nov 23 '13 at 17:50

1 Answers1

2

You can use extra queryset method:

MyModel.objects.extra(select={'field': "coalesce(field, 'Empty')"})

COALESCE should work similarly in most db engines.

mariodev
  • 13,928
  • 3
  • 49
  • 61