@@ -1305,7 +1305,7 @@ if Code.ensure_loaded?(Postgrex) do
13051305
13061306 def execute_ddl ( { command , % Index { } = index } ) when command in @ creates do
13071307 fields = Enum . map_intersperse ( index . columns , ", " , & index_expr / 1 )
1308- include_fields = Enum . map_intersperse ( index . include , ", " , & index_expr / 1 )
1308+ include_fields = Enum . map_intersperse ( index . include , ", " , & include_expr / 1 )
13091309
13101310 maybe_nulls_distinct =
13111311 case index . nulls_distinct do
@@ -1704,12 +1704,43 @@ if Code.ensure_loaded?(Postgrex) do
17041704 ":default may be a string, number, boolean, list of strings, list of integers, map (when type is Map), or a fragment(...)"
17051705 )
17061706
1707+ defp index_expr ( { dir , literal } ) when is_binary ( literal ) ,
1708+ do: index_dir ( dir , literal )
1709+
1710+ defp index_expr ( { dir , literal } ) ,
1711+ do: index_dir ( dir , quote_name ( literal ) )
1712+
17071713 defp index_expr ( literal ) when is_binary ( literal ) ,
17081714 do: literal
17091715
17101716 defp index_expr ( literal ) ,
17111717 do: quote_name ( literal )
17121718
1719+ defp index_dir ( dir , str )
1720+ when dir in [
1721+ :asc ,
1722+ :asc_nulls_first ,
1723+ :asc_nulls_last ,
1724+ :desc ,
1725+ :desc_nulls_first ,
1726+ :desc_nulls_last
1727+ ] do
1728+ case dir do
1729+ :asc -> [ str | " ASC" ]
1730+ :asc_nulls_first -> [ str | " ASC NULLS FIRST" ]
1731+ :asc_nulls_last -> [ str | " ASC NULLS LAST" ]
1732+ :desc -> [ str | " DESC" ]
1733+ :desc_nulls_first -> [ str | " DESC NULLS FIRST" ]
1734+ :desc_nulls_last -> [ str | " DESC NULLS LAST" ]
1735+ end
1736+ end
1737+
1738+ defp include_expr ( literal ) when is_binary ( literal ) ,
1739+ do: literal
1740+
1741+ defp include_expr ( literal ) ,
1742+ do: quote_name ( literal )
1743+
17131744 defp options_expr ( nil ) ,
17141745 do: [ ]
17151746
0 commit comments