You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
frompypikaimport*# setupt1=Table('t1')
q1=Query.from_(t1).select(t1.id)
a=AliasedQuery('test')
# broken querybroken_q=PostgreSQLQuery.with_(q1, 'test').delete().using(a).where(t1.id==a.id)
>>>str(broken_q)
'DELETE USING test WHERE "t1"."id"="test"."id"'# working queryok_q=PostgreSQLQuery.with_(q1, 'test').select(a.id).from_(a).where(t1.id==a.id)
>>>str(ok_q)
'WITH test AS (SELECT "id" FROM "t1") SELECT "test"."id" FROM test WHERE "t1"."id"="test"."id"'
"real life" use case
(just in case i'm using it wrong)
frompypikaimport*table=Table("tags")
implications_table=Table("tag_implications")
id_q=Query.from_(table).select(table.id)
tag_q=id_q.where(table.name==Parameter("$1"))
tag_a=AliasedQuery("tag")
implied_q=id_q.where(table.name==Parameter("$2"))
implied_a=AliasedQuery("implied_tag")
q= (
PostgreSQLQuery.from_(implications_table)
.delete()
.using(tag_a)
.using(implied_a)
.with_(tag_q, "tag")
.with_(implied_q, "implied_tag")
.where(table.tag_id==tag_a.id)
.where(table.implied_tag_id==implied_a.id)
)
>>>str(q)
'DELETE FROM "tag_implications" USING tag,implied_tag WHERE "tags"."tag_id"="tag"."id" AND "tags"."implied_tag_id"="implied_tag"."id"'
expected output (hand written sql i'm converting to pika):
WITH tag AS (SELECT id FROM tags WHERE name=$1),
implied_tag AS (SELECT id FROM tags WHERE name=$2)
DELETEFROM tag_implications USING tag, implied_tag
WHERE tag_id=tag.idAND implied_tag_id=implied_tag.id;
The text was updated successfully, but these errors were encountered:
simplified reproduction
"real life" use case
(just in case i'm using it wrong)
expected output (hand written sql i'm converting to pika):
The text was updated successfully, but these errors were encountered: