From 313fd6b2b9a8864329897e4ea2f29f2d6b49cc72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20JEAN?= <5880435+sebj54@users.noreply.github.com> Date: Fri, 20 Nov 2026 17:04:48 +0100 Subject: [PATCH 1/2] Support CHARACTER as a synonym of CHAR --- src/SQLParser.php | 2 ++ tests/FieldTest.php | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/SQLParser.php b/src/SQLParser.php index 82fa2ad..ac663ae 100644 --- a/src/SQLParser.php +++ b/src/SQLParser.php @@ -689,7 +689,9 @@ function parse_field($tokens){ break; # CHAR[(length)] [BINARY] [CHARACTER SET charset_name] [COLLATE collation_name] + # CHARACTER[(length)] is the standard SQL spelling of CHAR case 'CHAR': + case 'CHARACTER': $this->parse_field_binary($tokens, $f); $this->parse_field_length($tokens, $f); diff --git a/tests/FieldTest.php b/tests/FieldTest.php index 037c3ba..6cd8df6 100644 --- a/tests/FieldTest.php +++ b/tests/FieldTest.php @@ -253,6 +253,17 @@ function testChars(){ ) ), $fields); + # CHARACTER is the standard SQL spelling of CHAR, e.g. in PostgreSQL dumps + $fields = $this->get_fields("bar CHARACTER(36) NOT NULL"); + $this->assertEquals(array( + array( + 'name' => "bar", + 'type' => "CHARACTER", + 'length' => 36, + 'null' => false, + ) + ), $fields); + $fields = $this->get_fields("bar BINARY"); $this->assertEquals(array( array( From 362b83600838a3460a16265b7a53104f342d474c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20JEAN?= <5880435+sebj54@users.noreply.github.com> Date: Fri, 20 Nov 2026 17:04:48 +0100 Subject: [PATCH 2/2] Accept double-quoted identifiers --- src/SQLParser.php | 4 ++++ tests/TablesTest.php | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/SQLParser.php b/src/SQLParser.php index ac663ae..018274f 100644 --- a/src/SQLParser.php +++ b/src/SQLParser.php @@ -1148,6 +1148,10 @@ function decode_identifier($token){ if ($token[0] == '`'){ return substr($token, 1, -1); } + # standard SQL delimited identifier, e.g. PostgreSQL's "references" + if ($token[0] == '"'){ + return str_replace('""', '"', substr($token, 1, -1)); + } return $token; } diff --git a/tests/TablesTest.php b/tests/TablesTest.php index f9fc0ad..9ba2973 100644 --- a/tests/TablesTest.php +++ b/tests/TablesTest.php @@ -34,6 +34,16 @@ function testCreateTableLike(){ $this->assertEquals($tbl['like'], "bar"); } + function testDoubleQuotedIdentifiers(){ + + $tbl = $this->get_first_table('CREATE TABLE public."references" ("id" INT, "my ""odd"" name" INT)'); + + $this->assertEquals($tbl['name'], "references"); + $this->assertEquals($tbl['database'], "public"); + $this->assertEquals($tbl['fields'][0]['name'], "id"); + $this->assertEquals($tbl['fields'][1]['name'], 'my "odd" name'); + } + function testCreateTableLikeWithDb(){ $tbl = $this->get_first_table("CREATE TABLE db.foo LIKE `db2`.`bar`");