PostgreSQL-For-Wordpress / postgresql-for-wordpress

A maintained fork of https://wordpress.org/plugins/postgresql-for-wordpress/
GNU General Public License v2.0
209 stars 68 forks source link

Error when dealing with ALTER TABLE ... ADD INDEX #85

Closed hahnn closed 5 months ago

hahnn commented 8 months ago

There is an issue with the conversion of the kind of SQL code below:

[1701096116.0262] Error running :
ALTER TABLE wp_e_events
                ADD INDEX `created_at_index` (`created_at`)

---- converted to ----
ALTER TABLE wp_e_events
                ADD INDEX created_at_index (created_at)
----> ERREUR:  le type « created_at_index » n'existe pas
LINE 2:       ADD INDEX created_at_index (created_at)
                        ^
---------------------

So:

ALTER TABLE <table_name> ADD [UNIQUE] INDEX <index_name> (<column1_name>, <column2_name>, ...)

should be converted to:

CREATE [UNIQUE] INDEX IF NOT EXISTS <index_name> ON <table_name> (<column1_name>, <column2_name>, ...)

Then for this specific case, the result of the conversion should be something like:

CREATE INDEX IF NOT EXISTS wp_e_events_created_at_index ON wp_e_events (created_at)