0

I am wondering if there is a way to query a table for a partial match to a string.

For instance, I have a table that lists drug treatments, but sometimes there are multiple drugs in a single treatment. These come into the database as a varchar entry with both drugs separated by a semicolon (this formatting could be changed if it helped).

I know I can query on a full string, i.e.

Pharmacology() & 'treatment = "control"'

But if my entry is 'gabazine;TPMPA', is there a way to query on just 'TPMPA' and find all strings containing 'TPMPA'?

Alternatively, I could make a part table that populates just for cases where there are multiple drugs, which I could then use for querying these cases, but I am not sure how to set up the entries for better querying when the number of drugs is variable (i.e. is there a way to query inside a blob with a python list?)

Here's my table with some entries in case it helps: my table

and my table definition (part table only there as a dummy):

@schema
class Pharmacology(dj.Computed):
    definition = """
    # information about pharmacological treatments
    -> Presentation
    -> PharmInfo
    ---
    treatment           :varchar(255)       # string of the treatment name from hdf5 file
    control_flag        :int                # 1 if control 0 if in drug
    concentration       :varchar(255)       # drug concentration(s), "0" for controls
    multiple_drug_flag  :int                # 1 if multiple drugs, else 0
    """

    class MultipleDrugInfo(dj.Part):
        definition = """
        -> Pharmacology
        ---
        list_of_drugs     :blob           # list of drugs in multi-drug cases

1 Answers1

3

You can do that with the LIKE keyword

Pharmacology() & 'treatment LIKE "%TPMPA%"'

The % is wildcard in mysql.