@@ -60,6 +60,16 @@ export function getDuckDBColumnTypesMap(columns: DuckDBColumnDesc[]) {
6060 } , { } as Record < string , string > ) ;
6161}
6262
63+ /**
64+ * Quotes a column name for safe SQL usage.
65+ * Always quotes to handle all edge cases (spaces, special characters, reserved words).
66+ * @param columnName The column name to quote.
67+ * @returns The column name, properly quoted.
68+ */
69+ function quoteColumnName ( columnName : string ) : string {
70+ return `"${ columnName . replace ( / " / g, '""' ) } "` ;
71+ }
72+
6373/**
6474 * Constructs an SQL query to select all columns from a given table,
6575 * converting specified columns to Well-Known Binary (WKB) format using ST_AsWKB,
@@ -76,12 +86,13 @@ export function castDuckDBTypesForKepler(
7686) : string {
7787 const modifiedColumns = columns . map ( column => {
7888 const { name, type} = column ;
89+ const quotedName = quoteColumnName ( name ) ;
7990 if ( type === 'GEOMETRY' && options . geometryToWKB ) {
80- return `ST_AsWKB(${ name } ) as ${ name } ` ;
91+ return `ST_AsWKB(${ quotedName } ) as ${ quotedName } ` ;
8192 } else if ( type === 'BIGINT' && options . bigIntToDouble ) {
82- return `CAST(${ name } AS DOUBLE) as ${ name } ` ;
93+ return `CAST(${ quotedName } AS DOUBLE) as ${ quotedName } ` ;
8394 }
84- return name ;
95+ return quotedName ;
8596 } ) ;
8697
8798 return `SELECT ${ modifiedColumns . join ( ', ' ) } FROM '${ tableName } '` ;
0 commit comments