Describe the bug
The SQL exporter will not create SQL-compliant column names. If a column has spaces, they are replaced with "-" by default, and replaced with nothing if the "Trim Column Names" checkbox is unchecked. Hyphens are not an acceptable character in a SQL column name.
To Reproduce
Steps to reproduce the behavior:
ERROR: syntax error at or near "-"
LINE 11: Line1-Street TEXT NULL,
^
Current Results
What results occured or were shown.
Expected behavior
The SQL Exporter should, by default, convert column names to an SQL-compliant name, replacing spaces and other illegal characters with "_" (underscore). Column names can also not begin with numbers. They cannot have single quotes or punctuation.
Screenshots



Desktop (please complete the following information):
OpenRefine (please complete the following information):
@stevevance I'd prefer that we just throw a Warning signal on the SQL Exporter dialog...and then stating a small message just beneath the Content|Download tabs stating something like "Column names contain invalid chars or reserved words and need to be renamed before continuing"
This is because there are more restrictions than just characters, but whole reserved word lists, such as in PostgreSQL and others. (cannot have a column named BETWEEN) And for accuracy, you can have spaces and punctuation in Database objects, but often you have to quote the objects all the time for both creation as well as referring to the object.
SELECT filling, topping, crust FROM "3.14159";
Also, if we wanted to support highlighting any problematic column names, we would have to find a SQL Rules Library that has all the rules/restrictions for all kinds of databases. Or implement them ourselves (not an option) after we pay ISO a lot of $$$ dollars just to see the rules https://www.iso.org/standard/63565.html
Does the warning message sound like a fair tradeoff?
Incidentally, we had decided during design time of the SQL Exporter that it was up to users to get their data in the right order prior to export (which includes names/data)
I don't think we should just throw a warning, the expected behavior described above looks reasonable to me.
@wetneb Well, then the only way would be going "semi-safe"... where someone can write the Identifers conversion routines by following PostgreSQL Lexical Structure documentation as a general guide. Since ISO locks up the standard behind a paywall. https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS
Following whats in 4.1.1 of that Lexical Structure guide should make it compatible for all databases.
I am beginning to work on this. I am planning to convert the column names to valid SQL column names.
Please assign the issue to me. Thanks.
@yuepeng-unc Thanks for taking up this issue. Happy to work with you on this.
Most helpful comment
I am beginning to work on this. I am planning to convert the column names to valid SQL column names.
Please assign the issue to me. Thanks.