Is is possible to use .as_alias() for Json field from a joined table? #551
-
I struggle to apply Here is an example:
Here is my query:
The output is:
Here is AS coupled, and I have an obvious error:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
@Anton-Karpenko You're right this is a bug. I was able to replicate it using this script: import asyncio
from piccolo.table import Table, create_db_tables, drop_db_tables
from piccolo.columns import Varchar, JSONB, ForeignKey
from piccolo.engine.sqlite import SQLiteEngine
DB = SQLiteEngine()
class User(Table, tablename="my_user", db=DB):
name = Varchar(length=120)
config = JSONB(default={})
class Subscriber(Table, tablename="subscriber", db=DB):
name = Varchar(length=120)
user = ForeignKey(references=User)
async def main():
await drop_db_tables(User, Subscriber)
await create_db_tables(User, Subscriber)
user = await User.objects().create(name="Bob")
await Subscriber.objects().create(user=user, name="Susan")
results = await Subscriber.select(
Subscriber.name.as_alias("subscriber_name"),
Subscriber.user.config.as_alias("config")
)
print(results)
if __name__ == '__main__':
asyncio.run(main()) The problem just seems to be with piccolo/piccolo/columns/column_types.py Line 2230 in 2288596 The SQL query has multiple 'AS' when using SELECT
"subscriber"."name" AS subscriber_name,
"subscriber$user"."config" AS "user$config" AS config -- This is the problem, there are two 'AS' statements
FROM subscriber
LEFT JOIN my_user subscriber$user
ON (subscriber.user = subscriber$user.id) Hopefully it's quite a simple fix. In the meantime, you can use the |
Beta Was this translation helpful? Give feedback.
@Anton-Karpenko You're right this is a bug. I was able to replicate it using this script: