databases
databases copied to clipboard
KeyError when using returning(literal_column('*')) with insert
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.
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)
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.