Reputation: 158
I have a table name service_table which have some fields. A field have days name like Sunday, Monday, Tuesday etc.. I want to change all the column value in postgres database table into lower case. For Instance 'Sunday' update as 'sunday' I am written a query
update service_table set days=lower(days);
but it shows
Hint: No function matches the given name and argument types. You might need to add explicit type casts.
Note: This table has some foreign key.
Upvotes: 0
Views: 1850
Reputation: 449
You can do this in Django shell
from django.db.models import F
from django.db.models.functions import Lower
service_table.objects.update(days=Lower(F('days'))
Django update()
is a bulk operation for direct updates.
Django F()
makes it possible to refer to model field values and perform database operations using them without actually having to pull them out of the database into Python memory.
F()
helps to pull the model field value, then it process to the requirement and use update()
to save it back
Upvotes: 3