yugabyte / yugabyte-db

YugabyteDB - the cloud native distributed SQL database for mission-critical applications.
https://www.yugabyte.com
Other
8.99k stars 1.07k forks source link

Support AsyncPG #5154

Open p-null opened 4 years ago

p-null commented 4 years ago

Jira Link: DB-1359 Hi,

I am using asyncpg as database driver for my python application.

Currently, it will break on split_server_version_string() in asyncpg library: inside that function it will get version_string, and convert each part of that string to int. While YugabyteDB returns the version_string containing strings that cant be converted to int. In my case, it's '11.2-YB-2.2.0.0-b0'

A minimum example to reproduce:

import asyncio
import asyncpg

async def run():
    conn = await asyncpg.connect(user='1234',
                                 password='1234',
                                 database='1234',
                                 host='1234,
                                 port=1234)
    values = await conn.execute('''SELECT name, age, language FROM employee WHERE id = 1''')
    print(values)
    await conn.close()

loop = asyncio.get_event_loop()
loop.run_until_complete(run())
p-null commented 4 years ago

The purpose of this function( get_server_version) is to get the version of PostgreSQL server originally. It will let asyncpg choose the appropriate driver to connect with PostgreSQL server.

So here I think the purpose is to get YugabyteDB's PosrgreSQL version, like which version of PostgreSQL that YB is using.

tedyu commented 4 years ago

Within '11.2-YB-2.2.0.0-b0', the 11.2 is the corresponding Postgres version.

stevebang commented 4 years ago

See related blog post: 1M rows/s from Postgres to Python

andyondrya commented 3 years ago

Hey there. Something up to date on this thread, I'm having the same issue with Yugabyte running on a kubernetes cluster, would I define it something like this?


conn = await asyncpg.connect(user='1234',
                                 password='1234',
                                 database='1234',
                                 host='1234,
                                 port=1234)
conn = conn.get_server_version()```
sycured commented 3 years ago

Have you any fix?

andyondrya commented 3 years ago

I kinda figured out the issue when I rebuilt the wheel after editing serverversion.py