sql-parser icon indicating copy to clipboard operation
sql-parser copied to clipboard

Avoid back ticks on INSERT INTO columns with mode POSTGRESQL

Open bertrandjamin opened this issue 4 months ago • 1 comments

Hi,

I have a problem on parsing and build an INSERT INTO query using Context::SQL_MODE_POSTGRESQL.

Given this code

$query = "INSERT INTO foo (bar, baz) VALUES ('bar', 'baz');";
Context::setMode(Context::SQL_MODE_POSTGRESQL);
$parser = new Parser($query,true);
die($parser->statements[0]->build());

The printed result is :

INSERT INTO foo(`bar`, `baz`) VALUES ('bar', 'baz')

As we can see there are back ticks around the column names. But this format is not allowed on PostgreSQL.

I tough that the line Context::setMode(Context::SQL_MODE_POSTGRESQL); should resolve this.

Did I miss something ? Is there a way to configure the lib so the columns will be encapsulated with double quotes ?

Thanks

bertrandjamin avatar Aug 08 '25 05:08 bertrandjamin

Please try if this change works for you: https://github.com/phpmyadmin/sql-parser/pull/631/files#diff-a621f887ac229d5a92692d568319bded4bd2f92bf587e5539102ba847ec4d8f9

MoonE avatar Aug 23 '25 05:08 MoonE