Skip to content

Commit 8a295c4

Browse files
authored
fix: allow uppercase table names by quoting the table name when fetching the primary key of a table in PostgreSQL (#82)
1 parent 23bc6a3 commit 8a295c4

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

src/Codeception/Lib/Driver/PostgreSql.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public function getPrimaryKey(string $tableName): array
164164
FROM pg_index i
165165
JOIN pg_attribute a ON a.attrelid = i.indrelid
166166
AND a.attnum = ANY(i.indkey)
167-
WHERE i.indrelid = '{$tableName}'::regclass
167+
WHERE i.indrelid = '\"{$tableName}\"'::regclass
168168
AND i.indisprimary";
169169
$stmt = $this->executeQuery($query, []);
170170
$columns = $stmt->fetchAll(PDO::FETCH_ASSOC);

tests/data/dumps/postgres.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,10 @@ CREATE TABLE "no_pk" (
448448
"status" VARCHAR NOT NULL
449449
);
450450

451+
CREATE TABLE "NoPk" (
452+
"Status" VARCHAR NOT NULL
453+
);
454+
451455
CREATE TABLE "order" (
452456
"id" INTEGER NOT NULL PRIMARY KEY,
453457
"name" VARCHAR NOT NULL,

tests/unit/Codeception/Module/Db/PostgreSqlDbTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,10 @@ public function getConfig(): array
3333
'populate' => true
3434
];
3535
}
36+
37+
public function testHaveInDatabaseWithUppercaseTableName()
38+
{
39+
$testData = ['Status' => 'test'];
40+
$this->module->haveInDatabase('NoPk', $testData);
41+
}
3642
}

0 commit comments

Comments
 (0)