0

I have a sql:

select *
from my table
where exists (
    select
    from unnest(procedure) elem
    where elem like '%String%'
          )

It works well when directly execute in database ide.

My question is how can I set 'String' as a parameters ?

I have tried:

String = 'hello world'

my_query = '''
    select *
    from my_table
    where exists (
        select
        from unnest(procedure) elem
        where elem like '% :String %'
              )
    '''

result=connection.execute(text(my_query),String=String)

However it returns nothing,I think maybe "like %" is special ?

Any friend can help ?

0

1 Answer 1

2

I think a better solution is to put the percent signs in the variable itself, and have only :String in the query:

String = '%hello world%'
my_query = '''
    ...
    where elem like :String
'''
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.