5

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?

3

I solved my problem with the following approach:

In the field which holds the boolean value, I defined a checkbox as edit widget under layer properties -> fieöds and set the representation for checked as t and for unchecked as f ( see image) enter image description here

Another but similar approach is to use a value map field and use the two options (image 2)

enter image description here

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, ...

0

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.

0

Actually it is possible to doubleclick to the boolean field in the QGIS attribute table to get a checkbox where it is possible to change the value from true to false or vice versa. One must know this, since it isn't possible to edit this field otherwise. No chance to change the text from 'true' to 'false'. enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.