[Python] Delete all Occurences of a Substring in SQL-Statement in Python

Discussão em 'Python' iniciado por Stack, Abril 29, 2025.

  1. Stack

    Stack Membro Participativo

    I have a file from a mariadb containing 3GBs of SQL-Statements. Problem is, that my SQLlite DB doesn't support the contained Key-Statements.

    Is there a way to edit the Strings containing the Statements that cuts out all substrings or statements that contain the word "key"?

    I tried the following regex pattern :

    \n(.*Key.*)


    to filter out the key statements. Any other more efficient way of doing this in Python or with other tools?

    Input:


    CREATE TABLE Persons (
    PersonID int,
    LastName varchar(255),
    FirstName varchar(255),
    Address varchar(255),
    City varchar(255),
    Primary Key(`PersonID`),
    Foreign Key(`City`)
    );

    Desired Output:


    CREATE TABLE Persons (
    PersonID int,
    LastName varchar(255),
    FirstName varchar(255),
    Address varchar(255),
    City varchar(255)
    );

    Continue reading...

Compartilhe esta Página