diff --git a/core/lib/Drupal/Core/Database/Driver/pgsql/Select.php b/core/lib/Drupal/Core/Database/Driver/pgsql/Select.php
index 8c63044..b67ec5c 100644
--- a/core/lib/Drupal/Core/Database/Driver/pgsql/Select.php
+++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Select.php
@@ -52,11 +52,12 @@ public function orderRandom() {
    * directly in SelectQuery::orderBy().
    */
   public function orderBy($field, $direction = 'ASC') {
-    // Call parent function to order on this.
-    $return = parent::orderBy($field, $direction);
+    // Only allow ASC and DESC, default to ASC.
+    $direction = strtoupper($direction) == 'DESC' ? 'DESC NULLS LAST' : 'ASC NULLS FIRST';
+    $this->order[$field] = $direction;

     if ($this->hasTag('entity_query')) {
-      return $return;
+      return $this;
     }

     // If there is a table alias specified, split it up.
@@ -68,14 +69,14 @@ public function orderBy($field, $direction = 'ASC') {
       if (!empty($table)) {
         // If table alias is given, check if field and table exists.
         if ($existing_field['table'] == $table && $existing_field['field'] == $table_field) {
-          return $return;
+          return $this;
         }
       }
       else {
         // If there is no table, simply check if the field exists as a field or
         // an aliased field.
         if ($existing_field['alias'] == $field) {
-          return $return;
+          return $this;
         }
       }
     }
@@ -83,7 +84,7 @@ public function orderBy($field, $direction = 'ASC') {
     // Also check expression aliases.
     foreach ($this->expressions as $expression) {
       if ($expression['alias'] == $this->connection->escapeAlias($field)) {
-        return $return;
+        return $this;
       }
     }

@@ -93,7 +94,7 @@ public function orderBy($field, $direction = 'ASC') {
     // actually belongs to a different table, it must be added manually.
     foreach ($this->tables as $table) {
       if (!empty($table['all_fields'])) {
-        return $return;
+        return $this;
       }
     }

@@ -101,12 +102,12 @@ public function orderBy($field, $direction = 'ASC') {
     // it is considered an expression, these can't be handled automatically
     // either.
     if ($this->connection->escapeField($field) != $field) {
-      return $return;
+      return $this;
     }

     // This is a case that can be handled automatically, add the field.
     $this->addField(NULL, $field);
-    return $return;
+    return $this;
   }

   /**
diff --git a/core/modules/system/src/Tests/Database/SelectComplexTest.php b/core/modules/system/src/Tests/Database/SelectComplexTest.php
index f63d84d..d1fa3df 100644
--- a/core/modules/system/src/Tests/Database/SelectComplexTest.php
+++ b/core/modules/system/src/Tests/Database/SelectComplexTest.php
@@ -7,7 +7,8 @@

 namespace Drupal\system\Tests\Database;

-use \Drupal\Core\Database\RowCountException;
+use Drupal\Core\Database\Database;
+use Drupal\Core\Database\RowCountException;

 /**
  * Tests the Select query builder with more complex queries.
@@ -220,7 +221,9 @@ function testCountQueryRemovals() {

     // Check that the ordering clause is handled properly.
     $orderby = $query->getOrderBy();
-    $this->assertEqual($orderby['name'], 'ASC', 'Query correctly sets ordering clause.');
+    // The orderby string is different for postgreSQL.
+    $db_type = Database::getConnection()->databaseType();
+    $this->assertEqual($orderby['name'], ($db_type == 'pgsql' ? 'ASC NULLS FIRST' : 'ASC'), 'Query correctly sets ordering clause.');
     $orderby = $count->getOrderBy();
     $this->assertFalse(isset($orderby['name']), 'Count query correctly unsets ordering caluse.');

