How to Solve Error ERROR: syntax error at or near “[” on the Restore Process of a Database in PostgreSQL Database

Posted on


Actually, this article has a relation with the existence of the previous article. That previous article exist in this link with the title of ‘How to Solve Error Message Model Attribute Problem SyntaxError: invalid syntax in Django Application’. It is actually just inappropriate format of the column name available in the SQL file. That SQL file actually containing an INSERT statement for restoring data to the targeted database. But since there is a column name which is not following the standard rule which starts with a character that is not number or letter, it cause the restore process to fail.

The following is just to describe that accessing the database is not the cause of the problem.

Microsoft Windows [Version 10.0.19042.1288]
(c) Microsoft Corporation. All rights reserved.

C:\Users\Personal>cd \

C:\>psql -Upostgres -d db_app
Password for user postgres:
psql (14.0)
WARNING: Console code page (437) differs from Windows code page (1252)
8-bit characters might not work correctly. See psql reference
page "Notes for Windows users" for details.
Type "help" for help.

db_app=# \q

After that, the process for inserting records by importing it or restoring it using the following command exist as follows :

C:\>psql -Uuser_app -d db_app < "C:\Users\Personal\Downloads\insert-current-product.sql"
Password for user db_user:
ERROR: syntax error at or near "["
LINE 1: ...,[product_code...

As in the above command execution, it fail with an error message appear.


Actually, the solution for the above error message causing it is because of the column’s character is not a proper name for a column name. In that case, just change it into a proper one. So, edit the SQL file and find the column’s character or the column name which is the cause for the database restore process to fail. Changing the column name from [product_code] to another proper one. That new column name is ‘product_code’. After editing the file, just execute the process for importing or restoring the data once more as follows :

C:\>psql -Uuser_sinergi -d db_sinergi < "C:\Users\Personal\Downloads\insert-current-product.sql"
Password for user db_user:
INSERT 0 556


Fortunately, the process is a success as in the output of the command above.

One thought on “How to Solve Error ERROR: syntax error at or near “[” on the Restore Process of a Database in PostgreSQL Database

Leave a Reply