{"action":"created","issue":{"url":"https://api.github.com/repos/MagicStack/asyncpg/issues/280","repository_url":"https://api.github.com/repos/MagicStack/asyncpg","labels_url":"https://api.github.com/repos/MagicStack/asyncpg/issues/280/labels{/name}","comments_url":"https://api.github.com/repos/MagicStack/asyncpg/issues/280/comments","events_url":"https://api.github.com/repos/MagicStack/asyncpg/issues/280/events","html_url":"https://github.com/MagicStack/asyncpg/issues/280","id":313820852,"number":280,"title":"Search in text array not working with variable column name.","user":{"login":"feluxe","id":6545589,"avatar_url":"https://avatars3.githubusercontent.com/u/6545589?v=4","gravatar_id":"","url":"https://api.github.com/users/feluxe","html_url":"https://github.com/feluxe","followers_url":"https://api.github.com/users/feluxe/followers","following_url":"https://api.github.com/users/feluxe/following{/other_user}","gists_url":"https://api.github.com/users/feluxe/gists{/gist_id}","starred_url":"https://api.github.com/users/feluxe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/feluxe/subscriptions","organizations_url":"https://api.github.com/users/feluxe/orgs","repos_url":"https://api.github.com/users/feluxe/repos","events_url":"https://api.github.com/users/feluxe/events{/privacy}","received_events_url":"https://api.github.com/users/feluxe/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-04-12T17:31:15Z","updated_at":"2018-05-16T15:11:45Z","closed_at":"2018-04-12T17:40:13Z","author_association":"NONE","body":"<!--\r\nThank you for reporting an issue/feature request.\r\n\r\nIf this is a feature request, please disregard this template.  If this is\r\na bug report, please answer to the questions below.\r\n\r\nIt will be much easier for us to fix the issue if a test case that reproduces\r\nthe problem is provided, with clear instructions on how to run it.\r\n\r\nThank you!\r\n-->\r\n\r\n* **asyncpg version**: `0.15.0`\r\n* **PostgreSQL version**: `10.3`\r\n* **Do you use a PostgreSQL SaaS?  If so, which?  Can you reproduce\r\n  the issue with a local PostgreSQL install?**:\r\n* **Python version**: `3.6`\r\n* **Platform**: `linux`\r\n* **Do you use pgbouncer?**: I use the offical Docker Postgres image. Never heard of pgbouncer.\r\n* **Did you install asyncpg with pip?**: `pipenv install asyncpg==0.15.0`\r\n* **If you built asyncpg locally, which version of Cython did you use?**:\r\n* **Can the issue be reproduced under both asyncio and\r\n  [uvloop](https://github.com/magicstack/uvloop)?**:\r\n\r\n<!-- Enter your issue details below this comment. -->\r\nHi there!\r\n\r\nI have a table such as this one (Note: the `parents` column is of type *text array*):\r\n```python\r\nasync def create_tables(conn):\r\n\r\n    SQL = \"\"\"\r\n    CREATE TABLE IF NOT EXISTS records (\r\n        id_ SERIAL,\r\n        parents TEXT[],\r\n        subject TEXT\r\n    );\"\"\"\r\n\r\n    await conn.execute(SQL)\r\n```\r\n\r\nLet's say the table contains values such as these:\r\n\r\n```\r\nid  | parents         | subject\r\n----------------------------------\r\n0  | {foo,bar,baz}    | subj1\r\n1  | {foo,bar}        | subj2\r\n2  | {bar,baz}        | subj3\r\n```\r\n\r\nNow if I want to retrieve all rows from the table in which any of the array items for `parents` equals `foo`, I can run a query like this one:\r\n\r\n```python\r\nq = \"SELECT subject FROM records  WHERE $1 = ANY (parents);\"\r\n\r\nasync with pg_pool.acquire() as connection:\r\n    rows = await connection.fetch(q, 'foo')\r\n```\r\n\r\nIt works fine. I get row `0` and `1`.\r\n\r\nBut if I run the same query with a second variable `$2` for the column name:\r\n\r\n```python\r\nq = \"SELECT subject FROM records  WHERE $2 = ANY ($1);\"\r\n\r\nasync with pg_pool.acquire() as connection:\r\n    rows= await connection.fetch(q, 'parents', 'foo')\r\n```\r\nit fails with this error message:\r\n\r\n```\r\n    return await connection.fetch(q, 'parents', 'foo')\r\n  File \"/usr/local/lib/python3.6/site-packages/asyncpg/connection.py\", line 359, in fetch\r\n    return await self._execute(query, args, 0, timeout)\r\n  File \"/usr/local/lib/python3.6/site-packages/asyncpg/connection.py\", line 1303, in _execute\r\n    query, args, limit, timeout, return_status=return_status)\r\n  File \"/usr/local/lib/python3.6/site-packages/asyncpg/connection.py\", line 1311, in __execute\r\n    return await self._do_execute(query, executor, timeout)\r\n  File \"/usr/local/lib/python3.6/site-packages/asyncpg/connection.py\", line 1333, in _do_execute\r\n    result = await executor(stmt, None)\r\n  File \"asyncpg/protocol/protocol.pyx\", line 185, in bind_execute\r\n  File \"asyncpg/protocol/prepared_stmt.pyx\", line 148, in asyncpg.protocol.protocol.PreparedStatementState._encode_bind_msg\r\n  File \"asyncpg/protocol/codecs/base.pyx\", line 164, in asyncpg.protocol.protocol.Codec.encode\r\n  File \"asyncpg/protocol/codecs/base.pyx\", line 100, in asyncpg.protocol.protocol.Codec.encode_scalar\r\n  File \"asyncpg/protocol/codecs/array.pyx\", line 832, in asyncpg.protocol.protocol.arraytext_encode\r\n  File \"asyncpg/protocol/codecs/array.pyx\", line 105, in asyncpg.protocol.protocol.array_encode\r\nTypeError: a non-trivial iterable expected (got type 'str')\r\n```\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/MagicStack/asyncpg/issues/comments/389554976","html_url":"https://github.com/MagicStack/asyncpg/issues/280#issuecomment-389554976","issue_url":"https://api.github.com/repos/MagicStack/asyncpg/issues/280","id":389554976,"user":{"login":"approxit","id":6125496,"avatar_url":"https://avatars3.githubusercontent.com/u/6125496?v=4","gravatar_id":"","url":"https://api.github.com/users/approxit","html_url":"https://github.com/approxit","followers_url":"https://api.github.com/users/approxit/followers","following_url":"https://api.github.com/users/approxit/following{/other_user}","gists_url":"https://api.github.com/users/approxit/gists{/gist_id}","starred_url":"https://api.github.com/users/approxit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/approxit/subscriptions","organizations_url":"https://api.github.com/users/approxit/orgs","repos_url":"https://api.github.com/users/approxit/repos","events_url":"https://api.github.com/users/approxit/events{/privacy}","received_events_url":"https://api.github.com/users/approxit/received_events","type":"User","site_admin":false},"created_at":"2018-05-16T15:11:45Z","updated_at":"2018-05-16T15:11:45Z","author_association":"NONE","body":"@elprans So is there anything that asyncpg ships for escaping variables to safety use it as column name?"}}
{"actor":{"display_login":"approxit"}}