Skip to main content
Solved

_ in fieldname change to - underscore. How to solve?


Forum|alt.badge.img

Dear all, I having problems with writing an - character in a fieldname. If i chance it to - then FME will automaticaly change it to _ (underscore) do have have a idea?

I use the writer Spatialite. FME 2017.1. If i manualy change it to - then FME changes it to _....

Best answer by hollyatsafe

Hi @tbaving,

 

The answer provided by @ChrisAtSafe is the best way to do this. Since the correct formatting is showing in the Data Inspector it may be that spatialite doesn't except the hyphen character so FME automatically changes it to one it will.

This note: "SQL names cannot contain forbidden characters (such as spaces, brackets, colons, hyphens and so on" found here: https://www.gaia-gis.it/spatialite-3.0.0-BETA/spatialite-cookbook/html/basic-sql.html supports my suggestion.

There are some other articles online that suggest you can include forbidden characters in an SQLite field name if they are escaped in quotes or brackets, but sites contradict themselves on how this should be written:

https://stackoverflow.com/questions/23770480/sqlite-table-and-column-name-requirements?rq=1http://sqlite.1065341.n5.nabble.com/special-characters-as-column-names-td36677.html

Please consider voting for this idea to support special characters in writers and include a comment with details on the specific writer and your use case.

View original
Did this help you find an answer to your question?

11 replies

danilo_fme
Evangelist
Forum|alt.badge.img+42
  • Evangelist
  • August 29, 2018

Hi @tbaving

Try to use the transformer StringReplacer.

Thanks,

Danilo


danilo_fme
Evangelist
Forum|alt.badge.img+42
  • Evangelist
  • August 29, 2018
danilo_fme wrote:

Hi @tbaving

Try to use the transformer StringReplacer.

Thanks,

Danilo

 

Please, see it

 


chrisatsafe
Contributor
Forum|alt.badge.img+2
  • Contributor
  • August 29, 2018

Hi @tbaving,

If you want to change multiple attribute names you can use the BulkAttributeRenamer. Set the Action to String Replace, Text to Find to "-", and String (to replace) to "_".

I've attached an example workspace for you to test out for yourself.

-Chris

rename-attribute-name.fmwt


Forum|alt.badge.img
  • Author
  • August 29, 2018

Dear all, with the inspecotor it works.... But if i add the spatialite writer it writes again an underscore instead of - . What im doing wrong? Many thanks guys.


Forum|alt.badge.img
  • Author
  • August 29, 2018
chrisatsafe wrote:

Hi @tbaving,

If you want to change multiple attribute names you can use the BulkAttributeRenamer. Set the Action to String Replace, Text to Find to "-", and String (to replace) to "_".

I've attached an example workspace for you to test out for yourself.

-Chris

rename-attribute-name.fmwt

@ChrisAtSafe


Forum|alt.badge.img
  • Author
  • August 29, 2018

Sorry i changed it. I mean _ to -.. change the topic tiltle.....


Forum|alt.badge.img+2
  • Best Answer
  • August 29, 2018

Hi @tbaving,

 

The answer provided by @ChrisAtSafe is the best way to do this. Since the correct formatting is showing in the Data Inspector it may be that spatialite doesn't except the hyphen character so FME automatically changes it to one it will.

This note: "SQL names cannot contain forbidden characters (such as spaces, brackets, colons, hyphens and so on" found here: https://www.gaia-gis.it/spatialite-3.0.0-BETA/spatialite-cookbook/html/basic-sql.html supports my suggestion.

There are some other articles online that suggest you can include forbidden characters in an SQLite field name if they are escaped in quotes or brackets, but sites contradict themselves on how this should be written:

https://stackoverflow.com/questions/23770480/sqlite-table-and-column-name-requirements?rq=1http://sqlite.1065341.n5.nabble.com/special-characters-as-column-names-td36677.html

Please consider voting for this idea to support special characters in writers and include a comment with details on the specific writer and your use case.


Forum|alt.badge.img+2
tbaving wrote:

Dear all, with the inspecotor it works.... But if i add the spatialite writer it writes again an underscore instead of - . What im doing wrong? Many thanks guys.

Hi @tbaving,

 

It may be that the spatialite doesn't except the - character so FME automatically changes it to one it will.

 

This note: "SQL names cannot contain forbidden characters (such as spaces, brackets, colons, hyphens and so on" found here: https://www.gaia-gis.it/spatialite-3.0.0-BETA/spatialite-cookbook/html/basic-sql.html supports my suggestion.

 


Forum|alt.badge.img
  • Author
  • August 30, 2018
hollyatsafe wrote:

Hi @tbaving,

 

The answer provided by @ChrisAtSafe is the best way to do this. Since the correct formatting is showing in the Data Inspector it may be that spatialite doesn't except the hyphen character so FME automatically changes it to one it will.

This note: "SQL names cannot contain forbidden characters (such as spaces, brackets, colons, hyphens and so on" found here: https://www.gaia-gis.it/spatialite-3.0.0-BETA/spatialite-cookbook/html/basic-sql.html supports my suggestion.

There are some other articles online that suggest you can include forbidden characters in an SQLite field name if they are escaped in quotes or brackets, but sites contradict themselves on how this should be written:

https://stackoverflow.com/questions/23770480/sqlite-table-and-column-name-requirements?rq=1http://sqlite.1065341.n5.nabble.com/special-characters-as-column-names-td36677.html

Please consider voting for this idea to support special characters in writers and include a comment with details on the specific writer and your use case.

 

And what about geopackage? Normally in qgis it accepts dashes. But in FME it automaticaly changes back to _ :(

david_r
Evangelist
  • August 30, 2018

Here's a workaround for the Geopackage format that probably isn't condoned by Safe at all ;-)

Open the file <FME Home>\metafile\geopackage.fmf in a text editor.

Modify lines 281 and 282 (or thereabouts, depending on your FME version) to remove the "-" character, the lines should read like this, notice the lack of the "-" character:

MACRO _FeatureTypeInvalidCharacters \\\"{}()',@&`~!#$%^*+=|[]:;<>?./
MACRO _AttributeInvalidCharacters \\\"{}()',@&`~!#$%^*+=|[]:;<>?./

Restart FME. You should now be able to create both feature types and attributes containing dashes:

0684Q00000ArKjqQAF.png

Tested with FME 2018.1 and QGIS 2.18.10, but no guarantees given whatsoever...


david_r
Evangelist
  • August 30, 2018
hollyatsafe wrote:

Hi @tbaving,

 

The answer provided by @ChrisAtSafe is the best way to do this. Since the correct formatting is showing in the Data Inspector it may be that spatialite doesn't except the hyphen character so FME automatically changes it to one it will.

This note: "SQL names cannot contain forbidden characters (such as spaces, brackets, colons, hyphens and so on" found here: https://www.gaia-gis.it/spatialite-3.0.0-BETA/spatialite-cookbook/html/basic-sql.html supports my suggestion.

There are some other articles online that suggest you can include forbidden characters in an SQLite field name if they are escaped in quotes or brackets, but sites contradict themselves on how this should be written:

https://stackoverflow.com/questions/23770480/sqlite-table-and-column-name-requirements?rq=1http://sqlite.1065341.n5.nabble.com/special-characters-as-column-names-td36677.html

Please consider voting for this idea to support special characters in writers and include a comment with details on the specific writer and your use case.

Actually, dashes seem to work just fine in GeoPackage, see my workaround below.

Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings