Pass parameters to cursor.execute('Listen ')?

From: Dumitru Melenteanu <d(dot)melenteanu(at)dekart(dot)com>
To: psycopg(at)postgresql(dot)org
Subject: Pass parameters to cursor.execute('Listen ')?
Date: 2016-05-24 09:52:20
Message-ID: 57442454.9020206@dekart.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

When performing LISTEN on a channel, passing parameters results in a
syntax error

>>> cursor.execute('Listen %s', ('hello',))`

ProgrammingError: syntax error at or near "'hello'"
LINE 1: Listen 'hello'

The only way I could get it to work is to % format it, which seems to be
very frowned upon in the documentation, with good reason, and would
prevent using `executemany` for multiple channels.

>>> cursor.execute('Listen %s'% ('hello',))

Is there any way to pass the channel as a parameter?

Attachment Content-Type Size
0xFC6C5548.asc application/pgp-keys 3.1 KB

Responses

Browse psycopg by date

  From Date Subject
Next Message Daniele Varrazzo 2016-05-24 10:58:29 Re: Pass parameters to cursor.execute('Listen ')?
Previous Message Levente Kovacs 2016-05-07 12:34:13 Re: install on windows