Search code examples
python-3.xpostgresqlpsycopg2pgadmin-4

psycopg2 "ALTER TABLE File_Data_details DROP COLUMN left" syntax error


I was trying to delete a column named "left" from my POSTGRES table called "File_Data_details", using psycopg2 python

This is my query:

query="ALTER TABLE public.File_Data_details DROP COLUMN left"

I am getting the below error.

** SyntaxError: syntax error at or near "left" LINE 1: ALTER TABLE public.File_Data_details DROP COLUMN left **

I think 'left' is some keyword that is used for some operation in POSTGRES. But I have no idea how to delete this column from my table.

Some site suggested to use square brackets. I tried that way also.

query="ALTER TABLE public.File_Data_details DROP COLUMN [left]"

But didn't work.

Could someone help me solve this?


Solution

  • The square brackets are for MSSQL. Use double quotes.

    alter table public.File_Data_details drop column "left"