Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kamilglod opened this issue Apr 22, 2020 · 2 comments
Open

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

kamilglod opened this issue Apr 22, 2020 · 2 comments

Comments

@kamilglod
Copy link

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.

@michaeloliverx
Copy link
Member

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)

@kamilglod
Copy link
Author

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.

@tomchristie tomchristie reopened this Apr 23, 2020
rsommer pushed a commit to rsommer/databases that referenced this issue Apr 1, 2022
If no explicit colum info is present, the postgres Record class causes a
KeyError. Besides the given example in encode#190 this also
happens if you construct the queries from text-clauses.

Handling this the same way as if there is no entry in `self._column_map`
fixes the error.

A simple testcase is added as well.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants