[Python] psycopg2.errors.SyntaxError: syntax error at or near "'Klines'"

Discussão em 'Python' iniciado por Stack, Agosto 3, 2025.

  1. Stack

    Stack Membro Participativo

    Can't create a new PostgreSQL table because of this error. Here is the code that I use to create a new table:

    class KlineTable(TableInterface):
    def __init__(self):
    super().__init__()
    self.__table_name: str = "Klines"

    def create(self):
    if self._is_exists(self.__table_name):
    print("table already exists.")
    return
    with self.conn_context_m() as connection:
    with connection.cursor() as cursor:
    s_command: str = """
    CREATE UNLOGGED TABLE %s(
    time INTEGER
    );
    """
    cursor.execute(s_command, (self.__table_name,))
    print("new table successfully created.")


    Here is an error that I get every time:

    Traceback (most recent call last):
    File "D:\Casper\CBranch\DataBase\table_interface.py", line 87, in conn_context_m
    yield connection
    File "D:\Casper\CBranch\DataBase\kline_table.py", line 100, in create
    cursor.execute(s_command, (self.__table_name,))
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    psycopg2.errors.SyntaxError: syntax error at or near "'Klines'"
    LINE 2: CREATE UNLOGGED TABLE 'Klines'(
    ^


    I don't understand why it appears. Would be grateful for your help.

    Continue reading...

Compartilhe esta Página