I have a layer in QGIS loaded from a postgis database. In the layer properties dialog in QGIS, under the fields tab, layers with a typename of 'bool' (which are boolean fields in the postgis database) appear as type 'QString'. The values then behave as strings in QGIS. Is there a way to bring the layer in so that the boolean fields are treated as booleans in QGIS?
I solved my problem with the following approach:
Another but similar approach is to use a value map field and use the two options (image 2)
I then defined a standard layer style for my layer in QGIS and saved this style into the database with properties -> style(the button down left) -> Save as default -> Save to datasource database
So every time I load the layer the bool field is shown as checkbox which is either t or f and which is understood by Postgres as a boolean value and if I query the field inside postgres with:
SELECT bool_field from my_table
I get something like
bool_field: false, false. true, ...
I think it's impossible. But you can use the field like a boolean with the selection box (ex:
myfield = 't' ). Result will be same as
myfield is true in Postgresql.