diff --git a/src/Codeception/Lib/Driver/PostgreSql.php b/src/Codeception/Lib/Driver/PostgreSql.php index 45bed775..3d0818eb 100644 --- a/src/Codeception/Lib/Driver/PostgreSql.php +++ b/src/Codeception/Lib/Driver/PostgreSql.php @@ -164,7 +164,7 @@ public function getPrimaryKey(string $tableName): array FROM pg_index i JOIN pg_attribute a ON a.attrelid = i.indrelid AND a.attnum = ANY(i.indkey) - WHERE i.indrelid = '{$tableName}'::regclass + WHERE i.indrelid = '\"{$tableName}\"'::regclass AND i.indisprimary"; $stmt = $this->executeQuery($query, []); $columns = $stmt->fetchAll(PDO::FETCH_ASSOC); diff --git a/tests/data/dumps/postgres.sql b/tests/data/dumps/postgres.sql index 13b87d0e..30af3596 100755 --- a/tests/data/dumps/postgres.sql +++ b/tests/data/dumps/postgres.sql @@ -448,6 +448,10 @@ CREATE TABLE "no_pk" ( "status" VARCHAR NOT NULL ); +CREATE TABLE "NoPk" ( + "Status" VARCHAR NOT NULL +); + CREATE TABLE "order" ( "id" INTEGER NOT NULL PRIMARY KEY, "name" VARCHAR NOT NULL, diff --git a/tests/unit/Codeception/Module/Db/PostgreSqlDbTest.php b/tests/unit/Codeception/Module/Db/PostgreSqlDbTest.php index 0f2c4900..ee2f8396 100644 --- a/tests/unit/Codeception/Module/Db/PostgreSqlDbTest.php +++ b/tests/unit/Codeception/Module/Db/PostgreSqlDbTest.php @@ -33,4 +33,10 @@ public function getConfig(): array 'populate' => true ]; } + + public function testHaveInDatabaseWithUppercaseTableName() + { + $testData = ['Status' => 'test']; + $this->module->haveInDatabase('NoPk', $testData); + } }