@@ -1863,7 +1863,7 @@ public function getCompiledInsert(bool $reset = true)
18631863 }
18641864
18651865 $ sql = $ this ->_insert (
1866- $ this ->db ->protectIdentifiers ($ this ->QBFrom [0 ], true , null , false ),
1866+ $ this ->db ->protectIdentifiers ($ this ->removeAlias ( $ this -> QBFrom [0 ]) , true , null , false ),
18671867 array_keys ($ this ->QBSet ),
18681868 array_values ($ this ->QBSet )
18691869 );
@@ -1895,7 +1895,7 @@ public function insert($set = null, ?bool $escape = null)
18951895 }
18961896
18971897 $ sql = $ this ->_insert (
1898- $ this ->db ->protectIdentifiers ($ this ->QBFrom [0 ], true , $ escape , false ),
1898+ $ this ->db ->protectIdentifiers ($ this ->removeAlias ( $ this -> QBFrom [0 ]) , true , $ escape , false ),
18991899 array_keys ($ this ->QBSet ),
19001900 array_values ($ this ->QBSet )
19011901 );
@@ -1914,6 +1914,19 @@ public function insert($set = null, ?bool $escape = null)
19141914 return false ;
19151915 }
19161916
1917+ protected function removeAlias (string $ from ): string
1918+ {
1919+ if (strpos ($ from , ' ' ) !== false ) {
1920+ // if the alias is written with the AS keyword, remove it
1921+ $ from = preg_replace ('/\s+AS\s+/i ' , ' ' , $ from );
1922+
1923+ $ parts = explode (' ' , $ from );
1924+ $ from = $ parts [0 ];
1925+ }
1926+
1927+ return $ from ;
1928+ }
1929+
19171930 /**
19181931 * This method is used by both insert() and getCompiledInsert() to
19191932 * validate that the there data is actually being set and that table
0 commit comments