Title: [Bug]: Problem exporting an unsual index (IFNULL expression) · Issue #640 · phpmyadmin/sql-parser · GitHub
Open Graph Title: [Bug]: Problem exporting an unsual index (IFNULL expression) · Issue #640 · phpmyadmin/sql-parser
X Title: [Bug]: Problem exporting an unsual index (IFNULL expression) · Issue #640 · phpmyadmin/sql-parser
Description: Describe the bug I added this index to a table: ALTER TABLE drafts ADD UNIQUE unique_draft (type,user,(IFNULL(touser,'_CHAT_'))) USING BTREE; and when I try to export it fails with this error (on hosting phpmyadmin version 5.1.0, mysql i...
Open Graph Description: Describe the bug I added this index to a table: ALTER TABLE drafts ADD UNIQUE unique_draft (type,user,(IFNULL(touser,'_CHAT_'))) USING BTREE; and when I try to export it fails with this error (on h...
X Description: Describe the bug I added this index to a table: ALTER TABLE drafts ADD UNIQUE unique_draft (type,user,(IFNULL(touser,'_CHAT_'))) USING BTREE; and when I try to export it fails with this err...
Opengraph URL: https://github.com/phpmyadmin/sql-parser/issues/640
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: Problem exporting an unsual index (IFNULL expression) ","articleBody":"### Describe the bug\n\nI added this index to a table:\n```sql\nALTER TABLE drafts\n ADD UNIQUE unique_draft (type,user,(IFNULL(touser,'_CHAT_'))) USING BTREE;\n```\nand when I try to export it fails with this error (on hosting phpmyadmin version 5.1.0, mysql is Percona 8.0.43-34):\n\n> \u003cb>Fatal error\u003c/b>: Uncaught TypeError: str_replace(): Argument phpmyadmin/phpmyadmin#3 ($subject) must be of type array|string, null given in /var/www/html/phpMyAdmin/vendor/phpmyadmin/sql-parser/src/Context.php:608\n> Stack trace:\n> #0 /var/www/html/phpMyAdmin/vendor/phpmyadmin/sql-parser/src/Context.php(608): str_replace()\n> phpmyadmin/phpmyadmin#1 /var/www/html/phpMyAdmin/vendor/phpmyadmin/sql-parser/src/Components/Key.php(203): PhpMyAdmin\\SqlParser\\Context::escape()\n> phpmyadmin/phpmyadmin#2 /var/www/html/phpMyAdmin/vendor/phpmyadmin/sql-parser/src/Component.php(74): PhpMyAdmin\\SqlParser\\Components\\Key::build()\n> phpmyadmin/phpmyadmin#3 /var/www/html/phpMyAdmin/vendor/phpmyadmin/sql-parser/src/Components/CreateDefinition.php(360): PhpMyAdmin\\SqlParser\\Component->__toString()\n> phpmyadmin/phpmyadmin#4 /var/www/html/phpMyAdmin/vendor/phpmyadmin/sql-parser/src/Component.php(74): PhpMyAdmin\\SqlParser\\Components\\CreateDefinition::build()\n> phpmyadmin/phpmyadmin#5 [internal function]: PhpMyAdmin\\SqlParser\\Component->__toString()\n> phpmyadmin/phpmyadmin#6 /var/www/html/phpMyAdmin/vendor/phpmyadmin/sql-parser/src/Components/CreateDefinition.php(339): implode()\n> phpmyadmin/phpmyadmin#7 /var/www/html/phpMyAdmin/vendor/phpmyadmin/sql-parser/src/Statements/CreateStatement.php(380): PhpMyAdmin\\SqlParser\\Components\\CreateDefinition::build()\n> phpmyadmin/phpmyadmin#8 /var/www/html/phpMyAdmin/libraries/classes/Plugins/Export/ExportSql.php(2951): PhpMyAdmin\\SqlParser\\Statements\\CreateStatement->build()\n> phpmyadmin/phpmyadmin#9 /var/www/html/phpMyAdmin/libraries/classes/Plugins/Export/ExportSql.php(1638): PhpMyAdmin\\Plugins\\Export\\ExportSql->replaceWithAliases()\n> phpmyadmin/phpmyadmin#10 /var/www/html/phpMyAdmin/libraries/classes/Plugins/Export/ExportSql.php(2138): PhpMyAdmin\\Plugins\\Export\\ExportSql->getTableDef()\n> phpmyadmin/phpmyadmin#11 /var/www/html/phpMyAdmin/libraries/classes/Export.php(813): PhpMyAdmin\\Plugins\\Export\\ExportSql->exportStructure()\n> phpmyadmin/phpmyadmin#12 /var/www/html/phpMyAdmin/libraries/classes/Controllers/ExportController.php(549): PhpMyAdmin\\Export->exportDatabase()\n> phpmyadmin/phpmyadmin#13 /var/www/html/phpMyAdmin/libraries/classes/Routing.php(186): PhpMyAdmin\\Controllers\\ExportController->index()\n> phpmyadmin/phpmyadmin#14 /var/www/html/phpMyAdmin/index.php(50): PhpMyAdmin\\Routing::callControllerForRoute()\n> phpmyadmin/phpmyadmin#15 {main}\n> thrown in \u003cb>/var/www/html/phpMyAdmin/vendor/phpmyadmin/sql-parser/src/Context.php\u003c/b> on line \u003cb>608\u003c/b>\u003cbr />\n\nOn version 5.2.1 with mysql 8.0.41 it won't fails but the export result is like this \n```sql\nALTER TABLE drafts ADD UNIQUE KEY unique_draft (type,user,(_CHAT_));\n```\nwhich is wrong.\n\n### How to Reproduce\n\nTable structure is:\n```sql\nCREATE TABLE drafts (\n type enum('CHAT','MSGS') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,\n user varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,\n touser varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,\n text text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,\n date datetime NOT NULL\n);\nALTER TABLE drafts ADD UNIQUE unique_draft (type, user,(IFNULL(touser,'_CHAT_'))) USING BTREE;\n```\n\n\n### Expected behavior\n\nI expect it to export the index like the original one\n\n### Screenshots\n\n_No response_\n\n### Operating System\n\n_No response_\n\n### Web Server\n\n_No response_\n\n### Database Server\n\nMySQL\n\n### Database version\n\n_No response_\n\n### PHP version\n\n_No response_\n\n### phpMyAdmin version\n\n5.1.0\n\n### browser\n\n_No response_\n\n### Additional context\n\n_No response_","author":{"url":"https://github.com/alescan86","@type":"Person","name":"alescan86"},"datePublished":"2025-12-09T14:36:30Z","url":"https://github.com/phpmyadmin/sql-parser/issues/640"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:fc577444-9bd6-3268-bac9-5f21ebe20c47 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E346:1567FF:34E4E1:477DB7:6B0436BA |
| html-safe-nonce | 7e1613a930e51305126d3524bc026498699b09b10c8eb6b654e264d1bf04a2c9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMzQ2OjE1NjdGRjozNEU0RTE6NDc3REI3OjZCMDQzNkJBIiwidmlzaXRvcl9pZCI6IjY3OTcyOTA5NDc1Mzg1OTc1NjIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 92a732e8f18d45e47cf558536c8de93bab4464965e7c003c19a94f786a58b7a4 |
| hovercard-subject-tag | issue:3911110365 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/phpmyadmin/sql-parser/640/issue_layout |
| twitter:image | https://opengraph.githubassets.com/768eb09b7c7ebff315ac7ba60a7e0d5719472f4f300fce9a54e979311a5df9d2/phpmyadmin/sql-parser/issues/640 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/768eb09b7c7ebff315ac7ba60a7e0d5719472f4f300fce9a54e979311a5df9d2/phpmyadmin/sql-parser/issues/640 |
| og:image:alt | Describe the bug I added this index to a table: ALTER TABLE drafts ADD UNIQUE unique_draft (type,user,(IFNULL(touser,'_CHAT_'))) USING BTREE; and when I try to export it fails with this error (on h... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | alescan86 |
| hostname | github.com |
| expected-hostname | github.com |
| None | b7a1d2b9101496921b08579fbee988d014345aef2f5bd660d1f8c7332d81560e |
| turbo-cache-control | no-preview |
| go-import | github.com/phpmyadmin/sql-parser git https://github.com/phpmyadmin/sql-parser.git |
| octolytics-dimension-user_id | 1351977 |
| octolytics-dimension-user_login | phpmyadmin |
| octolytics-dimension-repository_id | 36256604 |
| octolytics-dimension-repository_nwo | phpmyadmin/sql-parser |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 36256604 |
| octolytics-dimension-repository_network_root_nwo | phpmyadmin/sql-parser |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | c3dd496c3da6ea6b77e69c09279d2b81604654f1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width