I'm new to QGIS, and Geographic Information Systems in general, and also have no experience with informatics.

I a have shapefile which works fine, and then I have a file in CSV format, and I try to join these two files, using a column which should be equal between two files. The problem is, some of the numbers have leading zeros (they are some sort of postcode in my country), that disappear from the CSV file when I import it to QGIS...

Is there any simple way to keep leading zeros?

In the shapefile the leading zeros don't disappear.

  • Definitely you must treat the postcode fields as Strings / text. Commented Sep 19, 2016 at 8:01

1 Answer 1


You can specify type values by using a CSVT file, as follow :


If your csv file is named data.csv you will name your csvt file data.csvt.

Anita Graser (here known as underdark) has written a blogpost related to this. It is available at : https://anitagraser.com/2011/03/07/how-to-specify-data-types-of-csv-columns-for-use-in-qgis/

I would also refer to this Q/A for more information.

Edit : to be more precise, you should specify your column as "String" to keep leading zeros. An other option would also be to use lpad() function from calculator. See following Q/A.

For example : lpad('22', 4, 0), will return '0022'

  • I wonder who has invented that example, but it returns 2200 for me. Instead, I suggest left padding, as explained in gis.stackexchange.com/questions/208686/…
    – AndreJ
    Commented Sep 18, 2016 at 5:41
  • thanks for pointing this out ... Was late when I answered ;-)
    – simo
    Commented Sep 18, 2016 at 9:16
  • I am not sure, but enclosing the string values between double quotes "0082" in the CSV file could be enough.
    – user30184
    Commented Sep 18, 2016 at 16:06
  • 1
    I also wanted to add that it is necessary to upload the .csv and the .csvt files at the same time in QGis via Layer --> Add Layer --> Add Vector Layer method. Commented Nov 6, 2017 at 23:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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