diff --git a/core/lib/Drupal/Core/Database/Driver/pgsql/Select.php b/core/lib/Drupal/Core/Database/Driver/pgsql/Select.php
index bf9f23a..08bfa90 100644
--- a/core/lib/Drupal/Core/Database/Driver/pgsql/Select.php
+++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Select.php
@@ -54,6 +54,10 @@ public function orderRandom() {
   public function orderBy($field, $direction = 'ASC') {
     // Call parent function to order on this.
     $return = parent::orderBy($field, $direction);
+    
+    if ($this->hasTag('pgsql_no_addfield_on_orderby')) {
+      return $return;
+    }
 
     // If there is a table alias specified, split it up.
     if (strpos($field, '.') !== FALSE) {
diff --git a/core/lib/Drupal/Core/Entity/Query/Sql/Query.php b/core/lib/Drupal/Core/Entity/Query/Sql/Query.php
index f5c84b4..e7179c4 100644
--- a/core/lib/Drupal/Core/Entity/Query/Sql/Query.php
+++ b/core/lib/Drupal/Core/Entity/Query/Sql/Query.php
@@ -206,6 +206,7 @@ protected function addSort() {
     }
     // Now we know whether this is a simple query or not, actually do the
     // sorting.
+    $this->sqlQuery->addTag('pgsql_no_addfield_on_orderby');
     foreach ($sort as $key => $sql_alias) {
       $direction = $this->sort[$key]['direction'];
       if ($simple_query || isset($this->sqlGroupBy[$sql_alias])) {
