databases icon indicating copy to clipboard operation
databases copied to clipboard

KeyError when using returning(literal_column('*')) with insert

Open kamilglod opened this issue 5 years ago • 2 comments

slqlalchemy supports "*" as a returning value, however when I'm using it with postgres backend

row = await db.fetch_one(table.insert().values(**values).returning(literal_column('*')))

and then try to get row data KeyError shows up in this line https://github.com/encode/databases/blob/master/databases/backends/postgres.py#L105 That's because self._column_map has value {'*': (0, NullType())}

So there should be probably some extra check for the wildcard column.

kamilglod avatar Apr 22 '20 06:04 kamilglod

I ran into this issue too, this will give you what you want:

query = table.insert().values(**data).returning(*table.columns)
row = await database.fetch_one(query=query)

michaeloliverx avatar Apr 22 '20 13:04 michaeloliverx

Why it is closed? It's a bug, even if it's possible to work around it by explicit passing columns. If this library supports sqlalchemy core queries than it should support asterisk column lookup too.

kamilglod avatar Apr 23 '20 08:04 kamilglod