I have a layer loaded from a WFS server that contains fields with æøå in some of the names. I am making SQL queries to make virtual layers from this layer, but whenever I query a field with æøå in its name, it only returns an empty layer. I am mainly trying to do this with pyqgis, but have tried from the QGIS GUI as well with the same results. Note that there is no problem if the value contains æøå, just the field name. Does anyone know how to fix this, or a workaround?

example of my SQL query:

 "SELECT * FROM TettstedInngangBygg WHERE dørtype = 'skyvedør'"

I got the layer TettstedInngangBygg from the WFS: https://wfs.geonorge.no/skwms1/wfs.tilgjengelighettettsted?request=GetCapabilities&service=WFS

EDIT: By writing the following code in python console:

field_names = [field.name() for field in vlayer.pendingFields() ]
print field_names

I get the name u'd\xf8rtype'. I have tryed to write the name like that, but withe the same result as before.

UPDATE: It seems that if i add a where statement before a statement with special characters, it works fine. I don't know why this is. By adding something that is always true, i make it work, but it does not look very pretty, and i would like to know why it only works like this.

eksample of working query:

"SELECT * FROM TettstedInngangBygg WHERE lokalId > 0 AND dørtype = 'skyvedør'"
  • Did you try to write the query like: 'SELECT * FROM TettstedInngangBygg WHERE "dørtype" = 'skyvedør'' ? – LaughU Nov 8 '17 at 13:25
  • @LaughU I have, but without the single ' at the ends, as that leads to syntax error. I did however try with "dørtype" from the QGIS GUI, and 'dørtype' from pyQgis. No luck unfortunately. – Kasper Skjeggestad Nov 8 '17 at 14:00
  • Have you try to put transform into Unicode. Just put u' some ëéê' at the beginning of your string. Every string in QGIS is in Unicode. – SIGIS Nov 8 '17 at 20:02
  • @SIGIS I have, if i don't i usualy get a UnicodeDecodeError on the creation of the query – Kasper Skjeggestad Nov 9 '17 at 10:06

Your Answer

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

Browse other questions tagged or ask your own question.