@@ -191,8 +191,10 @@ if Code.ensure_loaded?(Postgrex) do
191191 limit = limit ( query , sources )
192192 offset = offset ( query , sources )
193193 lock = lock ( query , sources )
194+ label = label ( query )
194195
195196 [
197+ label ,
196198 cte ,
197199 select ,
198200 from ,
@@ -213,25 +215,25 @@ if Code.ensure_loaded?(Postgrex) do
213215 sources = create_names ( query , [ ] )
214216 cte = cte ( query , sources )
215217 { from , name } = get_source ( query , sources , 0 , source )
216-
218+ label = label ( query )
217219 prefix = prefix || [ "UPDATE " , from , " AS " , name | " SET " ]
218220 fields = update_fields ( query , sources )
219221 { join , wheres } = using_join ( query , :update_all , "FROM" , sources )
220222 where = where ( % { query | wheres: wheres ++ query . wheres } , sources )
221223
222- [ cte , prefix , fields , join , where | returning ( query , sources ) ]
224+ [ label , cte , prefix , fields , join , where | returning ( query , sources ) ]
223225 end
224226
225227 @ impl true
226228 def delete_all ( % { from: from } = query ) do
227229 sources = create_names ( query , [ ] )
228230 cte = cte ( query , sources )
229231 { from , name } = get_source ( query , sources , 0 , from )
230-
232+ label = label ( query )
231233 { join , wheres } = using_join ( query , :delete_all , "USING" , sources )
232234 where = where ( % { query | wheres: wheres ++ query . wheres } , sources )
233235
234- [ cte , "DELETE FROM " , from , " AS " , name , join , where | returning ( query , sources ) ]
236+ [ label , cte , "DELETE FROM " , from , " AS " , name , join , where | returning ( query , sources ) ]
235237 end
236238
237239 @ impl true
@@ -880,6 +882,9 @@ if Code.ensure_loaded?(Postgrex) do
880882 end )
881883 end
882884
885+ defp label ( % { label: nil } ) , do: [ ]
886+ defp label ( % { label: label } ) , do: [ "/* " , label , " */ " ]
887+
883888 defp lock ( % { lock: nil } , _sources ) , do: [ ]
884889 defp lock ( % { lock: binary } , _sources ) when is_binary ( binary ) , do: [ ?\s | binary ]
885890 defp lock ( % { lock: expr } = query , sources ) , do: [ ?\s | expr ( expr , sources , query ) ]
0 commit comments