0

in the below code, i am trying to create table.at run time i receive the following error:

psycopg2.errors.SyntaxError: FEHLER:  Syntaxfehler bei »(«
LINE 2:             CREATE TABLE IF NOT EXISTS ('distancesFromPoints...
                               

to solve this issue, i enclosed the %s between curly-brackets but it did not solve the issue. please let me know how to fix it ^

code

    def executeCreateTableDistancesFromPointToNearestEdge(self):
    query="""
        CREATE TABLE IF NOT EXISTS (%s) (pointGeometry distanceToNearestEdge);   
    """.format(table=config['Distance_To_Nearest_Edge']['table_name'])
    data = self.connection.execute(query,[config['Distance_To_Nearest_Edge']['table_name']])
    # print("data: ",data)        
    return data
LetsamrIt
  • 3,653
  • 7
  • 39
  • 72
  • You can't. It has to be formatted. – rdas Oct 26 '21 at 09:31
  • @rdas would you please show me how? – LetsamrIt Oct 26 '21 at 09:32
  • @LetsamrIt it is a issue in the string concatenation. The SQL statement created has single quotes in the table name, which is not valid. Perhaps a difference placeholder would do the trick. Check the documentation for `.format()`. – Jim Jones Oct 26 '21 at 09:54

0 Answers0