1

I am trying to insert records to a redshift table using a lambda function. I am using

boto3.client('redshift-data')

for the same. Now I have the query as below.

query1 = "insert into dbname.tablename values('aaaa','bbbb','cccc')"

response = rsclient.execute_statement(
        ClusterIdentifier='xxxxx',
        Database='yyyy',
        DbUser='zzzz',
        Sql= query1,
        StatementName='examplestatement'
        )

This works fine. But I want to pass variables here instead of values. For instance,

var1 = 'aaaa'
var2 = 'bbbb'
var3 = 'cccc'

Then try the query as below but it it doesn't work, I think it something silly to do with quotes.

query1 = "insert into dbname.tablename values(var1,var2,var3)"

How can I achieve this. I write lambda function using python3. Any help is appreciated.

1 Answer 1

1

You can use f-strings:

query1 = f"insert into dbname.tablename values('{var1}','{var2}','{var3}')"
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.