commit e960331081f15ef80ed30690cbcfcf1476c8ef22
Author: Karoly Negyesi <chx1975@gmail.com>
Date:   Sat Aug 3 02:24:30 2013 -0700

    we need https://drupal.org/node/2056363 as well

diff --git a/core/lib/Drupal/Core/Database/Driver/mysql/Insert.php b/core/lib/Drupal/Core/Database/Driver/mysql/Insert.php
index 233118c..d7a8a59 100644
--- a/core/lib/Drupal/Core/Database/Driver/mysql/Insert.php
+++ b/core/lib/Drupal/Core/Database/Driver/mysql/Insert.php
@@ -49,7 +49,8 @@ public function __toString() {
     // If we're selecting from a SelectQuery, finish building the query and
     // pass it back, as any remaining options are irrelevant.
     if (!empty($this->fromQuery)) {
-      return $comments . 'INSERT INTO {' . $this->table . '} (' . implode(', ', $insert_fields) . ') ' . $this->fromQuery;
+      $insert_fields_string = $insert_fields ? ' (' . implode(', ', $insert_fields) . ') ' : '';
+      return $comments . 'INSERT INTO {' . $this->table . '} ' . $insert_fields_string . $this->fromQuery;
     }
 
     $query = $comments . 'INSERT INTO {' . $this->table . '} (' . implode(', ', $insert_fields) . ') VALUES ';
diff --git a/core/lib/Drupal/Core/Database/Driver/pgsql/Insert.php b/core/lib/Drupal/Core/Database/Driver/pgsql/Insert.php
index dffa1fd..e2380dd 100644
--- a/core/lib/Drupal/Core/Database/Driver/pgsql/Insert.php
+++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Insert.php
@@ -118,7 +118,8 @@ public function __toString() {
     // If we're selecting from a SelectQuery, finish building the query and
     // pass it back, as any remaining options are irrelevant.
     if (!empty($this->fromQuery)) {
-      return $comments . 'INSERT INTO {' . $this->table . '} (' . implode(', ', $insert_fields) . ') ' . $this->fromQuery;
+      $insert_fields_string = $insert_fields ? ' (' . implode(', ', $insert_fields) . ') ' : '';
+      return $comments . 'INSERT INTO {' . $this->table . '} ' . $insert_fields_string . $this->fromQuery;
     }
 
     $query = $comments . 'INSERT INTO {' . $this->table . '} (' . implode(', ', $insert_fields) . ') VALUES ';
diff --git a/core/lib/Drupal/Core/Database/Driver/sqlite/Insert.php b/core/lib/Drupal/Core/Database/Driver/sqlite/Insert.php
index e584943..83f01fe 100644
--- a/core/lib/Drupal/Core/Database/Driver/sqlite/Insert.php
+++ b/core/lib/Drupal/Core/Database/Driver/sqlite/Insert.php
@@ -40,10 +40,11 @@ public function __toString() {
     // If we're selecting from a SelectQuery, finish building the query and
     // pass it back, as any remaining options are irrelevant.
     if (!empty($this->fromQuery)) {
-      return $comments . 'INSERT INTO {' . $this->table . '} (' . implode(', ', $this->insertFields) . ') ' . $this->fromQuery;
+      $insert_fields_string = $this->insertFields ? ' (' . implode(', ', $this->insertFields) . ') ' : '';
+      return $comments . 'INSERT INTO {' . $this->table . '} ' . $insert_fields_string . $this->fromQuery;
     }
 
     return $comments . 'INSERT INTO {' . $this->table . '} (' . implode(', ', $this->insertFields) . ') VALUES (' . implode(', ', $placeholders) . ')';
   }
 
-}
\ No newline at end of file
+}
diff --git a/core/lib/Drupal/Core/Database/Query/Insert.php b/core/lib/Drupal/Core/Database/Query/Insert.php
index 7862436..a0d4655 100644
--- a/core/lib/Drupal/Core/Database/Query/Insert.php
+++ b/core/lib/Drupal/Core/Database/Query/Insert.php
@@ -266,8 +266,8 @@ public function __toString() {
    * @return
    *   TRUE if the validation was successful, FALSE if not.
    *
-   * @throws Drupal\Core\Database\Query\FieldsOverlapException
-   * @throws Drupal\Core\Database\Query\NoFieldsException
+   * @throws \Drupal\Core\Database\Query\FieldsOverlapException
+   * @throws \Drupal\Core\Database\Query\NoFieldsException
    */
   public function preExecute() {
     // Confirm that the user did not try to specify an identical
@@ -284,9 +284,8 @@ public function preExecute() {
       // first call to fields() does have an effect.
       $this->fields(array_merge(array_keys($this->fromQuery->getFields()), array_keys($this->fromQuery->getExpressions())));
     }
-
     // Don't execute query without fields.
-    if (count($this->insertFields) + count($this->defaultFields) == 0) {
+    elseif (count($this->insertFields) + count($this->defaultFields) == 0) {
       throw new NoFieldsException('There are no fields available to insert with.');
     }
 
diff --git a/core/modules/system/lib/Drupal/system/Tests/Database/DatabaseTestBase.php b/core/modules/system/lib/Drupal/system/Tests/Database/DatabaseTestBase.php
index 17d7ec0..0aa4d5b 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Database/DatabaseTestBase.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Database/DatabaseTestBase.php
@@ -24,6 +24,7 @@ function setUp() {
     $this->installSchema('database_test', array(
       'test',
       'test_people',
+      'test_people_copy',
       'test_one_blob',
       'test_two_blobs',
       'test_task',
diff --git a/core/modules/system/lib/Drupal/system/Tests/Database/InsertTest.php b/core/modules/system/lib/Drupal/system/Tests/Database/InsertTest.php
index 76afcf8..ae98918 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Database/InsertTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Database/InsertTest.php
@@ -165,5 +165,21 @@ function testInsertSelect() {
 
     $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Meredith'))->fetchField();
     $this->assertIdentical($saved_age, '30', 'Can retrieve after inserting.');
+
+    // Test the "INSERT INTO ... SELECT * FROM" syntax.
+    $query = db_select('test_people', 'tp')
+      ->fields('tp')
+      ->condition('tp.name', 'Meredith');
+    // The resulting query should be equivalent to:
+    // INSERT INTO test_people_copy
+    // SELECT *
+    // FROM test_people tp
+    // WHERE tp.name = 'Meredith'
+    db_insert('test_people_copy')
+      ->from($query)
+      ->execute();
+
+    $saved_age = db_query('SELECT age FROM {test_people_copy} WHERE name = :name', array(':name' => 'Meredith'))->fetchField();
+    $this->assertIdentical($saved_age, '30', 'Can retrieve after inserting.');
   }
 }
diff --git a/core/modules/system/tests/modules/database_test/database_test.install b/core/modules/system/tests/modules/database_test/database_test.install
index 867d813..866d453 100644
--- a/core/modules/system/tests/modules/database_test/database_test.install
+++ b/core/modules/system/tests/modules/database_test/database_test.install
@@ -87,6 +87,37 @@ function database_test_schema() {
     ),
   );
 
+  $schema['test_people_copy'] = array(
+    'description' => 'A duplicate version of the test_people table, used for additional tests.',
+    'fields' => array(
+      'name' => array(
+        'description' => "A person's name",
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE,
+        'default' => '',
+      ),
+      'age' => array(
+        'description' => "The person's age",
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'job' => array(
+        'description' => "The person's job",
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE,
+        'default' => '',
+      ),
+    ),
+    'primary key' => array('job'),
+    'indexes' => array(
+      'ages' => array('age'),
+    ),
+  );
+
   $schema['test_one_blob'] = array(
     'description' => 'A simple table including a BLOB field for testing BLOB behavior.',
     'fields' => array(
