diff options
Diffstat (limited to 'docs/sqlglot/dialects/redshift.html')
-rw-r--r-- | docs/sqlglot/dialects/redshift.html | 1461 |
1 files changed, 978 insertions, 483 deletions
diff --git a/docs/sqlglot/dialects/redshift.html b/docs/sqlglot/dialects/redshift.html index df8dba1..e6fbcb8 100644 --- a/docs/sqlglot/dialects/redshift.html +++ b/docs/sqlglot/dialects/redshift.html @@ -317,159 +317,323 @@ </span><span id="L-79"><a href="#L-79"><span class="linenos"> 79</span></a> <span class="n">alias_tokens</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Collection</span><span class="p">[</span><span class="n">TokenType</span><span class="p">]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> </span><span id="L-80"><a href="#L-80"><span class="linenos"> 80</span></a> <span class="n">parse_bracket</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span> </span><span id="L-81"><a href="#L-81"><span class="linenos"> 81</span></a> <span class="n">is_db_reference</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span> -</span><span id="L-82"><a href="#L-82"><span class="linenos"> 82</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">]:</span> -</span><span id="L-83"><a href="#L-83"><span class="linenos"> 83</span></a> <span class="c1"># Redshift supports UNPIVOTing SUPER objects, e.g. `UNPIVOT foo.obj[0] AS val AT attr`</span> -</span><span id="L-84"><a href="#L-84"><span class="linenos"> 84</span></a> <span class="n">unpivot</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_match</span><span class="p">(</span><span class="n">TokenType</span><span class="o">.</span><span class="n">UNPIVOT</span><span class="p">)</span> -</span><span id="L-85"><a href="#L-85"><span class="linenos"> 85</span></a> <span class="n">table</span> <span class="o">=</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">_parse_table</span><span class="p">(</span> -</span><span id="L-86"><a href="#L-86"><span class="linenos"> 86</span></a> <span class="n">schema</span><span class="o">=</span><span class="n">schema</span><span class="p">,</span> -</span><span id="L-87"><a href="#L-87"><span class="linenos"> 87</span></a> <span class="n">joins</span><span class="o">=</span><span class="n">joins</span><span class="p">,</span> -</span><span id="L-88"><a href="#L-88"><span class="linenos"> 88</span></a> <span class="n">alias_tokens</span><span class="o">=</span><span class="n">alias_tokens</span><span class="p">,</span> -</span><span id="L-89"><a href="#L-89"><span class="linenos"> 89</span></a> <span class="n">parse_bracket</span><span class="o">=</span><span class="n">parse_bracket</span><span class="p">,</span> -</span><span id="L-90"><a href="#L-90"><span class="linenos"> 90</span></a> <span class="n">is_db_reference</span><span class="o">=</span><span class="n">is_db_reference</span><span class="p">,</span> -</span><span id="L-91"><a href="#L-91"><span class="linenos"> 91</span></a> <span class="p">)</span> -</span><span id="L-92"><a href="#L-92"><span class="linenos"> 92</span></a> -</span><span id="L-93"><a href="#L-93"><span class="linenos"> 93</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Pivot</span><span class="p">,</span> <span class="n">this</span><span class="o">=</span><span class="n">table</span><span class="p">,</span> <span class="n">unpivot</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> <span class="k">if</span> <span class="n">unpivot</span> <span class="k">else</span> <span class="n">table</span> -</span><span id="L-94"><a href="#L-94"><span class="linenos"> 94</span></a> -</span><span id="L-95"><a href="#L-95"><span class="linenos"> 95</span></a> <span class="k">def</span> <span class="nf">_parse_convert</span><span class="p">(</span> -</span><span id="L-96"><a href="#L-96"><span class="linenos"> 96</span></a> <span class="bp">self</span><span class="p">,</span> <span class="n">strict</span><span class="p">:</span> <span class="nb">bool</span><span class="p">,</span> <span class="n">safe</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">bool</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span> -</span><span id="L-97"><a href="#L-97"><span class="linenos"> 97</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">]:</span> -</span><span id="L-98"><a href="#L-98"><span class="linenos"> 98</span></a> <span class="n">to</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_types</span><span class="p">()</span> -</span><span id="L-99"><a href="#L-99"><span class="linenos"> 99</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">_match</span><span class="p">(</span><span class="n">TokenType</span><span class="o">.</span><span class="n">COMMA</span><span class="p">)</span> -</span><span id="L-100"><a href="#L-100"><span class="linenos">100</span></a> <span class="n">this</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_bitwise</span><span class="p">()</span> -</span><span id="L-101"><a href="#L-101"><span class="linenos">101</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">TryCast</span><span class="p">,</span> <span class="n">this</span><span class="o">=</span><span class="n">this</span><span class="p">,</span> <span class="n">to</span><span class="o">=</span><span class="n">to</span><span class="p">,</span> <span class="n">safe</span><span class="o">=</span><span class="n">safe</span><span class="p">)</span> -</span><span id="L-102"><a href="#L-102"><span class="linenos">102</span></a> -</span><span id="L-103"><a href="#L-103"><span class="linenos">103</span></a> <span class="k">def</span> <span class="nf">_parse_approximate_count</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">exp</span><span class="o">.</span><span class="n">ApproxDistinct</span><span class="p">]:</span> -</span><span id="L-104"><a href="#L-104"><span class="linenos">104</span></a> <span class="n">index</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_index</span> <span class="o">-</span> <span class="mi">1</span> -</span><span id="L-105"><a href="#L-105"><span class="linenos">105</span></a> <span class="n">func</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_function</span><span class="p">()</span> -</span><span id="L-106"><a href="#L-106"><span class="linenos">106</span></a> -</span><span id="L-107"><a href="#L-107"><span class="linenos">107</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">func</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Count</span><span class="p">)</span> <span class="ow">and</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">func</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Distinct</span><span class="p">):</span> -</span><span id="L-108"><a href="#L-108"><span class="linenos">108</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">ApproxDistinct</span><span class="p">,</span> <span class="n">this</span><span class="o">=</span><span class="n">seq_get</span><span class="p">(</span><span class="n">func</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">expressions</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span> -</span><span id="L-109"><a href="#L-109"><span class="linenos">109</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">_retreat</span><span class="p">(</span><span class="n">index</span><span class="p">)</span> -</span><span id="L-110"><a href="#L-110"><span class="linenos">110</span></a> <span class="k">return</span> <span class="kc">None</span> -</span><span id="L-111"><a href="#L-111"><span class="linenos">111</span></a> -</span><span id="L-112"><a href="#L-112"><span class="linenos">112</span></a> <span class="k">class</span> <span class="nc">Tokenizer</span><span class="p">(</span><span class="n">Postgres</span><span class="o">.</span><span class="n">Tokenizer</span><span class="p">):</span> -</span><span id="L-113"><a href="#L-113"><span class="linenos">113</span></a> <span class="n">BIT_STRINGS</span> <span class="o">=</span> <span class="p">[]</span> -</span><span id="L-114"><a href="#L-114"><span class="linenos">114</span></a> <span class="n">HEX_STRINGS</span> <span class="o">=</span> <span class="p">[]</span> -</span><span id="L-115"><a href="#L-115"><span class="linenos">115</span></a> <span class="n">STRING_ESCAPES</span> <span class="o">=</span> <span class="p">[</span><span class="s2">"</span><span class="se">\\</span><span class="s2">"</span><span class="p">,</span> <span class="s2">"'"</span><span class="p">]</span> -</span><span id="L-116"><a href="#L-116"><span class="linenos">116</span></a> -</span><span id="L-117"><a href="#L-117"><span class="linenos">117</span></a> <span class="n">KEYWORDS</span> <span class="o">=</span> <span class="p">{</span> -</span><span id="L-118"><a href="#L-118"><span class="linenos">118</span></a> <span class="o">**</span><span class="n">Postgres</span><span class="o">.</span><span class="n">Tokenizer</span><span class="o">.</span><span class="n">KEYWORDS</span><span class="p">,</span> -</span><span id="L-119"><a href="#L-119"><span class="linenos">119</span></a> <span class="s2">"HLLSKETCH"</span><span class="p">:</span> <span class="n">TokenType</span><span class="o">.</span><span class="n">HLLSKETCH</span><span class="p">,</span> -</span><span id="L-120"><a href="#L-120"><span class="linenos">120</span></a> <span class="s2">"SUPER"</span><span class="p">:</span> <span class="n">TokenType</span><span class="o">.</span><span class="n">SUPER</span><span class="p">,</span> -</span><span id="L-121"><a href="#L-121"><span class="linenos">121</span></a> <span class="s2">"TOP"</span><span class="p">:</span> <span class="n">TokenType</span><span class="o">.</span><span class="n">TOP</span><span class="p">,</span> -</span><span id="L-122"><a href="#L-122"><span class="linenos">122</span></a> <span class="s2">"UNLOAD"</span><span class="p">:</span> <span class="n">TokenType</span><span class="o">.</span><span class="n">COMMAND</span><span class="p">,</span> -</span><span id="L-123"><a href="#L-123"><span class="linenos">123</span></a> <span class="s2">"VARBYTE"</span><span class="p">:</span> <span class="n">TokenType</span><span class="o">.</span><span class="n">VARBINARY</span><span class="p">,</span> -</span><span id="L-124"><a href="#L-124"><span class="linenos">124</span></a> <span class="p">}</span> -</span><span id="L-125"><a href="#L-125"><span class="linenos">125</span></a> <span class="n">KEYWORDS</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s2">"VALUES"</span><span class="p">)</span> -</span><span id="L-126"><a href="#L-126"><span class="linenos">126</span></a> -</span><span id="L-127"><a href="#L-127"><span class="linenos">127</span></a> <span class="c1"># Redshift allows # to appear as a table identifier prefix</span> -</span><span id="L-128"><a href="#L-128"><span class="linenos">128</span></a> <span class="n">SINGLE_TOKENS</span> <span class="o">=</span> <span class="n">Postgres</span><span class="o">.</span><span class="n">Tokenizer</span><span class="o">.</span><span class="n">SINGLE_TOKENS</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> -</span><span id="L-129"><a href="#L-129"><span class="linenos">129</span></a> <span class="n">SINGLE_TOKENS</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s2">"#"</span><span class="p">)</span> -</span><span id="L-130"><a href="#L-130"><span class="linenos">130</span></a> -</span><span id="L-131"><a href="#L-131"><span class="linenos">131</span></a> <span class="k">class</span> <span class="nc">Generator</span><span class="p">(</span><span class="n">Postgres</span><span class="o">.</span><span class="n">Generator</span><span class="p">):</span> -</span><span id="L-132"><a href="#L-132"><span class="linenos">132</span></a> <span class="n">LOCKING_READS_SUPPORTED</span> <span class="o">=</span> <span class="kc">False</span> -</span><span id="L-133"><a href="#L-133"><span class="linenos">133</span></a> <span class="n">QUERY_HINTS</span> <span class="o">=</span> <span class="kc">False</span> -</span><span id="L-134"><a href="#L-134"><span class="linenos">134</span></a> <span class="n">VALUES_AS_TABLE</span> <span class="o">=</span> <span class="kc">False</span> -</span><span id="L-135"><a href="#L-135"><span class="linenos">135</span></a> <span class="n">TZ_TO_WITH_TIME_ZONE</span> <span class="o">=</span> <span class="kc">True</span> -</span><span id="L-136"><a href="#L-136"><span class="linenos">136</span></a> <span class="n">NVL2_SUPPORTED</span> <span class="o">=</span> <span class="kc">True</span> -</span><span id="L-137"><a href="#L-137"><span class="linenos">137</span></a> <span class="n">LAST_DAY_SUPPORTS_DATE_PART</span> <span class="o">=</span> <span class="kc">False</span> -</span><span id="L-138"><a href="#L-138"><span class="linenos">138</span></a> <span class="n">CAN_IMPLEMENT_ARRAY_ANY</span> <span class="o">=</span> <span class="kc">False</span> -</span><span id="L-139"><a href="#L-139"><span class="linenos">139</span></a> <span class="n">MULTI_ARG_DISTINCT</span> <span class="o">=</span> <span class="kc">True</span> -</span><span id="L-140"><a href="#L-140"><span class="linenos">140</span></a> -</span><span id="L-141"><a href="#L-141"><span class="linenos">141</span></a> <span class="n">TYPE_MAPPING</span> <span class="o">=</span> <span class="p">{</span> -</span><span id="L-142"><a href="#L-142"><span class="linenos">142</span></a> <span class="o">**</span><span class="n">Postgres</span><span class="o">.</span><span class="n">Generator</span><span class="o">.</span><span class="n">TYPE_MAPPING</span><span class="p">,</span> -</span><span id="L-143"><a href="#L-143"><span class="linenos">143</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">BINARY</span><span class="p">:</span> <span class="s2">"VARBYTE"</span><span class="p">,</span> -</span><span id="L-144"><a href="#L-144"><span class="linenos">144</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">INT</span><span class="p">:</span> <span class="s2">"INTEGER"</span><span class="p">,</span> -</span><span id="L-145"><a href="#L-145"><span class="linenos">145</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">TIMETZ</span><span class="p">:</span> <span class="s2">"TIME"</span><span class="p">,</span> -</span><span id="L-146"><a href="#L-146"><span class="linenos">146</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">TIMESTAMPTZ</span><span class="p">:</span> <span class="s2">"TIMESTAMP"</span><span class="p">,</span> -</span><span id="L-147"><a href="#L-147"><span class="linenos">147</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">VARBINARY</span><span class="p">:</span> <span class="s2">"VARBYTE"</span><span class="p">,</span> -</span><span id="L-148"><a href="#L-148"><span class="linenos">148</span></a> <span class="p">}</span> -</span><span id="L-149"><a href="#L-149"><span class="linenos">149</span></a> -</span><span id="L-150"><a href="#L-150"><span class="linenos">150</span></a> <span class="n">TRANSFORMS</span> <span class="o">=</span> <span class="p">{</span> -</span><span id="L-151"><a href="#L-151"><span class="linenos">151</span></a> <span class="o">**</span><span class="n">Postgres</span><span class="o">.</span><span class="n">Generator</span><span class="o">.</span><span class="n">TRANSFORMS</span><span class="p">,</span> -</span><span id="L-152"><a href="#L-152"><span class="linenos">152</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Concat</span><span class="p">:</span> <span class="n">concat_to_dpipe_sql</span><span class="p">,</span> -</span><span id="L-153"><a href="#L-153"><span class="linenos">153</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">ConcatWs</span><span class="p">:</span> <span class="n">concat_ws_to_dpipe_sql</span><span class="p">,</span> -</span><span id="L-154"><a href="#L-154"><span class="linenos">154</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">ApproxDistinct</span><span class="p">:</span> <span class="k">lambda</span> <span class="bp">self</span><span class="p">,</span> -</span><span id="L-155"><a href="#L-155"><span class="linenos">155</span></a> <span class="n">e</span><span class="p">:</span> <span class="sa">f</span><span class="s2">"APPROXIMATE COUNT(DISTINCT </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="p">,</span><span class="w"> </span><span class="s1">'this'</span><span class="p">)</span><span class="si">}</span><span class="s2">)"</span><span class="p">,</span> -</span><span id="L-156"><a href="#L-156"><span class="linenos">156</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">CurrentTimestamp</span><span class="p">:</span> <span class="k">lambda</span> <span class="bp">self</span><span class="p">,</span> <span class="n">e</span><span class="p">:</span> <span class="p">(</span> -</span><span id="L-157"><a href="#L-157"><span class="linenos">157</span></a> <span class="s2">"SYSDATE"</span> <span class="k">if</span> <span class="n">e</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"transaction"</span><span class="p">)</span> <span class="k">else</span> <span class="s2">"GETDATE()"</span> -</span><span id="L-158"><a href="#L-158"><span class="linenos">158</span></a> <span class="p">),</span> -</span><span id="L-159"><a href="#L-159"><span class="linenos">159</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DateAdd</span><span class="p">:</span> <span class="n">date_delta_sql</span><span class="p">(</span><span class="s2">"DATEADD"</span><span class="p">),</span> -</span><span id="L-160"><a href="#L-160"><span class="linenos">160</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DateDiff</span><span class="p">:</span> <span class="n">date_delta_sql</span><span class="p">(</span><span class="s2">"DATEDIFF"</span><span class="p">),</span> -</span><span id="L-161"><a href="#L-161"><span class="linenos">161</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DistKeyProperty</span><span class="p">:</span> <span class="k">lambda</span> <span class="bp">self</span><span class="p">,</span> <span class="n">e</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="s2">"DISTKEY"</span><span class="p">,</span> <span class="n">e</span><span class="o">.</span><span class="n">this</span><span class="p">),</span> -</span><span id="L-162"><a href="#L-162"><span class="linenos">162</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DistStyleProperty</span><span class="p">:</span> <span class="k">lambda</span> <span class="bp">self</span><span class="p">,</span> <span class="n">e</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">naked_property</span><span class="p">(</span><span class="n">e</span><span class="p">),</span> -</span><span id="L-163"><a href="#L-163"><span class="linenos">163</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">FromBase</span><span class="p">:</span> <span class="n">rename_func</span><span class="p">(</span><span class="s2">"STRTOL"</span><span class="p">),</span> -</span><span id="L-164"><a href="#L-164"><span class="linenos">164</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">GeneratedAsIdentityColumnConstraint</span><span class="p">:</span> <span class="n">generatedasidentitycolumnconstraint_sql</span><span class="p">,</span> -</span><span id="L-165"><a href="#L-165"><span class="linenos">165</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">JSONExtract</span><span class="p">:</span> <span class="n">json_extract_segments</span><span class="p">(</span><span class="s2">"JSON_EXTRACT_PATH_TEXT"</span><span class="p">),</span> -</span><span id="L-166"><a href="#L-166"><span class="linenos">166</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">JSONExtractScalar</span><span class="p">:</span> <span class="n">json_extract_segments</span><span class="p">(</span><span class="s2">"JSON_EXTRACT_PATH_TEXT"</span><span class="p">),</span> -</span><span id="L-167"><a href="#L-167"><span class="linenos">167</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">GroupConcat</span><span class="p">:</span> <span class="n">rename_func</span><span class="p">(</span><span class="s2">"LISTAGG"</span><span class="p">),</span> -</span><span id="L-168"><a href="#L-168"><span class="linenos">168</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">ParseJSON</span><span class="p">:</span> <span class="n">rename_func</span><span class="p">(</span><span class="s2">"JSON_PARSE"</span><span class="p">),</span> -</span><span id="L-169"><a href="#L-169"><span class="linenos">169</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Select</span><span class="p">:</span> <span class="n">transforms</span><span class="o">.</span><span class="n">preprocess</span><span class="p">(</span> -</span><span id="L-170"><a href="#L-170"><span class="linenos">170</span></a> <span class="p">[</span><span class="n">transforms</span><span class="o">.</span><span class="n">eliminate_distinct_on</span><span class="p">,</span> <span class="n">transforms</span><span class="o">.</span><span class="n">eliminate_semi_and_anti_joins</span><span class="p">]</span> -</span><span id="L-171"><a href="#L-171"><span class="linenos">171</span></a> <span class="p">),</span> -</span><span id="L-172"><a href="#L-172"><span class="linenos">172</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">SortKeyProperty</span><span class="p">:</span> <span class="k">lambda</span> <span class="bp">self</span><span class="p">,</span> -</span><span id="L-173"><a href="#L-173"><span class="linenos">173</span></a> <span class="n">e</span><span class="p">:</span> <span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="s1">'COMPOUND '</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">e</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s1">'compound'</span><span class="p">]</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="s1">''</span><span class="si">}</span><span class="s2">SORTKEY(</span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">format_args</span><span class="p">(</span><span class="o">*</span><span class="n">e</span><span class="o">.</span><span class="n">this</span><span class="p">)</span><span class="si">}</span><span class="s2">)"</span><span class="p">,</span> -</span><span id="L-174"><a href="#L-174"><span class="linenos">174</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">StartsWith</span><span class="p">:</span> <span class="k">lambda</span> <span class="bp">self</span><span class="p">,</span> -</span><span id="L-175"><a href="#L-175"><span class="linenos">175</span></a> <span class="n">e</span><span class="p">:</span> <span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">this</span><span class="p">)</span><span class="si">}</span><span class="s2"> LIKE </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">expression</span><span class="p">)</span><span class="si">}</span><span class="s2"> || '%'"</span><span class="p">,</span> -</span><span id="L-176"><a href="#L-176"><span class="linenos">176</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">TableSample</span><span class="p">:</span> <span class="n">no_tablesample_sql</span><span class="p">,</span> -</span><span id="L-177"><a href="#L-177"><span class="linenos">177</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">TsOrDsAdd</span><span class="p">:</span> <span class="n">date_delta_sql</span><span class="p">(</span><span class="s2">"DATEADD"</span><span class="p">),</span> -</span><span id="L-178"><a href="#L-178"><span class="linenos">178</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">TsOrDsDiff</span><span class="p">:</span> <span class="n">date_delta_sql</span><span class="p">(</span><span class="s2">"DATEDIFF"</span><span class="p">),</span> -</span><span id="L-179"><a href="#L-179"><span class="linenos">179</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">UnixToTime</span><span class="p">:</span> <span class="k">lambda</span> <span class="bp">self</span><span class="p">,</span> -</span><span id="L-180"><a href="#L-180"><span class="linenos">180</span></a> <span class="n">e</span><span class="p">:</span> <span class="sa">f</span><span class="s2">"(TIMESTAMP 'epoch' + </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">this</span><span class="p">)</span><span class="si">}</span><span class="s2"> * INTERVAL '1 SECOND')"</span><span class="p">,</span> -</span><span id="L-181"><a href="#L-181"><span class="linenos">181</span></a> <span class="p">}</span> -</span><span id="L-182"><a href="#L-182"><span class="linenos">182</span></a> -</span><span id="L-183"><a href="#L-183"><span class="linenos">183</span></a> <span class="c1"># Postgres maps exp.Pivot to no_pivot_sql, but Redshift support pivots</span> -</span><span id="L-184"><a href="#L-184"><span class="linenos">184</span></a> <span class="n">TRANSFORMS</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Pivot</span><span class="p">)</span> -</span><span id="L-185"><a href="#L-185"><span class="linenos">185</span></a> -</span><span id="L-186"><a href="#L-186"><span class="linenos">186</span></a> <span class="c1"># Redshift uses the POW | POWER (expr1, expr2) syntax instead of expr1 ^ expr2 (postgres)</span> -</span><span id="L-187"><a href="#L-187"><span class="linenos">187</span></a> <span class="n">TRANSFORMS</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Pow</span><span class="p">)</span> +</span><span id="L-82"><a href="#L-82"><span class="linenos"> 82</span></a> <span class="n">parse_partition</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span> +</span><span id="L-83"><a href="#L-83"><span class="linenos"> 83</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">]:</span> +</span><span id="L-84"><a href="#L-84"><span class="linenos"> 84</span></a> <span class="c1"># Redshift supports UNPIVOTing SUPER objects, e.g. `UNPIVOT foo.obj[0] AS val AT attr`</span> +</span><span id="L-85"><a href="#L-85"><span class="linenos"> 85</span></a> <span class="n">unpivot</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_match</span><span class="p">(</span><span class="n">TokenType</span><span class="o">.</span><span class="n">UNPIVOT</span><span class="p">)</span> +</span><span id="L-86"><a href="#L-86"><span class="linenos"> 86</span></a> <span class="n">table</span> <span class="o">=</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">_parse_table</span><span class="p">(</span> +</span><span id="L-87"><a href="#L-87"><span class="linenos"> 87</span></a> <span class="n">schema</span><span class="o">=</span><span class="n">schema</span><span class="p">,</span> +</span><span id="L-88"><a href="#L-88"><span class="linenos"> 88</span></a> <span class="n">joins</span><span class="o">=</span><span class="n">joins</span><span class="p">,</span> +</span><span id="L-89"><a href="#L-89"><span class="linenos"> 89</span></a> <span class="n">alias_tokens</span><span class="o">=</span><span class="n">alias_tokens</span><span class="p">,</span> +</span><span id="L-90"><a href="#L-90"><span class="linenos"> 90</span></a> <span class="n">parse_bracket</span><span class="o">=</span><span class="n">parse_bracket</span><span class="p">,</span> +</span><span id="L-91"><a href="#L-91"><span class="linenos"> 91</span></a> <span class="n">is_db_reference</span><span class="o">=</span><span class="n">is_db_reference</span><span class="p">,</span> +</span><span id="L-92"><a href="#L-92"><span class="linenos"> 92</span></a> <span class="p">)</span> +</span><span id="L-93"><a href="#L-93"><span class="linenos"> 93</span></a> +</span><span id="L-94"><a href="#L-94"><span class="linenos"> 94</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Pivot</span><span class="p">,</span> <span class="n">this</span><span class="o">=</span><span class="n">table</span><span class="p">,</span> <span class="n">unpivot</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> <span class="k">if</span> <span class="n">unpivot</span> <span class="k">else</span> <span class="n">table</span> +</span><span id="L-95"><a href="#L-95"><span class="linenos"> 95</span></a> +</span><span id="L-96"><a href="#L-96"><span class="linenos"> 96</span></a> <span class="k">def</span> <span class="nf">_parse_convert</span><span class="p">(</span> +</span><span id="L-97"><a href="#L-97"><span class="linenos"> 97</span></a> <span class="bp">self</span><span class="p">,</span> <span class="n">strict</span><span class="p">:</span> <span class="nb">bool</span><span class="p">,</span> <span class="n">safe</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">bool</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span> +</span><span id="L-98"><a href="#L-98"><span class="linenos"> 98</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">]:</span> +</span><span id="L-99"><a href="#L-99"><span class="linenos"> 99</span></a> <span class="n">to</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_types</span><span class="p">()</span> +</span><span id="L-100"><a href="#L-100"><span class="linenos">100</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">_match</span><span class="p">(</span><span class="n">TokenType</span><span class="o">.</span><span class="n">COMMA</span><span class="p">)</span> +</span><span id="L-101"><a href="#L-101"><span class="linenos">101</span></a> <span class="n">this</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_bitwise</span><span class="p">()</span> +</span><span id="L-102"><a href="#L-102"><span class="linenos">102</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">TryCast</span><span class="p">,</span> <span class="n">this</span><span class="o">=</span><span class="n">this</span><span class="p">,</span> <span class="n">to</span><span class="o">=</span><span class="n">to</span><span class="p">,</span> <span class="n">safe</span><span class="o">=</span><span class="n">safe</span><span class="p">)</span> +</span><span id="L-103"><a href="#L-103"><span class="linenos">103</span></a> +</span><span id="L-104"><a href="#L-104"><span class="linenos">104</span></a> <span class="k">def</span> <span class="nf">_parse_approximate_count</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">exp</span><span class="o">.</span><span class="n">ApproxDistinct</span><span class="p">]:</span> +</span><span id="L-105"><a href="#L-105"><span class="linenos">105</span></a> <span class="n">index</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_index</span> <span class="o">-</span> <span class="mi">1</span> +</span><span id="L-106"><a href="#L-106"><span class="linenos">106</span></a> <span class="n">func</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_function</span><span class="p">()</span> +</span><span id="L-107"><a href="#L-107"><span class="linenos">107</span></a> +</span><span id="L-108"><a href="#L-108"><span class="linenos">108</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">func</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Count</span><span class="p">)</span> <span class="ow">and</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">func</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Distinct</span><span class="p">):</span> +</span><span id="L-109"><a href="#L-109"><span class="linenos">109</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">ApproxDistinct</span><span class="p">,</span> <span class="n">this</span><span class="o">=</span><span class="n">seq_get</span><span class="p">(</span><span class="n">func</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">expressions</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span> +</span><span id="L-110"><a href="#L-110"><span class="linenos">110</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">_retreat</span><span class="p">(</span><span class="n">index</span><span class="p">)</span> +</span><span id="L-111"><a href="#L-111"><span class="linenos">111</span></a> <span class="k">return</span> <span class="kc">None</span> +</span><span id="L-112"><a href="#L-112"><span class="linenos">112</span></a> +</span><span id="L-113"><a href="#L-113"><span class="linenos">113</span></a> <span class="k">class</span> <span class="nc">Tokenizer</span><span class="p">(</span><span class="n">Postgres</span><span class="o">.</span><span class="n">Tokenizer</span><span class="p">):</span> +</span><span id="L-114"><a href="#L-114"><span class="linenos">114</span></a> <span class="n">BIT_STRINGS</span> <span class="o">=</span> <span class="p">[]</span> +</span><span id="L-115"><a href="#L-115"><span class="linenos">115</span></a> <span class="n">HEX_STRINGS</span> <span class="o">=</span> <span class="p">[]</span> +</span><span id="L-116"><a href="#L-116"><span class="linenos">116</span></a> <span class="n">STRING_ESCAPES</span> <span class="o">=</span> <span class="p">[</span><span class="s2">"</span><span class="se">\\</span><span class="s2">"</span><span class="p">,</span> <span class="s2">"'"</span><span class="p">]</span> +</span><span id="L-117"><a href="#L-117"><span class="linenos">117</span></a> +</span><span id="L-118"><a href="#L-118"><span class="linenos">118</span></a> <span class="n">KEYWORDS</span> <span class="o">=</span> <span class="p">{</span> +</span><span id="L-119"><a href="#L-119"><span class="linenos">119</span></a> <span class="o">**</span><span class="n">Postgres</span><span class="o">.</span><span class="n">Tokenizer</span><span class="o">.</span><span class="n">KEYWORDS</span><span class="p">,</span> +</span><span id="L-120"><a href="#L-120"><span class="linenos">120</span></a> <span class="s2">"HLLSKETCH"</span><span class="p">:</span> <span class="n">TokenType</span><span class="o">.</span><span class="n">HLLSKETCH</span><span class="p">,</span> +</span><span id="L-121"><a href="#L-121"><span class="linenos">121</span></a> <span class="s2">"SUPER"</span><span class="p">:</span> <span class="n">TokenType</span><span class="o">.</span><span class="n">SUPER</span><span class="p">,</span> +</span><span id="L-122"><a href="#L-122"><span class="linenos">122</span></a> <span class="s2">"TOP"</span><span class="p">:</span> <span class="n">TokenType</span><span class="o">.</span><span class="n">TOP</span><span class="p">,</span> +</span><span id="L-123"><a href="#L-123"><span class="linenos">123</span></a> <span class="s2">"UNLOAD"</span><span class="p">:</span> <span class="n">TokenType</span><span class="o">.</span><span class="n">COMMAND</span><span class="p">,</span> +</span><span id="L-124"><a href="#L-124"><span class="linenos">124</span></a> <span class="s2">"VARBYTE"</span><span class="p">:</span> <span class="n">TokenType</span><span class="o">.</span><span class="n">VARBINARY</span><span class="p">,</span> +</span><span id="L-125"><a href="#L-125"><span class="linenos">125</span></a> <span class="p">}</span> +</span><span id="L-126"><a href="#L-126"><span class="linenos">126</span></a> <span class="n">KEYWORDS</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s2">"VALUES"</span><span class="p">)</span> +</span><span id="L-127"><a href="#L-127"><span class="linenos">127</span></a> +</span><span id="L-128"><a href="#L-128"><span class="linenos">128</span></a> <span class="c1"># Redshift allows # to appear as a table identifier prefix</span> +</span><span id="L-129"><a href="#L-129"><span class="linenos">129</span></a> <span class="n">SINGLE_TOKENS</span> <span class="o">=</span> <span class="n">Postgres</span><span class="o">.</span><span class="n">Tokenizer</span><span class="o">.</span><span class="n">SINGLE_TOKENS</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="L-130"><a href="#L-130"><span class="linenos">130</span></a> <span class="n">SINGLE_TOKENS</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s2">"#"</span><span class="p">)</span> +</span><span id="L-131"><a href="#L-131"><span class="linenos">131</span></a> +</span><span id="L-132"><a href="#L-132"><span class="linenos">132</span></a> <span class="k">class</span> <span class="nc">Generator</span><span class="p">(</span><span class="n">Postgres</span><span class="o">.</span><span class="n">Generator</span><span class="p">):</span> +</span><span id="L-133"><a href="#L-133"><span class="linenos">133</span></a> <span class="n">LOCKING_READS_SUPPORTED</span> <span class="o">=</span> <span class="kc">False</span> +</span><span id="L-134"><a href="#L-134"><span class="linenos">134</span></a> <span class="n">QUERY_HINTS</span> <span class="o">=</span> <span class="kc">False</span> +</span><span id="L-135"><a href="#L-135"><span class="linenos">135</span></a> <span class="n">VALUES_AS_TABLE</span> <span class="o">=</span> <span class="kc">False</span> +</span><span id="L-136"><a href="#L-136"><span class="linenos">136</span></a> <span class="n">TZ_TO_WITH_TIME_ZONE</span> <span class="o">=</span> <span class="kc">True</span> +</span><span id="L-137"><a href="#L-137"><span class="linenos">137</span></a> <span class="n">NVL2_SUPPORTED</span> <span class="o">=</span> <span class="kc">True</span> +</span><span id="L-138"><a href="#L-138"><span class="linenos">138</span></a> <span class="n">LAST_DAY_SUPPORTS_DATE_PART</span> <span class="o">=</span> <span class="kc">False</span> +</span><span id="L-139"><a href="#L-139"><span class="linenos">139</span></a> <span class="n">CAN_IMPLEMENT_ARRAY_ANY</span> <span class="o">=</span> <span class="kc">False</span> +</span><span id="L-140"><a href="#L-140"><span class="linenos">140</span></a> <span class="n">MULTI_ARG_DISTINCT</span> <span class="o">=</span> <span class="kc">True</span> +</span><span id="L-141"><a href="#L-141"><span class="linenos">141</span></a> +</span><span id="L-142"><a href="#L-142"><span class="linenos">142</span></a> <span class="n">TYPE_MAPPING</span> <span class="o">=</span> <span class="p">{</span> +</span><span id="L-143"><a href="#L-143"><span class="linenos">143</span></a> <span class="o">**</span><span class="n">Postgres</span><span class="o">.</span><span class="n">Generator</span><span class="o">.</span><span class="n">TYPE_MAPPING</span><span class="p">,</span> +</span><span id="L-144"><a href="#L-144"><span class="linenos">144</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">BINARY</span><span class="p">:</span> <span class="s2">"VARBYTE"</span><span class="p">,</span> +</span><span id="L-145"><a href="#L-145"><span class="linenos">145</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">INT</span><span class="p">:</span> <span class="s2">"INTEGER"</span><span class="p">,</span> +</span><span id="L-146"><a href="#L-146"><span class="linenos">146</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">TIMETZ</span><span class="p">:</span> <span class="s2">"TIME"</span><span class="p">,</span> +</span><span id="L-147"><a href="#L-147"><span class="linenos">147</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">TIMESTAMPTZ</span><span class="p">:</span> <span class="s2">"TIMESTAMP"</span><span class="p">,</span> +</span><span id="L-148"><a href="#L-148"><span class="linenos">148</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">VARBINARY</span><span class="p">:</span> <span class="s2">"VARBYTE"</span><span class="p">,</span> +</span><span id="L-149"><a href="#L-149"><span class="linenos">149</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">ROWVERSION</span><span class="p">:</span> <span class="s2">"VARBYTE"</span><span class="p">,</span> +</span><span id="L-150"><a href="#L-150"><span class="linenos">150</span></a> <span class="p">}</span> +</span><span id="L-151"><a href="#L-151"><span class="linenos">151</span></a> +</span><span id="L-152"><a href="#L-152"><span class="linenos">152</span></a> <span class="n">TRANSFORMS</span> <span class="o">=</span> <span class="p">{</span> +</span><span id="L-153"><a href="#L-153"><span class="linenos">153</span></a> <span class="o">**</span><span class="n">Postgres</span><span class="o">.</span><span class="n">Generator</span><span class="o">.</span><span class="n">TRANSFORMS</span><span class="p">,</span> +</span><span id="L-154"><a href="#L-154"><span class="linenos">154</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Concat</span><span class="p">:</span> <span class="n">concat_to_dpipe_sql</span><span class="p">,</span> +</span><span id="L-155"><a href="#L-155"><span class="linenos">155</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">ConcatWs</span><span class="p">:</span> <span class="n">concat_ws_to_dpipe_sql</span><span class="p">,</span> +</span><span id="L-156"><a href="#L-156"><span class="linenos">156</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">ApproxDistinct</span><span class="p">:</span> <span class="k">lambda</span> <span class="bp">self</span><span class="p">,</span> +</span><span id="L-157"><a href="#L-157"><span class="linenos">157</span></a> <span class="n">e</span><span class="p">:</span> <span class="sa">f</span><span class="s2">"APPROXIMATE COUNT(DISTINCT </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="p">,</span><span class="w"> </span><span class="s1">'this'</span><span class="p">)</span><span class="si">}</span><span class="s2">)"</span><span class="p">,</span> +</span><span id="L-158"><a href="#L-158"><span class="linenos">158</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">CurrentTimestamp</span><span class="p">:</span> <span class="k">lambda</span> <span class="bp">self</span><span class="p">,</span> <span class="n">e</span><span class="p">:</span> <span class="p">(</span> +</span><span id="L-159"><a href="#L-159"><span class="linenos">159</span></a> <span class="s2">"SYSDATE"</span> <span class="k">if</span> <span class="n">e</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"transaction"</span><span class="p">)</span> <span class="k">else</span> <span class="s2">"GETDATE()"</span> +</span><span id="L-160"><a href="#L-160"><span class="linenos">160</span></a> <span class="p">),</span> +</span><span id="L-161"><a href="#L-161"><span class="linenos">161</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DateAdd</span><span class="p">:</span> <span class="n">date_delta_sql</span><span class="p">(</span><span class="s2">"DATEADD"</span><span class="p">),</span> +</span><span id="L-162"><a href="#L-162"><span class="linenos">162</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DateDiff</span><span class="p">:</span> <span class="n">date_delta_sql</span><span class="p">(</span><span class="s2">"DATEDIFF"</span><span class="p">),</span> +</span><span id="L-163"><a href="#L-163"><span class="linenos">163</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DistKeyProperty</span><span class="p">:</span> <span class="k">lambda</span> <span class="bp">self</span><span class="p">,</span> <span class="n">e</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="s2">"DISTKEY"</span><span class="p">,</span> <span class="n">e</span><span class="o">.</span><span class="n">this</span><span class="p">),</span> +</span><span id="L-164"><a href="#L-164"><span class="linenos">164</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DistStyleProperty</span><span class="p">:</span> <span class="k">lambda</span> <span class="bp">self</span><span class="p">,</span> <span class="n">e</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">naked_property</span><span class="p">(</span><span class="n">e</span><span class="p">),</span> +</span><span id="L-165"><a href="#L-165"><span class="linenos">165</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">FromBase</span><span class="p">:</span> <span class="n">rename_func</span><span class="p">(</span><span class="s2">"STRTOL"</span><span class="p">),</span> +</span><span id="L-166"><a href="#L-166"><span class="linenos">166</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">GeneratedAsIdentityColumnConstraint</span><span class="p">:</span> <span class="n">generatedasidentitycolumnconstraint_sql</span><span class="p">,</span> +</span><span id="L-167"><a href="#L-167"><span class="linenos">167</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">JSONExtract</span><span class="p">:</span> <span class="n">json_extract_segments</span><span class="p">(</span><span class="s2">"JSON_EXTRACT_PATH_TEXT"</span><span class="p">),</span> +</span><span id="L-168"><a href="#L-168"><span class="linenos">168</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">JSONExtractScalar</span><span class="p">:</span> <span class="n">json_extract_segments</span><span class="p">(</span><span class="s2">"JSON_EXTRACT_PATH_TEXT"</span><span class="p">),</span> +</span><span id="L-169"><a href="#L-169"><span class="linenos">169</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">GroupConcat</span><span class="p">:</span> <span class="n">rename_func</span><span class="p">(</span><span class="s2">"LISTAGG"</span><span class="p">),</span> +</span><span id="L-170"><a href="#L-170"><span class="linenos">170</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">ParseJSON</span><span class="p">:</span> <span class="n">rename_func</span><span class="p">(</span><span class="s2">"JSON_PARSE"</span><span class="p">),</span> +</span><span id="L-171"><a href="#L-171"><span class="linenos">171</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Select</span><span class="p">:</span> <span class="n">transforms</span><span class="o">.</span><span class="n">preprocess</span><span class="p">(</span> +</span><span id="L-172"><a href="#L-172"><span class="linenos">172</span></a> <span class="p">[</span> +</span><span id="L-173"><a href="#L-173"><span class="linenos">173</span></a> <span class="n">transforms</span><span class="o">.</span><span class="n">eliminate_distinct_on</span><span class="p">,</span> +</span><span id="L-174"><a href="#L-174"><span class="linenos">174</span></a> <span class="n">transforms</span><span class="o">.</span><span class="n">eliminate_semi_and_anti_joins</span><span class="p">,</span> +</span><span id="L-175"><a href="#L-175"><span class="linenos">175</span></a> <span class="n">transforms</span><span class="o">.</span><span class="n">unqualify_unnest</span><span class="p">,</span> +</span><span id="L-176"><a href="#L-176"><span class="linenos">176</span></a> <span class="p">]</span> +</span><span id="L-177"><a href="#L-177"><span class="linenos">177</span></a> <span class="p">),</span> +</span><span id="L-178"><a href="#L-178"><span class="linenos">178</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">SortKeyProperty</span><span class="p">:</span> <span class="k">lambda</span> <span class="bp">self</span><span class="p">,</span> +</span><span id="L-179"><a href="#L-179"><span class="linenos">179</span></a> <span class="n">e</span><span class="p">:</span> <span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="s1">'COMPOUND '</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">e</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s1">'compound'</span><span class="p">]</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="s1">''</span><span class="si">}</span><span class="s2">SORTKEY(</span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">format_args</span><span class="p">(</span><span class="o">*</span><span class="n">e</span><span class="o">.</span><span class="n">this</span><span class="p">)</span><span class="si">}</span><span class="s2">)"</span><span class="p">,</span> +</span><span id="L-180"><a href="#L-180"><span class="linenos">180</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">StartsWith</span><span class="p">:</span> <span class="k">lambda</span> <span class="bp">self</span><span class="p">,</span> +</span><span id="L-181"><a href="#L-181"><span class="linenos">181</span></a> <span class="n">e</span><span class="p">:</span> <span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">this</span><span class="p">)</span><span class="si">}</span><span class="s2"> LIKE </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">expression</span><span class="p">)</span><span class="si">}</span><span class="s2"> || '%'"</span><span class="p">,</span> +</span><span id="L-182"><a href="#L-182"><span class="linenos">182</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">TableSample</span><span class="p">:</span> <span class="n">no_tablesample_sql</span><span class="p">,</span> +</span><span id="L-183"><a href="#L-183"><span class="linenos">183</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">TsOrDsAdd</span><span class="p">:</span> <span class="n">date_delta_sql</span><span class="p">(</span><span class="s2">"DATEADD"</span><span class="p">),</span> +</span><span id="L-184"><a href="#L-184"><span class="linenos">184</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">TsOrDsDiff</span><span class="p">:</span> <span class="n">date_delta_sql</span><span class="p">(</span><span class="s2">"DATEDIFF"</span><span class="p">),</span> +</span><span id="L-185"><a href="#L-185"><span class="linenos">185</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">UnixToTime</span><span class="p">:</span> <span class="k">lambda</span> <span class="bp">self</span><span class="p">,</span> +</span><span id="L-186"><a href="#L-186"><span class="linenos">186</span></a> <span class="n">e</span><span class="p">:</span> <span class="sa">f</span><span class="s2">"(TIMESTAMP 'epoch' + </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">this</span><span class="p">)</span><span class="si">}</span><span class="s2"> * INTERVAL '1 SECOND')"</span><span class="p">,</span> +</span><span id="L-187"><a href="#L-187"><span class="linenos">187</span></a> <span class="p">}</span> </span><span id="L-188"><a href="#L-188"><span class="linenos">188</span></a> -</span><span id="L-189"><a href="#L-189"><span class="linenos">189</span></a> <span class="c1"># Redshift supports ANY_VALUE(..)</span> -</span><span id="L-190"><a href="#L-190"><span class="linenos">190</span></a> <span class="n">TRANSFORMS</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">AnyValue</span><span class="p">)</span> +</span><span id="L-189"><a href="#L-189"><span class="linenos">189</span></a> <span class="c1"># Postgres maps exp.Pivot to no_pivot_sql, but Redshift support pivots</span> +</span><span id="L-190"><a href="#L-190"><span class="linenos">190</span></a> <span class="n">TRANSFORMS</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Pivot</span><span class="p">)</span> </span><span id="L-191"><a href="#L-191"><span class="linenos">191</span></a> -</span><span id="L-192"><a href="#L-192"><span class="linenos">192</span></a> <span class="c1"># Redshift supports LAST_DAY(..)</span> -</span><span id="L-193"><a href="#L-193"><span class="linenos">193</span></a> <span class="n">TRANSFORMS</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">LastDay</span><span class="p">)</span> +</span><span id="L-192"><a href="#L-192"><span class="linenos">192</span></a> <span class="c1"># Redshift uses the POW | POWER (expr1, expr2) syntax instead of expr1 ^ expr2 (postgres)</span> +</span><span id="L-193"><a href="#L-193"><span class="linenos">193</span></a> <span class="n">TRANSFORMS</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Pow</span><span class="p">)</span> </span><span id="L-194"><a href="#L-194"><span class="linenos">194</span></a> -</span><span id="L-195"><a href="#L-195"><span class="linenos">195</span></a> <span class="n">RESERVED_KEYWORDS</span> <span class="o">=</span> <span class="p">{</span><span class="o">*</span><span class="n">Postgres</span><span class="o">.</span><span class="n">Generator</span><span class="o">.</span><span class="n">RESERVED_KEYWORDS</span><span class="p">,</span> <span class="s2">"snapshot"</span><span class="p">,</span> <span class="s2">"type"</span><span class="p">}</span> -</span><span id="L-196"><a href="#L-196"><span class="linenos">196</span></a> -</span><span id="L-197"><a href="#L-197"><span class="linenos">197</span></a> <span class="k">def</span> <span class="nf">unnest_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Unnest</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-198"><a href="#L-198"><span class="linenos">198</span></a> <span class="n">args</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">expressions</span> -</span><span id="L-199"><a href="#L-199"><span class="linenos">199</span></a> <span class="n">num_args</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> +</span><span id="L-195"><a href="#L-195"><span class="linenos">195</span></a> <span class="c1"># Redshift supports ANY_VALUE(..)</span> +</span><span id="L-196"><a href="#L-196"><span class="linenos">196</span></a> <span class="n">TRANSFORMS</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">AnyValue</span><span class="p">)</span> +</span><span id="L-197"><a href="#L-197"><span class="linenos">197</span></a> +</span><span id="L-198"><a href="#L-198"><span class="linenos">198</span></a> <span class="c1"># Redshift supports LAST_DAY(..)</span> +</span><span id="L-199"><a href="#L-199"><span class="linenos">199</span></a> <span class="n">TRANSFORMS</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">LastDay</span><span class="p">)</span> </span><span id="L-200"><a href="#L-200"><span class="linenos">200</span></a> -</span><span id="L-201"><a href="#L-201"><span class="linenos">201</span></a> <span class="k">if</span> <span class="n">num_args</span> <span class="o">></span> <span class="mi">1</span><span class="p">:</span> -</span><span id="L-202"><a href="#L-202"><span class="linenos">202</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Unsupported number of arguments in UNNEST: </span><span class="si">{</span><span class="n">num_args</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> -</span><span id="L-203"><a href="#L-203"><span class="linenos">203</span></a> <span class="k">return</span> <span class="s2">""</span> -</span><span id="L-204"><a href="#L-204"><span class="linenos">204</span></a> -</span><span id="L-205"><a href="#L-205"><span class="linenos">205</span></a> <span class="n">arg</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span> -</span><span id="L-206"><a href="#L-206"><span class="linenos">206</span></a> <span class="n">alias</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">expressions</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"alias"</span><span class="p">),</span> <span class="n">key</span><span class="o">=</span><span class="s2">"columns"</span><span class="p">)</span> -</span><span id="L-207"><a href="#L-207"><span class="linenos">207</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">arg</span><span class="si">}</span><span class="s2"> AS </span><span class="si">{</span><span class="n">alias</span><span class="si">}</span><span class="s2">"</span> <span class="k">if</span> <span class="n">alias</span> <span class="k">else</span> <span class="n">arg</span> -</span><span id="L-208"><a href="#L-208"><span class="linenos">208</span></a> -</span><span id="L-209"><a href="#L-209"><span class="linenos">209</span></a> <span class="k">def</span> <span class="nf">with_properties</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">properties</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Properties</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-210"><a href="#L-210"><span class="linenos">210</span></a><span class="w"> </span><span class="sd">"""Redshift doesn't have `WITH` as part of their with_properties so we remove it"""</span> -</span><span id="L-211"><a href="#L-211"><span class="linenos">211</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">properties</span><span class="p">(</span><span class="n">properties</span><span class="p">,</span> <span class="n">prefix</span><span class="o">=</span><span class="s2">" "</span><span class="p">,</span> <span class="n">suffix</span><span class="o">=</span><span class="s2">""</span><span class="p">)</span> -</span><span id="L-212"><a href="#L-212"><span class="linenos">212</span></a> -</span><span id="L-213"><a href="#L-213"><span class="linenos">213</span></a> <span class="k">def</span> <span class="nf">cast_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Cast</span><span class="p">,</span> <span class="n">safe_prefix</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-214"><a href="#L-214"><span class="linenos">214</span></a> <span class="k">if</span> <span class="n">expression</span><span class="o">.</span><span class="n">is_type</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">JSON</span><span class="p">):</span> -</span><span id="L-215"><a href="#L-215"><span class="linenos">215</span></a> <span class="c1"># Redshift doesn't support a JSON type, so casting to it is treated as a noop</span> -</span><span id="L-216"><a href="#L-216"><span class="linenos">216</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="s2">"this"</span><span class="p">)</span> -</span><span id="L-217"><a href="#L-217"><span class="linenos">217</span></a> -</span><span id="L-218"><a href="#L-218"><span class="linenos">218</span></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">cast_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="n">safe_prefix</span><span class="o">=</span><span class="n">safe_prefix</span><span class="p">)</span> -</span><span id="L-219"><a href="#L-219"><span class="linenos">219</span></a> -</span><span id="L-220"><a href="#L-220"><span class="linenos">220</span></a> <span class="k">def</span> <span class="nf">datatype_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="L-221"><a href="#L-221"><span class="linenos">221</span></a><span class="w"> </span><span class="sd">"""</span> -</span><span id="L-222"><a href="#L-222"><span class="linenos">222</span></a><span class="sd"> Redshift converts the `TEXT` data type to `VARCHAR(255)` by default when people more generally mean</span> -</span><span id="L-223"><a href="#L-223"><span class="linenos">223</span></a><span class="sd"> VARCHAR of max length which is `VARCHAR(max)` in Redshift. Therefore if we get a `TEXT` data type</span> -</span><span id="L-224"><a href="#L-224"><span class="linenos">224</span></a><span class="sd"> without precision we convert it to `VARCHAR(max)` and if it does have precision then we just convert</span> -</span><span id="L-225"><a href="#L-225"><span class="linenos">225</span></a><span class="sd"> `TEXT` to `VARCHAR`.</span> -</span><span id="L-226"><a href="#L-226"><span class="linenos">226</span></a><span class="sd"> """</span> -</span><span id="L-227"><a href="#L-227"><span class="linenos">227</span></a> <span class="k">if</span> <span class="n">expression</span><span class="o">.</span><span class="n">is_type</span><span class="p">(</span><span class="s2">"text"</span><span class="p">):</span> -</span><span id="L-228"><a href="#L-228"><span class="linenos">228</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"this"</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">VARCHAR</span><span class="p">)</span> -</span><span id="L-229"><a href="#L-229"><span class="linenos">229</span></a> <span class="n">precision</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"expressions"</span><span class="p">)</span> -</span><span id="L-230"><a href="#L-230"><span class="linenos">230</span></a> -</span><span id="L-231"><a href="#L-231"><span class="linenos">231</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">precision</span><span class="p">:</span> -</span><span id="L-232"><a href="#L-232"><span class="linenos">232</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">"expressions"</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">var</span><span class="p">(</span><span class="s2">"MAX"</span><span class="p">))</span> -</span><span id="L-233"><a href="#L-233"><span class="linenos">233</span></a> -</span><span id="L-234"><a href="#L-234"><span class="linenos">234</span></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">datatype_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> +</span><span id="L-201"><a href="#L-201"><span class="linenos">201</span></a> <span class="n">RESERVED_KEYWORDS</span> <span class="o">=</span> <span class="p">{</span> +</span><span id="L-202"><a href="#L-202"><span class="linenos">202</span></a> <span class="s2">"aes128"</span><span class="p">,</span> +</span><span id="L-203"><a href="#L-203"><span class="linenos">203</span></a> <span class="s2">"aes256"</span><span class="p">,</span> +</span><span id="L-204"><a href="#L-204"><span class="linenos">204</span></a> <span class="s2">"all"</span><span class="p">,</span> +</span><span id="L-205"><a href="#L-205"><span class="linenos">205</span></a> <span class="s2">"allowoverwrite"</span><span class="p">,</span> +</span><span id="L-206"><a href="#L-206"><span class="linenos">206</span></a> <span class="s2">"analyse"</span><span class="p">,</span> +</span><span id="L-207"><a href="#L-207"><span class="linenos">207</span></a> <span class="s2">"analyze"</span><span class="p">,</span> +</span><span id="L-208"><a href="#L-208"><span class="linenos">208</span></a> <span class="s2">"and"</span><span class="p">,</span> +</span><span id="L-209"><a href="#L-209"><span class="linenos">209</span></a> <span class="s2">"any"</span><span class="p">,</span> +</span><span id="L-210"><a href="#L-210"><span class="linenos">210</span></a> <span class="s2">"array"</span><span class="p">,</span> +</span><span id="L-211"><a href="#L-211"><span class="linenos">211</span></a> <span class="s2">"as"</span><span class="p">,</span> +</span><span id="L-212"><a href="#L-212"><span class="linenos">212</span></a> <span class="s2">"asc"</span><span class="p">,</span> +</span><span id="L-213"><a href="#L-213"><span class="linenos">213</span></a> <span class="s2">"authorization"</span><span class="p">,</span> +</span><span id="L-214"><a href="#L-214"><span class="linenos">214</span></a> <span class="s2">"az64"</span><span class="p">,</span> +</span><span id="L-215"><a href="#L-215"><span class="linenos">215</span></a> <span class="s2">"backup"</span><span class="p">,</span> +</span><span id="L-216"><a href="#L-216"><span class="linenos">216</span></a> <span class="s2">"between"</span><span class="p">,</span> +</span><span id="L-217"><a href="#L-217"><span class="linenos">217</span></a> <span class="s2">"binary"</span><span class="p">,</span> +</span><span id="L-218"><a href="#L-218"><span class="linenos">218</span></a> <span class="s2">"blanksasnull"</span><span class="p">,</span> +</span><span id="L-219"><a href="#L-219"><span class="linenos">219</span></a> <span class="s2">"both"</span><span class="p">,</span> +</span><span id="L-220"><a href="#L-220"><span class="linenos">220</span></a> <span class="s2">"bytedict"</span><span class="p">,</span> +</span><span id="L-221"><a href="#L-221"><span class="linenos">221</span></a> <span class="s2">"bzip2"</span><span class="p">,</span> +</span><span id="L-222"><a href="#L-222"><span class="linenos">222</span></a> <span class="s2">"case"</span><span class="p">,</span> +</span><span id="L-223"><a href="#L-223"><span class="linenos">223</span></a> <span class="s2">"cast"</span><span class="p">,</span> +</span><span id="L-224"><a href="#L-224"><span class="linenos">224</span></a> <span class="s2">"check"</span><span class="p">,</span> +</span><span id="L-225"><a href="#L-225"><span class="linenos">225</span></a> <span class="s2">"collate"</span><span class="p">,</span> +</span><span id="L-226"><a href="#L-226"><span class="linenos">226</span></a> <span class="s2">"column"</span><span class="p">,</span> +</span><span id="L-227"><a href="#L-227"><span class="linenos">227</span></a> <span class="s2">"constraint"</span><span class="p">,</span> +</span><span id="L-228"><a href="#L-228"><span class="linenos">228</span></a> <span class="s2">"create"</span><span class="p">,</span> +</span><span id="L-229"><a href="#L-229"><span class="linenos">229</span></a> <span class="s2">"credentials"</span><span class="p">,</span> +</span><span id="L-230"><a href="#L-230"><span class="linenos">230</span></a> <span class="s2">"cross"</span><span class="p">,</span> +</span><span id="L-231"><a href="#L-231"><span class="linenos">231</span></a> <span class="s2">"current_date"</span><span class="p">,</span> +</span><span id="L-232"><a href="#L-232"><span class="linenos">232</span></a> <span class="s2">"current_time"</span><span class="p">,</span> +</span><span id="L-233"><a href="#L-233"><span class="linenos">233</span></a> <span class="s2">"current_timestamp"</span><span class="p">,</span> +</span><span id="L-234"><a href="#L-234"><span class="linenos">234</span></a> <span class="s2">"current_user"</span><span class="p">,</span> +</span><span id="L-235"><a href="#L-235"><span class="linenos">235</span></a> <span class="s2">"current_user_id"</span><span class="p">,</span> +</span><span id="L-236"><a href="#L-236"><span class="linenos">236</span></a> <span class="s2">"default"</span><span class="p">,</span> +</span><span id="L-237"><a href="#L-237"><span class="linenos">237</span></a> <span class="s2">"deferrable"</span><span class="p">,</span> +</span><span id="L-238"><a href="#L-238"><span class="linenos">238</span></a> <span class="s2">"deflate"</span><span class="p">,</span> +</span><span id="L-239"><a href="#L-239"><span class="linenos">239</span></a> <span class="s2">"defrag"</span><span class="p">,</span> +</span><span id="L-240"><a href="#L-240"><span class="linenos">240</span></a> <span class="s2">"delta"</span><span class="p">,</span> +</span><span id="L-241"><a href="#L-241"><span class="linenos">241</span></a> <span class="s2">"delta32k"</span><span class="p">,</span> +</span><span id="L-242"><a href="#L-242"><span class="linenos">242</span></a> <span class="s2">"desc"</span><span class="p">,</span> +</span><span id="L-243"><a href="#L-243"><span class="linenos">243</span></a> <span class="s2">"disable"</span><span class="p">,</span> +</span><span id="L-244"><a href="#L-244"><span class="linenos">244</span></a> <span class="s2">"distinct"</span><span class="p">,</span> +</span><span id="L-245"><a href="#L-245"><span class="linenos">245</span></a> <span class="s2">"do"</span><span class="p">,</span> +</span><span id="L-246"><a href="#L-246"><span class="linenos">246</span></a> <span class="s2">"else"</span><span class="p">,</span> +</span><span id="L-247"><a href="#L-247"><span class="linenos">247</span></a> <span class="s2">"emptyasnull"</span><span class="p">,</span> +</span><span id="L-248"><a href="#L-248"><span class="linenos">248</span></a> <span class="s2">"enable"</span><span class="p">,</span> +</span><span id="L-249"><a href="#L-249"><span class="linenos">249</span></a> <span class="s2">"encode"</span><span class="p">,</span> +</span><span id="L-250"><a href="#L-250"><span class="linenos">250</span></a> <span class="s2">"encrypt "</span><span class="p">,</span> +</span><span id="L-251"><a href="#L-251"><span class="linenos">251</span></a> <span class="s2">"encryption"</span><span class="p">,</span> +</span><span id="L-252"><a href="#L-252"><span class="linenos">252</span></a> <span class="s2">"end"</span><span class="p">,</span> +</span><span id="L-253"><a href="#L-253"><span class="linenos">253</span></a> <span class="s2">"except"</span><span class="p">,</span> +</span><span id="L-254"><a href="#L-254"><span class="linenos">254</span></a> <span class="s2">"explicit"</span><span class="p">,</span> +</span><span id="L-255"><a href="#L-255"><span class="linenos">255</span></a> <span class="s2">"false"</span><span class="p">,</span> +</span><span id="L-256"><a href="#L-256"><span class="linenos">256</span></a> <span class="s2">"for"</span><span class="p">,</span> +</span><span id="L-257"><a href="#L-257"><span class="linenos">257</span></a> <span class="s2">"foreign"</span><span class="p">,</span> +</span><span id="L-258"><a href="#L-258"><span class="linenos">258</span></a> <span class="s2">"freeze"</span><span class="p">,</span> +</span><span id="L-259"><a href="#L-259"><span class="linenos">259</span></a> <span class="s2">"from"</span><span class="p">,</span> +</span><span id="L-260"><a href="#L-260"><span class="linenos">260</span></a> <span class="s2">"full"</span><span class="p">,</span> +</span><span id="L-261"><a href="#L-261"><span class="linenos">261</span></a> <span class="s2">"globaldict256"</span><span class="p">,</span> +</span><span id="L-262"><a href="#L-262"><span class="linenos">262</span></a> <span class="s2">"globaldict64k"</span><span class="p">,</span> +</span><span id="L-263"><a href="#L-263"><span class="linenos">263</span></a> <span class="s2">"grant"</span><span class="p">,</span> +</span><span id="L-264"><a href="#L-264"><span class="linenos">264</span></a> <span class="s2">"group"</span><span class="p">,</span> +</span><span id="L-265"><a href="#L-265"><span class="linenos">265</span></a> <span class="s2">"gzip"</span><span class="p">,</span> +</span><span id="L-266"><a href="#L-266"><span class="linenos">266</span></a> <span class="s2">"having"</span><span class="p">,</span> +</span><span id="L-267"><a href="#L-267"><span class="linenos">267</span></a> <span class="s2">"identity"</span><span class="p">,</span> +</span><span id="L-268"><a href="#L-268"><span class="linenos">268</span></a> <span class="s2">"ignore"</span><span class="p">,</span> +</span><span id="L-269"><a href="#L-269"><span class="linenos">269</span></a> <span class="s2">"ilike"</span><span class="p">,</span> +</span><span id="L-270"><a href="#L-270"><span class="linenos">270</span></a> <span class="s2">"in"</span><span class="p">,</span> +</span><span id="L-271"><a href="#L-271"><span class="linenos">271</span></a> <span class="s2">"initially"</span><span class="p">,</span> +</span><span id="L-272"><a href="#L-272"><span class="linenos">272</span></a> <span class="s2">"inner"</span><span class="p">,</span> +</span><span id="L-273"><a href="#L-273"><span class="linenos">273</span></a> <span class="s2">"intersect"</span><span class="p">,</span> +</span><span id="L-274"><a href="#L-274"><span class="linenos">274</span></a> <span class="s2">"interval"</span><span class="p">,</span> +</span><span id="L-275"><a href="#L-275"><span class="linenos">275</span></a> <span class="s2">"into"</span><span class="p">,</span> +</span><span id="L-276"><a href="#L-276"><span class="linenos">276</span></a> <span class="s2">"is"</span><span class="p">,</span> +</span><span id="L-277"><a href="#L-277"><span class="linenos">277</span></a> <span class="s2">"isnull"</span><span class="p">,</span> +</span><span id="L-278"><a href="#L-278"><span class="linenos">278</span></a> <span class="s2">"join"</span><span class="p">,</span> +</span><span id="L-279"><a href="#L-279"><span class="linenos">279</span></a> <span class="s2">"leading"</span><span class="p">,</span> +</span><span id="L-280"><a href="#L-280"><span class="linenos">280</span></a> <span class="s2">"left"</span><span class="p">,</span> +</span><span id="L-281"><a href="#L-281"><span class="linenos">281</span></a> <span class="s2">"like"</span><span class="p">,</span> +</span><span id="L-282"><a href="#L-282"><span class="linenos">282</span></a> <span class="s2">"limit"</span><span class="p">,</span> +</span><span id="L-283"><a href="#L-283"><span class="linenos">283</span></a> <span class="s2">"localtime"</span><span class="p">,</span> +</span><span id="L-284"><a href="#L-284"><span class="linenos">284</span></a> <span class="s2">"localtimestamp"</span><span class="p">,</span> +</span><span id="L-285"><a href="#L-285"><span class="linenos">285</span></a> <span class="s2">"lun"</span><span class="p">,</span> +</span><span id="L-286"><a href="#L-286"><span class="linenos">286</span></a> <span class="s2">"luns"</span><span class="p">,</span> +</span><span id="L-287"><a href="#L-287"><span class="linenos">287</span></a> <span class="s2">"lzo"</span><span class="p">,</span> +</span><span id="L-288"><a href="#L-288"><span class="linenos">288</span></a> <span class="s2">"lzop"</span><span class="p">,</span> +</span><span id="L-289"><a href="#L-289"><span class="linenos">289</span></a> <span class="s2">"minus"</span><span class="p">,</span> +</span><span id="L-290"><a href="#L-290"><span class="linenos">290</span></a> <span class="s2">"mostly16"</span><span class="p">,</span> +</span><span id="L-291"><a href="#L-291"><span class="linenos">291</span></a> <span class="s2">"mostly32"</span><span class="p">,</span> +</span><span id="L-292"><a href="#L-292"><span class="linenos">292</span></a> <span class="s2">"mostly8"</span><span class="p">,</span> +</span><span id="L-293"><a href="#L-293"><span class="linenos">293</span></a> <span class="s2">"natural"</span><span class="p">,</span> +</span><span id="L-294"><a href="#L-294"><span class="linenos">294</span></a> <span class="s2">"new"</span><span class="p">,</span> +</span><span id="L-295"><a href="#L-295"><span class="linenos">295</span></a> <span class="s2">"not"</span><span class="p">,</span> +</span><span id="L-296"><a href="#L-296"><span class="linenos">296</span></a> <span class="s2">"notnull"</span><span class="p">,</span> +</span><span id="L-297"><a href="#L-297"><span class="linenos">297</span></a> <span class="s2">"null"</span><span class="p">,</span> +</span><span id="L-298"><a href="#L-298"><span class="linenos">298</span></a> <span class="s2">"nulls"</span><span class="p">,</span> +</span><span id="L-299"><a href="#L-299"><span class="linenos">299</span></a> <span class="s2">"off"</span><span class="p">,</span> +</span><span id="L-300"><a href="#L-300"><span class="linenos">300</span></a> <span class="s2">"offline"</span><span class="p">,</span> +</span><span id="L-301"><a href="#L-301"><span class="linenos">301</span></a> <span class="s2">"offset"</span><span class="p">,</span> +</span><span id="L-302"><a href="#L-302"><span class="linenos">302</span></a> <span class="s2">"oid"</span><span class="p">,</span> +</span><span id="L-303"><a href="#L-303"><span class="linenos">303</span></a> <span class="s2">"old"</span><span class="p">,</span> +</span><span id="L-304"><a href="#L-304"><span class="linenos">304</span></a> <span class="s2">"on"</span><span class="p">,</span> +</span><span id="L-305"><a href="#L-305"><span class="linenos">305</span></a> <span class="s2">"only"</span><span class="p">,</span> +</span><span id="L-306"><a href="#L-306"><span class="linenos">306</span></a> <span class="s2">"open"</span><span class="p">,</span> +</span><span id="L-307"><a href="#L-307"><span class="linenos">307</span></a> <span class="s2">"or"</span><span class="p">,</span> +</span><span id="L-308"><a href="#L-308"><span class="linenos">308</span></a> <span class="s2">"order"</span><span class="p">,</span> +</span><span id="L-309"><a href="#L-309"><span class="linenos">309</span></a> <span class="s2">"outer"</span><span class="p">,</span> +</span><span id="L-310"><a href="#L-310"><span class="linenos">310</span></a> <span class="s2">"overlaps"</span><span class="p">,</span> +</span><span id="L-311"><a href="#L-311"><span class="linenos">311</span></a> <span class="s2">"parallel"</span><span class="p">,</span> +</span><span id="L-312"><a href="#L-312"><span class="linenos">312</span></a> <span class="s2">"partition"</span><span class="p">,</span> +</span><span id="L-313"><a href="#L-313"><span class="linenos">313</span></a> <span class="s2">"percent"</span><span class="p">,</span> +</span><span id="L-314"><a href="#L-314"><span class="linenos">314</span></a> <span class="s2">"permissions"</span><span class="p">,</span> +</span><span id="L-315"><a href="#L-315"><span class="linenos">315</span></a> <span class="s2">"pivot"</span><span class="p">,</span> +</span><span id="L-316"><a href="#L-316"><span class="linenos">316</span></a> <span class="s2">"placing"</span><span class="p">,</span> +</span><span id="L-317"><a href="#L-317"><span class="linenos">317</span></a> <span class="s2">"primary"</span><span class="p">,</span> +</span><span id="L-318"><a href="#L-318"><span class="linenos">318</span></a> <span class="s2">"raw"</span><span class="p">,</span> +</span><span id="L-319"><a href="#L-319"><span class="linenos">319</span></a> <span class="s2">"readratio"</span><span class="p">,</span> +</span><span id="L-320"><a href="#L-320"><span class="linenos">320</span></a> <span class="s2">"recover"</span><span class="p">,</span> +</span><span id="L-321"><a href="#L-321"><span class="linenos">321</span></a> <span class="s2">"references"</span><span class="p">,</span> +</span><span id="L-322"><a href="#L-322"><span class="linenos">322</span></a> <span class="s2">"rejectlog"</span><span class="p">,</span> +</span><span id="L-323"><a href="#L-323"><span class="linenos">323</span></a> <span class="s2">"resort"</span><span class="p">,</span> +</span><span id="L-324"><a href="#L-324"><span class="linenos">324</span></a> <span class="s2">"respect"</span><span class="p">,</span> +</span><span id="L-325"><a href="#L-325"><span class="linenos">325</span></a> <span class="s2">"restore"</span><span class="p">,</span> +</span><span id="L-326"><a href="#L-326"><span class="linenos">326</span></a> <span class="s2">"right"</span><span class="p">,</span> +</span><span id="L-327"><a href="#L-327"><span class="linenos">327</span></a> <span class="s2">"select"</span><span class="p">,</span> +</span><span id="L-328"><a href="#L-328"><span class="linenos">328</span></a> <span class="s2">"session_user"</span><span class="p">,</span> +</span><span id="L-329"><a href="#L-329"><span class="linenos">329</span></a> <span class="s2">"similar"</span><span class="p">,</span> +</span><span id="L-330"><a href="#L-330"><span class="linenos">330</span></a> <span class="s2">"snapshot"</span><span class="p">,</span> +</span><span id="L-331"><a href="#L-331"><span class="linenos">331</span></a> <span class="s2">"some"</span><span class="p">,</span> +</span><span id="L-332"><a href="#L-332"><span class="linenos">332</span></a> <span class="s2">"sysdate"</span><span class="p">,</span> +</span><span id="L-333"><a href="#L-333"><span class="linenos">333</span></a> <span class="s2">"system"</span><span class="p">,</span> +</span><span id="L-334"><a href="#L-334"><span class="linenos">334</span></a> <span class="s2">"table"</span><span class="p">,</span> +</span><span id="L-335"><a href="#L-335"><span class="linenos">335</span></a> <span class="s2">"tag"</span><span class="p">,</span> +</span><span id="L-336"><a href="#L-336"><span class="linenos">336</span></a> <span class="s2">"tdes"</span><span class="p">,</span> +</span><span id="L-337"><a href="#L-337"><span class="linenos">337</span></a> <span class="s2">"text255"</span><span class="p">,</span> +</span><span id="L-338"><a href="#L-338"><span class="linenos">338</span></a> <span class="s2">"text32k"</span><span class="p">,</span> +</span><span id="L-339"><a href="#L-339"><span class="linenos">339</span></a> <span class="s2">"then"</span><span class="p">,</span> +</span><span id="L-340"><a href="#L-340"><span class="linenos">340</span></a> <span class="s2">"timestamp"</span><span class="p">,</span> +</span><span id="L-341"><a href="#L-341"><span class="linenos">341</span></a> <span class="s2">"to"</span><span class="p">,</span> +</span><span id="L-342"><a href="#L-342"><span class="linenos">342</span></a> <span class="s2">"top"</span><span class="p">,</span> +</span><span id="L-343"><a href="#L-343"><span class="linenos">343</span></a> <span class="s2">"trailing"</span><span class="p">,</span> +</span><span id="L-344"><a href="#L-344"><span class="linenos">344</span></a> <span class="s2">"true"</span><span class="p">,</span> +</span><span id="L-345"><a href="#L-345"><span class="linenos">345</span></a> <span class="s2">"truncatecolumns"</span><span class="p">,</span> +</span><span id="L-346"><a href="#L-346"><span class="linenos">346</span></a> <span class="s2">"type"</span><span class="p">,</span> +</span><span id="L-347"><a href="#L-347"><span class="linenos">347</span></a> <span class="s2">"union"</span><span class="p">,</span> +</span><span id="L-348"><a href="#L-348"><span class="linenos">348</span></a> <span class="s2">"unique"</span><span class="p">,</span> +</span><span id="L-349"><a href="#L-349"><span class="linenos">349</span></a> <span class="s2">"unnest"</span><span class="p">,</span> +</span><span id="L-350"><a href="#L-350"><span class="linenos">350</span></a> <span class="s2">"unpivot"</span><span class="p">,</span> +</span><span id="L-351"><a href="#L-351"><span class="linenos">351</span></a> <span class="s2">"user"</span><span class="p">,</span> +</span><span id="L-352"><a href="#L-352"><span class="linenos">352</span></a> <span class="s2">"using"</span><span class="p">,</span> +</span><span id="L-353"><a href="#L-353"><span class="linenos">353</span></a> <span class="s2">"verbose"</span><span class="p">,</span> +</span><span id="L-354"><a href="#L-354"><span class="linenos">354</span></a> <span class="s2">"wallet"</span><span class="p">,</span> +</span><span id="L-355"><a href="#L-355"><span class="linenos">355</span></a> <span class="s2">"when"</span><span class="p">,</span> +</span><span id="L-356"><a href="#L-356"><span class="linenos">356</span></a> <span class="s2">"where"</span><span class="p">,</span> +</span><span id="L-357"><a href="#L-357"><span class="linenos">357</span></a> <span class="s2">"with"</span><span class="p">,</span> +</span><span id="L-358"><a href="#L-358"><span class="linenos">358</span></a> <span class="s2">"without"</span><span class="p">,</span> +</span><span id="L-359"><a href="#L-359"><span class="linenos">359</span></a> <span class="p">}</span> +</span><span id="L-360"><a href="#L-360"><span class="linenos">360</span></a> +</span><span id="L-361"><a href="#L-361"><span class="linenos">361</span></a> <span class="k">def</span> <span class="nf">unnest_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Unnest</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-362"><a href="#L-362"><span class="linenos">362</span></a> <span class="n">args</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">expressions</span> +</span><span id="L-363"><a href="#L-363"><span class="linenos">363</span></a> <span class="n">num_args</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> +</span><span id="L-364"><a href="#L-364"><span class="linenos">364</span></a> +</span><span id="L-365"><a href="#L-365"><span class="linenos">365</span></a> <span class="k">if</span> <span class="n">num_args</span> <span class="o">></span> <span class="mi">1</span><span class="p">:</span> +</span><span id="L-366"><a href="#L-366"><span class="linenos">366</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Unsupported number of arguments in UNNEST: </span><span class="si">{</span><span class="n">num_args</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> +</span><span id="L-367"><a href="#L-367"><span class="linenos">367</span></a> <span class="k">return</span> <span class="s2">""</span> +</span><span id="L-368"><a href="#L-368"><span class="linenos">368</span></a> +</span><span id="L-369"><a href="#L-369"><span class="linenos">369</span></a> <span class="n">arg</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span> +</span><span id="L-370"><a href="#L-370"><span class="linenos">370</span></a> <span class="n">alias</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">expressions</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"alias"</span><span class="p">),</span> <span class="n">key</span><span class="o">=</span><span class="s2">"columns"</span><span class="p">,</span> <span class="n">flat</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> +</span><span id="L-371"><a href="#L-371"><span class="linenos">371</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">arg</span><span class="si">}</span><span class="s2"> AS </span><span class="si">{</span><span class="n">alias</span><span class="si">}</span><span class="s2">"</span> <span class="k">if</span> <span class="n">alias</span> <span class="k">else</span> <span class="n">arg</span> +</span><span id="L-372"><a href="#L-372"><span class="linenos">372</span></a> +</span><span id="L-373"><a href="#L-373"><span class="linenos">373</span></a> <span class="k">def</span> <span class="nf">with_properties</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">properties</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Properties</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-374"><a href="#L-374"><span class="linenos">374</span></a><span class="w"> </span><span class="sd">"""Redshift doesn't have `WITH` as part of their with_properties so we remove it"""</span> +</span><span id="L-375"><a href="#L-375"><span class="linenos">375</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">properties</span><span class="p">(</span><span class="n">properties</span><span class="p">,</span> <span class="n">prefix</span><span class="o">=</span><span class="s2">" "</span><span class="p">,</span> <span class="n">suffix</span><span class="o">=</span><span class="s2">""</span><span class="p">)</span> +</span><span id="L-376"><a href="#L-376"><span class="linenos">376</span></a> +</span><span id="L-377"><a href="#L-377"><span class="linenos">377</span></a> <span class="k">def</span> <span class="nf">cast_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Cast</span><span class="p">,</span> <span class="n">safe_prefix</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-378"><a href="#L-378"><span class="linenos">378</span></a> <span class="k">if</span> <span class="n">expression</span><span class="o">.</span><span class="n">is_type</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">JSON</span><span class="p">):</span> +</span><span id="L-379"><a href="#L-379"><span class="linenos">379</span></a> <span class="c1"># Redshift doesn't support a JSON type, so casting to it is treated as a noop</span> +</span><span id="L-380"><a href="#L-380"><span class="linenos">380</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="s2">"this"</span><span class="p">)</span> +</span><span id="L-381"><a href="#L-381"><span class="linenos">381</span></a> +</span><span id="L-382"><a href="#L-382"><span class="linenos">382</span></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">cast_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="n">safe_prefix</span><span class="o">=</span><span class="n">safe_prefix</span><span class="p">)</span> +</span><span id="L-383"><a href="#L-383"><span class="linenos">383</span></a> +</span><span id="L-384"><a href="#L-384"><span class="linenos">384</span></a> <span class="k">def</span> <span class="nf">datatype_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="L-385"><a href="#L-385"><span class="linenos">385</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="L-386"><a href="#L-386"><span class="linenos">386</span></a><span class="sd"> Redshift converts the `TEXT` data type to `VARCHAR(255)` by default when people more generally mean</span> +</span><span id="L-387"><a href="#L-387"><span class="linenos">387</span></a><span class="sd"> VARCHAR of max length which is `VARCHAR(max)` in Redshift. Therefore if we get a `TEXT` data type</span> +</span><span id="L-388"><a href="#L-388"><span class="linenos">388</span></a><span class="sd"> without precision we convert it to `VARCHAR(max)` and if it does have precision then we just convert</span> +</span><span id="L-389"><a href="#L-389"><span class="linenos">389</span></a><span class="sd"> `TEXT` to `VARCHAR`.</span> +</span><span id="L-390"><a href="#L-390"><span class="linenos">390</span></a><span class="sd"> """</span> +</span><span id="L-391"><a href="#L-391"><span class="linenos">391</span></a> <span class="k">if</span> <span class="n">expression</span><span class="o">.</span><span class="n">is_type</span><span class="p">(</span><span class="s2">"text"</span><span class="p">):</span> +</span><span id="L-392"><a href="#L-392"><span class="linenos">392</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"this"</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">VARCHAR</span><span class="p">)</span> +</span><span id="L-393"><a href="#L-393"><span class="linenos">393</span></a> <span class="n">precision</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"expressions"</span><span class="p">)</span> +</span><span id="L-394"><a href="#L-394"><span class="linenos">394</span></a> +</span><span id="L-395"><a href="#L-395"><span class="linenos">395</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">precision</span><span class="p">:</span> +</span><span id="L-396"><a href="#L-396"><span class="linenos">396</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">"expressions"</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">var</span><span class="p">(</span><span class="s2">"MAX"</span><span class="p">))</span> +</span><span id="L-397"><a href="#L-397"><span class="linenos">397</span></a> +</span><span id="L-398"><a href="#L-398"><span class="linenos">398</span></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">datatype_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> </span></pre></div> @@ -532,159 +696,323 @@ </span><span id="Redshift-80"><a href="#Redshift-80"><span class="linenos"> 80</span></a> <span class="n">alias_tokens</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Collection</span><span class="p">[</span><span class="n">TokenType</span><span class="p">]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> </span><span id="Redshift-81"><a href="#Redshift-81"><span class="linenos"> 81</span></a> <span class="n">parse_bracket</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span> </span><span id="Redshift-82"><a href="#Redshift-82"><span class="linenos"> 82</span></a> <span class="n">is_db_reference</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span> -</span><span id="Redshift-83"><a href="#Redshift-83"><span class="linenos"> 83</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">]:</span> -</span><span id="Redshift-84"><a href="#Redshift-84"><span class="linenos"> 84</span></a> <span class="c1"># Redshift supports UNPIVOTing SUPER objects, e.g. `UNPIVOT foo.obj[0] AS val AT attr`</span> -</span><span id="Redshift-85"><a href="#Redshift-85"><span class="linenos"> 85</span></a> <span class="n">unpivot</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_match</span><span class="p">(</span><span class="n">TokenType</span><span class="o">.</span><span class="n">UNPIVOT</span><span class="p">)</span> -</span><span id="Redshift-86"><a href="#Redshift-86"><span class="linenos"> 86</span></a> <span class="n">table</span> <span class="o">=</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">_parse_table</span><span class="p">(</span> -</span><span id="Redshift-87"><a href="#Redshift-87"><span class="linenos"> 87</span></a> <span class="n">schema</span><span class="o">=</span><span class="n">schema</span><span class="p">,</span> -</span><span id="Redshift-88"><a href="#Redshift-88"><span class="linenos"> 88</span></a> <span class="n">joins</span><span class="o">=</span><span class="n">joins</span><span class="p">,</span> -</span><span id="Redshift-89"><a href="#Redshift-89"><span class="linenos"> 89</span></a> <span class="n">alias_tokens</span><span class="o">=</span><span class="n">alias_tokens</span><span class="p">,</span> -</span><span id="Redshift-90"><a href="#Redshift-90"><span class="linenos"> 90</span></a> <span class="n">parse_bracket</span><span class="o">=</span><span class="n">parse_bracket</span><span class="p">,</span> -</span><span id="Redshift-91"><a href="#Redshift-91"><span class="linenos"> 91</span></a> <span class="n">is_db_reference</span><span class="o">=</span><span class="n">is_db_reference</span><span class="p">,</span> -</span><span id="Redshift-92"><a href="#Redshift-92"><span class="linenos"> 92</span></a> <span class="p">)</span> -</span><span id="Redshift-93"><a href="#Redshift-93"><span class="linenos"> 93</span></a> -</span><span id="Redshift-94"><a href="#Redshift-94"><span class="linenos"> 94</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Pivot</span><span class="p">,</span> <span class="n">this</span><span class="o">=</span><span class="n">table</span><span class="p">,</span> <span class="n">unpivot</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> <span class="k">if</span> <span class="n">unpivot</span> <span class="k">else</span> <span class="n">table</span> -</span><span id="Redshift-95"><a href="#Redshift-95"><span class="linenos"> 95</span></a> -</span><span id="Redshift-96"><a href="#Redshift-96"><span class="linenos"> 96</span></a> <span class="k">def</span> <span class="nf">_parse_convert</span><span class="p">(</span> -</span><span id="Redshift-97"><a href="#Redshift-97"><span class="linenos"> 97</span></a> <span class="bp">self</span><span class="p">,</span> <span class="n">strict</span><span class="p">:</span> <span class="nb">bool</span><span class="p">,</span> <span class="n">safe</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">bool</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span> -</span><span id="Redshift-98"><a href="#Redshift-98"><span class="linenos"> 98</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">]:</span> -</span><span id="Redshift-99"><a href="#Redshift-99"><span class="linenos"> 99</span></a> <span class="n">to</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_types</span><span class="p">()</span> -</span><span id="Redshift-100"><a href="#Redshift-100"><span class="linenos">100</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">_match</span><span class="p">(</span><span class="n">TokenType</span><span class="o">.</span><span class="n">COMMA</span><span class="p">)</span> -</span><span id="Redshift-101"><a href="#Redshift-101"><span class="linenos">101</span></a> <span class="n">this</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_bitwise</span><span class="p">()</span> -</span><span id="Redshift-102"><a href="#Redshift-102"><span class="linenos">102</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">TryCast</span><span class="p">,</span> <span class="n">this</span><span class="o">=</span><span class="n">this</span><span class="p">,</span> <span class="n">to</span><span class="o">=</span><span class="n">to</span><span class="p">,</span> <span class="n">safe</span><span class="o">=</span><span class="n">safe</span><span class="p">)</span> -</span><span id="Redshift-103"><a href="#Redshift-103"><span class="linenos">103</span></a> -</span><span id="Redshift-104"><a href="#Redshift-104"><span class="linenos">104</span></a> <span class="k">def</span> <span class="nf">_parse_approximate_count</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">exp</span><span class="o">.</span><span class="n">ApproxDistinct</span><span class="p">]:</span> -</span><span id="Redshift-105"><a href="#Redshift-105"><span class="linenos">105</span></a> <span class="n">index</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_index</span> <span class="o">-</span> <span class="mi">1</span> -</span><span id="Redshift-106"><a href="#Redshift-106"><span class="linenos">106</span></a> <span class="n">func</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_function</span><span class="p">()</span> -</span><span id="Redshift-107"><a href="#Redshift-107"><span class="linenos">107</span></a> -</span><span id="Redshift-108"><a href="#Redshift-108"><span class="linenos">108</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">func</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Count</span><span class="p">)</span> <span class="ow">and</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">func</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Distinct</span><span class="p">):</span> -</span><span id="Redshift-109"><a href="#Redshift-109"><span class="linenos">109</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">ApproxDistinct</span><span class="p">,</span> <span class="n">this</span><span class="o">=</span><span class="n">seq_get</span><span class="p">(</span><span class="n">func</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">expressions</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span> -</span><span id="Redshift-110"><a href="#Redshift-110"><span class="linenos">110</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">_retreat</span><span class="p">(</span><span class="n">index</span><span class="p">)</span> -</span><span id="Redshift-111"><a href="#Redshift-111"><span class="linenos">111</span></a> <span class="k">return</span> <span class="kc">None</span> -</span><span id="Redshift-112"><a href="#Redshift-112"><span class="linenos">112</span></a> -</span><span id="Redshift-113"><a href="#Redshift-113"><span class="linenos">113</span></a> <span class="k">class</span> <span class="nc">Tokenizer</span><span class="p">(</span><span class="n">Postgres</span><span class="o">.</span><span class="n">Tokenizer</span><span class="p">):</span> -</span><span id="Redshift-114"><a href="#Redshift-114"><span class="linenos">114</span></a> <span class="n">BIT_STRINGS</span> <span class="o">=</span> <span class="p">[]</span> -</span><span id="Redshift-115"><a href="#Redshift-115"><span class="linenos">115</span></a> <span class="n">HEX_STRINGS</span> <span class="o">=</span> <span class="p">[]</span> -</span><span id="Redshift-116"><a href="#Redshift-116"><span class="linenos">116</span></a> <span class="n">STRING_ESCAPES</span> <span class="o">=</span> <span class="p">[</span><span class="s2">"</span><span class="se">\\</span><span class="s2">"</span><span class="p">,</span> <span class="s2">"'"</span><span class="p">]</span> -</span><span id="Redshift-117"><a href="#Redshift-117"><span class="linenos">117</span></a> -</span><span id="Redshift-118"><a href="#Redshift-118"><span class="linenos">118</span></a> <span class="n">KEYWORDS</span> <span class="o">=</span> <span class="p">{</span> -</span><span id="Redshift-119"><a href="#Redshift-119"><span class="linenos">119</span></a> <span class="o">**</span><span class="n">Postgres</span><span class="o">.</span><span class="n">Tokenizer</span><span class="o">.</span><span class="n">KEYWORDS</span><span class="p">,</span> -</span><span id="Redshift-120"><a href="#Redshift-120"><span class="linenos">120</span></a> <span class="s2">"HLLSKETCH"</span><span class="p">:</span> <span class="n">TokenType</span><span class="o">.</span><span class="n">HLLSKETCH</span><span class="p">,</span> -</span><span id="Redshift-121"><a href="#Redshift-121"><span class="linenos">121</span></a> <span class="s2">"SUPER"</span><span class="p">:</span> <span class="n">TokenType</span><span class="o">.</span><span class="n">SUPER</span><span class="p">,</span> -</span><span id="Redshift-122"><a href="#Redshift-122"><span class="linenos">122</span></a> <span class="s2">"TOP"</span><span class="p">:</span> <span class="n">TokenType</span><span class="o">.</span><span class="n">TOP</span><span class="p">,</span> -</span><span id="Redshift-123"><a href="#Redshift-123"><span class="linenos">123</span></a> <span class="s2">"UNLOAD"</span><span class="p">:</span> <span class="n">TokenType</span><span class="o">.</span><span class="n">COMMAND</span><span class="p">,</span> -</span><span id="Redshift-124"><a href="#Redshift-124"><span class="linenos">124</span></a> <span class="s2">"VARBYTE"</span><span class="p">:</span> <span class="n">TokenType</span><span class="o">.</span><span class="n">VARBINARY</span><span class="p">,</span> -</span><span id="Redshift-125"><a href="#Redshift-125"><span class="linenos">125</span></a> <span class="p">}</span> -</span><span id="Redshift-126"><a href="#Redshift-126"><span class="linenos">126</span></a> <span class="n">KEYWORDS</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s2">"VALUES"</span><span class="p">)</span> -</span><span id="Redshift-127"><a href="#Redshift-127"><span class="linenos">127</span></a> -</span><span id="Redshift-128"><a href="#Redshift-128"><span class="linenos">128</span></a> <span class="c1"># Redshift allows # to appear as a table identifier prefix</span> -</span><span id="Redshift-129"><a href="#Redshift-129"><span class="linenos">129</span></a> <span class="n">SINGLE_TOKENS</span> <span class="o">=</span> <span class="n">Postgres</span><span class="o">.</span><span class="n">Tokenizer</span><span class="o">.</span><span class="n">SINGLE_TOKENS</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> -</span><span id="Redshift-130"><a href="#Redshift-130"><span class="linenos">130</span></a> <span class="n">SINGLE_TOKENS</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s2">"#"</span><span class="p">)</span> -</span><span id="Redshift-131"><a href="#Redshift-131"><span class="linenos">131</span></a> -</span><span id="Redshift-132"><a href="#Redshift-132"><span class="linenos">132</span></a> <span class="k">class</span> <span class="nc">Generator</span><span class="p">(</span><span class="n">Postgres</span><span class="o">.</span><span class="n">Generator</span><span class="p">):</span> -</span><span id="Redshift-133"><a href="#Redshift-133"><span class="linenos">133</span></a> <span class="n">LOCKING_READS_SUPPORTED</span> <span class="o">=</span> <span class="kc">False</span> -</span><span id="Redshift-134"><a href="#Redshift-134"><span class="linenos">134</span></a> <span class="n">QUERY_HINTS</span> <span class="o">=</span> <span class="kc">False</span> -</span><span id="Redshift-135"><a href="#Redshift-135"><span class="linenos">135</span></a> <span class="n">VALUES_AS_TABLE</span> <span class="o">=</span> <span class="kc">False</span> -</span><span id="Redshift-136"><a href="#Redshift-136"><span class="linenos">136</span></a> <span class="n">TZ_TO_WITH_TIME_ZONE</span> <span class="o">=</span> <span class="kc">True</span> -</span><span id="Redshift-137"><a href="#Redshift-137"><span class="linenos">137</span></a> <span class="n">NVL2_SUPPORTED</span> <span class="o">=</span> <span class="kc">True</span> -</span><span id="Redshift-138"><a href="#Redshift-138"><span class="linenos">138</span></a> <span class="n">LAST_DAY_SUPPORTS_DATE_PART</span> <span class="o">=</span> <span class="kc">False</span> -</span><span id="Redshift-139"><a href="#Redshift-139"><span class="linenos">139</span></a> <span class="n">CAN_IMPLEMENT_ARRAY_ANY</span> <span class="o">=</span> <span class="kc">False</span> -</span><span id="Redshift-140"><a href="#Redshift-140"><span class="linenos">140</span></a> <span class="n">MULTI_ARG_DISTINCT</span> <span class="o">=</span> <span class="kc">True</span> -</span><span id="Redshift-141"><a href="#Redshift-141"><span class="linenos">141</span></a> -</span><span id="Redshift-142"><a href="#Redshift-142"><span class="linenos">142</span></a> <span class="n">TYPE_MAPPING</span> <span class="o">=</span> <span class="p">{</span> -</span><span id="Redshift-143"><a href="#Redshift-143"><span class="linenos">143</span></a> <span class="o">**</span><span class="n">Postgres</span><span class="o">.</span><span class="n">Generator</span><span class="o">.</span><span class="n">TYPE_MAPPING</span><span class="p">,</span> -</span><span id="Redshift-144"><a href="#Redshift-144"><span class="linenos">144</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">BINARY</span><span class="p">:</span> <span class="s2">"VARBYTE"</span><span class="p">,</span> -</span><span id="Redshift-145"><a href="#Redshift-145"><span class="linenos">145</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">INT</span><span class="p">:</span> <span class="s2">"INTEGER"</span><span class="p">,</span> -</span><span id="Redshift-146"><a href="#Redshift-146"><span class="linenos">146</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">TIMETZ</span><span class="p">:</span> <span class="s2">"TIME"</span><span class="p">,</span> -</span><span id="Redshift-147"><a href="#Redshift-147"><span class="linenos">147</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">TIMESTAMPTZ</span><span class="p">:</span> <span class="s2">"TIMESTAMP"</span><span class="p">,</span> -</span><span id="Redshift-148"><a href="#Redshift-148"><span class="linenos">148</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">VARBINARY</span><span class="p">:</span> <span class="s2">"VARBYTE"</span><span class="p">,</span> -</span><span id="Redshift-149"><a href="#Redshift-149"><span class="linenos">149</span></a> <span class="p">}</span> -</span><span id="Redshift-150"><a href="#Redshift-150"><span class="linenos">150</span></a> -</span><span id="Redshift-151"><a href="#Redshift-151"><span class="linenos">151</span></a> <span class="n">TRANSFORMS</span> <span class="o">=</span> <span class="p">{</span> -</span><span id="Redshift-152"><a href="#Redshift-152"><span class="linenos">152</span></a> <span class="o">**</span><span class="n">Postgres</span><span class="o">.</span><span class="n">Generator</span><span class="o">.</span><span class="n">TRANSFORMS</span><span class="p">,</span> -</span><span id="Redshift-153"><a href="#Redshift-153"><span class="linenos">153</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Concat</span><span class="p">:</span> <span class="n">concat_to_dpipe_sql</span><span class="p">,</span> -</span><span id="Redshift-154"><a href="#Redshift-154"><span class="linenos">154</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">ConcatWs</span><span class="p">:</span> <span class="n">concat_ws_to_dpipe_sql</span><span class="p">,</span> -</span><span id="Redshift-155"><a href="#Redshift-155"><span class="linenos">155</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">ApproxDistinct</span><span class="p">:</span> <span class="k">lambda</span> <span class="bp">self</span><span class="p">,</span> -</span><span id="Redshift-156"><a href="#Redshift-156"><span class="linenos">156</span></a> <span class="n">e</span><span class="p">:</span> <span class="sa">f</span><span class="s2">"APPROXIMATE COUNT(DISTINCT </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="p">,</span><span class="w"> </span><span class="s1">'this'</span><span class="p">)</span><span class="si">}</span><span class="s2">)"</span><span class="p">,</span> -</span><span id="Redshift-157"><a href="#Redshift-157"><span class="linenos">157</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">CurrentTimestamp</span><span class="p">:</span> <span class="k">lambda</span> <span class="bp">self</span><span class="p">,</span> <span class="n">e</span><span class="p">:</span> <span class="p">(</span> -</span><span id="Redshift-158"><a href="#Redshift-158"><span class="linenos">158</span></a> <span class="s2">"SYSDATE"</span> <span class="k">if</span> <span class="n">e</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"transaction"</span><span class="p">)</span> <span class="k">else</span> <span class="s2">"GETDATE()"</span> -</span><span id="Redshift-159"><a href="#Redshift-159"><span class="linenos">159</span></a> <span class="p">),</span> -</span><span id="Redshift-160"><a href="#Redshift-160"><span class="linenos">160</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DateAdd</span><span class="p">:</span> <span class="n">date_delta_sql</span><span class="p">(</span><span class="s2">"DATEADD"</span><span class="p">),</span> -</span><span id="Redshift-161"><a href="#Redshift-161"><span class="linenos">161</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DateDiff</span><span class="p">:</span> <span class="n">date_delta_sql</span><span class="p">(</span><span class="s2">"DATEDIFF"</span><span class="p">),</span> -</span><span id="Redshift-162"><a href="#Redshift-162"><span class="linenos">162</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DistKeyProperty</span><span class="p">:</span> <span class="k">lambda</span> <span class="bp">self</span><span class="p">,</span> <span class="n">e</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="s2">"DISTKEY"</span><span class="p">,</span> <span class="n">e</span><span class="o">.</span><span class="n">this</span><span class="p">),</span> -</span><span id="Redshift-163"><a href="#Redshift-163"><span class="linenos">163</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DistStyleProperty</span><span class="p">:</span> <span class="k">lambda</span> <span class="bp">self</span><span class="p">,</span> <span class="n">e</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">naked_property</span><span class="p">(</span><span class="n">e</span><span class="p">),</span> -</span><span id="Redshift-164"><a href="#Redshift-164"><span class="linenos">164</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">FromBase</span><span class="p">:</span> <span class="n">rename_func</span><span class="p">(</span><span class="s2">"STRTOL"</span><span class="p">),</span> -</span><span id="Redshift-165"><a href="#Redshift-165"><span class="linenos">165</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">GeneratedAsIdentityColumnConstraint</span><span class="p">:</span> <span class="n">generatedasidentitycolumnconstraint_sql</span><span class="p">,</span> -</span><span id="Redshift-166"><a href="#Redshift-166"><span class="linenos">166</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">JSONExtract</span><span class="p">:</span> <span class="n">json_extract_segments</span><span class="p">(</span><span class="s2">"JSON_EXTRACT_PATH_TEXT"</span><span class="p">),</span> -</span><span id="Redshift-167"><a href="#Redshift-167"><span class="linenos">167</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">JSONExtractScalar</span><span class="p">:</span> <span class="n">json_extract_segments</span><span class="p">(</span><span class="s2">"JSON_EXTRACT_PATH_TEXT"</span><span class="p">),</span> -</span><span id="Redshift-168"><a href="#Redshift-168"><span class="linenos">168</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">GroupConcat</span><span class="p">:</span> <span class="n">rename_func</span><span class="p">(</span><span class="s2">"LISTAGG"</span><span class="p">),</span> -</span><span id="Redshift-169"><a href="#Redshift-169"><span class="linenos">169</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">ParseJSON</span><span class="p">:</span> <span class="n">rename_func</span><span class="p">(</span><span class="s2">"JSON_PARSE"</span><span class="p">),</span> -</span><span id="Redshift-170"><a href="#Redshift-170"><span class="linenos">170</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Select</span><span class="p">:</span> <span class="n">transforms</span><span class="o">.</span><span class="n">preprocess</span><span class="p">(</span> -</span><span id="Redshift-171"><a href="#Redshift-171"><span class="linenos">171</span></a> <span class="p">[</span><span class="n">transforms</span><span class="o">.</span><span class="n">eliminate_distinct_on</span><span class="p">,</span> <span class="n">transforms</span><span class="o">.</span><span class="n">eliminate_semi_and_anti_joins</span><span class="p">]</span> -</span><span id="Redshift-172"><a href="#Redshift-172"><span class="linenos">172</span></a> <span class="p">),</span> -</span><span id="Redshift-173"><a href="#Redshift-173"><span class="linenos">173</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">SortKeyProperty</span><span class="p">:</span> <span class="k">lambda</span> <span class="bp">self</span><span class="p">,</span> -</span><span id="Redshift-174"><a href="#Redshift-174"><span class="linenos">174</span></a> <span class="n">e</span><span class="p">:</span> <span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="s1">'COMPOUND '</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">e</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s1">'compound'</span><span class="p">]</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="s1">''</span><span class="si">}</span><span class="s2">SORTKEY(</span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">format_args</span><span class="p">(</span><span class="o">*</span><span class="n">e</span><span class="o">.</span><span class="n">this</span><span class="p">)</span><span class="si">}</span><span class="s2">)"</span><span class="p">,</span> -</span><span id="Redshift-175"><a href="#Redshift-175"><span class="linenos">175</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">StartsWith</span><span class="p">:</span> <span class="k">lambda</span> <span class="bp">self</span><span class="p">,</span> -</span><span id="Redshift-176"><a href="#Redshift-176"><span class="linenos">176</span></a> <span class="n">e</span><span class="p">:</span> <span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">this</span><span class="p">)</span><span class="si">}</span><span class="s2"> LIKE </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">expression</span><span class="p">)</span><span class="si">}</span><span class="s2"> || '%'"</span><span class="p">,</span> -</span><span id="Redshift-177"><a href="#Redshift-177"><span class="linenos">177</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">TableSample</span><span class="p">:</span> <span class="n">no_tablesample_sql</span><span class="p">,</span> -</span><span id="Redshift-178"><a href="#Redshift-178"><span class="linenos">178</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">TsOrDsAdd</span><span class="p">:</span> <span class="n">date_delta_sql</span><span class="p">(</span><span class="s2">"DATEADD"</span><span class="p">),</span> -</span><span id="Redshift-179"><a href="#Redshift-179"><span class="linenos">179</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">TsOrDsDiff</span><span class="p">:</span> <span class="n">date_delta_sql</span><span class="p">(</span><span class="s2">"DATEDIFF"</span><span class="p">),</span> -</span><span id="Redshift-180"><a href="#Redshift-180"><span class="linenos">180</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">UnixToTime</span><span class="p">:</span> <span class="k">lambda</span> <span class="bp">self</span><span class="p">,</span> -</span><span id="Redshift-181"><a href="#Redshift-181"><span class="linenos">181</span></a> <span class="n">e</span><span class="p">:</span> <span class="sa">f</span><span class="s2">"(TIMESTAMP 'epoch' + </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">this</span><span class="p">)</span><span class="si">}</span><span class="s2"> * INTERVAL '1 SECOND')"</span><span class="p">,</span> -</span><span id="Redshift-182"><a href="#Redshift-182"><span class="linenos">182</span></a> <span class="p">}</span> -</span><span id="Redshift-183"><a href="#Redshift-183"><span class="linenos">183</span></a> -</span><span id="Redshift-184"><a href="#Redshift-184"><span class="linenos">184</span></a> <span class="c1"># Postgres maps exp.Pivot to no_pivot_sql, but Redshift support pivots</span> -</span><span id="Redshift-185"><a href="#Redshift-185"><span class="linenos">185</span></a> <span class="n">TRANSFORMS</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Pivot</span><span class="p">)</span> -</span><span id="Redshift-186"><a href="#Redshift-186"><span class="linenos">186</span></a> -</span><span id="Redshift-187"><a href="#Redshift-187"><span class="linenos">187</span></a> <span class="c1"># Redshift uses the POW | POWER (expr1, expr2) syntax instead of expr1 ^ expr2 (postgres)</span> -</span><span id="Redshift-188"><a href="#Redshift-188"><span class="linenos">188</span></a> <span class="n">TRANSFORMS</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Pow</span><span class="p">)</span> +</span><span id="Redshift-83"><a href="#Redshift-83"><span class="linenos"> 83</span></a> <span class="n">parse_partition</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span> +</span><span id="Redshift-84"><a href="#Redshift-84"><span class="linenos"> 84</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">]:</span> +</span><span id="Redshift-85"><a href="#Redshift-85"><span class="linenos"> 85</span></a> <span class="c1"># Redshift supports UNPIVOTing SUPER objects, e.g. `UNPIVOT foo.obj[0] AS val AT attr`</span> +</span><span id="Redshift-86"><a href="#Redshift-86"><span class="linenos"> 86</span></a> <span class="n">unpivot</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_match</span><span class="p">(</span><span class="n">TokenType</span><span class="o">.</span><span class="n">UNPIVOT</span><span class="p">)</span> +</span><span id="Redshift-87"><a href="#Redshift-87"><span class="linenos"> 87</span></a> <span class="n">table</span> <span class="o">=</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">_parse_table</span><span class="p">(</span> +</span><span id="Redshift-88"><a href="#Redshift-88"><span class="linenos"> 88</span></a> <span class="n">schema</span><span class="o">=</span><span class="n">schema</span><span class="p">,</span> +</span><span id="Redshift-89"><a href="#Redshift-89"><span class="linenos"> 89</span></a> <span class="n">joins</span><span class="o">=</span><span class="n">joins</span><span class="p">,</span> +</span><span id="Redshift-90"><a href="#Redshift-90"><span class="linenos"> 90</span></a> <span class="n">alias_tokens</span><span class="o">=</span><span class="n">alias_tokens</span><span class="p">,</span> +</span><span id="Redshift-91"><a href="#Redshift-91"><span class="linenos"> 91</span></a> <span class="n">parse_bracket</span><span class="o">=</span><span class="n">parse_bracket</span><span class="p">,</span> +</span><span id="Redshift-92"><a href="#Redshift-92"><span class="linenos"> 92</span></a> <span class="n">is_db_reference</span><span class="o">=</span><span class="n">is_db_reference</span><span class="p">,</span> +</span><span id="Redshift-93"><a href="#Redshift-93"><span class="linenos"> 93</span></a> <span class="p">)</span> +</span><span id="Redshift-94"><a href="#Redshift-94"><span class="linenos"> 94</span></a> +</span><span id="Redshift-95"><a href="#Redshift-95"><span class="linenos"> 95</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Pivot</span><span class="p">,</span> <span class="n">this</span><span class="o">=</span><span class="n">table</span><span class="p">,</span> <span class="n">unpivot</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> <span class="k">if</span> <span class="n">unpivot</span> <span class="k">else</span> <span class="n">table</span> +</span><span id="Redshift-96"><a href="#Redshift-96"><span class="linenos"> 96</span></a> +</span><span id="Redshift-97"><a href="#Redshift-97"><span class="linenos"> 97</span></a> <span class="k">def</span> <span class="nf">_parse_convert</span><span class="p">(</span> +</span><span id="Redshift-98"><a href="#Redshift-98"><span class="linenos"> 98</span></a> <span class="bp">self</span><span class="p">,</span> <span class="n">strict</span><span class="p">:</span> <span class="nb">bool</span><span class="p">,</span> <span class="n">safe</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">bool</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span> +</span><span id="Redshift-99"><a href="#Redshift-99"><span class="linenos"> 99</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">]:</span> +</span><span id="Redshift-100"><a href="#Redshift-100"><span class="linenos">100</span></a> <span class="n">to</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_types</span><span class="p">()</span> +</span><span id="Redshift-101"><a href="#Redshift-101"><span class="linenos">101</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">_match</span><span class="p">(</span><span class="n">TokenType</span><span class="o">.</span><span class="n">COMMA</span><span class="p">)</span> +</span><span id="Redshift-102"><a href="#Redshift-102"><span class="linenos">102</span></a> <span class="n">this</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_bitwise</span><span class="p">()</span> +</span><span id="Redshift-103"><a href="#Redshift-103"><span class="linenos">103</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">TryCast</span><span class="p">,</span> <span class="n">this</span><span class="o">=</span><span class="n">this</span><span class="p">,</span> <span class="n">to</span><span class="o">=</span><span class="n">to</span><span class="p">,</span> <span class="n">safe</span><span class="o">=</span><span class="n">safe</span><span class="p">)</span> +</span><span id="Redshift-104"><a href="#Redshift-104"><span class="linenos">104</span></a> +</span><span id="Redshift-105"><a href="#Redshift-105"><span class="linenos">105</span></a> <span class="k">def</span> <span class="nf">_parse_approximate_count</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">exp</span><span class="o">.</span><span class="n">ApproxDistinct</span><span class="p">]:</span> +</span><span id="Redshift-106"><a href="#Redshift-106"><span class="linenos">106</span></a> <span class="n">index</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_index</span> <span class="o">-</span> <span class="mi">1</span> +</span><span id="Redshift-107"><a href="#Redshift-107"><span class="linenos">107</span></a> <span class="n">func</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_function</span><span class="p">()</span> +</span><span id="Redshift-108"><a href="#Redshift-108"><span class="linenos">108</span></a> +</span><span id="Redshift-109"><a href="#Redshift-109"><span class="linenos">109</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">func</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Count</span><span class="p">)</span> <span class="ow">and</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">func</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Distinct</span><span class="p">):</span> +</span><span id="Redshift-110"><a href="#Redshift-110"><span class="linenos">110</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">ApproxDistinct</span><span class="p">,</span> <span class="n">this</span><span class="o">=</span><span class="n">seq_get</span><span class="p">(</span><span class="n">func</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">expressions</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span> +</span><span id="Redshift-111"><a href="#Redshift-111"><span class="linenos">111</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">_retreat</span><span class="p">(</span><span class="n">index</span><span class="p">)</span> +</span><span id="Redshift-112"><a href="#Redshift-112"><span class="linenos">112</span></a> <span class="k">return</span> <span class="kc">None</span> +</span><span id="Redshift-113"><a href="#Redshift-113"><span class="linenos">113</span></a> +</span><span id="Redshift-114"><a href="#Redshift-114"><span class="linenos">114</span></a> <span class="k">class</span> <span class="nc">Tokenizer</span><span class="p">(</span><span class="n">Postgres</span><span class="o">.</span><span class="n">Tokenizer</span><span class="p">):</span> +</span><span id="Redshift-115"><a href="#Redshift-115"><span class="linenos">115</span></a> <span class="n">BIT_STRINGS</span> <span class="o">=</span> <span class="p">[]</span> +</span><span id="Redshift-116"><a href="#Redshift-116"><span class="linenos">116</span></a> <span class="n">HEX_STRINGS</span> <span class="o">=</span> <span class="p">[]</span> +</span><span id="Redshift-117"><a href="#Redshift-117"><span class="linenos">117</span></a> <span class="n">STRING_ESCAPES</span> <span class="o">=</span> <span class="p">[</span><span class="s2">"</span><span class="se">\\</span><span class="s2">"</span><span class="p">,</span> <span class="s2">"'"</span><span class="p">]</span> +</span><span id="Redshift-118"><a href="#Redshift-118"><span class="linenos">118</span></a> +</span><span id="Redshift-119"><a href="#Redshift-119"><span class="linenos">119</span></a> <span class="n">KEYWORDS</span> <span class="o">=</span> <span class="p">{</span> +</span><span id="Redshift-120"><a href="#Redshift-120"><span class="linenos">120</span></a> <span class="o">**</span><span class="n">Postgres</span><span class="o">.</span><span class="n">Tokenizer</span><span class="o">.</span><span class="n">KEYWORDS</span><span class="p">,</span> +</span><span id="Redshift-121"><a href="#Redshift-121"><span class="linenos">121</span></a> <span class="s2">"HLLSKETCH"</span><span class="p">:</span> <span class="n">TokenType</span><span class="o">.</span><span class="n">HLLSKETCH</span><span class="p">,</span> +</span><span id="Redshift-122"><a href="#Redshift-122"><span class="linenos">122</span></a> <span class="s2">"SUPER"</span><span class="p">:</span> <span class="n">TokenType</span><span class="o">.</span><span class="n">SUPER</span><span class="p">,</span> +</span><span id="Redshift-123"><a href="#Redshift-123"><span class="linenos">123</span></a> <span class="s2">"TOP"</span><span class="p">:</span> <span class="n">TokenType</span><span class="o">.</span><span class="n">TOP</span><span class="p">,</span> +</span><span id="Redshift-124"><a href="#Redshift-124"><span class="linenos">124</span></a> <span class="s2">"UNLOAD"</span><span class="p">:</span> <span class="n">TokenType</span><span class="o">.</span><span class="n">COMMAND</span><span class="p">,</span> +</span><span id="Redshift-125"><a href="#Redshift-125"><span class="linenos">125</span></a> <span class="s2">"VARBYTE"</span><span class="p">:</span> <span class="n">TokenType</span><span class="o">.</span><span class="n">VARBINARY</span><span class="p">,</span> +</span><span id="Redshift-126"><a href="#Redshift-126"><span class="linenos">126</span></a> <span class="p">}</span> +</span><span id="Redshift-127"><a href="#Redshift-127"><span class="linenos">127</span></a> <span class="n">KEYWORDS</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s2">"VALUES"</span><span class="p">)</span> +</span><span id="Redshift-128"><a href="#Redshift-128"><span class="linenos">128</span></a> +</span><span id="Redshift-129"><a href="#Redshift-129"><span class="linenos">129</span></a> <span class="c1"># Redshift allows # to appear as a table identifier prefix</span> +</span><span id="Redshift-130"><a href="#Redshift-130"><span class="linenos">130</span></a> <span class="n">SINGLE_TOKENS</span> <span class="o">=</span> <span class="n">Postgres</span><span class="o">.</span><span class="n">Tokenizer</span><span class="o">.</span><span class="n">SINGLE_TOKENS</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="Redshift-131"><a href="#Redshift-131"><span class="linenos">131</span></a> <span class="n">SINGLE_TOKENS</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s2">"#"</span><span class="p">)</span> +</span><span id="Redshift-132"><a href="#Redshift-132"><span class="linenos">132</span></a> +</span><span id="Redshift-133"><a href="#Redshift-133"><span class="linenos">133</span></a> <span class="k">class</span> <span class="nc">Generator</span><span class="p">(</span><span class="n">Postgres</span><span class="o">.</span><span class="n">Generator</span><span class="p">):</span> +</span><span id="Redshift-134"><a href="#Redshift-134"><span class="linenos">134</span></a> <span class="n">LOCKING_READS_SUPPORTED</span> <span class="o">=</span> <span class="kc">False</span> +</span><span id="Redshift-135"><a href="#Redshift-135"><span class="linenos">135</span></a> <span class="n">QUERY_HINTS</span> <span class="o">=</span> <span class="kc">False</span> +</span><span id="Redshift-136"><a href="#Redshift-136"><span class="linenos">136</span></a> <span class="n">VALUES_AS_TABLE</span> <span class="o">=</span> <span class="kc">False</span> +</span><span id="Redshift-137"><a href="#Redshift-137"><span class="linenos">137</span></a> <span class="n">TZ_TO_WITH_TIME_ZONE</span> <span class="o">=</span> <span class="kc">True</span> +</span><span id="Redshift-138"><a href="#Redshift-138"><span class="linenos">138</span></a> <span class="n">NVL2_SUPPORTED</span> <span class="o">=</span> <span class="kc">True</span> +</span><span id="Redshift-139"><a href="#Redshift-139"><span class="linenos">139</span></a> <span class="n">LAST_DAY_SUPPORTS_DATE_PART</span> <span class="o">=</span> <span class="kc">False</span> +</span><span id="Redshift-140"><a href="#Redshift-140"><span class="linenos">140</span></a> <span class="n">CAN_IMPLEMENT_ARRAY_ANY</span> <span class="o">=</span> <span class="kc">False</span> +</span><span id="Redshift-141"><a href="#Redshift-141"><span class="linenos">141</span></a> <span class="n">MULTI_ARG_DISTINCT</span> <span class="o">=</span> <span class="kc">True</span> +</span><span id="Redshift-142"><a href="#Redshift-142"><span class="linenos">142</span></a> +</span><span id="Redshift-143"><a href="#Redshift-143"><span class="linenos">143</span></a> <span class="n">TYPE_MAPPING</span> <span class="o">=</span> <span class="p">{</span> +</span><span id="Redshift-144"><a href="#Redshift-144"><span class="linenos">144</span></a> <span class="o">**</span><span class="n">Postgres</span><span class="o">.</span><span class="n">Generator</span><span class="o">.</span><span class="n">TYPE_MAPPING</span><span class="p">,</span> +</span><span id="Redshift-145"><a href="#Redshift-145"><span class="linenos">145</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">BINARY</span><span class="p">:</span> <span class="s2">"VARBYTE"</span><span class="p">,</span> +</span><span id="Redshift-146"><a href="#Redshift-146"><span class="linenos">146</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">INT</span><span class="p">:</span> <span class="s2">"INTEGER"</span><span class="p">,</span> +</span><span id="Redshift-147"><a href="#Redshift-147"><span class="linenos">147</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">TIMETZ</span><span class="p">:</span> <span class="s2">"TIME"</span><span class="p">,</span> +</span><span id="Redshift-148"><a href="#Redshift-148"><span class="linenos">148</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">TIMESTAMPTZ</span><span class="p">:</span> <span class="s2">"TIMESTAMP"</span><span class="p">,</span> +</span><span id="Redshift-149"><a href="#Redshift-149"><span class="linenos">149</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">VARBINARY</span><span class="p">:</span> <span class="s2">"VARBYTE"</span><span class="p">,</span> +</span><span id="Redshift-150"><a href="#Redshift-150"><span class="linenos">150</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">ROWVERSION</span><span class="p">:</span> <span class="s2">"VARBYTE"</span><span class="p">,</span> +</span><span id="Redshift-151"><a href="#Redshift-151"><span class="linenos">151</span></a> <span class="p">}</span> +</span><span id="Redshift-152"><a href="#Redshift-152"><span class="linenos">152</span></a> +</span><span id="Redshift-153"><a href="#Redshift-153"><span class="linenos">153</span></a> <span class="n">TRANSFORMS</span> <span class="o">=</span> <span class="p">{</span> +</span><span id="Redshift-154"><a href="#Redshift-154"><span class="linenos">154</span></a> <span class="o">**</span><span class="n">Postgres</span><span class="o">.</span><span class="n">Generator</span><span class="o">.</span><span class="n">TRANSFORMS</span><span class="p">,</span> +</span><span id="Redshift-155"><a href="#Redshift-155"><span class="linenos">155</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Concat</span><span class="p">:</span> <span class="n">concat_to_dpipe_sql</span><span class="p">,</span> +</span><span id="Redshift-156"><a href="#Redshift-156"><span class="linenos">156</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">ConcatWs</span><span class="p">:</span> <span class="n">concat_ws_to_dpipe_sql</span><span class="p">,</span> +</span><span id="Redshift-157"><a href="#Redshift-157"><span class="linenos">157</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">ApproxDistinct</span><span class="p">:</span> <span class="k">lambda</span> <span class="bp">self</span><span class="p">,</span> +</span><span id="Redshift-158"><a href="#Redshift-158"><span class="linenos">158</span></a> <span class="n">e</span><span class="p">:</span> <span class="sa">f</span><span class="s2">"APPROXIMATE COUNT(DISTINCT </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="p">,</span><span class="w"> </span><span class="s1">'this'</span><span class="p">)</span><span class="si">}</span><span class="s2">)"</span><span class="p">,</span> +</span><span id="Redshift-159"><a href="#Redshift-159"><span class="linenos">159</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">CurrentTimestamp</span><span class="p">:</span> <span class="k">lambda</span> <span class="bp">self</span><span class="p">,</span> <span class="n">e</span><span class="p">:</span> <span class="p">(</span> +</span><span id="Redshift-160"><a href="#Redshift-160"><span class="linenos">160</span></a> <span class="s2">"SYSDATE"</span> <span class="k">if</span> <span class="n">e</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"transaction"</span><span class="p">)</span> <span class="k">else</span> <span class="s2">"GETDATE()"</span> +</span><span id="Redshift-161"><a href="#Redshift-161"><span class="linenos">161</span></a> <span class="p">),</span> +</span><span id="Redshift-162"><a href="#Redshift-162"><span class="linenos">162</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DateAdd</span><span class="p">:</span> <span class="n">date_delta_sql</span><span class="p">(</span><span class="s2">"DATEADD"</span><span class="p">),</span> +</span><span id="Redshift-163"><a href="#Redshift-163"><span class="linenos">163</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DateDiff</span><span class="p">:</span> <span class="n">date_delta_sql</span><span class="p">(</span><span class="s2">"DATEDIFF"</span><span class="p">),</span> +</span><span id="Redshift-164"><a href="#Redshift-164"><span class="linenos">164</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DistKeyProperty</span><span class="p">:</span> <span class="k">lambda</span> <span class="bp">self</span><span class="p">,</span> <span class="n">e</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="s2">"DISTKEY"</span><span class="p">,</span> <span class="n">e</span><span class="o">.</span><span class="n">this</span><span class="p">),</span> +</span><span id="Redshift-165"><a href="#Redshift-165"><span class="linenos">165</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DistStyleProperty</span><span class="p">:</span> <span class="k">lambda</span> <span class="bp">self</span><span class="p">,</span> <span class="n">e</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">naked_property</span><span class="p">(</span><span class="n">e</span><span class="p">),</span> +</span><span id="Redshift-166"><a href="#Redshift-166"><span class="linenos">166</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">FromBase</span><span class="p">:</span> <span class="n">rename_func</span><span class="p">(</span><span class="s2">"STRTOL"</span><span class="p">),</span> +</span><span id="Redshift-167"><a href="#Redshift-167"><span class="linenos">167</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">GeneratedAsIdentityColumnConstraint</span><span class="p">:</span> <span class="n">generatedasidentitycolumnconstraint_sql</span><span class="p">,</span> +</span><span id="Redshift-168"><a href="#Redshift-168"><span class="linenos">168</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">JSONExtract</span><span class="p">:</span> <span class="n">json_extract_segments</span><span class="p">(</span><span class="s2">"JSON_EXTRACT_PATH_TEXT"</span><span class="p">),</span> +</span><span id="Redshift-169"><a href="#Redshift-169"><span class="linenos">169</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">JSONExtractScalar</span><span class="p">:</span> <span class="n">json_extract_segments</span><span class="p">(</span><span class="s2">"JSON_EXTRACT_PATH_TEXT"</span><span class="p">),</span> +</span><span id="Redshift-170"><a href="#Redshift-170"><span class="linenos">170</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">GroupConcat</span><span class="p">:</span> <span class="n">rename_func</span><span class="p">(</span><span class="s2">"LISTAGG"</span><span class="p">),</span> +</span><span id="Redshift-171"><a href="#Redshift-171"><span class="linenos">171</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">ParseJSON</span><span class="p">:</span> <span class="n">rename_func</span><span class="p">(</span><span class="s2">"JSON_PARSE"</span><span class="p">),</span> +</span><span id="Redshift-172"><a href="#Redshift-172"><span class="linenos">172</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Select</span><span class="p">:</span> <span class="n">transforms</span><span class="o">.</span><span class="n">preprocess</span><span class="p">(</span> +</span><span id="Redshift-173"><a href="#Redshift-173"><span class="linenos">173</span></a> <span class="p">[</span> +</span><span id="Redshift-174"><a href="#Redshift-174"><span class="linenos">174</span></a> <span class="n">transforms</span><span class="o">.</span><span class="n">eliminate_distinct_on</span><span class="p">,</span> +</span><span id="Redshift-175"><a href="#Redshift-175"><span class="linenos">175</span></a> <span class="n">transforms</span><span class="o">.</span><span class="n">eliminate_semi_and_anti_joins</span><span class="p">,</span> +</span><span id="Redshift-176"><a href="#Redshift-176"><span class="linenos">176</span></a> <span class="n">transforms</span><span class="o">.</span><span class="n">unqualify_unnest</span><span class="p">,</span> +</span><span id="Redshift-177"><a href="#Redshift-177"><span class="linenos">177</span></a> <span class="p">]</span> +</span><span id="Redshift-178"><a href="#Redshift-178"><span class="linenos">178</span></a> <span class="p">),</span> +</span><span id="Redshift-179"><a href="#Redshift-179"><span class="linenos">179</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">SortKeyProperty</span><span class="p">:</span> <span class="k">lambda</span> <span class="bp">self</span><span class="p">,</span> +</span><span id="Redshift-180"><a href="#Redshift-180"><span class="linenos">180</span></a> <span class="n">e</span><span class="p">:</span> <span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="s1">'COMPOUND '</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">e</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s1">'compound'</span><span class="p">]</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="s1">''</span><span class="si">}</span><span class="s2">SORTKEY(</span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">format_args</span><span class="p">(</span><span class="o">*</span><span class="n">e</span><span class="o">.</span><span class="n">this</span><span class="p">)</span><span class="si">}</span><span class="s2">)"</span><span class="p">,</span> +</span><span id="Redshift-181"><a href="#Redshift-181"><span class="linenos">181</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">StartsWith</span><span class="p">:</span> <span class="k">lambda</span> <span class="bp">self</span><span class="p">,</span> +</span><span id="Redshift-182"><a href="#Redshift-182"><span class="linenos">182</span></a> <span class="n">e</span><span class="p">:</span> <span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">this</span><span class="p">)</span><span class="si">}</span><span class="s2"> LIKE </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">expression</span><span class="p">)</span><span class="si">}</span><span class="s2"> || '%'"</span><span class="p">,</span> +</span><span id="Redshift-183"><a href="#Redshift-183"><span class="linenos">183</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">TableSample</span><span class="p">:</span> <span class="n">no_tablesample_sql</span><span class="p">,</span> +</span><span id="Redshift-184"><a href="#Redshift-184"><span class="linenos">184</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">TsOrDsAdd</span><span class="p">:</span> <span class="n">date_delta_sql</span><span class="p">(</span><span class="s2">"DATEADD"</span><span class="p">),</span> +</span><span id="Redshift-185"><a href="#Redshift-185"><span class="linenos">185</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">TsOrDsDiff</span><span class="p">:</span> <span class="n">date_delta_sql</span><span class="p">(</span><span class="s2">"DATEDIFF"</span><span class="p">),</span> +</span><span id="Redshift-186"><a href="#Redshift-186"><span class="linenos">186</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">UnixToTime</span><span class="p">:</span> <span class="k">lambda</span> <span class="bp">self</span><span class="p">,</span> +</span><span id="Redshift-187"><a href="#Redshift-187"><span class="linenos">187</span></a> <span class="n">e</span><span class="p">:</span> <span class="sa">f</span><span class="s2">"(TIMESTAMP 'epoch' + </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">this</span><span class="p">)</span><span class="si">}</span><span class="s2"> * INTERVAL '1 SECOND')"</span><span class="p">,</span> +</span><span id="Redshift-188"><a href="#Redshift-188"><span class="linenos">188</span></a> <span class="p">}</span> </span><span id="Redshift-189"><a href="#Redshift-189"><span class="linenos">189</span></a> -</span><span id="Redshift-190"><a href="#Redshift-190"><span class="linenos">190</span></a> <span class="c1"># Redshift supports ANY_VALUE(..)</span> -</span><span id="Redshift-191"><a href="#Redshift-191"><span class="linenos">191</span></a> <span class="n">TRANSFORMS</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">AnyValue</span><span class="p">)</span> +</span><span id="Redshift-190"><a href="#Redshift-190"><span class="linenos">190</span></a> <span class="c1"># Postgres maps exp.Pivot to no_pivot_sql, but Redshift support pivots</span> +</span><span id="Redshift-191"><a href="#Redshift-191"><span class="linenos">191</span></a> <span class="n">TRANSFORMS</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Pivot</span><span class="p">)</span> </span><span id="Redshift-192"><a href="#Redshift-192"><span class="linenos">192</span></a> -</span><span id="Redshift-193"><a href="#Redshift-193"><span class="linenos">193</span></a> <span class="c1"># Redshift supports LAST_DAY(..)</span> -</span><span id="Redshift-194"><a href="#Redshift-194"><span class="linenos">194</span></a> <span class="n">TRANSFORMS</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">LastDay</span><span class="p">)</span> +</span><span id="Redshift-193"><a href="#Redshift-193"><span class="linenos">193</span></a> <span class="c1"># Redshift uses the POW | POWER (expr1, expr2) syntax instead of expr1 ^ expr2 (postgres)</span> +</span><span id="Redshift-194"><a href="#Redshift-194"><span class="linenos">194</span></a> <span class="n">TRANSFORMS</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Pow</span><span class="p">)</span> </span><span id="Redshift-195"><a href="#Redshift-195"><span class="linenos">195</span></a> -</span><span id="Redshift-196"><a href="#Redshift-196"><span class="linenos">196</span></a> <span class="n">RESERVED_KEYWORDS</span> <span class="o">=</span> <span class="p">{</span><span class="o">*</span><span class="n">Postgres</span><span class="o">.</span><span class="n">Generator</span><span class="o">.</span><span class="n">RESERVED_KEYWORDS</span><span class="p">,</span> <span class="s2">"snapshot"</span><span class="p">,</span> <span class="s2">"type"</span><span class="p">}</span> -</span><span id="Redshift-197"><a href="#Redshift-197"><span class="linenos">197</span></a> -</span><span id="Redshift-198"><a href="#Redshift-198"><span class="linenos">198</span></a> <span class="k">def</span> <span class="nf">unnest_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Unnest</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="Redshift-199"><a href="#Redshift-199"><span class="linenos">199</span></a> <span class="n">args</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">expressions</span> -</span><span id="Redshift-200"><a href="#Redshift-200"><span class="linenos">200</span></a> <span class="n">num_args</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> +</span><span id="Redshift-196"><a href="#Redshift-196"><span class="linenos">196</span></a> <span class="c1"># Redshift supports ANY_VALUE(..)</span> +</span><span id="Redshift-197"><a href="#Redshift-197"><span class="linenos">197</span></a> <span class="n">TRANSFORMS</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">AnyValue</span><span class="p">)</span> +</span><span id="Redshift-198"><a href="#Redshift-198"><span class="linenos">198</span></a> +</span><span id="Redshift-199"><a href="#Redshift-199"><span class="linenos">199</span></a> <span class="c1"># Redshift supports LAST_DAY(..)</span> +</span><span id="Redshift-200"><a href="#Redshift-200"><span class="linenos">200</span></a> <span class="n">TRANSFORMS</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">LastDay</span><span class="p">)</span> </span><span id="Redshift-201"><a href="#Redshift-201"><span class="linenos">201</span></a> -</span><span id="Redshift-202"><a href="#Redshift-202"><span class="linenos">202</span></a> <span class="k">if</span> <span class="n">num_args</span> <span class="o">></span> <span class="mi">1</span><span class="p">:</span> -</span><span id="Redshift-203"><a href="#Redshift-203"><span class="linenos">203</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Unsupported number of arguments in UNNEST: </span><span class="si">{</span><span class="n">num_args</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> -</span><span id="Redshift-204"><a href="#Redshift-204"><span class="linenos">204</span></a> <span class="k">return</span> <span class="s2">""</span> -</span><span id="Redshift-205"><a href="#Redshift-205"><span class="linenos">205</span></a> -</span><span id="Redshift-206"><a href="#Redshift-206"><span class="linenos">206</span></a> <span class="n">arg</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span> -</span><span id="Redshift-207"><a href="#Redshift-207"><span class="linenos">207</span></a> <span class="n">alias</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">expressions</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"alias"</span><span class="p">),</span> <span class="n">key</span><span class="o">=</span><span class="s2">"columns"</span><span class="p">)</span> -</span><span id="Redshift-208"><a href="#Redshift-208"><span class="linenos">208</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">arg</span><span class="si">}</span><span class="s2"> AS </span><span class="si">{</span><span class="n">alias</span><span class="si">}</span><span class="s2">"</span> <span class="k">if</span> <span class="n">alias</span> <span class="k">else</span> <span class="n">arg</span> -</span><span id="Redshift-209"><a href="#Redshift-209"><span class="linenos">209</span></a> -</span><span id="Redshift-210"><a href="#Redshift-210"><span class="linenos">210</span></a> <span class="k">def</span> <span class="nf">with_properties</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">properties</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Properties</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="Redshift-211"><a href="#Redshift-211"><span class="linenos">211</span></a><span class="w"> </span><span class="sd">"""Redshift doesn't have `WITH` as part of their with_properties so we remove it"""</span> -</span><span id="Redshift-212"><a href="#Redshift-212"><span class="linenos">212</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">properties</span><span class="p">(</span><span class="n">properties</span><span class="p">,</span> <span class="n">prefix</span><span class="o">=</span><span class="s2">" "</span><span class="p">,</span> <span class="n">suffix</span><span class="o">=</span><span class="s2">""</span><span class="p">)</span> -</span><span id="Redshift-213"><a href="#Redshift-213"><span class="linenos">213</span></a> -</span><span id="Redshift-214"><a href="#Redshift-214"><span class="linenos">214</span></a> <span class="k">def</span> <span class="nf">cast_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Cast</span><span class="p">,</span> <span class="n">safe_prefix</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="Redshift-215"><a href="#Redshift-215"><span class="linenos">215</span></a> <span class="k">if</span> <span class="n">expression</span><span class="o">.</span><span class="n">is_type</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">JSON</span><span class="p">):</span> -</span><span id="Redshift-216"><a href="#Redshift-216"><span class="linenos">216</span></a> <span class="c1"># Redshift doesn't support a JSON type, so casting to it is treated as a noop</span> -</span><span id="Redshift-217"><a href="#Redshift-217"><span class="linenos">217</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="s2">"this"</span><span class="p">)</span> -</span><span id="Redshift-218"><a href="#Redshift-218"><span class="linenos">218</span></a> -</span><span id="Redshift-219"><a href="#Redshift-219"><span class="linenos">219</span></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">cast_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="n">safe_prefix</span><span class="o">=</span><span class="n">safe_prefix</span><span class="p">)</span> -</span><span id="Redshift-220"><a href="#Redshift-220"><span class="linenos">220</span></a> -</span><span id="Redshift-221"><a href="#Redshift-221"><span class="linenos">221</span></a> <span class="k">def</span> <span class="nf">datatype_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="Redshift-222"><a href="#Redshift-222"><span class="linenos">222</span></a><span class="w"> </span><span class="sd">"""</span> -</span><span id="Redshift-223"><a href="#Redshift-223"><span class="linenos">223</span></a><span class="sd"> Redshift converts the `TEXT` data type to `VARCHAR(255)` by default when people more generally mean</span> -</span><span id="Redshift-224"><a href="#Redshift-224"><span class="linenos">224</span></a><span class="sd"> VARCHAR of max length which is `VARCHAR(max)` in Redshift. Therefore if we get a `TEXT` data type</span> -</span><span id="Redshift-225"><a href="#Redshift-225"><span class="linenos">225</span></a><span class="sd"> without precision we convert it to `VARCHAR(max)` and if it does have precision then we just convert</span> -</span><span id="Redshift-226"><a href="#Redshift-226"><span class="linenos">226</span></a><span class="sd"> `TEXT` to `VARCHAR`.</span> -</span><span id="Redshift-227"><a href="#Redshift-227"><span class="linenos">227</span></a><span class="sd"> """</span> -</span><span id="Redshift-228"><a href="#Redshift-228"><span class="linenos">228</span></a> <span class="k">if</span> <span class="n">expression</span><span class="o">.</span><span class="n">is_type</span><span class="p">(</span><span class="s2">"text"</span><span class="p">):</span> -</span><span id="Redshift-229"><a href="#Redshift-229"><span class="linenos">229</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"this"</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">VARCHAR</span><span class="p">)</span> -</span><span id="Redshift-230"><a href="#Redshift-230"><span class="linenos">230</span></a> <span class="n">precision</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"expressions"</span><span class="p">)</span> -</span><span id="Redshift-231"><a href="#Redshift-231"><span class="linenos">231</span></a> -</span><span id="Redshift-232"><a href="#Redshift-232"><span class="linenos">232</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">precision</span><span class="p">:</span> -</span><span id="Redshift-233"><a href="#Redshift-233"><span class="linenos">233</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">"expressions"</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">var</span><span class="p">(</span><span class="s2">"MAX"</span><span class="p">))</span> -</span><span id="Redshift-234"><a href="#Redshift-234"><span class="linenos">234</span></a> -</span><span id="Redshift-235"><a href="#Redshift-235"><span class="linenos">235</span></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">datatype_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> +</span><span id="Redshift-202"><a href="#Redshift-202"><span class="linenos">202</span></a> <span class="n">RESERVED_KEYWORDS</span> <span class="o">=</span> <span class="p">{</span> +</span><span id="Redshift-203"><a href="#Redshift-203"><span class="linenos">203</span></a> <span class="s2">"aes128"</span><span class="p">,</span> +</span><span id="Redshift-204"><a href="#Redshift-204"><span class="linenos">204</span></a> <span class="s2">"aes256"</span><span class="p">,</span> +</span><span id="Redshift-205"><a href="#Redshift-205"><span class="linenos">205</span></a> <span class="s2">"all"</span><span class="p">,</span> +</span><span id="Redshift-206"><a href="#Redshift-206"><span class="linenos">206</span></a> <span class="s2">"allowoverwrite"</span><span class="p">,</span> +</span><span id="Redshift-207"><a href="#Redshift-207"><span class="linenos">207</span></a> <span class="s2">"analyse"</span><span class="p">,</span> +</span><span id="Redshift-208"><a href="#Redshift-208"><span class="linenos">208</span></a> <span class="s2">"analyze"</span><span class="p">,</span> +</span><span id="Redshift-209"><a href="#Redshift-209"><span class="linenos">209</span></a> <span class="s2">"and"</span><span class="p">,</span> +</span><span id="Redshift-210"><a href="#Redshift-210"><span class="linenos">210</span></a> <span class="s2">"any"</span><span class="p">,</span> +</span><span id="Redshift-211"><a href="#Redshift-211"><span class="linenos">211</span></a> <span class="s2">"array"</span><span class="p">,</span> +</span><span id="Redshift-212"><a href="#Redshift-212"><span class="linenos">212</span></a> <span class="s2">"as"</span><span class="p">,</span> +</span><span id="Redshift-213"><a href="#Redshift-213"><span class="linenos">213</span></a> <span class="s2">"asc"</span><span class="p">,</span> +</span><span id="Redshift-214"><a href="#Redshift-214"><span class="linenos">214</span></a> <span class="s2">"authorization"</span><span class="p">,</span> +</span><span id="Redshift-215"><a href="#Redshift-215"><span class="linenos">215</span></a> <span class="s2">"az64"</span><span class="p">,</span> +</span><span id="Redshift-216"><a href="#Redshift-216"><span class="linenos">216</span></a> <span class="s2">"backup"</span><span class="p">,</span> +</span><span id="Redshift-217"><a href="#Redshift-217"><span class="linenos">217</span></a> <span class="s2">"between"</span><span class="p">,</span> +</span><span id="Redshift-218"><a href="#Redshift-218"><span class="linenos">218</span></a> <span class="s2">"binary"</span><span class="p">,</span> +</span><span id="Redshift-219"><a href="#Redshift-219"><span class="linenos">219</span></a> <span class="s2">"blanksasnull"</span><span class="p">,</span> +</span><span id="Redshift-220"><a href="#Redshift-220"><span class="linenos">220</span></a> <span class="s2">"both"</span><span class="p">,</span> +</span><span id="Redshift-221"><a href="#Redshift-221"><span class="linenos">221</span></a> <span class="s2">"bytedict"</span><span class="p">,</span> +</span><span id="Redshift-222"><a href="#Redshift-222"><span class="linenos">222</span></a> <span class="s2">"bzip2"</span><span class="p">,</span> +</span><span id="Redshift-223"><a href="#Redshift-223"><span class="linenos">223</span></a> <span class="s2">"case"</span><span class="p">,</span> +</span><span id="Redshift-224"><a href="#Redshift-224"><span class="linenos">224</span></a> <span class="s2">"cast"</span><span class="p">,</span> +</span><span id="Redshift-225"><a href="#Redshift-225"><span class="linenos">225</span></a> <span class="s2">"check"</span><span class="p">,</span> +</span><span id="Redshift-226"><a href="#Redshift-226"><span class="linenos">226</span></a> <span class="s2">"collate"</span><span class="p">,</span> +</span><span id="Redshift-227"><a href="#Redshift-227"><span class="linenos">227</span></a> <span class="s2">"column"</span><span class="p">,</span> +</span><span id="Redshift-228"><a href="#Redshift-228"><span class="linenos">228</span></a> <span class="s2">"constraint"</span><span class="p">,</span> +</span><span id="Redshift-229"><a href="#Redshift-229"><span class="linenos">229</span></a> <span class="s2">"create"</span><span class="p">,</span> +</span><span id="Redshift-230"><a href="#Redshift-230"><span class="linenos">230</span></a> <span class="s2">"credentials"</span><span class="p">,</span> +</span><span id="Redshift-231"><a href="#Redshift-231"><span class="linenos">231</span></a> <span class="s2">"cross"</span><span class="p">,</span> +</span><span id="Redshift-232"><a href="#Redshift-232"><span class="linenos">232</span></a> <span class="s2">"current_date"</span><span class="p">,</span> +</span><span id="Redshift-233"><a href="#Redshift-233"><span class="linenos">233</span></a> <span class="s2">"current_time"</span><span class="p">,</span> +</span><span id="Redshift-234"><a href="#Redshift-234"><span class="linenos">234</span></a> <span class="s2">"current_timestamp"</span><span class="p">,</span> +</span><span id="Redshift-235"><a href="#Redshift-235"><span class="linenos">235</span></a> <span class="s2">"current_user"</span><span class="p">,</span> +</span><span id="Redshift-236"><a href="#Redshift-236"><span class="linenos">236</span></a> <span class="s2">"current_user_id"</span><span class="p">,</span> +</span><span id="Redshift-237"><a href="#Redshift-237"><span class="linenos">237</span></a> <span class="s2">"default"</span><span class="p">,</span> +</span><span id="Redshift-238"><a href="#Redshift-238"><span class="linenos">238</span></a> <span class="s2">"deferrable"</span><span class="p">,</span> +</span><span id="Redshift-239"><a href="#Redshift-239"><span class="linenos">239</span></a> <span class="s2">"deflate"</span><span class="p">,</span> +</span><span id="Redshift-240"><a href="#Redshift-240"><span class="linenos">240</span></a> <span class="s2">"defrag"</span><span class="p">,</span> +</span><span id="Redshift-241"><a href="#Redshift-241"><span class="linenos">241</span></a> <span class="s2">"delta"</span><span class="p">,</span> +</span><span id="Redshift-242"><a href="#Redshift-242"><span class="linenos">242</span></a> <span class="s2">"delta32k"</span><span class="p">,</span> +</span><span id="Redshift-243"><a href="#Redshift-243"><span class="linenos">243</span></a> <span class="s2">"desc"</span><span class="p">,</span> +</span><span id="Redshift-244"><a href="#Redshift-244"><span class="linenos">244</span></a> <span class="s2">"disable"</span><span class="p">,</span> +</span><span id="Redshift-245"><a href="#Redshift-245"><span class="linenos">245</span></a> <span class="s2">"distinct"</span><span class="p">,</span> +</span><span id="Redshift-246"><a href="#Redshift-246"><span class="linenos">246</span></a> <span class="s2">"do"</span><span class="p">,</span> +</span><span id="Redshift-247"><a href="#Redshift-247"><span class="linenos">247</span></a> <span class="s2">"else"</span><span class="p">,</span> +</span><span id="Redshift-248"><a href="#Redshift-248"><span class="linenos">248</span></a> <span class="s2">"emptyasnull"</span><span class="p">,</span> +</span><span id="Redshift-249"><a href="#Redshift-249"><span class="linenos">249</span></a> <span class="s2">"enable"</span><span class="p">,</span> +</span><span id="Redshift-250"><a href="#Redshift-250"><span class="linenos">250</span></a> <span class="s2">"encode"</span><span class="p">,</span> +</span><span id="Redshift-251"><a href="#Redshift-251"><span class="linenos">251</span></a> <span class="s2">"encrypt "</span><span class="p">,</span> +</span><span id="Redshift-252"><a href="#Redshift-252"><span class="linenos">252</span></a> <span class="s2">"encryption"</span><span class="p">,</span> +</span><span id="Redshift-253"><a href="#Redshift-253"><span class="linenos">253</span></a> <span class="s2">"end"</span><span class="p">,</span> +</span><span id="Redshift-254"><a href="#Redshift-254"><span class="linenos">254</span></a> <span class="s2">"except"</span><span class="p">,</span> +</span><span id="Redshift-255"><a href="#Redshift-255"><span class="linenos">255</span></a> <span class="s2">"explicit"</span><span class="p">,</span> +</span><span id="Redshift-256"><a href="#Redshift-256"><span class="linenos">256</span></a> <span class="s2">"false"</span><span class="p">,</span> +</span><span id="Redshift-257"><a href="#Redshift-257"><span class="linenos">257</span></a> <span class="s2">"for"</span><span class="p">,</span> +</span><span id="Redshift-258"><a href="#Redshift-258"><span class="linenos">258</span></a> <span class="s2">"foreign"</span><span class="p">,</span> +</span><span id="Redshift-259"><a href="#Redshift-259"><span class="linenos">259</span></a> <span class="s2">"freeze"</span><span class="p">,</span> +</span><span id="Redshift-260"><a href="#Redshift-260"><span class="linenos">260</span></a> <span class="s2">"from"</span><span class="p">,</span> +</span><span id="Redshift-261"><a href="#Redshift-261"><span class="linenos">261</span></a> <span class="s2">"full"</span><span class="p">,</span> +</span><span id="Redshift-262"><a href="#Redshift-262"><span class="linenos">262</span></a> <span class="s2">"globaldict256"</span><span class="p">,</span> +</span><span id="Redshift-263"><a href="#Redshift-263"><span class="linenos">263</span></a> <span class="s2">"globaldict64k"</span><span class="p">,</span> +</span><span id="Redshift-264"><a href="#Redshift-264"><span class="linenos">264</span></a> <span class="s2">"grant"</span><span class="p">,</span> +</span><span id="Redshift-265"><a href="#Redshift-265"><span class="linenos">265</span></a> <span class="s2">"group"</span><span class="p">,</span> +</span><span id="Redshift-266"><a href="#Redshift-266"><span class="linenos">266</span></a> <span class="s2">"gzip"</span><span class="p">,</span> +</span><span id="Redshift-267"><a href="#Redshift-267"><span class="linenos">267</span></a> <span class="s2">"having"</span><span class="p">,</span> +</span><span id="Redshift-268"><a href="#Redshift-268"><span class="linenos">268</span></a> <span class="s2">"identity"</span><span class="p">,</span> +</span><span id="Redshift-269"><a href="#Redshift-269"><span class="linenos">269</span></a> <span class="s2">"ignore"</span><span class="p">,</span> +</span><span id="Redshift-270"><a href="#Redshift-270"><span class="linenos">270</span></a> <span class="s2">"ilike"</span><span class="p">,</span> +</span><span id="Redshift-271"><a href="#Redshift-271"><span class="linenos">271</span></a> <span class="s2">"in"</span><span class="p">,</span> +</span><span id="Redshift-272"><a href="#Redshift-272"><span class="linenos">272</span></a> <span class="s2">"initially"</span><span class="p">,</span> +</span><span id="Redshift-273"><a href="#Redshift-273"><span class="linenos">273</span></a> <span class="s2">"inner"</span><span class="p">,</span> +</span><span id="Redshift-274"><a href="#Redshift-274"><span class="linenos">274</span></a> <span class="s2">"intersect"</span><span class="p">,</span> +</span><span id="Redshift-275"><a href="#Redshift-275"><span class="linenos">275</span></a> <span class="s2">"interval"</span><span class="p">,</span> +</span><span id="Redshift-276"><a href="#Redshift-276"><span class="linenos">276</span></a> <span class="s2">"into"</span><span class="p">,</span> +</span><span id="Redshift-277"><a href="#Redshift-277"><span class="linenos">277</span></a> <span class="s2">"is"</span><span class="p">,</span> +</span><span id="Redshift-278"><a href="#Redshift-278"><span class="linenos">278</span></a> <span class="s2">"isnull"</span><span class="p">,</span> +</span><span id="Redshift-279"><a href="#Redshift-279"><span class="linenos">279</span></a> <span class="s2">"join"</span><span class="p">,</span> +</span><span id="Redshift-280"><a href="#Redshift-280"><span class="linenos">280</span></a> <span class="s2">"leading"</span><span class="p">,</span> +</span><span id="Redshift-281"><a href="#Redshift-281"><span class="linenos">281</span></a> <span class="s2">"left"</span><span class="p">,</span> +</span><span id="Redshift-282"><a href="#Redshift-282"><span class="linenos">282</span></a> <span class="s2">"like"</span><span class="p">,</span> +</span><span id="Redshift-283"><a href="#Redshift-283"><span class="linenos">283</span></a> <span class="s2">"limit"</span><span class="p">,</span> +</span><span id="Redshift-284"><a href="#Redshift-284"><span class="linenos">284</span></a> <span class="s2">"localtime"</span><span class="p">,</span> +</span><span id="Redshift-285"><a href="#Redshift-285"><span class="linenos">285</span></a> <span class="s2">"localtimestamp"</span><span class="p">,</span> +</span><span id="Redshift-286"><a href="#Redshift-286"><span class="linenos">286</span></a> <span class="s2">"lun"</span><span class="p">,</span> +</span><span id="Redshift-287"><a href="#Redshift-287"><span class="linenos">287</span></a> <span class="s2">"luns"</span><span class="p">,</span> +</span><span id="Redshift-288"><a href="#Redshift-288"><span class="linenos">288</span></a> <span class="s2">"lzo"</span><span class="p">,</span> +</span><span id="Redshift-289"><a href="#Redshift-289"><span class="linenos">289</span></a> <span class="s2">"lzop"</span><span class="p">,</span> +</span><span id="Redshift-290"><a href="#Redshift-290"><span class="linenos">290</span></a> <span class="s2">"minus"</span><span class="p">,</span> +</span><span id="Redshift-291"><a href="#Redshift-291"><span class="linenos">291</span></a> <span class="s2">"mostly16"</span><span class="p">,</span> +</span><span id="Redshift-292"><a href="#Redshift-292"><span class="linenos">292</span></a> <span class="s2">"mostly32"</span><span class="p">,</span> +</span><span id="Redshift-293"><a href="#Redshift-293"><span class="linenos">293</span></a> <span class="s2">"mostly8"</span><span class="p">,</span> +</span><span id="Redshift-294"><a href="#Redshift-294"><span class="linenos">294</span></a> <span class="s2">"natural"</span><span class="p">,</span> +</span><span id="Redshift-295"><a href="#Redshift-295"><span class="linenos">295</span></a> <span class="s2">"new"</span><span class="p">,</span> +</span><span id="Redshift-296"><a href="#Redshift-296"><span class="linenos">296</span></a> <span class="s2">"not"</span><span class="p">,</span> +</span><span id="Redshift-297"><a href="#Redshift-297"><span class="linenos">297</span></a> <span class="s2">"notnull"</span><span class="p">,</span> +</span><span id="Redshift-298"><a href="#Redshift-298"><span class="linenos">298</span></a> <span class="s2">"null"</span><span class="p">,</span> +</span><span id="Redshift-299"><a href="#Redshift-299"><span class="linenos">299</span></a> <span class="s2">"nulls"</span><span class="p">,</span> +</span><span id="Redshift-300"><a href="#Redshift-300"><span class="linenos">300</span></a> <span class="s2">"off"</span><span class="p">,</span> +</span><span id="Redshift-301"><a href="#Redshift-301"><span class="linenos">301</span></a> <span class="s2">"offline"</span><span class="p">,</span> +</span><span id="Redshift-302"><a href="#Redshift-302"><span class="linenos">302</span></a> <span class="s2">"offset"</span><span class="p">,</span> +</span><span id="Redshift-303"><a href="#Redshift-303"><span class="linenos">303</span></a> <span class="s2">"oid"</span><span class="p">,</span> +</span><span id="Redshift-304"><a href="#Redshift-304"><span class="linenos">304</span></a> <span class="s2">"old"</span><span class="p">,</span> +</span><span id="Redshift-305"><a href="#Redshift-305"><span class="linenos">305</span></a> <span class="s2">"on"</span><span class="p">,</span> +</span><span id="Redshift-306"><a href="#Redshift-306"><span class="linenos">306</span></a> <span class="s2">"only"</span><span class="p">,</span> +</span><span id="Redshift-307"><a href="#Redshift-307"><span class="linenos">307</span></a> <span class="s2">"open"</span><span class="p">,</span> +</span><span id="Redshift-308"><a href="#Redshift-308"><span class="linenos">308</span></a> <span class="s2">"or"</span><span class="p">,</span> +</span><span id="Redshift-309"><a href="#Redshift-309"><span class="linenos">309</span></a> <span class="s2">"order"</span><span class="p">,</span> +</span><span id="Redshift-310"><a href="#Redshift-310"><span class="linenos">310</span></a> <span class="s2">"outer"</span><span class="p">,</span> +</span><span id="Redshift-311"><a href="#Redshift-311"><span class="linenos">311</span></a> <span class="s2">"overlaps"</span><span class="p">,</span> +</span><span id="Redshift-312"><a href="#Redshift-312"><span class="linenos">312</span></a> <span class="s2">"parallel"</span><span class="p">,</span> +</span><span id="Redshift-313"><a href="#Redshift-313"><span class="linenos">313</span></a> <span class="s2">"partition"</span><span class="p">,</span> +</span><span id="Redshift-314"><a href="#Redshift-314"><span class="linenos">314</span></a> <span class="s2">"percent"</span><span class="p">,</span> +</span><span id="Redshift-315"><a href="#Redshift-315"><span class="linenos">315</span></a> <span class="s2">"permissions"</span><span class="p">,</span> +</span><span id="Redshift-316"><a href="#Redshift-316"><span class="linenos">316</span></a> <span class="s2">"pivot"</span><span class="p">,</span> +</span><span id="Redshift-317"><a href="#Redshift-317"><span class="linenos">317</span></a> <span class="s2">"placing"</span><span class="p">,</span> +</span><span id="Redshift-318"><a href="#Redshift-318"><span class="linenos">318</span></a> <span class="s2">"primary"</span><span class="p">,</span> +</span><span id="Redshift-319"><a href="#Redshift-319"><span class="linenos">319</span></a> <span class="s2">"raw"</span><span class="p">,</span> +</span><span id="Redshift-320"><a href="#Redshift-320"><span class="linenos">320</span></a> <span class="s2">"readratio"</span><span class="p">,</span> +</span><span id="Redshift-321"><a href="#Redshift-321"><span class="linenos">321</span></a> <span class="s2">"recover"</span><span class="p">,</span> +</span><span id="Redshift-322"><a href="#Redshift-322"><span class="linenos">322</span></a> <span class="s2">"references"</span><span class="p">,</span> +</span><span id="Redshift-323"><a href="#Redshift-323"><span class="linenos">323</span></a> <span class="s2">"rejectlog"</span><span class="p">,</span> +</span><span id="Redshift-324"><a href="#Redshift-324"><span class="linenos">324</span></a> <span class="s2">"resort"</span><span class="p">,</span> +</span><span id="Redshift-325"><a href="#Redshift-325"><span class="linenos">325</span></a> <span class="s2">"respect"</span><span class="p">,</span> +</span><span id="Redshift-326"><a href="#Redshift-326"><span class="linenos">326</span></a> <span class="s2">"restore"</span><span class="p">,</span> +</span><span id="Redshift-327"><a href="#Redshift-327"><span class="linenos">327</span></a> <span class="s2">"right"</span><span class="p">,</span> +</span><span id="Redshift-328"><a href="#Redshift-328"><span class="linenos">328</span></a> <span class="s2">"select"</span><span class="p">,</span> +</span><span id="Redshift-329"><a href="#Redshift-329"><span class="linenos">329</span></a> <span class="s2">"session_user"</span><span class="p">,</span> +</span><span id="Redshift-330"><a href="#Redshift-330"><span class="linenos">330</span></a> <span class="s2">"similar"</span><span class="p">,</span> +</span><span id="Redshift-331"><a href="#Redshift-331"><span class="linenos">331</span></a> <span class="s2">"snapshot"</span><span class="p">,</span> +</span><span id="Redshift-332"><a href="#Redshift-332"><span class="linenos">332</span></a> <span class="s2">"some"</span><span class="p">,</span> +</span><span id="Redshift-333"><a href="#Redshift-333"><span class="linenos">333</span></a> <span class="s2">"sysdate"</span><span class="p">,</span> +</span><span id="Redshift-334"><a href="#Redshift-334"><span class="linenos">334</span></a> <span class="s2">"system"</span><span class="p">,</span> +</span><span id="Redshift-335"><a href="#Redshift-335"><span class="linenos">335</span></a> <span class="s2">"table"</span><span class="p">,</span> +</span><span id="Redshift-336"><a href="#Redshift-336"><span class="linenos">336</span></a> <span class="s2">"tag"</span><span class="p">,</span> +</span><span id="Redshift-337"><a href="#Redshift-337"><span class="linenos">337</span></a> <span class="s2">"tdes"</span><span class="p">,</span> +</span><span id="Redshift-338"><a href="#Redshift-338"><span class="linenos">338</span></a> <span class="s2">"text255"</span><span class="p">,</span> +</span><span id="Redshift-339"><a href="#Redshift-339"><span class="linenos">339</span></a> <span class="s2">"text32k"</span><span class="p">,</span> +</span><span id="Redshift-340"><a href="#Redshift-340"><span class="linenos">340</span></a> <span class="s2">"then"</span><span class="p">,</span> +</span><span id="Redshift-341"><a href="#Redshift-341"><span class="linenos">341</span></a> <span class="s2">"timestamp"</span><span class="p">,</span> +</span><span id="Redshift-342"><a href="#Redshift-342"><span class="linenos">342</span></a> <span class="s2">"to"</span><span class="p">,</span> +</span><span id="Redshift-343"><a href="#Redshift-343"><span class="linenos">343</span></a> <span class="s2">"top"</span><span class="p">,</span> +</span><span id="Redshift-344"><a href="#Redshift-344"><span class="linenos">344</span></a> <span class="s2">"trailing"</span><span class="p">,</span> +</span><span id="Redshift-345"><a href="#Redshift-345"><span class="linenos">345</span></a> <span class="s2">"true"</span><span class="p">,</span> +</span><span id="Redshift-346"><a href="#Redshift-346"><span class="linenos">346</span></a> <span class="s2">"truncatecolumns"</span><span class="p">,</span> +</span><span id="Redshift-347"><a href="#Redshift-347"><span class="linenos">347</span></a> <span class="s2">"type"</span><span class="p">,</span> +</span><span id="Redshift-348"><a href="#Redshift-348"><span class="linenos">348</span></a> <span class="s2">"union"</span><span class="p">,</span> +</span><span id="Redshift-349"><a href="#Redshift-349"><span class="linenos">349</span></a> <span class="s2">"unique"</span><span class="p">,</span> +</span><span id="Redshift-350"><a href="#Redshift-350"><span class="linenos">350</span></a> <span class="s2">"unnest"</span><span class="p">,</span> +</span><span id="Redshift-351"><a href="#Redshift-351"><span class="linenos">351</span></a> <span class="s2">"unpivot"</span><span class="p">,</span> +</span><span id="Redshift-352"><a href="#Redshift-352"><span class="linenos">352</span></a> <span class="s2">"user"</span><span class="p">,</span> +</span><span id="Redshift-353"><a href="#Redshift-353"><span class="linenos">353</span></a> <span class="s2">"using"</span><span class="p">,</span> +</span><span id="Redshift-354"><a href="#Redshift-354"><span class="linenos">354</span></a> <span class="s2">"verbose"</span><span class="p">,</span> +</span><span id="Redshift-355"><a href="#Redshift-355"><span class="linenos">355</span></a> <span class="s2">"wallet"</span><span class="p">,</span> +</span><span id="Redshift-356"><a href="#Redshift-356"><span class="linenos">356</span></a> <span class="s2">"when"</span><span class="p">,</span> +</span><span id="Redshift-357"><a href="#Redshift-357"><span class="linenos">357</span></a> <span class="s2">"where"</span><span class="p">,</span> +</span><span id="Redshift-358"><a href="#Redshift-358"><span class="linenos">358</span></a> <span class="s2">"with"</span><span class="p">,</span> +</span><span id="Redshift-359"><a href="#Redshift-359"><span class="linenos">359</span></a> <span class="s2">"without"</span><span class="p">,</span> +</span><span id="Redshift-360"><a href="#Redshift-360"><span class="linenos">360</span></a> <span class="p">}</span> +</span><span id="Redshift-361"><a href="#Redshift-361"><span class="linenos">361</span></a> +</span><span id="Redshift-362"><a href="#Redshift-362"><span class="linenos">362</span></a> <span class="k">def</span> <span class="nf">unnest_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Unnest</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="Redshift-363"><a href="#Redshift-363"><span class="linenos">363</span></a> <span class="n">args</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">expressions</span> +</span><span id="Redshift-364"><a href="#Redshift-364"><span class="linenos">364</span></a> <span class="n">num_args</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> +</span><span id="Redshift-365"><a href="#Redshift-365"><span class="linenos">365</span></a> +</span><span id="Redshift-366"><a href="#Redshift-366"><span class="linenos">366</span></a> <span class="k">if</span> <span class="n">num_args</span> <span class="o">></span> <span class="mi">1</span><span class="p">:</span> +</span><span id="Redshift-367"><a href="#Redshift-367"><span class="linenos">367</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Unsupported number of arguments in UNNEST: </span><span class="si">{</span><span class="n">num_args</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> +</span><span id="Redshift-368"><a href="#Redshift-368"><span class="linenos">368</span></a> <span class="k">return</span> <span class="s2">""</span> +</span><span id="Redshift-369"><a href="#Redshift-369"><span class="linenos">369</span></a> +</span><span id="Redshift-370"><a href="#Redshift-370"><span class="linenos">370</span></a> <span class="n">arg</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span> +</span><span id="Redshift-371"><a href="#Redshift-371"><span class="linenos">371</span></a> <span class="n">alias</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">expressions</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"alias"</span><span class="p">),</span> <span class="n">key</span><span class="o">=</span><span class="s2">"columns"</span><span class="p">,</span> <span class="n">flat</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> +</span><span id="Redshift-372"><a href="#Redshift-372"><span class="linenos">372</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">arg</span><span class="si">}</span><span class="s2"> AS </span><span class="si">{</span><span class="n">alias</span><span class="si">}</span><span class="s2">"</span> <span class="k">if</span> <span class="n">alias</span> <span class="k">else</span> <span class="n">arg</span> +</span><span id="Redshift-373"><a href="#Redshift-373"><span class="linenos">373</span></a> +</span><span id="Redshift-374"><a href="#Redshift-374"><span class="linenos">374</span></a> <span class="k">def</span> <span class="nf">with_properties</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">properties</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Properties</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="Redshift-375"><a href="#Redshift-375"><span class="linenos">375</span></a><span class="w"> </span><span class="sd">"""Redshift doesn't have `WITH` as part of their with_properties so we remove it"""</span> +</span><span id="Redshift-376"><a href="#Redshift-376"><span class="linenos">376</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">properties</span><span class="p">(</span><span class="n">properties</span><span class="p">,</span> <span class="n">prefix</span><span class="o">=</span><span class="s2">" "</span><span class="p">,</span> <span class="n">suffix</span><span class="o">=</span><span class="s2">""</span><span class="p">)</span> +</span><span id="Redshift-377"><a href="#Redshift-377"><span class="linenos">377</span></a> +</span><span id="Redshift-378"><a href="#Redshift-378"><span class="linenos">378</span></a> <span class="k">def</span> <span class="nf">cast_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Cast</span><span class="p">,</span> <span class="n">safe_prefix</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="Redshift-379"><a href="#Redshift-379"><span class="linenos">379</span></a> <span class="k">if</span> <span class="n">expression</span><span class="o">.</span><span class="n">is_type</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">JSON</span><span class="p">):</span> +</span><span id="Redshift-380"><a href="#Redshift-380"><span class="linenos">380</span></a> <span class="c1"># Redshift doesn't support a JSON type, so casting to it is treated as a noop</span> +</span><span id="Redshift-381"><a href="#Redshift-381"><span class="linenos">381</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="s2">"this"</span><span class="p">)</span> +</span><span id="Redshift-382"><a href="#Redshift-382"><span class="linenos">382</span></a> +</span><span id="Redshift-383"><a href="#Redshift-383"><span class="linenos">383</span></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">cast_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="n">safe_prefix</span><span class="o">=</span><span class="n">safe_prefix</span><span class="p">)</span> +</span><span id="Redshift-384"><a href="#Redshift-384"><span class="linenos">384</span></a> +</span><span id="Redshift-385"><a href="#Redshift-385"><span class="linenos">385</span></a> <span class="k">def</span> <span class="nf">datatype_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="Redshift-386"><a href="#Redshift-386"><span class="linenos">386</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="Redshift-387"><a href="#Redshift-387"><span class="linenos">387</span></a><span class="sd"> Redshift converts the `TEXT` data type to `VARCHAR(255)` by default when people more generally mean</span> +</span><span id="Redshift-388"><a href="#Redshift-388"><span class="linenos">388</span></a><span class="sd"> VARCHAR of max length which is `VARCHAR(max)` in Redshift. Therefore if we get a `TEXT` data type</span> +</span><span id="Redshift-389"><a href="#Redshift-389"><span class="linenos">389</span></a><span class="sd"> without precision we convert it to `VARCHAR(max)` and if it does have precision then we just convert</span> +</span><span id="Redshift-390"><a href="#Redshift-390"><span class="linenos">390</span></a><span class="sd"> `TEXT` to `VARCHAR`.</span> +</span><span id="Redshift-391"><a href="#Redshift-391"><span class="linenos">391</span></a><span class="sd"> """</span> +</span><span id="Redshift-392"><a href="#Redshift-392"><span class="linenos">392</span></a> <span class="k">if</span> <span class="n">expression</span><span class="o">.</span><span class="n">is_type</span><span class="p">(</span><span class="s2">"text"</span><span class="p">):</span> +</span><span id="Redshift-393"><a href="#Redshift-393"><span class="linenos">393</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"this"</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">VARCHAR</span><span class="p">)</span> +</span><span id="Redshift-394"><a href="#Redshift-394"><span class="linenos">394</span></a> <span class="n">precision</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"expressions"</span><span class="p">)</span> +</span><span id="Redshift-395"><a href="#Redshift-395"><span class="linenos">395</span></a> +</span><span id="Redshift-396"><a href="#Redshift-396"><span class="linenos">396</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">precision</span><span class="p">:</span> +</span><span id="Redshift-397"><a href="#Redshift-397"><span class="linenos">397</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">"expressions"</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">var</span><span class="p">(</span><span class="s2">"MAX"</span><span class="p">))</span> +</span><span id="Redshift-398"><a href="#Redshift-398"><span class="linenos">398</span></a> +</span><span id="Redshift-399"><a href="#Redshift-399"><span class="linenos">399</span></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">datatype_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> </span></pre></div> @@ -1111,35 +1439,36 @@ </span><span id="Redshift.Parser-80"><a href="#Redshift.Parser-80"><span class="linenos"> 80</span></a> <span class="n">alias_tokens</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">Collection</span><span class="p">[</span><span class="n">TokenType</span><span class="p">]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> </span><span id="Redshift.Parser-81"><a href="#Redshift.Parser-81"><span class="linenos"> 81</span></a> <span class="n">parse_bracket</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span> </span><span id="Redshift.Parser-82"><a href="#Redshift.Parser-82"><span class="linenos"> 82</span></a> <span class="n">is_db_reference</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span> -</span><span id="Redshift.Parser-83"><a href="#Redshift.Parser-83"><span class="linenos"> 83</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">]:</span> -</span><span id="Redshift.Parser-84"><a href="#Redshift.Parser-84"><span class="linenos"> 84</span></a> <span class="c1"># Redshift supports UNPIVOTing SUPER objects, e.g. `UNPIVOT foo.obj[0] AS val AT attr`</span> -</span><span id="Redshift.Parser-85"><a href="#Redshift.Parser-85"><span class="linenos"> 85</span></a> <span class="n">unpivot</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_match</span><span class="p">(</span><span class="n">TokenType</span><span class="o">.</span><span class="n">UNPIVOT</span><span class="p">)</span> -</span><span id="Redshift.Parser-86"><a href="#Redshift.Parser-86"><span class="linenos"> 86</span></a> <span class="n">table</span> <span class="o">=</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">_parse_table</span><span class="p">(</span> -</span><span id="Redshift.Parser-87"><a href="#Redshift.Parser-87"><span class="linenos"> 87</span></a> <span class="n">schema</span><span class="o">=</span><span class="n">schema</span><span class="p">,</span> -</span><span id="Redshift.Parser-88"><a href="#Redshift.Parser-88"><span class="linenos"> 88</span></a> <span class="n">joins</span><span class="o">=</span><span class="n">joins</span><span class="p">,</span> -</span><span id="Redshift.Parser-89"><a href="#Redshift.Parser-89"><span class="linenos"> 89</span></a> <span class="n">alias_tokens</span><span class="o">=</span><span class="n">alias_tokens</span><span class="p">,</span> -</span><span id="Redshift.Parser-90"><a href="#Redshift.Parser-90"><span class="linenos"> 90</span></a> <span class="n">parse_bracket</span><span class="o">=</span><span class="n">parse_bracket</span><span class="p">,</span> -</span><span id="Redshift.Parser-91"><a href="#Redshift.Parser-91"><span class="linenos"> 91</span></a> <span class="n">is_db_reference</span><span class="o">=</span><span class="n">is_db_reference</span><span class="p">,</span> -</span><span id="Redshift.Parser-92"><a href="#Redshift.Parser-92"><span class="linenos"> 92</span></a> <span class="p">)</span> -</span><span id="Redshift.Parser-93"><a href="#Redshift.Parser-93"><span class="linenos"> 93</span></a> -</span><span id="Redshift.Parser-94"><a href="#Redshift.Parser-94"><span class="linenos"> 94</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Pivot</span><span class="p">,</span> <span class="n">this</span><span class="o">=</span><span class="n">table</span><span class="p">,</span> <span class="n">unpivot</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> <span class="k">if</span> <span class="n">unpivot</span> <span class="k">else</span> <span class="n">table</span> -</span><span id="Redshift.Parser-95"><a href="#Redshift.Parser-95"><span class="linenos"> 95</span></a> -</span><span id="Redshift.Parser-96"><a href="#Redshift.Parser-96"><span class="linenos"> 96</span></a> <span class="k">def</span> <span class="nf">_parse_convert</span><span class="p">(</span> -</span><span id="Redshift.Parser-97"><a href="#Redshift.Parser-97"><span class="linenos"> 97</span></a> <span class="bp">self</span><span class="p">,</span> <span class="n">strict</span><span class="p">:</span> <span class="nb">bool</span><span class="p">,</span> <span class="n">safe</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">bool</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span> -</span><span id="Redshift.Parser-98"><a href="#Redshift.Parser-98"><span class="linenos"> 98</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">]:</span> -</span><span id="Redshift.Parser-99"><a href="#Redshift.Parser-99"><span class="linenos"> 99</span></a> <span class="n">to</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_types</span><span class="p">()</span> -</span><span id="Redshift.Parser-100"><a href="#Redshift.Parser-100"><span class="linenos">100</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">_match</span><span class="p">(</span><span class="n">TokenType</span><span class="o">.</span><span class="n">COMMA</span><span class="p">)</span> -</span><span id="Redshift.Parser-101"><a href="#Redshift.Parser-101"><span class="linenos">101</span></a> <span class="n">this</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_bitwise</span><span class="p">()</span> -</span><span id="Redshift.Parser-102"><a href="#Redshift.Parser-102"><span class="linenos">102</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">TryCast</span><span class="p">,</span> <span class="n">this</span><span class="o">=</span><span class="n">this</span><span class="p">,</span> <span class="n">to</span><span class="o">=</span><span class="n">to</span><span class="p">,</span> <span class="n">safe</span><span class="o">=</span><span class="n">safe</span><span class="p">)</span> -</span><span id="Redshift.Parser-103"><a href="#Redshift.Parser-103"><span class="linenos">103</span></a> -</span><span id="Redshift.Parser-104"><a href="#Redshift.Parser-104"><span class="linenos">104</span></a> <span class="k">def</span> <span class="nf">_parse_approximate_count</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">exp</span><span class="o">.</span><span class="n">ApproxDistinct</span><span class="p">]:</span> -</span><span id="Redshift.Parser-105"><a href="#Redshift.Parser-105"><span class="linenos">105</span></a> <span class="n">index</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_index</span> <span class="o">-</span> <span class="mi">1</span> -</span><span id="Redshift.Parser-106"><a href="#Redshift.Parser-106"><span class="linenos">106</span></a> <span class="n">func</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_function</span><span class="p">()</span> -</span><span id="Redshift.Parser-107"><a href="#Redshift.Parser-107"><span class="linenos">107</span></a> -</span><span id="Redshift.Parser-108"><a href="#Redshift.Parser-108"><span class="linenos">108</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">func</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Count</span><span class="p">)</span> <span class="ow">and</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">func</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Distinct</span><span class="p">):</span> -</span><span id="Redshift.Parser-109"><a href="#Redshift.Parser-109"><span class="linenos">109</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">ApproxDistinct</span><span class="p">,</span> <span class="n">this</span><span class="o">=</span><span class="n">seq_get</span><span class="p">(</span><span class="n">func</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">expressions</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span> -</span><span id="Redshift.Parser-110"><a href="#Redshift.Parser-110"><span class="linenos">110</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">_retreat</span><span class="p">(</span><span class="n">index</span><span class="p">)</span> -</span><span id="Redshift.Parser-111"><a href="#Redshift.Parser-111"><span class="linenos">111</span></a> <span class="k">return</span> <span class="kc">None</span> +</span><span id="Redshift.Parser-83"><a href="#Redshift.Parser-83"><span class="linenos"> 83</span></a> <span class="n">parse_partition</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span> +</span><span id="Redshift.Parser-84"><a href="#Redshift.Parser-84"><span class="linenos"> 84</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">]:</span> +</span><span id="Redshift.Parser-85"><a href="#Redshift.Parser-85"><span class="linenos"> 85</span></a> <span class="c1"># Redshift supports UNPIVOTing SUPER objects, e.g. `UNPIVOT foo.obj[0] AS val AT attr`</span> +</span><span id="Redshift.Parser-86"><a href="#Redshift.Parser-86"><span class="linenos"> 86</span></a> <span class="n">unpivot</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_match</span><span class="p">(</span><span class="n">TokenType</span><span class="o">.</span><span class="n">UNPIVOT</span><span class="p">)</span> +</span><span id="Redshift.Parser-87"><a href="#Redshift.Parser-87"><span class="linenos"> 87</span></a> <span class="n">table</span> <span class="o">=</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">_parse_table</span><span class="p">(</span> +</span><span id="Redshift.Parser-88"><a href="#Redshift.Parser-88"><span class="linenos"> 88</span></a> <span class="n">schema</span><span class="o">=</span><span class="n">schema</span><span class="p">,</span> +</span><span id="Redshift.Parser-89"><a href="#Redshift.Parser-89"><span class="linenos"> 89</span></a> <span class="n">joins</span><span class="o">=</span><span class="n">joins</span><span class="p">,</span> +</span><span id="Redshift.Parser-90"><a href="#Redshift.Parser-90"><span class="linenos"> 90</span></a> <span class="n">alias_tokens</span><span class="o">=</span><span class="n">alias_tokens</span><span class="p">,</span> +</span><span id="Redshift.Parser-91"><a href="#Redshift.Parser-91"><span class="linenos"> 91</span></a> <span class="n">parse_bracket</span><span class="o">=</span><span class="n">parse_bracket</span><span class="p">,</span> +</span><span id="Redshift.Parser-92"><a href="#Redshift.Parser-92"><span class="linenos"> 92</span></a> <span class="n">is_db_reference</span><span class="o">=</span><span class="n">is_db_reference</span><span class="p">,</span> +</span><span id="Redshift.Parser-93"><a href="#Redshift.Parser-93"><span class="linenos"> 93</span></a> <span class="p">)</span> +</span><span id="Redshift.Parser-94"><a href="#Redshift.Parser-94"><span class="linenos"> 94</span></a> +</span><span id="Redshift.Parser-95"><a href="#Redshift.Parser-95"><span class="linenos"> 95</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Pivot</span><span class="p">,</span> <span class="n">this</span><span class="o">=</span><span class="n">table</span><span class="p">,</span> <span class="n">unpivot</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> <span class="k">if</span> <span class="n">unpivot</span> <span class="k">else</span> <span class="n">table</span> +</span><span id="Redshift.Parser-96"><a href="#Redshift.Parser-96"><span class="linenos"> 96</span></a> +</span><span id="Redshift.Parser-97"><a href="#Redshift.Parser-97"><span class="linenos"> 97</span></a> <span class="k">def</span> <span class="nf">_parse_convert</span><span class="p">(</span> +</span><span id="Redshift.Parser-98"><a href="#Redshift.Parser-98"><span class="linenos"> 98</span></a> <span class="bp">self</span><span class="p">,</span> <span class="n">strict</span><span class="p">:</span> <span class="nb">bool</span><span class="p">,</span> <span class="n">safe</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">bool</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span> +</span><span id="Redshift.Parser-99"><a href="#Redshift.Parser-99"><span class="linenos"> 99</span></a> <span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">exp</span><span class="o">.</span><span class="n">Expression</span><span class="p">]:</span> +</span><span id="Redshift.Parser-100"><a href="#Redshift.Parser-100"><span class="linenos">100</span></a> <span class="n">to</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_types</span><span class="p">()</span> +</span><span id="Redshift.Parser-101"><a href="#Redshift.Parser-101"><span class="linenos">101</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">_match</span><span class="p">(</span><span class="n">TokenType</span><span class="o">.</span><span class="n">COMMA</span><span class="p">)</span> +</span><span id="Redshift.Parser-102"><a href="#Redshift.Parser-102"><span class="linenos">102</span></a> <span class="n">this</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_bitwise</span><span class="p">()</span> +</span><span id="Redshift.Parser-103"><a href="#Redshift.Parser-103"><span class="linenos">103</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">TryCast</span><span class="p">,</span> <span class="n">this</span><span class="o">=</span><span class="n">this</span><span class="p">,</span> <span class="n">to</span><span class="o">=</span><span class="n">to</span><span class="p">,</span> <span class="n">safe</span><span class="o">=</span><span class="n">safe</span><span class="p">)</span> +</span><span id="Redshift.Parser-104"><a href="#Redshift.Parser-104"><span class="linenos">104</span></a> +</span><span id="Redshift.Parser-105"><a href="#Redshift.Parser-105"><span class="linenos">105</span></a> <span class="k">def</span> <span class="nf">_parse_approximate_count</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">exp</span><span class="o">.</span><span class="n">ApproxDistinct</span><span class="p">]:</span> +</span><span id="Redshift.Parser-106"><a href="#Redshift.Parser-106"><span class="linenos">106</span></a> <span class="n">index</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_index</span> <span class="o">-</span> <span class="mi">1</span> +</span><span id="Redshift.Parser-107"><a href="#Redshift.Parser-107"><span class="linenos">107</span></a> <span class="n">func</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_parse_function</span><span class="p">()</span> +</span><span id="Redshift.Parser-108"><a href="#Redshift.Parser-108"><span class="linenos">108</span></a> +</span><span id="Redshift.Parser-109"><a href="#Redshift.Parser-109"><span class="linenos">109</span></a> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">func</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Count</span><span class="p">)</span> <span class="ow">and</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">func</span><span class="o">.</span><span class="n">this</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">Distinct</span><span class="p">):</span> +</span><span id="Redshift.Parser-110"><a href="#Redshift.Parser-110"><span class="linenos">110</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">expression</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">ApproxDistinct</span><span class="p">,</span> <span class="n">this</span><span class="o">=</span><span class="n">seq_get</span><span class="p">(</span><span class="n">func</span><span class="o">.</span><span class="n">this</span><span class="o">.</span><span class="n">expressions</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span> +</span><span id="Redshift.Parser-111"><a href="#Redshift.Parser-111"><span class="linenos">111</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">_retreat</span><span class="p">(</span><span class="n">index</span><span class="p">)</span> +</span><span id="Redshift.Parser-112"><a href="#Redshift.Parser-112"><span class="linenos">112</span></a> <span class="k">return</span> <span class="kc">None</span> </span></pre></div> @@ -1315,6 +1644,7 @@ Default: 3</li> <dd id="Redshift.Parser.NO_PAREN_IF_COMMANDS" class="variable"><a href="../parser.html#Parser.NO_PAREN_IF_COMMANDS">NO_PAREN_IF_COMMANDS</a></dd> <dd id="Redshift.Parser.VALUES_FOLLOWED_BY_PAREN" class="variable"><a href="../parser.html#Parser.VALUES_FOLLOWED_BY_PAREN">VALUES_FOLLOWED_BY_PAREN</a></dd> <dd id="Redshift.Parser.INTERVAL_SPANS" class="variable"><a href="../parser.html#Parser.INTERVAL_SPANS">INTERVAL_SPANS</a></dd> + <dd id="Redshift.Parser.SUPPORTS_PARTITION_SELECTION" class="variable"><a href="../parser.html#Parser.SUPPORTS_PARTITION_SELECTION">SUPPORTS_PARTITION_SELECTION</a></dd> <dd id="Redshift.Parser.error_level" class="variable"><a href="../parser.html#Parser.error_level">error_level</a></dd> <dd id="Redshift.Parser.error_message_context" class="variable"><a href="../parser.html#Parser.error_message_context">error_message_context</a></dd> <dd id="Redshift.Parser.max_errors" class="variable"><a href="../parser.html#Parser.max_errors">max_errors</a></dd> @@ -1355,24 +1685,24 @@ Default: 3</li> </div> <a class="headerlink" href="#Redshift.Tokenizer"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="Redshift.Tokenizer-113"><a href="#Redshift.Tokenizer-113"><span class="linenos">113</span></a> <span class="k">class</span> <span class="nc">Tokenizer</span><span class="p">(</span><span class="n">Postgres</span><span class="o">.</span><span class="n">Tokenizer</span><span class="p">):</span> -</span><span id="Redshift.Tokenizer-114"><a href="#Redshift.Tokenizer-114"><span class="linenos">114</span></a> <span class="n">BIT_STRINGS</span> <span class="o">=</span> <span class="p">[]</span> -</span><span id="Redshift.Tokenizer-115"><a href="#Redshift.Tokenizer-115"><span class="linenos">115</span></a> <span class="n">HEX_STRINGS</span> <span class="o">=</span> <span class="p">[]</span> -</span><span id="Redshift.Tokenizer-116"><a href="#Redshift.Tokenizer-116"><span class="linenos">116</span></a> <span class="n">STRING_ESCAPES</span> <span class="o">=</span> <span class="p">[</span><span class="s2">"</span><span class="se">\\</span><span class="s2">"</span><span class="p">,</span> <span class="s2">"'"</span><span class="p">]</span> -</span><span id="Redshift.Tokenizer-117"><a href="#Redshift.Tokenizer-117"><span class="linenos">117</span></a> -</span><span id="Redshift.Tokenizer-118"><a href="#Redshift.Tokenizer-118"><span class="linenos">118</span></a> <span class="n">KEYWORDS</span> <span class="o">=</span> <span class="p">{</span> -</span><span id="Redshift.Tokenizer-119"><a href="#Redshift.Tokenizer-119"><span class="linenos">119</span></a> <span class="o">**</span><span class="n">Postgres</span><span class="o">.</span><span class="n">Tokenizer</span><span class="o">.</span><span class="n">KEYWORDS</span><span class="p">,</span> -</span><span id="Redshift.Tokenizer-120"><a href="#Redshift.Tokenizer-120"><span class="linenos">120</span></a> <span class="s2">"HLLSKETCH"</span><span class="p">:</span> <span class="n">TokenType</span><span class="o">.</span><span class="n">HLLSKETCH</span><span class="p">,</span> -</span><span id="Redshift.Tokenizer-121"><a href="#Redshift.Tokenizer-121"><span class="linenos">121</span></a> <span class="s2">"SUPER"</span><span class="p">:</span> <span class="n">TokenType</span><span class="o">.</span><span class="n">SUPER</span><span class="p">,</span> -</span><span id="Redshift.Tokenizer-122"><a href="#Redshift.Tokenizer-122"><span class="linenos">122</span></a> <span class="s2">"TOP"</span><span class="p">:</span> <span class="n">TokenType</span><span class="o">.</span><span class="n">TOP</span><span class="p">,</span> -</span><span id="Redshift.Tokenizer-123"><a href="#Redshift.Tokenizer-123"><span class="linenos">123</span></a> <span class="s2">"UNLOAD"</span><span class="p">:</span> <span class="n">TokenType</span><span class="o">.</span><span class="n">COMMAND</span><span class="p">,</span> -</span><span id="Redshift.Tokenizer-124"><a href="#Redshift.Tokenizer-124"><span class="linenos">124</span></a> <span class="s2">"VARBYTE"</span><span class="p">:</span> <span class="n">TokenType</span><span class="o">.</span><span class="n">VARBINARY</span><span class="p">,</span> -</span><span id="Redshift.Tokenizer-125"><a href="#Redshift.Tokenizer-125"><span class="linenos">125</span></a> <span class="p">}</span> -</span><span id="Redshift.Tokenizer-126"><a href="#Redshift.Tokenizer-126"><span class="linenos">126</span></a> <span class="n">KEYWORDS</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s2">"VALUES"</span><span class="p">)</span> -</span><span id="Redshift.Tokenizer-127"><a href="#Redshift.Tokenizer-127"><span class="linenos">127</span></a> -</span><span id="Redshift.Tokenizer-128"><a href="#Redshift.Tokenizer-128"><span class="linenos">128</span></a> <span class="c1"># Redshift allows # to appear as a table identifier prefix</span> -</span><span id="Redshift.Tokenizer-129"><a href="#Redshift.Tokenizer-129"><span class="linenos">129</span></a> <span class="n">SINGLE_TOKENS</span> <span class="o">=</span> <span class="n">Postgres</span><span class="o">.</span><span class="n">Tokenizer</span><span class="o">.</span><span class="n">SINGLE_TOKENS</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> -</span><span id="Redshift.Tokenizer-130"><a href="#Redshift.Tokenizer-130"><span class="linenos">130</span></a> <span class="n">SINGLE_TOKENS</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s2">"#"</span><span class="p">)</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="Redshift.Tokenizer-114"><a href="#Redshift.Tokenizer-114"><span class="linenos">114</span></a> <span class="k">class</span> <span class="nc">Tokenizer</span><span class="p">(</span><span class="n">Postgres</span><span class="o">.</span><span class="n">Tokenizer</span><span class="p">):</span> +</span><span id="Redshift.Tokenizer-115"><a href="#Redshift.Tokenizer-115"><span class="linenos">115</span></a> <span class="n">BIT_STRINGS</span> <span class="o">=</span> <span class="p">[]</span> +</span><span id="Redshift.Tokenizer-116"><a href="#Redshift.Tokenizer-116"><span class="linenos">116</span></a> <span class="n">HEX_STRINGS</span> <span class="o">=</span> <span class="p">[]</span> +</span><span id="Redshift.Tokenizer-117"><a href="#Redshift.Tokenizer-117"><span class="linenos">117</span></a> <span class="n">STRING_ESCAPES</span> <span class="o">=</span> <span class="p">[</span><span class="s2">"</span><span class="se">\\</span><span class="s2">"</span><span class="p">,</span> <span class="s2">"'"</span><span class="p">]</span> +</span><span id="Redshift.Tokenizer-118"><a href="#Redshift.Tokenizer-118"><span class="linenos">118</span></a> +</span><span id="Redshift.Tokenizer-119"><a href="#Redshift.Tokenizer-119"><span class="linenos">119</span></a> <span class="n">KEYWORDS</span> <span class="o">=</span> <span class="p">{</span> +</span><span id="Redshift.Tokenizer-120"><a href="#Redshift.Tokenizer-120"><span class="linenos">120</span></a> <span class="o">**</span><span class="n">Postgres</span><span class="o">.</span><span class="n">Tokenizer</span><span class="o">.</span><span class="n">KEYWORDS</span><span class="p">,</span> +</span><span id="Redshift.Tokenizer-121"><a href="#Redshift.Tokenizer-121"><span class="linenos">121</span></a> <span class="s2">"HLLSKETCH"</span><span class="p">:</span> <span class="n">TokenType</span><span class="o">.</span><span class="n">HLLSKETCH</span><span class="p">,</span> +</span><span id="Redshift.Tokenizer-122"><a href="#Redshift.Tokenizer-122"><span class="linenos">122</span></a> <span class="s2">"SUPER"</span><span class="p">:</span> <span class="n">TokenType</span><span class="o">.</span><span class="n">SUPER</span><span class="p">,</span> +</span><span id="Redshift.Tokenizer-123"><a href="#Redshift.Tokenizer-123"><span class="linenos">123</span></a> <span class="s2">"TOP"</span><span class="p">:</span> <span class="n">TokenType</span><span class="o">.</span><span class="n">TOP</span><span class="p">,</span> +</span><span id="Redshift.Tokenizer-124"><a href="#Redshift.Tokenizer-124"><span class="linenos">124</span></a> <span class="s2">"UNLOAD"</span><span class="p">:</span> <span class="n">TokenType</span><span class="o">.</span><span class="n">COMMAND</span><span class="p">,</span> +</span><span id="Redshift.Tokenizer-125"><a href="#Redshift.Tokenizer-125"><span class="linenos">125</span></a> <span class="s2">"VARBYTE"</span><span class="p">:</span> <span class="n">TokenType</span><span class="o">.</span><span class="n">VARBINARY</span><span class="p">,</span> +</span><span id="Redshift.Tokenizer-126"><a href="#Redshift.Tokenizer-126"><span class="linenos">126</span></a> <span class="p">}</span> +</span><span id="Redshift.Tokenizer-127"><a href="#Redshift.Tokenizer-127"><span class="linenos">127</span></a> <span class="n">KEYWORDS</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s2">"VALUES"</span><span class="p">)</span> +</span><span id="Redshift.Tokenizer-128"><a href="#Redshift.Tokenizer-128"><span class="linenos">128</span></a> +</span><span id="Redshift.Tokenizer-129"><a href="#Redshift.Tokenizer-129"><span class="linenos">129</span></a> <span class="c1"># Redshift allows # to appear as a table identifier prefix</span> +</span><span id="Redshift.Tokenizer-130"><a href="#Redshift.Tokenizer-130"><span class="linenos">130</span></a> <span class="n">SINGLE_TOKENS</span> <span class="o">=</span> <span class="n">Postgres</span><span class="o">.</span><span class="n">Tokenizer</span><span class="o">.</span><span class="n">SINGLE_TOKENS</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> +</span><span id="Redshift.Tokenizer-131"><a href="#Redshift.Tokenizer-131"><span class="linenos">131</span></a> <span class="n">SINGLE_TOKENS</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s2">"#"</span><span class="p">)</span> </span></pre></div> @@ -1486,110 +1816,273 @@ Default: 3</li> </div> <a class="headerlink" href="#Redshift.Generator"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="Redshift.Generator-132"><a href="#Redshift.Generator-132"><span class="linenos">132</span></a> <span class="k">class</span> <span class="nc">Generator</span><span class="p">(</span><span class="n">Postgres</span><span class="o">.</span><span class="n">Generator</span><span class="p">):</span> -</span><span id="Redshift.Generator-133"><a href="#Redshift.Generator-133"><span class="linenos">133</span></a> <span class="n">LOCKING_READS_SUPPORTED</span> <span class="o">=</span> <span class="kc">False</span> -</span><span id="Redshift.Generator-134"><a href="#Redshift.Generator-134"><span class="linenos">134</span></a> <span class="n">QUERY_HINTS</span> <span class="o">=</span> <span class="kc">False</span> -</span><span id="Redshift.Generator-135"><a href="#Redshift.Generator-135"><span class="linenos">135</span></a> <span class="n">VALUES_AS_TABLE</span> <span class="o">=</span> <span class="kc">False</span> -</span><span id="Redshift.Generator-136"><a href="#Redshift.Generator-136"><span class="linenos">136</span></a> <span class="n">TZ_TO_WITH_TIME_ZONE</span> <span class="o">=</span> <span class="kc">True</span> -</span><span id="Redshift.Generator-137"><a href="#Redshift.Generator-137"><span class="linenos">137</span></a> <span class="n">NVL2_SUPPORTED</span> <span class="o">=</span> <span class="kc">True</span> -</span><span id="Redshift.Generator-138"><a href="#Redshift.Generator-138"><span class="linenos">138</span></a> <span class="n">LAST_DAY_SUPPORTS_DATE_PART</span> <span class="o">=</span> <span class="kc">False</span> -</span><span id="Redshift.Generator-139"><a href="#Redshift.Generator-139"><span class="linenos">139</span></a> <span class="n">CAN_IMPLEMENT_ARRAY_ANY</span> <span class="o">=</span> <span class="kc">False</span> -</span><span id="Redshift.Generator-140"><a href="#Redshift.Generator-140"><span class="linenos">140</span></a> <span class="n">MULTI_ARG_DISTINCT</span> <span class="o">=</span> <span class="kc">True</span> -</span><span id="Redshift.Generator-141"><a href="#Redshift.Generator-141"><span class="linenos">141</span></a> -</span><span id="Redshift.Generator-142"><a href="#Redshift.Generator-142"><span class="linenos">142</span></a> <span class="n">TYPE_MAPPING</span> <span class="o">=</span> <span class="p">{</span> -</span><span id="Redshift.Generator-143"><a href="#Redshift.Generator-143"><span class="linenos">143</span></a> <span class="o">**</span><span class="n">Postgres</span><span class="o">.</span><span class="n">Generator</span><span class="o">.</span><span class="n">TYPE_MAPPING</span><span class="p">,</span> -</span><span id="Redshift.Generator-144"><a href="#Redshift.Generator-144"><span class="linenos">144</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">BINARY</span><span class="p">:</span> <span class="s2">"VARBYTE"</span><span class="p">,</span> -</span><span id="Redshift.Generator-145"><a href="#Redshift.Generator-145"><span class="linenos">145</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">INT</span><span class="p">:</span> <span class="s2">"INTEGER"</span><span class="p">,</span> -</span><span id="Redshift.Generator-146"><a href="#Redshift.Generator-146"><span class="linenos">146</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">TIMETZ</span><span class="p">:</span> <span class="s2">"TIME"</span><span class="p">,</span> -</span><span id="Redshift.Generator-147"><a href="#Redshift.Generator-147"><span class="linenos">147</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">TIMESTAMPTZ</span><span class="p">:</span> <span class="s2">"TIMESTAMP"</span><span class="p">,</span> -</span><span id="Redshift.Generator-148"><a href="#Redshift.Generator-148"><span class="linenos">148</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">VARBINARY</span><span class="p">:</span> <span class="s2">"VARBYTE"</span><span class="p">,</span> -</span><span id="Redshift.Generator-149"><a href="#Redshift.Generator-149"><span class="linenos">149</span></a> <span class="p">}</span> -</span><span id="Redshift.Generator-150"><a href="#Redshift.Generator-150"><span class="linenos">150</span></a> -</span><span id="Redshift.Generator-151"><a href="#Redshift.Generator-151"><span class="linenos">151</span></a> <span class="n">TRANSFORMS</span> <span class="o">=</span> <span class="p">{</span> -</span><span id="Redshift.Generator-152"><a href="#Redshift.Generator-152"><span class="linenos">152</span></a> <span class="o">**</span><span class="n">Postgres</span><span class="o">.</span><span class="n">Generator</span><span class="o">.</span><span class="n">TRANSFORMS</span><span class="p">,</span> -</span><span id="Redshift.Generator-153"><a href="#Redshift.Generator-153"><span class="linenos">153</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Concat</span><span class="p">:</span> <span class="n">concat_to_dpipe_sql</span><span class="p">,</span> -</span><span id="Redshift.Generator-154"><a href="#Redshift.Generator-154"><span class="linenos">154</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">ConcatWs</span><span class="p">:</span> <span class="n">concat_ws_to_dpipe_sql</span><span class="p">,</span> -</span><span id="Redshift.Generator-155"><a href="#Redshift.Generator-155"><span class="linenos">155</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">ApproxDistinct</span><span class="p">:</span> <span class="k">lambda</span> <span class="bp">self</span><span class="p">,</span> -</span><span id="Redshift.Generator-156"><a href="#Redshift.Generator-156"><span class="linenos">156</span></a> <span class="n">e</span><span class="p">:</span> <span class="sa">f</span><span class="s2">"APPROXIMATE COUNT(DISTINCT </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="p">,</span><span class="w"> </span><span class="s1">'this'</span><span class="p">)</span><span class="si">}</span><span class="s2">)"</span><span class="p">,</span> -</span><span id="Redshift.Generator-157"><a href="#Redshift.Generator-157"><span class="linenos">157</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">CurrentTimestamp</span><span class="p">:</span> <span class="k">lambda</span> <span class="bp">self</span><span class="p">,</span> <span class="n">e</span><span class="p">:</span> <span class="p">(</span> -</span><span id="Redshift.Generator-158"><a href="#Redshift.Generator-158"><span class="linenos">158</span></a> <span class="s2">"SYSDATE"</span> <span class="k">if</span> <span class="n">e</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"transaction"</span><span class="p">)</span> <span class="k">else</span> <span class="s2">"GETDATE()"</span> -</span><span id="Redshift.Generator-159"><a href="#Redshift.Generator-159"><span class="linenos">159</span></a> <span class="p">),</span> -</span><span id="Redshift.Generator-160"><a href="#Redshift.Generator-160"><span class="linenos">160</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DateAdd</span><span class="p">:</span> <span class="n">date_delta_sql</span><span class="p">(</span><span class="s2">"DATEADD"</span><span class="p">),</span> -</span><span id="Redshift.Generator-161"><a href="#Redshift.Generator-161"><span class="linenos">161</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DateDiff</span><span class="p">:</span> <span class="n">date_delta_sql</span><span class="p">(</span><span class="s2">"DATEDIFF"</span><span class="p">),</span> -</span><span id="Redshift.Generator-162"><a href="#Redshift.Generator-162"><span class="linenos">162</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DistKeyProperty</span><span class="p">:</span> <span class="k">lambda</span> <span class="bp">self</span><span class="p">,</span> <span class="n">e</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="s2">"DISTKEY"</span><span class="p">,</span> <span class="n">e</span><span class="o">.</span><span class="n">this</span><span class="p">),</span> -</span><span id="Redshift.Generator-163"><a href="#Redshift.Generator-163"><span class="linenos">163</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DistStyleProperty</span><span class="p">:</span> <span class="k">lambda</span> <span class="bp">self</span><span class="p">,</span> <span class="n">e</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">naked_property</span><span class="p">(</span><span class="n">e</span><span class="p">),</span> -</span><span id="Redshift.Generator-164"><a href="#Redshift.Generator-164"><span class="linenos">164</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">FromBase</span><span class="p">:</span> <span class="n">rename_func</span><span class="p">(</span><span class="s2">"STRTOL"</span><span class="p">),</span> -</span><span id="Redshift.Generator-165"><a href="#Redshift.Generator-165"><span class="linenos">165</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">GeneratedAsIdentityColumnConstraint</span><span class="p">:</span> <span class="n">generatedasidentitycolumnconstraint_sql</span><span class="p">,</span> -</span><span id="Redshift.Generator-166"><a href="#Redshift.Generator-166"><span class="linenos">166</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">JSONExtract</span><span class="p">:</span> <span class="n">json_extract_segments</span><span class="p">(</span><span class="s2">"JSON_EXTRACT_PATH_TEXT"</span><span class="p">),</span> -</span><span id="Redshift.Generator-167"><a href="#Redshift.Generator-167"><span class="linenos">167</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">JSONExtractScalar</span><span class="p">:</span> <span class="n">json_extract_segments</span><span class="p">(</span><span class="s2">"JSON_EXTRACT_PATH_TEXT"</span><span class="p">),</span> -</span><span id="Redshift.Generator-168"><a href="#Redshift.Generator-168"><span class="linenos">168</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">GroupConcat</span><span class="p">:</span> <span class="n">rename_func</span><span class="p">(</span><span class="s2">"LISTAGG"</span><span class="p">),</span> -</span><span id="Redshift.Generator-169"><a href="#Redshift.Generator-169"><span class="linenos">169</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">ParseJSON</span><span class="p">:</span> <span class="n">rename_func</span><span class="p">(</span><span class="s2">"JSON_PARSE"</span><span class="p">),</span> -</span><span id="Redshift.Generator-170"><a href="#Redshift.Generator-170"><span class="linenos">170</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Select</span><span class="p">:</span> <span class="n">transforms</span><span class="o">.</span><span class="n">preprocess</span><span class="p">(</span> -</span><span id="Redshift.Generator-171"><a href="#Redshift.Generator-171"><span class="linenos">171</span></a> <span class="p">[</span><span class="n">transforms</span><span class="o">.</span><span class="n">eliminate_distinct_on</span><span class="p">,</span> <span class="n">transforms</span><span class="o">.</span><span class="n">eliminate_semi_and_anti_joins</span><span class="p">]</span> -</span><span id="Redshift.Generator-172"><a href="#Redshift.Generator-172"><span class="linenos">172</span></a> <span class="p">),</span> -</span><span id="Redshift.Generator-173"><a href="#Redshift.Generator-173"><span class="linenos">173</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">SortKeyProperty</span><span class="p">:</span> <span class="k">lambda</span> <span class="bp">self</span><span class="p">,</span> -</span><span id="Redshift.Generator-174"><a href="#Redshift.Generator-174"><span class="linenos">174</span></a> <span class="n">e</span><span class="p">:</span> <span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="s1">'COMPOUND '</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">e</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s1">'compound'</span><span class="p">]</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="s1">''</span><span class="si">}</span><span class="s2">SORTKEY(</span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">format_args</span><span class="p">(</span><span class="o">*</span><span class="n">e</span><span class="o">.</span><span class="n">this</span><span class="p">)</span><span class="si">}</span><span class="s2">)"</span><span class="p">,</span> -</span><span id="Redshift.Generator-175"><a href="#Redshift.Generator-175"><span class="linenos">175</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">StartsWith</span><span class="p">:</span> <span class="k">lambda</span> <span class="bp">self</span><span class="p">,</span> -</span><span id="Redshift.Generator-176"><a href="#Redshift.Generator-176"><span class="linenos">176</span></a> <span class="n">e</span><span class="p">:</span> <span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">this</span><span class="p">)</span><span class="si">}</span><span class="s2"> LIKE </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">expression</span><span class="p">)</span><span class="si">}</span><span class="s2"> || '%'"</span><span class="p">,</span> -</span><span id="Redshift.Generator-177"><a href="#Redshift.Generator-177"><span class="linenos">177</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">TableSample</span><span class="p">:</span> <span class="n">no_tablesample_sql</span><span class="p">,</span> -</span><span id="Redshift.Generator-178"><a href="#Redshift.Generator-178"><span class="linenos">178</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">TsOrDsAdd</span><span class="p">:</span> <span class="n">date_delta_sql</span><span class="p">(</span><span class="s2">"DATEADD"</span><span class="p">),</span> -</span><span id="Redshift.Generator-179"><a href="#Redshift.Generator-179"><span class="linenos">179</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">TsOrDsDiff</span><span class="p">:</span> <span class="n">date_delta_sql</span><span class="p">(</span><span class="s2">"DATEDIFF"</span><span class="p">),</span> -</span><span id="Redshift.Generator-180"><a href="#Redshift.Generator-180"><span class="linenos">180</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">UnixToTime</span><span class="p">:</span> <span class="k">lambda</span> <span class="bp">self</span><span class="p">,</span> -</span><span id="Redshift.Generator-181"><a href="#Redshift.Generator-181"><span class="linenos">181</span></a> <span class="n">e</span><span class="p">:</span> <span class="sa">f</span><span class="s2">"(TIMESTAMP 'epoch' + </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">this</span><span class="p">)</span><span class="si">}</span><span class="s2"> * INTERVAL '1 SECOND')"</span><span class="p">,</span> -</span><span id="Redshift.Generator-182"><a href="#Redshift.Generator-182"><span class="linenos">182</span></a> <span class="p">}</span> -</span><span id="Redshift.Generator-183"><a href="#Redshift.Generator-183"><span class="linenos">183</span></a> -</span><span id="Redshift.Generator-184"><a href="#Redshift.Generator-184"><span class="linenos">184</span></a> <span class="c1"># Postgres maps exp.Pivot to no_pivot_sql, but Redshift support pivots</span> -</span><span id="Redshift.Generator-185"><a href="#Redshift.Generator-185"><span class="linenos">185</span></a> <span class="n">TRANSFORMS</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Pivot</span><span class="p">)</span> -</span><span id="Redshift.Generator-186"><a href="#Redshift.Generator-186"><span class="linenos">186</span></a> -</span><span id="Redshift.Generator-187"><a href="#Redshift.Generator-187"><span class="linenos">187</span></a> <span class="c1"># Redshift uses the POW | POWER (expr1, expr2) syntax instead of expr1 ^ expr2 (postgres)</span> -</span><span id="Redshift.Generator-188"><a href="#Redshift.Generator-188"><span class="linenos">188</span></a> <span class="n">TRANSFORMS</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Pow</span><span class="p">)</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="Redshift.Generator-133"><a href="#Redshift.Generator-133"><span class="linenos">133</span></a> <span class="k">class</span> <span class="nc">Generator</span><span class="p">(</span><span class="n">Postgres</span><span class="o">.</span><span class="n">Generator</span><span class="p">):</span> +</span><span id="Redshift.Generator-134"><a href="#Redshift.Generator-134"><span class="linenos">134</span></a> <span class="n">LOCKING_READS_SUPPORTED</span> <span class="o">=</span> <span class="kc">False</span> +</span><span id="Redshift.Generator-135"><a href="#Redshift.Generator-135"><span class="linenos">135</span></a> <span class="n">QUERY_HINTS</span> <span class="o">=</span> <span class="kc">False</span> +</span><span id="Redshift.Generator-136"><a href="#Redshift.Generator-136"><span class="linenos">136</span></a> <span class="n">VALUES_AS_TABLE</span> <span class="o">=</span> <span class="kc">False</span> +</span><span id="Redshift.Generator-137"><a href="#Redshift.Generator-137"><span class="linenos">137</span></a> <span class="n">TZ_TO_WITH_TIME_ZONE</span> <span class="o">=</span> <span class="kc">True</span> +</span><span id="Redshift.Generator-138"><a href="#Redshift.Generator-138"><span class="linenos">138</span></a> <span class="n">NVL2_SUPPORTED</span> <span class="o">=</span> <span class="kc">True</span> +</span><span id="Redshift.Generator-139"><a href="#Redshift.Generator-139"><span class="linenos">139</span></a> <span class="n">LAST_DAY_SUPPORTS_DATE_PART</span> <span class="o">=</span> <span class="kc">False</span> +</span><span id="Redshift.Generator-140"><a href="#Redshift.Generator-140"><span class="linenos">140</span></a> <span class="n">CAN_IMPLEMENT_ARRAY_ANY</span> <span class="o">=</span> <span class="kc">False</span> +</span><span id="Redshift.Generator-141"><a href="#Redshift.Generator-141"><span class="linenos">141</span></a> <span class="n">MULTI_ARG_DISTINCT</span> <span class="o">=</span> <span class="kc">True</span> +</span><span id="Redshift.Generator-142"><a href="#Redshift.Generator-142"><span class="linenos">142</span></a> +</span><span id="Redshift.Generator-143"><a href="#Redshift.Generator-143"><span class="linenos">143</span></a> <span class="n">TYPE_MAPPING</span> <span class="o">=</span> <span class="p">{</span> +</span><span id="Redshift.Generator-144"><a href="#Redshift.Generator-144"><span class="linenos">144</span></a> <span class="o">**</span><span class="n">Postgres</span><span class="o">.</span><span class="n">Generator</span><span class="o">.</span><span class="n">TYPE_MAPPING</span><span class="p">,</span> +</span><span id="Redshift.Generator-145"><a href="#Redshift.Generator-145"><span class="linenos">145</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">BINARY</span><span class="p">:</span> <span class="s2">"VARBYTE"</span><span class="p">,</span> +</span><span id="Redshift.Generator-146"><a href="#Redshift.Generator-146"><span class="linenos">146</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">INT</span><span class="p">:</span> <span class="s2">"INTEGER"</span><span class="p">,</span> +</span><span id="Redshift.Generator-147"><a href="#Redshift.Generator-147"><span class="linenos">147</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">TIMETZ</span><span class="p">:</span> <span class="s2">"TIME"</span><span class="p">,</span> +</span><span id="Redshift.Generator-148"><a href="#Redshift.Generator-148"><span class="linenos">148</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">TIMESTAMPTZ</span><span class="p">:</span> <span class="s2">"TIMESTAMP"</span><span class="p">,</span> +</span><span id="Redshift.Generator-149"><a href="#Redshift.Generator-149"><span class="linenos">149</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">VARBINARY</span><span class="p">:</span> <span class="s2">"VARBYTE"</span><span class="p">,</span> +</span><span id="Redshift.Generator-150"><a href="#Redshift.Generator-150"><span class="linenos">150</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">ROWVERSION</span><span class="p">:</span> <span class="s2">"VARBYTE"</span><span class="p">,</span> +</span><span id="Redshift.Generator-151"><a href="#Redshift.Generator-151"><span class="linenos">151</span></a> <span class="p">}</span> +</span><span id="Redshift.Generator-152"><a href="#Redshift.Generator-152"><span class="linenos">152</span></a> +</span><span id="Redshift.Generator-153"><a href="#Redshift.Generator-153"><span class="linenos">153</span></a> <span class="n">TRANSFORMS</span> <span class="o">=</span> <span class="p">{</span> +</span><span id="Redshift.Generator-154"><a href="#Redshift.Generator-154"><span class="linenos">154</span></a> <span class="o">**</span><span class="n">Postgres</span><span class="o">.</span><span class="n">Generator</span><span class="o">.</span><span class="n">TRANSFORMS</span><span class="p">,</span> +</span><span id="Redshift.Generator-155"><a href="#Redshift.Generator-155"><span class="linenos">155</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Concat</span><span class="p">:</span> <span class="n">concat_to_dpipe_sql</span><span class="p">,</span> +</span><span id="Redshift.Generator-156"><a href="#Redshift.Generator-156"><span class="linenos">156</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">ConcatWs</span><span class="p">:</span> <span class="n">concat_ws_to_dpipe_sql</span><span class="p">,</span> +</span><span id="Redshift.Generator-157"><a href="#Redshift.Generator-157"><span class="linenos">157</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">ApproxDistinct</span><span class="p">:</span> <span class="k">lambda</span> <span class="bp">self</span><span class="p">,</span> +</span><span id="Redshift.Generator-158"><a href="#Redshift.Generator-158"><span class="linenos">158</span></a> <span class="n">e</span><span class="p">:</span> <span class="sa">f</span><span class="s2">"APPROXIMATE COUNT(DISTINCT </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="p">,</span><span class="w"> </span><span class="s1">'this'</span><span class="p">)</span><span class="si">}</span><span class="s2">)"</span><span class="p">,</span> +</span><span id="Redshift.Generator-159"><a href="#Redshift.Generator-159"><span class="linenos">159</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">CurrentTimestamp</span><span class="p">:</span> <span class="k">lambda</span> <span class="bp">self</span><span class="p">,</span> <span class="n">e</span><span class="p">:</span> <span class="p">(</span> +</span><span id="Redshift.Generator-160"><a href="#Redshift.Generator-160"><span class="linenos">160</span></a> <span class="s2">"SYSDATE"</span> <span class="k">if</span> <span class="n">e</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"transaction"</span><span class="p">)</span> <span class="k">else</span> <span class="s2">"GETDATE()"</span> +</span><span id="Redshift.Generator-161"><a href="#Redshift.Generator-161"><span class="linenos">161</span></a> <span class="p">),</span> +</span><span id="Redshift.Generator-162"><a href="#Redshift.Generator-162"><span class="linenos">162</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DateAdd</span><span class="p">:</span> <span class="n">date_delta_sql</span><span class="p">(</span><span class="s2">"DATEADD"</span><span class="p">),</span> +</span><span id="Redshift.Generator-163"><a href="#Redshift.Generator-163"><span class="linenos">163</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DateDiff</span><span class="p">:</span> <span class="n">date_delta_sql</span><span class="p">(</span><span class="s2">"DATEDIFF"</span><span class="p">),</span> +</span><span id="Redshift.Generator-164"><a href="#Redshift.Generator-164"><span class="linenos">164</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DistKeyProperty</span><span class="p">:</span> <span class="k">lambda</span> <span class="bp">self</span><span class="p">,</span> <span class="n">e</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="s2">"DISTKEY"</span><span class="p">,</span> <span class="n">e</span><span class="o">.</span><span class="n">this</span><span class="p">),</span> +</span><span id="Redshift.Generator-165"><a href="#Redshift.Generator-165"><span class="linenos">165</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">DistStyleProperty</span><span class="p">:</span> <span class="k">lambda</span> <span class="bp">self</span><span class="p">,</span> <span class="n">e</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">naked_property</span><span class="p">(</span><span class="n">e</span><span class="p">),</span> +</span><span id="Redshift.Generator-166"><a href="#Redshift.Generator-166"><span class="linenos">166</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">FromBase</span><span class="p">:</span> <span class="n">rename_func</span><span class="p">(</span><span class="s2">"STRTOL"</span><span class="p">),</span> +</span><span id="Redshift.Generator-167"><a href="#Redshift.Generator-167"><span class="linenos">167</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">GeneratedAsIdentityColumnConstraint</span><span class="p">:</span> <span class="n">generatedasidentitycolumnconstraint_sql</span><span class="p">,</span> +</span><span id="Redshift.Generator-168"><a href="#Redshift.Generator-168"><span class="linenos">168</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">JSONExtract</span><span class="p">:</span> <span class="n">json_extract_segments</span><span class="p">(</span><span class="s2">"JSON_EXTRACT_PATH_TEXT"</span><span class="p">),</span> +</span><span id="Redshift.Generator-169"><a href="#Redshift.Generator-169"><span class="linenos">169</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">JSONExtractScalar</span><span class="p">:</span> <span class="n">json_extract_segments</span><span class="p">(</span><span class="s2">"JSON_EXTRACT_PATH_TEXT"</span><span class="p">),</span> +</span><span id="Redshift.Generator-170"><a href="#Redshift.Generator-170"><span class="linenos">170</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">GroupConcat</span><span class="p">:</span> <span class="n">rename_func</span><span class="p">(</span><span class="s2">"LISTAGG"</span><span class="p">),</span> +</span><span id="Redshift.Generator-171"><a href="#Redshift.Generator-171"><span class="linenos">171</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">ParseJSON</span><span class="p">:</span> <span class="n">rename_func</span><span class="p">(</span><span class="s2">"JSON_PARSE"</span><span class="p">),</span> +</span><span id="Redshift.Generator-172"><a href="#Redshift.Generator-172"><span class="linenos">172</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">Select</span><span class="p">:</span> <span class="n">transforms</span><span class="o">.</span><span class="n">preprocess</span><span class="p">(</span> +</span><span id="Redshift.Generator-173"><a href="#Redshift.Generator-173"><span class="linenos">173</span></a> <span class="p">[</span> +</span><span id="Redshift.Generator-174"><a href="#Redshift.Generator-174"><span class="linenos">174</span></a> <span class="n">transforms</span><span class="o">.</span><span class="n">eliminate_distinct_on</span><span class="p">,</span> +</span><span id="Redshift.Generator-175"><a href="#Redshift.Generator-175"><span class="linenos">175</span></a> <span class="n">transforms</span><span class="o">.</span><span class="n">eliminate_semi_and_anti_joins</span><span class="p">,</span> +</span><span id="Redshift.Generator-176"><a href="#Redshift.Generator-176"><span class="linenos">176</span></a> <span class="n">transforms</span><span class="o">.</span><span class="n">unqualify_unnest</span><span class="p">,</span> +</span><span id="Redshift.Generator-177"><a href="#Redshift.Generator-177"><span class="linenos">177</span></a> <span class="p">]</span> +</span><span id="Redshift.Generator-178"><a href="#Redshift.Generator-178"><span class="linenos">178</span></a> <span class="p">),</span> +</span><span id="Redshift.Generator-179"><a href="#Redshift.Generator-179"><span class="linenos">179</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">SortKeyProperty</span><span class="p">:</span> <span class="k">lambda</span> <span class="bp">self</span><span class="p">,</span> +</span><span id="Redshift.Generator-180"><a href="#Redshift.Generator-180"><span class="linenos">180</span></a> <span class="n">e</span><span class="p">:</span> <span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="s1">'COMPOUND '</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">e</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s1">'compound'</span><span class="p">]</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="s1">''</span><span class="si">}</span><span class="s2">SORTKEY(</span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">format_args</span><span class="p">(</span><span class="o">*</span><span class="n">e</span><span class="o">.</span><span class="n">this</span><span class="p">)</span><span class="si">}</span><span class="s2">)"</span><span class="p">,</span> +</span><span id="Redshift.Generator-181"><a href="#Redshift.Generator-181"><span class="linenos">181</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">StartsWith</span><span class="p">:</span> <span class="k">lambda</span> <span class="bp">self</span><span class="p">,</span> +</span><span id="Redshift.Generator-182"><a href="#Redshift.Generator-182"><span class="linenos">182</span></a> <span class="n">e</span><span class="p">:</span> <span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">this</span><span class="p">)</span><span class="si">}</span><span class="s2"> LIKE </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">expression</span><span class="p">)</span><span class="si">}</span><span class="s2"> || '%'"</span><span class="p">,</span> +</span><span id="Redshift.Generator-183"><a href="#Redshift.Generator-183"><span class="linenos">183</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">TableSample</span><span class="p">:</span> <span class="n">no_tablesample_sql</span><span class="p">,</span> +</span><span id="Redshift.Generator-184"><a href="#Redshift.Generator-184"><span class="linenos">184</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">TsOrDsAdd</span><span class="p">:</span> <span class="n">date_delta_sql</span><span class="p">(</span><span class="s2">"DATEADD"</span><span class="p">),</span> +</span><span id="Redshift.Generator-185"><a href="#Redshift.Generator-185"><span class="linenos">185</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">TsOrDsDiff</span><span class="p">:</span> <span class="n">date_delta_sql</span><span class="p">(</span><span class="s2">"DATEDIFF"</span><span class="p">),</span> +</span><span id="Redshift.Generator-186"><a href="#Redshift.Generator-186"><span class="linenos">186</span></a> <span class="n">exp</span><span class="o">.</span><span class="n">UnixToTime</span><span class="p">:</span> <span class="k">lambda</span> <span class="bp">self</span><span class="p">,</span> +</span><span id="Redshift.Generator-187"><a href="#Redshift.Generator-187"><span class="linenos">187</span></a> <span class="n">e</span><span class="p">:</span> <span class="sa">f</span><span class="s2">"(TIMESTAMP 'epoch' + </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">this</span><span class="p">)</span><span class="si">}</span><span class="s2"> * INTERVAL '1 SECOND')"</span><span class="p">,</span> +</span><span id="Redshift.Generator-188"><a href="#Redshift.Generator-188"><span class="linenos">188</span></a> <span class="p">}</span> </span><span id="Redshift.Generator-189"><a href="#Redshift.Generator-189"><span class="linenos">189</span></a> -</span><span id="Redshift.Generator-190"><a href="#Redshift.Generator-190"><span class="linenos">190</span></a> <span class="c1"># Redshift supports ANY_VALUE(..)</span> -</span><span id="Redshift.Generator-191"><a href="#Redshift.Generator-191"><span class="linenos">191</span></a> <span class="n">TRANSFORMS</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">AnyValue</span><span class="p">)</span> +</span><span id="Redshift.Generator-190"><a href="#Redshift.Generator-190"><span class="linenos">190</span></a> <span class="c1"># Postgres maps exp.Pivot to no_pivot_sql, but Redshift support pivots</span> +</span><span id="Redshift.Generator-191"><a href="#Redshift.Generator-191"><span class="linenos">191</span></a> <span class="n">TRANSFORMS</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Pivot</span><span class="p">)</span> </span><span id="Redshift.Generator-192"><a href="#Redshift.Generator-192"><span class="linenos">192</span></a> -</span><span id="Redshift.Generator-193"><a href="#Redshift.Generator-193"><span class="linenos">193</span></a> <span class="c1"># Redshift supports LAST_DAY(..)</span> -</span><span id="Redshift.Generator-194"><a href="#Redshift.Generator-194"><span class="linenos">194</span></a> <span class="n">TRANSFORMS</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">LastDay</span><span class="p">)</span> +</span><span id="Redshift.Generator-193"><a href="#Redshift.Generator-193"><span class="linenos">193</span></a> <span class="c1"># Redshift uses the POW | POWER (expr1, expr2) syntax instead of expr1 ^ expr2 (postgres)</span> +</span><span id="Redshift.Generator-194"><a href="#Redshift.Generator-194"><span class="linenos">194</span></a> <span class="n">TRANSFORMS</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">Pow</span><span class="p">)</span> </span><span id="Redshift.Generator-195"><a href="#Redshift.Generator-195"><span class="linenos">195</span></a> -</span><span id="Redshift.Generator-196"><a href="#Redshift.Generator-196"><span class="linenos">196</span></a> <span class="n">RESERVED_KEYWORDS</span> <span class="o">=</span> <span class="p">{</span><span class="o">*</span><span class="n">Postgres</span><span class="o">.</span><span class="n">Generator</span><span class="o">.</span><span class="n">RESERVED_KEYWORDS</span><span class="p">,</span> <span class="s2">"snapshot"</span><span class="p">,</span> <span class="s2">"type"</span><span class="p">}</span> -</span><span id="Redshift.Generator-197"><a href="#Redshift.Generator-197"><span class="linenos">197</span></a> -</span><span id="Redshift.Generator-198"><a href="#Redshift.Generator-198"><span class="linenos">198</span></a> <span class="k">def</span> <span class="nf">unnest_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Unnest</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="Redshift.Generator-199"><a href="#Redshift.Generator-199"><span class="linenos">199</span></a> <span class="n">args</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">expressions</span> -</span><span id="Redshift.Generator-200"><a href="#Redshift.Generator-200"><span class="linenos">200</span></a> <span class="n">num_args</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> +</span><span id="Redshift.Generator-196"><a href="#Redshift.Generator-196"><span class="linenos">196</span></a> <span class="c1"># Redshift supports ANY_VALUE(..)</span> +</span><span id="Redshift.Generator-197"><a href="#Redshift.Generator-197"><span class="linenos">197</span></a> <span class="n">TRANSFORMS</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">AnyValue</span><span class="p">)</span> +</span><span id="Redshift.Generator-198"><a href="#Redshift.Generator-198"><span class="linenos">198</span></a> +</span><span id="Redshift.Generator-199"><a href="#Redshift.Generator-199"><span class="linenos">199</span></a> <span class="c1"># Redshift supports LAST_DAY(..)</span> +</span><span id="Redshift.Generator-200"><a href="#Redshift.Generator-200"><span class="linenos">200</span></a> <span class="n">TRANSFORMS</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">LastDay</span><span class="p">)</span> </span><span id="Redshift.Generator-201"><a href="#Redshift.Generator-201"><span class="linenos">201</span></a> -</span><span id="Redshift.Generator-202"><a href="#Redshift.Generator-202"><span class="linenos">202</span></a> <span class="k">if</span> <span class="n">num_args</span> <span class="o">></span> <span class="mi">1</span><span class="p">:</span> -</span><span id="Redshift.Generator-203"><a href="#Redshift.Generator-203"><span class="linenos">203</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Unsupported number of arguments in UNNEST: </span><span class="si">{</span><span class="n">num_args</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> -</span><span id="Redshift.Generator-204"><a href="#Redshift.Generator-204"><span class="linenos">204</span></a> <span class="k">return</span> <span class="s2">""</span> -</span><span id="Redshift.Generator-205"><a href="#Redshift.Generator-205"><span class="linenos">205</span></a> -</span><span id="Redshift.Generator-206"><a href="#Redshift.Generator-206"><span class="linenos">206</span></a> <span class="n">arg</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span> -</span><span id="Redshift.Generator-207"><a href="#Redshift.Generator-207"><span class="linenos">207</span></a> <span class="n">alias</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">expressions</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"alias"</span><span class="p">),</span> <span class="n">key</span><span class="o">=</span><span class="s2">"columns"</span><span class="p">)</span> -</span><span id="Redshift.Generator-208"><a href="#Redshift.Generator-208"><span class="linenos">208</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">arg</span><span class="si">}</span><span class="s2"> AS </span><span class="si">{</span><span class="n">alias</span><span class="si">}</span><span class="s2">"</span> <span class="k">if</span> <span class="n">alias</span> <span class="k">else</span> <span class="n">arg</span> -</span><span id="Redshift.Generator-209"><a href="#Redshift.Generator-209"><span class="linenos">209</span></a> -</span><span id="Redshift.Generator-210"><a href="#Redshift.Generator-210"><span class="linenos">210</span></a> <span class="k">def</span> <span class="nf">with_properties</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">properties</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Properties</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="Redshift.Generator-211"><a href="#Redshift.Generator-211"><span class="linenos">211</span></a><span class="w"> </span><span class="sd">"""Redshift doesn't have `WITH` as part of their with_properties so we remove it"""</span> -</span><span id="Redshift.Generator-212"><a href="#Redshift.Generator-212"><span class="linenos">212</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">properties</span><span class="p">(</span><span class="n">properties</span><span class="p">,</span> <span class="n">prefix</span><span class="o">=</span><span class="s2">" "</span><span class="p">,</span> <span class="n">suffix</span><span class="o">=</span><span class="s2">""</span><span class="p">)</span> -</span><span id="Redshift.Generator-213"><a href="#Redshift.Generator-213"><span class="linenos">213</span></a> -</span><span id="Redshift.Generator-214"><a href="#Redshift.Generator-214"><span class="linenos">214</span></a> <span class="k">def</span> <span class="nf">cast_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Cast</span><span class="p">,</span> <span class="n">safe_prefix</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="Redshift.Generator-215"><a href="#Redshift.Generator-215"><span class="linenos">215</span></a> <span class="k">if</span> <span class="n">expression</span><span class="o">.</span><span class="n">is_type</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">JSON</span><span class="p">):</span> -</span><span id="Redshift.Generator-216"><a href="#Redshift.Generator-216"><span class="linenos">216</span></a> <span class="c1"># Redshift doesn't support a JSON type, so casting to it is treated as a noop</span> -</span><span id="Redshift.Generator-217"><a href="#Redshift.Generator-217"><span class="linenos">217</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="s2">"this"</span><span class="p">)</span> -</span><span id="Redshift.Generator-218"><a href="#Redshift.Generator-218"><span class="linenos">218</span></a> -</span><span id="Redshift.Generator-219"><a href="#Redshift.Generator-219"><span class="linenos">219</span></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">cast_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="n">safe_prefix</span><span class="o">=</span><span class="n">safe_prefix</span><span class="p">)</span> -</span><span id="Redshift.Generator-220"><a href="#Redshift.Generator-220"><span class="linenos">220</span></a> -</span><span id="Redshift.Generator-221"><a href="#Redshift.Generator-221"><span class="linenos">221</span></a> <span class="k">def</span> <span class="nf">datatype_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="Redshift.Generator-222"><a href="#Redshift.Generator-222"><span class="linenos">222</span></a><span class="w"> </span><span class="sd">"""</span> -</span><span id="Redshift.Generator-223"><a href="#Redshift.Generator-223"><span class="linenos">223</span></a><span class="sd"> Redshift converts the `TEXT` data type to `VARCHAR(255)` by default when people more generally mean</span> -</span><span id="Redshift.Generator-224"><a href="#Redshift.Generator-224"><span class="linenos">224</span></a><span class="sd"> VARCHAR of max length which is `VARCHAR(max)` in Redshift. Therefore if we get a `TEXT` data type</span> -</span><span id="Redshift.Generator-225"><a href="#Redshift.Generator-225"><span class="linenos">225</span></a><span class="sd"> without precision we convert it to `VARCHAR(max)` and if it does have precision then we just convert</span> -</span><span id="Redshift.Generator-226"><a href="#Redshift.Generator-226"><span class="linenos">226</span></a><span class="sd"> `TEXT` to `VARCHAR`.</span> -</span><span id="Redshift.Generator-227"><a href="#Redshift.Generator-227"><span class="linenos">227</span></a><span class="sd"> """</span> -</span><span id="Redshift.Generator-228"><a href="#Redshift.Generator-228"><span class="linenos">228</span></a> <span class="k">if</span> <span class="n">expression</span><span class="o">.</span><span class="n">is_type</span><span class="p">(</span><span class="s2">"text"</span><span class="p">):</span> -</span><span id="Redshift.Generator-229"><a href="#Redshift.Generator-229"><span class="linenos">229</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"this"</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">VARCHAR</span><span class="p">)</span> -</span><span id="Redshift.Generator-230"><a href="#Redshift.Generator-230"><span class="linenos">230</span></a> <span class="n">precision</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"expressions"</span><span class="p">)</span> -</span><span id="Redshift.Generator-231"><a href="#Redshift.Generator-231"><span class="linenos">231</span></a> -</span><span id="Redshift.Generator-232"><a href="#Redshift.Generator-232"><span class="linenos">232</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">precision</span><span class="p">:</span> -</span><span id="Redshift.Generator-233"><a href="#Redshift.Generator-233"><span class="linenos">233</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">"expressions"</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">var</span><span class="p">(</span><span class="s2">"MAX"</span><span class="p">))</span> -</span><span id="Redshift.Generator-234"><a href="#Redshift.Generator-234"><span class="linenos">234</span></a> -</span><span id="Redshift.Generator-235"><a href="#Redshift.Generator-235"><span class="linenos">235</span></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">datatype_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> +</span><span id="Redshift.Generator-202"><a href="#Redshift.Generator-202"><span class="linenos">202</span></a> <span class="n">RESERVED_KEYWORDS</span> <span class="o">=</span> <span class="p">{</span> +</span><span id="Redshift.Generator-203"><a href="#Redshift.Generator-203"><span class="linenos">203</span></a> <span class="s2">"aes128"</span><span class="p">,</span> +</span><span id="Redshift.Generator-204"><a href="#Redshift.Generator-204"><span class="linenos">204</span></a> <span class="s2">"aes256"</span><span class="p">,</span> +</span><span id="Redshift.Generator-205"><a href="#Redshift.Generator-205"><span class="linenos">205</span></a> <span class="s2">"all"</span><span class="p">,</span> +</span><span id="Redshift.Generator-206"><a href="#Redshift.Generator-206"><span class="linenos">206</span></a> <span class="s2">"allowoverwrite"</span><span class="p">,</span> +</span><span id="Redshift.Generator-207"><a href="#Redshift.Generator-207"><span class="linenos">207</span></a> <span class="s2">"analyse"</span><span class="p">,</span> +</span><span id="Redshift.Generator-208"><a href="#Redshift.Generator-208"><span class="linenos">208</span></a> <span class="s2">"analyze"</span><span class="p">,</span> +</span><span id="Redshift.Generator-209"><a href="#Redshift.Generator-209"><span class="linenos">209</span></a> <span class="s2">"and"</span><span class="p">,</span> +</span><span id="Redshift.Generator-210"><a href="#Redshift.Generator-210"><span class="linenos">210</span></a> <span class="s2">"any"</span><span class="p">,</span> +</span><span id="Redshift.Generator-211"><a href="#Redshift.Generator-211"><span class="linenos">211</span></a> <span class="s2">"array"</span><span class="p">,</span> +</span><span id="Redshift.Generator-212"><a href="#Redshift.Generator-212"><span class="linenos">212</span></a> <span class="s2">"as"</span><span class="p">,</span> +</span><span id="Redshift.Generator-213"><a href="#Redshift.Generator-213"><span class="linenos">213</span></a> <span class="s2">"asc"</span><span class="p">,</span> +</span><span id="Redshift.Generator-214"><a href="#Redshift.Generator-214"><span class="linenos">214</span></a> <span class="s2">"authorization"</span><span class="p">,</span> +</span><span id="Redshift.Generator-215"><a href="#Redshift.Generator-215"><span class="linenos">215</span></a> <span class="s2">"az64"</span><span class="p">,</span> +</span><span id="Redshift.Generator-216"><a href="#Redshift.Generator-216"><span class="linenos">216</span></a> <span class="s2">"backup"</span><span class="p">,</span> +</span><span id="Redshift.Generator-217"><a href="#Redshift.Generator-217"><span class="linenos">217</span></a> <span class="s2">"between"</span><span class="p">,</span> +</span><span id="Redshift.Generator-218"><a href="#Redshift.Generator-218"><span class="linenos">218</span></a> <span class="s2">"binary"</span><span class="p">,</span> +</span><span id="Redshift.Generator-219"><a href="#Redshift.Generator-219"><span class="linenos">219</span></a> <span class="s2">"blanksasnull"</span><span class="p">,</span> +</span><span id="Redshift.Generator-220"><a href="#Redshift.Generator-220"><span class="linenos">220</span></a> <span class="s2">"both"</span><span class="p">,</span> +</span><span id="Redshift.Generator-221"><a href="#Redshift.Generator-221"><span class="linenos">221</span></a> <span class="s2">"bytedict"</span><span class="p">,</span> +</span><span id="Redshift.Generator-222"><a href="#Redshift.Generator-222"><span class="linenos">222</span></a> <span class="s2">"bzip2"</span><span class="p">,</span> +</span><span id="Redshift.Generator-223"><a href="#Redshift.Generator-223"><span class="linenos">223</span></a> <span class="s2">"case"</span><span class="p">,</span> +</span><span id="Redshift.Generator-224"><a href="#Redshift.Generator-224"><span class="linenos">224</span></a> <span class="s2">"cast"</span><span class="p">,</span> +</span><span id="Redshift.Generator-225"><a href="#Redshift.Generator-225"><span class="linenos">225</span></a> <span class="s2">"check"</span><span class="p">,</span> +</span><span id="Redshift.Generator-226"><a href="#Redshift.Generator-226"><span class="linenos">226</span></a> <span class="s2">"collate"</span><span class="p">,</span> +</span><span id="Redshift.Generator-227"><a href="#Redshift.Generator-227"><span class="linenos">227</span></a> <span class="s2">"column"</span><span class="p">,</span> +</span><span id="Redshift.Generator-228"><a href="#Redshift.Generator-228"><span class="linenos">228</span></a> <span class="s2">"constraint"</span><span class="p">,</span> +</span><span id="Redshift.Generator-229"><a href="#Redshift.Generator-229"><span class="linenos">229</span></a> <span class="s2">"create"</span><span class="p">,</span> +</span><span id="Redshift.Generator-230"><a href="#Redshift.Generator-230"><span class="linenos">230</span></a> <span class="s2">"credentials"</span><span class="p">,</span> +</span><span id="Redshift.Generator-231"><a href="#Redshift.Generator-231"><span class="linenos">231</span></a> <span class="s2">"cross"</span><span class="p">,</span> +</span><span id="Redshift.Generator-232"><a href="#Redshift.Generator-232"><span class="linenos">232</span></a> <span class="s2">"current_date"</span><span class="p">,</span> +</span><span id="Redshift.Generator-233"><a href="#Redshift.Generator-233"><span class="linenos">233</span></a> <span class="s2">"current_time"</span><span class="p">,</span> +</span><span id="Redshift.Generator-234"><a href="#Redshift.Generator-234"><span class="linenos">234</span></a> <span class="s2">"current_timestamp"</span><span class="p">,</span> +</span><span id="Redshift.Generator-235"><a href="#Redshift.Generator-235"><span class="linenos">235</span></a> <span class="s2">"current_user"</span><span class="p">,</span> +</span><span id="Redshift.Generator-236"><a href="#Redshift.Generator-236"><span class="linenos">236</span></a> <span class="s2">"current_user_id"</span><span class="p">,</span> +</span><span id="Redshift.Generator-237"><a href="#Redshift.Generator-237"><span class="linenos">237</span></a> <span class="s2">"default"</span><span class="p">,</span> +</span><span id="Redshift.Generator-238"><a href="#Redshift.Generator-238"><span class="linenos">238</span></a> <span class="s2">"deferrable"</span><span class="p">,</span> +</span><span id="Redshift.Generator-239"><a href="#Redshift.Generator-239"><span class="linenos">239</span></a> <span class="s2">"deflate"</span><span class="p">,</span> +</span><span id="Redshift.Generator-240"><a href="#Redshift.Generator-240"><span class="linenos">240</span></a> <span class="s2">"defrag"</span><span class="p">,</span> +</span><span id="Redshift.Generator-241"><a href="#Redshift.Generator-241"><span class="linenos">241</span></a> <span class="s2">"delta"</span><span class="p">,</span> +</span><span id="Redshift.Generator-242"><a href="#Redshift.Generator-242"><span class="linenos">242</span></a> <span class="s2">"delta32k"</span><span class="p">,</span> +</span><span id="Redshift.Generator-243"><a href="#Redshift.Generator-243"><span class="linenos">243</span></a> <span class="s2">"desc"</span><span class="p">,</span> +</span><span id="Redshift.Generator-244"><a href="#Redshift.Generator-244"><span class="linenos">244</span></a> <span class="s2">"disable"</span><span class="p">,</span> +</span><span id="Redshift.Generator-245"><a href="#Redshift.Generator-245"><span class="linenos">245</span></a> <span class="s2">"distinct"</span><span class="p">,</span> +</span><span id="Redshift.Generator-246"><a href="#Redshift.Generator-246"><span class="linenos">246</span></a> <span class="s2">"do"</span><span class="p">,</span> +</span><span id="Redshift.Generator-247"><a href="#Redshift.Generator-247"><span class="linenos">247</span></a> <span class="s2">"else"</span><span class="p">,</span> +</span><span id="Redshift.Generator-248"><a href="#Redshift.Generator-248"><span class="linenos">248</span></a> <span class="s2">"emptyasnull"</span><span class="p">,</span> +</span><span id="Redshift.Generator-249"><a href="#Redshift.Generator-249"><span class="linenos">249</span></a> <span class="s2">"enable"</span><span class="p">,</span> +</span><span id="Redshift.Generator-250"><a href="#Redshift.Generator-250"><span class="linenos">250</span></a> <span class="s2">"encode"</span><span class="p">,</span> +</span><span id="Redshift.Generator-251"><a href="#Redshift.Generator-251"><span class="linenos">251</span></a> <span class="s2">"encrypt "</span><span class="p">,</span> +</span><span id="Redshift.Generator-252"><a href="#Redshift.Generator-252"><span class="linenos">252</span></a> <span class="s2">"encryption"</span><span class="p">,</span> +</span><span id="Redshift.Generator-253"><a href="#Redshift.Generator-253"><span class="linenos">253</span></a> <span class="s2">"end"</span><span class="p">,</span> +</span><span id="Redshift.Generator-254"><a href="#Redshift.Generator-254"><span class="linenos">254</span></a> <span class="s2">"except"</span><span class="p">,</span> +</span><span id="Redshift.Generator-255"><a href="#Redshift.Generator-255"><span class="linenos">255</span></a> <span class="s2">"explicit"</span><span class="p">,</span> +</span><span id="Redshift.Generator-256"><a href="#Redshift.Generator-256"><span class="linenos">256</span></a> <span class="s2">"false"</span><span class="p">,</span> +</span><span id="Redshift.Generator-257"><a href="#Redshift.Generator-257"><span class="linenos">257</span></a> <span class="s2">"for"</span><span class="p">,</span> +</span><span id="Redshift.Generator-258"><a href="#Redshift.Generator-258"><span class="linenos">258</span></a> <span class="s2">"foreign"</span><span class="p">,</span> +</span><span id="Redshift.Generator-259"><a href="#Redshift.Generator-259"><span class="linenos">259</span></a> <span class="s2">"freeze"</span><span class="p">,</span> +</span><span id="Redshift.Generator-260"><a href="#Redshift.Generator-260"><span class="linenos">260</span></a> <span class="s2">"from"</span><span class="p">,</span> +</span><span id="Redshift.Generator-261"><a href="#Redshift.Generator-261"><span class="linenos">261</span></a> <span class="s2">"full"</span><span class="p">,</span> +</span><span id="Redshift.Generator-262"><a href="#Redshift.Generator-262"><span class="linenos">262</span></a> <span class="s2">"globaldict256"</span><span class="p">,</span> +</span><span id="Redshift.Generator-263"><a href="#Redshift.Generator-263"><span class="linenos">263</span></a> <span class="s2">"globaldict64k"</span><span class="p">,</span> +</span><span id="Redshift.Generator-264"><a href="#Redshift.Generator-264"><span class="linenos">264</span></a> <span class="s2">"grant"</span><span class="p">,</span> +</span><span id="Redshift.Generator-265"><a href="#Redshift.Generator-265"><span class="linenos">265</span></a> <span class="s2">"group"</span><span class="p">,</span> +</span><span id="Redshift.Generator-266"><a href="#Redshift.Generator-266"><span class="linenos">266</span></a> <span class="s2">"gzip"</span><span class="p">,</span> +</span><span id="Redshift.Generator-267"><a href="#Redshift.Generator-267"><span class="linenos">267</span></a> <span class="s2">"having"</span><span class="p">,</span> +</span><span id="Redshift.Generator-268"><a href="#Redshift.Generator-268"><span class="linenos">268</span></a> <span class="s2">"identity"</span><span class="p">,</span> +</span><span id="Redshift.Generator-269"><a href="#Redshift.Generator-269"><span class="linenos">269</span></a> <span class="s2">"ignore"</span><span class="p">,</span> +</span><span id="Redshift.Generator-270"><a href="#Redshift.Generator-270"><span class="linenos">270</span></a> <span class="s2">"ilike"</span><span class="p">,</span> +</span><span id="Redshift.Generator-271"><a href="#Redshift.Generator-271"><span class="linenos">271</span></a> <span class="s2">"in"</span><span class="p">,</span> +</span><span id="Redshift.Generator-272"><a href="#Redshift.Generator-272"><span class="linenos">272</span></a> <span class="s2">"initially"</span><span class="p">,</span> +</span><span id="Redshift.Generator-273"><a href="#Redshift.Generator-273"><span class="linenos">273</span></a> <span class="s2">"inner"</span><span class="p">,</span> +</span><span id="Redshift.Generator-274"><a href="#Redshift.Generator-274"><span class="linenos">274</span></a> <span class="s2">"intersect"</span><span class="p">,</span> +</span><span id="Redshift.Generator-275"><a href="#Redshift.Generator-275"><span class="linenos">275</span></a> <span class="s2">"interval"</span><span class="p">,</span> +</span><span id="Redshift.Generator-276"><a href="#Redshift.Generator-276"><span class="linenos">276</span></a> <span class="s2">"into"</span><span class="p">,</span> +</span><span id="Redshift.Generator-277"><a href="#Redshift.Generator-277"><span class="linenos">277</span></a> <span class="s2">"is"</span><span class="p">,</span> +</span><span id="Redshift.Generator-278"><a href="#Redshift.Generator-278"><span class="linenos">278</span></a> <span class="s2">"isnull"</span><span class="p">,</span> +</span><span id="Redshift.Generator-279"><a href="#Redshift.Generator-279"><span class="linenos">279</span></a> <span class="s2">"join"</span><span class="p">,</span> +</span><span id="Redshift.Generator-280"><a href="#Redshift.Generator-280"><span class="linenos">280</span></a> <span class="s2">"leading"</span><span class="p">,</span> +</span><span id="Redshift.Generator-281"><a href="#Redshift.Generator-281"><span class="linenos">281</span></a> <span class="s2">"left"</span><span class="p">,</span> +</span><span id="Redshift.Generator-282"><a href="#Redshift.Generator-282"><span class="linenos">282</span></a> <span class="s2">"like"</span><span class="p">,</span> +</span><span id="Redshift.Generator-283"><a href="#Redshift.Generator-283"><span class="linenos">283</span></a> <span class="s2">"limit"</span><span class="p">,</span> +</span><span id="Redshift.Generator-284"><a href="#Redshift.Generator-284"><span class="linenos">284</span></a> <span class="s2">"localtime"</span><span class="p">,</span> +</span><span id="Redshift.Generator-285"><a href="#Redshift.Generator-285"><span class="linenos">285</span></a> <span class="s2">"localtimestamp"</span><span class="p">,</span> +</span><span id="Redshift.Generator-286"><a href="#Redshift.Generator-286"><span class="linenos">286</span></a> <span class="s2">"lun"</span><span class="p">,</span> +</span><span id="Redshift.Generator-287"><a href="#Redshift.Generator-287"><span class="linenos">287</span></a> <span class="s2">"luns"</span><span class="p">,</span> +</span><span id="Redshift.Generator-288"><a href="#Redshift.Generator-288"><span class="linenos">288</span></a> <span class="s2">"lzo"</span><span class="p">,</span> +</span><span id="Redshift.Generator-289"><a href="#Redshift.Generator-289"><span class="linenos">289</span></a> <span class="s2">"lzop"</span><span class="p">,</span> +</span><span id="Redshift.Generator-290"><a href="#Redshift.Generator-290"><span class="linenos">290</span></a> <span class="s2">"minus"</span><span class="p">,</span> +</span><span id="Redshift.Generator-291"><a href="#Redshift.Generator-291"><span class="linenos">291</span></a> <span class="s2">"mostly16"</span><span class="p">,</span> +</span><span id="Redshift.Generator-292"><a href="#Redshift.Generator-292"><span class="linenos">292</span></a> <span class="s2">"mostly32"</span><span class="p">,</span> +</span><span id="Redshift.Generator-293"><a href="#Redshift.Generator-293"><span class="linenos">293</span></a> <span class="s2">"mostly8"</span><span class="p">,</span> +</span><span id="Redshift.Generator-294"><a href="#Redshift.Generator-294"><span class="linenos">294</span></a> <span class="s2">"natural"</span><span class="p">,</span> +</span><span id="Redshift.Generator-295"><a href="#Redshift.Generator-295"><span class="linenos">295</span></a> <span class="s2">"new"</span><span class="p">,</span> +</span><span id="Redshift.Generator-296"><a href="#Redshift.Generator-296"><span class="linenos">296</span></a> <span class="s2">"not"</span><span class="p">,</span> +</span><span id="Redshift.Generator-297"><a href="#Redshift.Generator-297"><span class="linenos">297</span></a> <span class="s2">"notnull"</span><span class="p">,</span> +</span><span id="Redshift.Generator-298"><a href="#Redshift.Generator-298"><span class="linenos">298</span></a> <span class="s2">"null"</span><span class="p">,</span> +</span><span id="Redshift.Generator-299"><a href="#Redshift.Generator-299"><span class="linenos">299</span></a> <span class="s2">"nulls"</span><span class="p">,</span> +</span><span id="Redshift.Generator-300"><a href="#Redshift.Generator-300"><span class="linenos">300</span></a> <span class="s2">"off"</span><span class="p">,</span> +</span><span id="Redshift.Generator-301"><a href="#Redshift.Generator-301"><span class="linenos">301</span></a> <span class="s2">"offline"</span><span class="p">,</span> +</span><span id="Redshift.Generator-302"><a href="#Redshift.Generator-302"><span class="linenos">302</span></a> <span class="s2">"offset"</span><span class="p">,</span> +</span><span id="Redshift.Generator-303"><a href="#Redshift.Generator-303"><span class="linenos">303</span></a> <span class="s2">"oid"</span><span class="p">,</span> +</span><span id="Redshift.Generator-304"><a href="#Redshift.Generator-304"><span class="linenos">304</span></a> <span class="s2">"old"</span><span class="p">,</span> +</span><span id="Redshift.Generator-305"><a href="#Redshift.Generator-305"><span class="linenos">305</span></a> <span class="s2">"on"</span><span class="p">,</span> +</span><span id="Redshift.Generator-306"><a href="#Redshift.Generator-306"><span class="linenos">306</span></a> <span class="s2">"only"</span><span class="p">,</span> +</span><span id="Redshift.Generator-307"><a href="#Redshift.Generator-307"><span class="linenos">307</span></a> <span class="s2">"open"</span><span class="p">,</span> +</span><span id="Redshift.Generator-308"><a href="#Redshift.Generator-308"><span class="linenos">308</span></a> <span class="s2">"or"</span><span class="p">,</span> +</span><span id="Redshift.Generator-309"><a href="#Redshift.Generator-309"><span class="linenos">309</span></a> <span class="s2">"order"</span><span class="p">,</span> +</span><span id="Redshift.Generator-310"><a href="#Redshift.Generator-310"><span class="linenos">310</span></a> <span class="s2">"outer"</span><span class="p">,</span> +</span><span id="Redshift.Generator-311"><a href="#Redshift.Generator-311"><span class="linenos">311</span></a> <span class="s2">"overlaps"</span><span class="p">,</span> +</span><span id="Redshift.Generator-312"><a href="#Redshift.Generator-312"><span class="linenos">312</span></a> <span class="s2">"parallel"</span><span class="p">,</span> +</span><span id="Redshift.Generator-313"><a href="#Redshift.Generator-313"><span class="linenos">313</span></a> <span class="s2">"partition"</span><span class="p">,</span> +</span><span id="Redshift.Generator-314"><a href="#Redshift.Generator-314"><span class="linenos">314</span></a> <span class="s2">"percent"</span><span class="p">,</span> +</span><span id="Redshift.Generator-315"><a href="#Redshift.Generator-315"><span class="linenos">315</span></a> <span class="s2">"permissions"</span><span class="p">,</span> +</span><span id="Redshift.Generator-316"><a href="#Redshift.Generator-316"><span class="linenos">316</span></a> <span class="s2">"pivot"</span><span class="p">,</span> +</span><span id="Redshift.Generator-317"><a href="#Redshift.Generator-317"><span class="linenos">317</span></a> <span class="s2">"placing"</span><span class="p">,</span> +</span><span id="Redshift.Generator-318"><a href="#Redshift.Generator-318"><span class="linenos">318</span></a> <span class="s2">"primary"</span><span class="p">,</span> +</span><span id="Redshift.Generator-319"><a href="#Redshift.Generator-319"><span class="linenos">319</span></a> <span class="s2">"raw"</span><span class="p">,</span> +</span><span id="Redshift.Generator-320"><a href="#Redshift.Generator-320"><span class="linenos">320</span></a> <span class="s2">"readratio"</span><span class="p">,</span> +</span><span id="Redshift.Generator-321"><a href="#Redshift.Generator-321"><span class="linenos">321</span></a> <span class="s2">"recover"</span><span class="p">,</span> +</span><span id="Redshift.Generator-322"><a href="#Redshift.Generator-322"><span class="linenos">322</span></a> <span class="s2">"references"</span><span class="p">,</span> +</span><span id="Redshift.Generator-323"><a href="#Redshift.Generator-323"><span class="linenos">323</span></a> <span class="s2">"rejectlog"</span><span class="p">,</span> +</span><span id="Redshift.Generator-324"><a href="#Redshift.Generator-324"><span class="linenos">324</span></a> <span class="s2">"resort"</span><span class="p">,</span> +</span><span id="Redshift.Generator-325"><a href="#Redshift.Generator-325"><span class="linenos">325</span></a> <span class="s2">"respect"</span><span class="p">,</span> +</span><span id="Redshift.Generator-326"><a href="#Redshift.Generator-326"><span class="linenos">326</span></a> <span class="s2">"restore"</span><span class="p">,</span> +</span><span id="Redshift.Generator-327"><a href="#Redshift.Generator-327"><span class="linenos">327</span></a> <span class="s2">"right"</span><span class="p">,</span> +</span><span id="Redshift.Generator-328"><a href="#Redshift.Generator-328"><span class="linenos">328</span></a> <span class="s2">"select"</span><span class="p">,</span> +</span><span id="Redshift.Generator-329"><a href="#Redshift.Generator-329"><span class="linenos">329</span></a> <span class="s2">"session_user"</span><span class="p">,</span> +</span><span id="Redshift.Generator-330"><a href="#Redshift.Generator-330"><span class="linenos">330</span></a> <span class="s2">"similar"</span><span class="p">,</span> +</span><span id="Redshift.Generator-331"><a href="#Redshift.Generator-331"><span class="linenos">331</span></a> <span class="s2">"snapshot"</span><span class="p">,</span> +</span><span id="Redshift.Generator-332"><a href="#Redshift.Generator-332"><span class="linenos">332</span></a> <span class="s2">"some"</span><span class="p">,</span> +</span><span id="Redshift.Generator-333"><a href="#Redshift.Generator-333"><span class="linenos">333</span></a> <span class="s2">"sysdate"</span><span class="p">,</span> +</span><span id="Redshift.Generator-334"><a href="#Redshift.Generator-334"><span class="linenos">334</span></a> <span class="s2">"system"</span><span class="p">,</span> +</span><span id="Redshift.Generator-335"><a href="#Redshift.Generator-335"><span class="linenos">335</span></a> <span class="s2">"table"</span><span class="p">,</span> +</span><span id="Redshift.Generator-336"><a href="#Redshift.Generator-336"><span class="linenos">336</span></a> <span class="s2">"tag"</span><span class="p">,</span> +</span><span id="Redshift.Generator-337"><a href="#Redshift.Generator-337"><span class="linenos">337</span></a> <span class="s2">"tdes"</span><span class="p">,</span> +</span><span id="Redshift.Generator-338"><a href="#Redshift.Generator-338"><span class="linenos">338</span></a> <span class="s2">"text255"</span><span class="p">,</span> +</span><span id="Redshift.Generator-339"><a href="#Redshift.Generator-339"><span class="linenos">339</span></a> <span class="s2">"text32k"</span><span class="p">,</span> +</span><span id="Redshift.Generator-340"><a href="#Redshift.Generator-340"><span class="linenos">340</span></a> <span class="s2">"then"</span><span class="p">,</span> +</span><span id="Redshift.Generator-341"><a href="#Redshift.Generator-341"><span class="linenos">341</span></a> <span class="s2">"timestamp"</span><span class="p">,</span> +</span><span id="Redshift.Generator-342"><a href="#Redshift.Generator-342"><span class="linenos">342</span></a> <span class="s2">"to"</span><span class="p">,</span> +</span><span id="Redshift.Generator-343"><a href="#Redshift.Generator-343"><span class="linenos">343</span></a> <span class="s2">"top"</span><span class="p">,</span> +</span><span id="Redshift.Generator-344"><a href="#Redshift.Generator-344"><span class="linenos">344</span></a> <span class="s2">"trailing"</span><span class="p">,</span> +</span><span id="Redshift.Generator-345"><a href="#Redshift.Generator-345"><span class="linenos">345</span></a> <span class="s2">"true"</span><span class="p">,</span> +</span><span id="Redshift.Generator-346"><a href="#Redshift.Generator-346"><span class="linenos">346</span></a> <span class="s2">"truncatecolumns"</span><span class="p">,</span> +</span><span id="Redshift.Generator-347"><a href="#Redshift.Generator-347"><span class="linenos">347</span></a> <span class="s2">"type"</span><span class="p">,</span> +</span><span id="Redshift.Generator-348"><a href="#Redshift.Generator-348"><span class="linenos">348</span></a> <span class="s2">"union"</span><span class="p">,</span> +</span><span id="Redshift.Generator-349"><a href="#Redshift.Generator-349"><span class="linenos">349</span></a> <span class="s2">"unique"</span><span class="p">,</span> +</span><span id="Redshift.Generator-350"><a href="#Redshift.Generator-350"><span class="linenos">350</span></a> <span class="s2">"unnest"</span><span class="p">,</span> +</span><span id="Redshift.Generator-351"><a href="#Redshift.Generator-351"><span class="linenos">351</span></a> <span class="s2">"unpivot"</span><span class="p">,</span> +</span><span id="Redshift.Generator-352"><a href="#Redshift.Generator-352"><span class="linenos">352</span></a> <span class="s2">"user"</span><span class="p">,</span> +</span><span id="Redshift.Generator-353"><a href="#Redshift.Generator-353"><span class="linenos">353</span></a> <span class="s2">"using"</span><span class="p">,</span> +</span><span id="Redshift.Generator-354"><a href="#Redshift.Generator-354"><span class="linenos">354</span></a> <span class="s2">"verbose"</span><span class="p">,</span> +</span><span id="Redshift.Generator-355"><a href="#Redshift.Generator-355"><span class="linenos">355</span></a> <span class="s2">"wallet"</span><span class="p">,</span> +</span><span id="Redshift.Generator-356"><a href="#Redshift.Generator-356"><span class="linenos">356</span></a> <span class="s2">"when"</span><span class="p">,</span> +</span><span id="Redshift.Generator-357"><a href="#Redshift.Generator-357"><span class="linenos">357</span></a> <span class="s2">"where"</span><span class="p">,</span> +</span><span id="Redshift.Generator-358"><a href="#Redshift.Generator-358"><span class="linenos">358</span></a> <span class="s2">"with"</span><span class="p">,</span> +</span><span id="Redshift.Generator-359"><a href="#Redshift.Generator-359"><span class="linenos">359</span></a> <span class="s2">"without"</span><span class="p">,</span> +</span><span id="Redshift.Generator-360"><a href="#Redshift.Generator-360"><span class="linenos">360</span></a> <span class="p">}</span> +</span><span id="Redshift.Generator-361"><a href="#Redshift.Generator-361"><span class="linenos">361</span></a> +</span><span id="Redshift.Generator-362"><a href="#Redshift.Generator-362"><span class="linenos">362</span></a> <span class="k">def</span> <span class="nf">unnest_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Unnest</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="Redshift.Generator-363"><a href="#Redshift.Generator-363"><span class="linenos">363</span></a> <span class="n">args</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">expressions</span> +</span><span id="Redshift.Generator-364"><a href="#Redshift.Generator-364"><span class="linenos">364</span></a> <span class="n">num_args</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> +</span><span id="Redshift.Generator-365"><a href="#Redshift.Generator-365"><span class="linenos">365</span></a> +</span><span id="Redshift.Generator-366"><a href="#Redshift.Generator-366"><span class="linenos">366</span></a> <span class="k">if</span> <span class="n">num_args</span> <span class="o">></span> <span class="mi">1</span><span class="p">:</span> +</span><span id="Redshift.Generator-367"><a href="#Redshift.Generator-367"><span class="linenos">367</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Unsupported number of arguments in UNNEST: </span><span class="si">{</span><span class="n">num_args</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> +</span><span id="Redshift.Generator-368"><a href="#Redshift.Generator-368"><span class="linenos">368</span></a> <span class="k">return</span> <span class="s2">""</span> +</span><span id="Redshift.Generator-369"><a href="#Redshift.Generator-369"><span class="linenos">369</span></a> +</span><span id="Redshift.Generator-370"><a href="#Redshift.Generator-370"><span class="linenos">370</span></a> <span class="n">arg</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span> +</span><span id="Redshift.Generator-371"><a href="#Redshift.Generator-371"><span class="linenos">371</span></a> <span class="n">alias</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">expressions</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"alias"</span><span class="p">),</span> <span class="n">key</span><span class="o">=</span><span class="s2">"columns"</span><span class="p">,</span> <span class="n">flat</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> +</span><span id="Redshift.Generator-372"><a href="#Redshift.Generator-372"><span class="linenos">372</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">arg</span><span class="si">}</span><span class="s2"> AS </span><span class="si">{</span><span class="n">alias</span><span class="si">}</span><span class="s2">"</span> <span class="k">if</span> <span class="n">alias</span> <span class="k">else</span> <span class="n">arg</span> +</span><span id="Redshift.Generator-373"><a href="#Redshift.Generator-373"><span class="linenos">373</span></a> +</span><span id="Redshift.Generator-374"><a href="#Redshift.Generator-374"><span class="linenos">374</span></a> <span class="k">def</span> <span class="nf">with_properties</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">properties</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Properties</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="Redshift.Generator-375"><a href="#Redshift.Generator-375"><span class="linenos">375</span></a><span class="w"> </span><span class="sd">"""Redshift doesn't have `WITH` as part of their with_properties so we remove it"""</span> +</span><span id="Redshift.Generator-376"><a href="#Redshift.Generator-376"><span class="linenos">376</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">properties</span><span class="p">(</span><span class="n">properties</span><span class="p">,</span> <span class="n">prefix</span><span class="o">=</span><span class="s2">" "</span><span class="p">,</span> <span class="n">suffix</span><span class="o">=</span><span class="s2">""</span><span class="p">)</span> +</span><span id="Redshift.Generator-377"><a href="#Redshift.Generator-377"><span class="linenos">377</span></a> +</span><span id="Redshift.Generator-378"><a href="#Redshift.Generator-378"><span class="linenos">378</span></a> <span class="k">def</span> <span class="nf">cast_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Cast</span><span class="p">,</span> <span class="n">safe_prefix</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="Redshift.Generator-379"><a href="#Redshift.Generator-379"><span class="linenos">379</span></a> <span class="k">if</span> <span class="n">expression</span><span class="o">.</span><span class="n">is_type</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">JSON</span><span class="p">):</span> +</span><span id="Redshift.Generator-380"><a href="#Redshift.Generator-380"><span class="linenos">380</span></a> <span class="c1"># Redshift doesn't support a JSON type, so casting to it is treated as a noop</span> +</span><span id="Redshift.Generator-381"><a href="#Redshift.Generator-381"><span class="linenos">381</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="s2">"this"</span><span class="p">)</span> +</span><span id="Redshift.Generator-382"><a href="#Redshift.Generator-382"><span class="linenos">382</span></a> +</span><span id="Redshift.Generator-383"><a href="#Redshift.Generator-383"><span class="linenos">383</span></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">cast_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="n">safe_prefix</span><span class="o">=</span><span class="n">safe_prefix</span><span class="p">)</span> +</span><span id="Redshift.Generator-384"><a href="#Redshift.Generator-384"><span class="linenos">384</span></a> +</span><span id="Redshift.Generator-385"><a href="#Redshift.Generator-385"><span class="linenos">385</span></a> <span class="k">def</span> <span class="nf">datatype_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="Redshift.Generator-386"><a href="#Redshift.Generator-386"><span class="linenos">386</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="Redshift.Generator-387"><a href="#Redshift.Generator-387"><span class="linenos">387</span></a><span class="sd"> Redshift converts the `TEXT` data type to `VARCHAR(255)` by default when people more generally mean</span> +</span><span id="Redshift.Generator-388"><a href="#Redshift.Generator-388"><span class="linenos">388</span></a><span class="sd"> VARCHAR of max length which is `VARCHAR(max)` in Redshift. Therefore if we get a `TEXT` data type</span> +</span><span id="Redshift.Generator-389"><a href="#Redshift.Generator-389"><span class="linenos">389</span></a><span class="sd"> without precision we convert it to `VARCHAR(max)` and if it does have precision then we just convert</span> +</span><span id="Redshift.Generator-390"><a href="#Redshift.Generator-390"><span class="linenos">390</span></a><span class="sd"> `TEXT` to `VARCHAR`.</span> +</span><span id="Redshift.Generator-391"><a href="#Redshift.Generator-391"><span class="linenos">391</span></a><span class="sd"> """</span> +</span><span id="Redshift.Generator-392"><a href="#Redshift.Generator-392"><span class="linenos">392</span></a> <span class="k">if</span> <span class="n">expression</span><span class="o">.</span><span class="n">is_type</span><span class="p">(</span><span class="s2">"text"</span><span class="p">):</span> +</span><span id="Redshift.Generator-393"><a href="#Redshift.Generator-393"><span class="linenos">393</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"this"</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">VARCHAR</span><span class="p">)</span> +</span><span id="Redshift.Generator-394"><a href="#Redshift.Generator-394"><span class="linenos">394</span></a> <span class="n">precision</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"expressions"</span><span class="p">)</span> +</span><span id="Redshift.Generator-395"><a href="#Redshift.Generator-395"><span class="linenos">395</span></a> +</span><span id="Redshift.Generator-396"><a href="#Redshift.Generator-396"><span class="linenos">396</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">precision</span><span class="p">:</span> +</span><span id="Redshift.Generator-397"><a href="#Redshift.Generator-397"><span class="linenos">397</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">"expressions"</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">var</span><span class="p">(</span><span class="s2">"MAX"</span><span class="p">))</span> +</span><span id="Redshift.Generator-398"><a href="#Redshift.Generator-398"><span class="linenos">398</span></a> +</span><span id="Redshift.Generator-399"><a href="#Redshift.Generator-399"><span class="linenos">399</span></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">datatype_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> </span></pre></div> @@ -1734,7 +2227,7 @@ Default: True</li> <div class="attr variable"> <span class="name">TYPE_MAPPING</span> = <input id="Redshift.Generator.TYPE_MAPPING-view-value" class="view-value-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> - <label class="view-value-button pdoc-button" for="Redshift.Generator.TYPE_MAPPING-view-value"></label><span class="default_value">{<Type.NCHAR: 'NCHAR'>: 'CHAR', <Type.NVARCHAR: 'NVARCHAR'>: 'VARCHAR', <Type.MEDIUMTEXT: 'MEDIUMTEXT'>: 'TEXT', <Type.LONGTEXT: 'LONGTEXT'>: 'TEXT', <Type.TINYTEXT: 'TINYTEXT'>: 'TEXT', <Type.MEDIUMBLOB: 'MEDIUMBLOB'>: 'BLOB', <Type.LONGBLOB: 'LONGBLOB'>: 'BLOB', <Type.TINYBLOB: 'TINYBLOB'>: 'BLOB', <Type.INET: 'INET'>: 'INET', <Type.TINYINT: 'TINYINT'>: 'SMALLINT', <Type.FLOAT: 'FLOAT'>: 'REAL', <Type.DOUBLE: 'DOUBLE'>: 'DOUBLE PRECISION', <Type.BINARY: 'BINARY'>: 'VARBYTE', <Type.VARBINARY: 'VARBINARY'>: 'VARBYTE', <Type.DATETIME: 'DATETIME'>: 'TIMESTAMP', <Type.INT: 'INT'>: 'INTEGER', <Type.TIMETZ: 'TIMETZ'>: 'TIME', <Type.TIMESTAMPTZ: 'TIMESTAMPTZ'>: 'TIMESTAMP'}</span> + <label class="view-value-button pdoc-button" for="Redshift.Generator.TYPE_MAPPING-view-value"></label><span class="default_value">{<Type.NCHAR: 'NCHAR'>: 'CHAR', <Type.NVARCHAR: 'NVARCHAR'>: 'VARCHAR', <Type.MEDIUMTEXT: 'MEDIUMTEXT'>: 'TEXT', <Type.LONGTEXT: 'LONGTEXT'>: 'TEXT', <Type.TINYTEXT: 'TINYTEXT'>: 'TEXT', <Type.MEDIUMBLOB: 'MEDIUMBLOB'>: 'BLOB', <Type.LONGBLOB: 'LONGBLOB'>: 'BLOB', <Type.TINYBLOB: 'TINYBLOB'>: 'BLOB', <Type.INET: 'INET'>: 'INET', <Type.ROWVERSION: 'ROWVERSION'>: 'VARBYTE', <Type.TINYINT: 'TINYINT'>: 'SMALLINT', <Type.FLOAT: 'FLOAT'>: 'REAL', <Type.DOUBLE: 'DOUBLE'>: 'DOUBLE PRECISION', <Type.BINARY: 'BINARY'>: 'VARBYTE', <Type.VARBINARY: 'VARBINARY'>: 'VARBYTE', <Type.DATETIME: 'DATETIME'>: 'TIMESTAMP', <Type.INT: 'INT'>: 'INTEGER', <Type.TIMETZ: 'TIMETZ'>: 'TIME', <Type.TIMESTAMPTZ: 'TIMESTAMPTZ'>: 'TIMESTAMP'}</span> </div> @@ -1759,7 +2252,8 @@ Default: True</li> <div id="Redshift.Generator.RESERVED_KEYWORDS" class="classattr"> <div class="attr variable"> <span class="name">RESERVED_KEYWORDS</span> = -<span class="default_value">{'type', 'snapshot'}</span> +<input id="Redshift.Generator.RESERVED_KEYWORDS-view-value" class="view-value-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1"> + <label class="view-value-button pdoc-button" for="Redshift.Generator.RESERVED_KEYWORDS-view-value"></label><span class="default_value">{'mostly32', 'null', 'deferrable', 'cross', 'both', 'globaldict64k', 'raw', 'grant', 'default', 'bytedict', 'do', 'blanksasnull', 'analyse', 'current_user', 'references', 'end', 'pivot', 'text255', 'top', 'asc', 'as', 'percent', 'text32k', 'limit', 'rejectlog', 'column', 'order', 'emptyasnull', 'lzo', 'restore', 'bzip2', 'offline', 'type', 'using', 'lun', 'on', 'cast', 'timestamp', 'verbose', 'new', 'only', 'snapshot', 'allowoverwrite', 'credentials', 'identity', 'ignore', 'partition', 'in', 'current_timestamp', 'group', 'recover', 'check', 'disable', 'some', 'between', 'intersect', 'offset', 'readratio', 'lzop', 'resort', 'system', 'then', 'truncatecolumns', 'aes256', 'collate', 'localtime', 'unnest', 'with', 'gzip', 'unpivot', 'natural', 'user', 'create', 'full', 'union', 'or', 'globaldict256', 'all', 'current_time', 'analyze', 'primary', 'where', 'deflate', 'old', 'off', 'encryption', 'aes128', 'authorization', 'select', 'mostly16', 'without', 'freeze', 'luns', 'table', 'true', 'binary', 'nulls', 'interval', 'any', 'current_date', 'left', 'else', 'encode', 'isnull', 'open', 'is', 'to', 'except', 'enable', 'distinct', 'explicit', 'from', 'like', 'minus', 'permissions', 'defrag', 'outer', 'and', 'for', 'delta', 'right', 'encrypt ', 'case', 'similar', 'delta32k', 'parallel', 'into', 'placing', 'backup', 'ilike', 'mostly8', 'initially', 'wallet', 'leading', 'foreign', 'oid', 'desc', 'trailing', 'array', 'notnull', 'constraint', 'respect', 'when', 'tag', 'not', 'having', 'az64', 'current_user_id', 'inner', 'false', 'tdes', 'join', 'localtimestamp', 'session_user', 'unique', 'overlaps', 'sysdate'}</span> </div> @@ -1779,17 +2273,17 @@ Default: True</li> </div> <a class="headerlink" href="#Redshift.Generator.unnest_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="Redshift.Generator.unnest_sql-198"><a href="#Redshift.Generator.unnest_sql-198"><span class="linenos">198</span></a> <span class="k">def</span> <span class="nf">unnest_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Unnest</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="Redshift.Generator.unnest_sql-199"><a href="#Redshift.Generator.unnest_sql-199"><span class="linenos">199</span></a> <span class="n">args</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">expressions</span> -</span><span id="Redshift.Generator.unnest_sql-200"><a href="#Redshift.Generator.unnest_sql-200"><span class="linenos">200</span></a> <span class="n">num_args</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> -</span><span id="Redshift.Generator.unnest_sql-201"><a href="#Redshift.Generator.unnest_sql-201"><span class="linenos">201</span></a> -</span><span id="Redshift.Generator.unnest_sql-202"><a href="#Redshift.Generator.unnest_sql-202"><span class="linenos">202</span></a> <span class="k">if</span> <span class="n">num_args</span> <span class="o">></span> <span class="mi">1</span><span class="p">:</span> -</span><span id="Redshift.Generator.unnest_sql-203"><a href="#Redshift.Generator.unnest_sql-203"><span class="linenos">203</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Unsupported number of arguments in UNNEST: </span><span class="si">{</span><span class="n">num_args</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> -</span><span id="Redshift.Generator.unnest_sql-204"><a href="#Redshift.Generator.unnest_sql-204"><span class="linenos">204</span></a> <span class="k">return</span> <span class="s2">""</span> -</span><span id="Redshift.Generator.unnest_sql-205"><a href="#Redshift.Generator.unnest_sql-205"><span class="linenos">205</span></a> -</span><span id="Redshift.Generator.unnest_sql-206"><a href="#Redshift.Generator.unnest_sql-206"><span class="linenos">206</span></a> <span class="n">arg</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span> -</span><span id="Redshift.Generator.unnest_sql-207"><a href="#Redshift.Generator.unnest_sql-207"><span class="linenos">207</span></a> <span class="n">alias</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">expressions</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"alias"</span><span class="p">),</span> <span class="n">key</span><span class="o">=</span><span class="s2">"columns"</span><span class="p">)</span> -</span><span id="Redshift.Generator.unnest_sql-208"><a href="#Redshift.Generator.unnest_sql-208"><span class="linenos">208</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">arg</span><span class="si">}</span><span class="s2"> AS </span><span class="si">{</span><span class="n">alias</span><span class="si">}</span><span class="s2">"</span> <span class="k">if</span> <span class="n">alias</span> <span class="k">else</span> <span class="n">arg</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="Redshift.Generator.unnest_sql-362"><a href="#Redshift.Generator.unnest_sql-362"><span class="linenos">362</span></a> <span class="k">def</span> <span class="nf">unnest_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Unnest</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="Redshift.Generator.unnest_sql-363"><a href="#Redshift.Generator.unnest_sql-363"><span class="linenos">363</span></a> <span class="n">args</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">expressions</span> +</span><span id="Redshift.Generator.unnest_sql-364"><a href="#Redshift.Generator.unnest_sql-364"><span class="linenos">364</span></a> <span class="n">num_args</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> +</span><span id="Redshift.Generator.unnest_sql-365"><a href="#Redshift.Generator.unnest_sql-365"><span class="linenos">365</span></a> +</span><span id="Redshift.Generator.unnest_sql-366"><a href="#Redshift.Generator.unnest_sql-366"><span class="linenos">366</span></a> <span class="k">if</span> <span class="n">num_args</span> <span class="o">></span> <span class="mi">1</span><span class="p">:</span> +</span><span id="Redshift.Generator.unnest_sql-367"><a href="#Redshift.Generator.unnest_sql-367"><span class="linenos">367</span></a> <span class="bp">self</span><span class="o">.</span><span class="n">unsupported</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Unsupported number of arguments in UNNEST: </span><span class="si">{</span><span class="n">num_args</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> +</span><span id="Redshift.Generator.unnest_sql-368"><a href="#Redshift.Generator.unnest_sql-368"><span class="linenos">368</span></a> <span class="k">return</span> <span class="s2">""</span> +</span><span id="Redshift.Generator.unnest_sql-369"><a href="#Redshift.Generator.unnest_sql-369"><span class="linenos">369</span></a> +</span><span id="Redshift.Generator.unnest_sql-370"><a href="#Redshift.Generator.unnest_sql-370"><span class="linenos">370</span></a> <span class="n">arg</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">seq_get</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span> +</span><span id="Redshift.Generator.unnest_sql-371"><a href="#Redshift.Generator.unnest_sql-371"><span class="linenos">371</span></a> <span class="n">alias</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">expressions</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"alias"</span><span class="p">),</span> <span class="n">key</span><span class="o">=</span><span class="s2">"columns"</span><span class="p">,</span> <span class="n">flat</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> +</span><span id="Redshift.Generator.unnest_sql-372"><a href="#Redshift.Generator.unnest_sql-372"><span class="linenos">372</span></a> <span class="k">return</span> <span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">arg</span><span class="si">}</span><span class="s2"> AS </span><span class="si">{</span><span class="n">alias</span><span class="si">}</span><span class="s2">"</span> <span class="k">if</span> <span class="n">alias</span> <span class="k">else</span> <span class="n">arg</span> </span></pre></div> @@ -1807,9 +2301,9 @@ Default: True</li> </div> <a class="headerlink" href="#Redshift.Generator.with_properties"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="Redshift.Generator.with_properties-210"><a href="#Redshift.Generator.with_properties-210"><span class="linenos">210</span></a> <span class="k">def</span> <span class="nf">with_properties</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">properties</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Properties</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="Redshift.Generator.with_properties-211"><a href="#Redshift.Generator.with_properties-211"><span class="linenos">211</span></a><span class="w"> </span><span class="sd">"""Redshift doesn't have `WITH` as part of their with_properties so we remove it"""</span> -</span><span id="Redshift.Generator.with_properties-212"><a href="#Redshift.Generator.with_properties-212"><span class="linenos">212</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">properties</span><span class="p">(</span><span class="n">properties</span><span class="p">,</span> <span class="n">prefix</span><span class="o">=</span><span class="s2">" "</span><span class="p">,</span> <span class="n">suffix</span><span class="o">=</span><span class="s2">""</span><span class="p">)</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="Redshift.Generator.with_properties-374"><a href="#Redshift.Generator.with_properties-374"><span class="linenos">374</span></a> <span class="k">def</span> <span class="nf">with_properties</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">properties</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Properties</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="Redshift.Generator.with_properties-375"><a href="#Redshift.Generator.with_properties-375"><span class="linenos">375</span></a><span class="w"> </span><span class="sd">"""Redshift doesn't have `WITH` as part of their with_properties so we remove it"""</span> +</span><span id="Redshift.Generator.with_properties-376"><a href="#Redshift.Generator.with_properties-376"><span class="linenos">376</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">properties</span><span class="p">(</span><span class="n">properties</span><span class="p">,</span> <span class="n">prefix</span><span class="o">=</span><span class="s2">" "</span><span class="p">,</span> <span class="n">suffix</span><span class="o">=</span><span class="s2">""</span><span class="p">)</span> </span></pre></div> @@ -1829,12 +2323,12 @@ Default: True</li> </div> <a class="headerlink" href="#Redshift.Generator.cast_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="Redshift.Generator.cast_sql-214"><a href="#Redshift.Generator.cast_sql-214"><span class="linenos">214</span></a> <span class="k">def</span> <span class="nf">cast_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Cast</span><span class="p">,</span> <span class="n">safe_prefix</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="Redshift.Generator.cast_sql-215"><a href="#Redshift.Generator.cast_sql-215"><span class="linenos">215</span></a> <span class="k">if</span> <span class="n">expression</span><span class="o">.</span><span class="n">is_type</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">JSON</span><span class="p">):</span> -</span><span id="Redshift.Generator.cast_sql-216"><a href="#Redshift.Generator.cast_sql-216"><span class="linenos">216</span></a> <span class="c1"># Redshift doesn't support a JSON type, so casting to it is treated as a noop</span> -</span><span id="Redshift.Generator.cast_sql-217"><a href="#Redshift.Generator.cast_sql-217"><span class="linenos">217</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="s2">"this"</span><span class="p">)</span> -</span><span id="Redshift.Generator.cast_sql-218"><a href="#Redshift.Generator.cast_sql-218"><span class="linenos">218</span></a> -</span><span id="Redshift.Generator.cast_sql-219"><a href="#Redshift.Generator.cast_sql-219"><span class="linenos">219</span></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">cast_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="n">safe_prefix</span><span class="o">=</span><span class="n">safe_prefix</span><span class="p">)</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="Redshift.Generator.cast_sql-378"><a href="#Redshift.Generator.cast_sql-378"><span class="linenos">378</span></a> <span class="k">def</span> <span class="nf">cast_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">Cast</span><span class="p">,</span> <span class="n">safe_prefix</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="Redshift.Generator.cast_sql-379"><a href="#Redshift.Generator.cast_sql-379"><span class="linenos">379</span></a> <span class="k">if</span> <span class="n">expression</span><span class="o">.</span><span class="n">is_type</span><span class="p">(</span><span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">JSON</span><span class="p">):</span> +</span><span id="Redshift.Generator.cast_sql-380"><a href="#Redshift.Generator.cast_sql-380"><span class="linenos">380</span></a> <span class="c1"># Redshift doesn't support a JSON type, so casting to it is treated as a noop</span> +</span><span id="Redshift.Generator.cast_sql-381"><a href="#Redshift.Generator.cast_sql-381"><span class="linenos">381</span></a> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">sql</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="s2">"this"</span><span class="p">)</span> +</span><span id="Redshift.Generator.cast_sql-382"><a href="#Redshift.Generator.cast_sql-382"><span class="linenos">382</span></a> +</span><span id="Redshift.Generator.cast_sql-383"><a href="#Redshift.Generator.cast_sql-383"><span class="linenos">383</span></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">cast_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">,</span> <span class="n">safe_prefix</span><span class="o">=</span><span class="n">safe_prefix</span><span class="p">)</span> </span></pre></div> @@ -1852,21 +2346,21 @@ Default: True</li> </div> <a class="headerlink" href="#Redshift.Generator.datatype_sql"></a> - <div class="pdoc-code codehilite"><pre><span></span><span id="Redshift.Generator.datatype_sql-221"><a href="#Redshift.Generator.datatype_sql-221"><span class="linenos">221</span></a> <span class="k">def</span> <span class="nf">datatype_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> -</span><span id="Redshift.Generator.datatype_sql-222"><a href="#Redshift.Generator.datatype_sql-222"><span class="linenos">222</span></a><span class="w"> </span><span class="sd">"""</span> -</span><span id="Redshift.Generator.datatype_sql-223"><a href="#Redshift.Generator.datatype_sql-223"><span class="linenos">223</span></a><span class="sd"> Redshift converts the `TEXT` data type to `VARCHAR(255)` by default when people more generally mean</span> -</span><span id="Redshift.Generator.datatype_sql-224"><a href="#Redshift.Generator.datatype_sql-224"><span class="linenos">224</span></a><span class="sd"> VARCHAR of max length which is `VARCHAR(max)` in Redshift. Therefore if we get a `TEXT` data type</span> -</span><span id="Redshift.Generator.datatype_sql-225"><a href="#Redshift.Generator.datatype_sql-225"><span class="linenos">225</span></a><span class="sd"> without precision we convert it to `VARCHAR(max)` and if it does have precision then we just convert</span> -</span><span id="Redshift.Generator.datatype_sql-226"><a href="#Redshift.Generator.datatype_sql-226"><span class="linenos">226</span></a><span class="sd"> `TEXT` to `VARCHAR`.</span> -</span><span id="Redshift.Generator.datatype_sql-227"><a href="#Redshift.Generator.datatype_sql-227"><span class="linenos">227</span></a><span class="sd"> """</span> -</span><span id="Redshift.Generator.datatype_sql-228"><a href="#Redshift.Generator.datatype_sql-228"><span class="linenos">228</span></a> <span class="k">if</span> <span class="n">expression</span><span class="o">.</span><span class="n">is_type</span><span class="p">(</span><span class="s2">"text"</span><span class="p">):</span> -</span><span id="Redshift.Generator.datatype_sql-229"><a href="#Redshift.Generator.datatype_sql-229"><span class="linenos">229</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"this"</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">VARCHAR</span><span class="p">)</span> -</span><span id="Redshift.Generator.datatype_sql-230"><a href="#Redshift.Generator.datatype_sql-230"><span class="linenos">230</span></a> <span class="n">precision</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"expressions"</span><span class="p">)</span> -</span><span id="Redshift.Generator.datatype_sql-231"><a href="#Redshift.Generator.datatype_sql-231"><span class="linenos">231</span></a> -</span><span id="Redshift.Generator.datatype_sql-232"><a href="#Redshift.Generator.datatype_sql-232"><span class="linenos">232</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">precision</span><span class="p">:</span> -</span><span id="Redshift.Generator.datatype_sql-233"><a href="#Redshift.Generator.datatype_sql-233"><span class="linenos">233</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">"expressions"</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">var</span><span class="p">(</span><span class="s2">"MAX"</span><span class="p">))</span> -</span><span id="Redshift.Generator.datatype_sql-234"><a href="#Redshift.Generator.datatype_sql-234"><span class="linenos">234</span></a> -</span><span id="Redshift.Generator.datatype_sql-235"><a href="#Redshift.Generator.datatype_sql-235"><span class="linenos">235</span></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">datatype_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> + <div class="pdoc-code codehilite"><pre><span></span><span id="Redshift.Generator.datatype_sql-385"><a href="#Redshift.Generator.datatype_sql-385"><span class="linenos">385</span></a> <span class="k">def</span> <span class="nf">datatype_sql</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">expression</span><span class="p">:</span> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span> +</span><span id="Redshift.Generator.datatype_sql-386"><a href="#Redshift.Generator.datatype_sql-386"><span class="linenos">386</span></a><span class="w"> </span><span class="sd">"""</span> +</span><span id="Redshift.Generator.datatype_sql-387"><a href="#Redshift.Generator.datatype_sql-387"><span class="linenos">387</span></a><span class="sd"> Redshift converts the `TEXT` data type to `VARCHAR(255)` by default when people more generally mean</span> +</span><span id="Redshift.Generator.datatype_sql-388"><a href="#Redshift.Generator.datatype_sql-388"><span class="linenos">388</span></a><span class="sd"> VARCHAR of max length which is `VARCHAR(max)` in Redshift. Therefore if we get a `TEXT` data type</span> +</span><span id="Redshift.Generator.datatype_sql-389"><a href="#Redshift.Generator.datatype_sql-389"><span class="linenos">389</span></a><span class="sd"> without precision we convert it to `VARCHAR(max)` and if it does have precision then we just convert</span> +</span><span id="Redshift.Generator.datatype_sql-390"><a href="#Redshift.Generator.datatype_sql-390"><span class="linenos">390</span></a><span class="sd"> `TEXT` to `VARCHAR`.</span> +</span><span id="Redshift.Generator.datatype_sql-391"><a href="#Redshift.Generator.datatype_sql-391"><span class="linenos">391</span></a><span class="sd"> """</span> +</span><span id="Redshift.Generator.datatype_sql-392"><a href="#Redshift.Generator.datatype_sql-392"><span class="linenos">392</span></a> <span class="k">if</span> <span class="n">expression</span><span class="o">.</span><span class="n">is_type</span><span class="p">(</span><span class="s2">"text"</span><span class="p">):</span> +</span><span id="Redshift.Generator.datatype_sql-393"><a href="#Redshift.Generator.datatype_sql-393"><span class="linenos">393</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"this"</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">DataType</span><span class="o">.</span><span class="n">Type</span><span class="o">.</span><span class="n">VARCHAR</span><span class="p">)</span> +</span><span id="Redshift.Generator.datatype_sql-394"><a href="#Redshift.Generator.datatype_sql-394"><span class="linenos">394</span></a> <span class="n">precision</span> <span class="o">=</span> <span class="n">expression</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"expressions"</span><span class="p">)</span> +</span><span id="Redshift.Generator.datatype_sql-395"><a href="#Redshift.Generator.datatype_sql-395"><span class="linenos">395</span></a> +</span><span id="Redshift.Generator.datatype_sql-396"><a href="#Redshift.Generator.datatype_sql-396"><span class="linenos">396</span></a> <span class="k">if</span> <span class="ow">not</span> <span class="n">precision</span><span class="p">:</span> +</span><span id="Redshift.Generator.datatype_sql-397"><a href="#Redshift.Generator.datatype_sql-397"><span class="linenos">397</span></a> <span class="n">expression</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">"expressions"</span><span class="p">,</span> <span class="n">exp</span><span class="o">.</span><span class="n">var</span><span class="p">(</span><span class="s2">"MAX"</span><span class="p">))</span> +</span><span id="Redshift.Generator.datatype_sql-398"><a href="#Redshift.Generator.datatype_sql-398"><span class="linenos">398</span></a> +</span><span id="Redshift.Generator.datatype_sql-399"><a href="#Redshift.Generator.datatype_sql-399"><span class="linenos">399</span></a> <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">datatype_sql</span><span class="p">(</span><span class="n">expression</span><span class="p">)</span> </span></pre></div> @@ -1986,6 +2480,7 @@ without precision we convert it to <code>VARCHAR(max)</code> and if it does have <dd id="Redshift.Generator.uncache_sql" class="function"><a href="../generator.html#Generator.uncache_sql">uncache_sql</a></dd> <dd id="Redshift.Generator.cache_sql" class="function"><a href="../generator.html#Generator.cache_sql">cache_sql</a></dd> <dd id="Redshift.Generator.characterset_sql" class="function"><a href="../generator.html#Generator.characterset_sql">characterset_sql</a></dd> + <dd id="Redshift.Generator.column_parts" class="function"><a href="../generator.html#Generator.column_parts">column_parts</a></dd> <dd id="Redshift.Generator.column_sql" class="function"><a href="../generator.html#Generator.column_sql">column_sql</a></dd> <dd id="Redshift.Generator.columnposition_sql" class="function"><a href="../generator.html#Generator.columnposition_sql">columnposition_sql</a></dd> <dd id="Redshift.Generator.columndef_sql" class="function"><a href="../generator.html#Generator.columndef_sql">columndef_sql</a></dd> @@ -2234,7 +2729,7 @@ without precision we convert it to <code>VARCHAR(max)</code> and if it does have <dd id="Redshift.Generator.function_fallback_sql" class="function"><a href="../generator.html#Generator.function_fallback_sql">function_fallback_sql</a></dd> <dd id="Redshift.Generator.func" class="function"><a href="../generator.html#Generator.func">func</a></dd> <dd id="Redshift.Generator.format_args" class="function"><a href="../generator.html#Generator.format_args">format_args</a></dd> - <dd id="Redshift.Generator.text_width" class="function"><a href="../generator.html#Generator.text_width">text_width</a></dd> + <dd id="Redshift.Generator.too_wide" class="function"><a href="../generator.html#Generator.too_wide">too_wide</a></dd> <dd id="Redshift.Generator.format_time" class="function"><a href="../generator.html#Generator.format_time">format_time</a></dd> <dd id="Redshift.Generator.expressions" class="function"><a href="../generator.html#Generator.expressions">expressions</a></dd> <dd id="Redshift.Generator.op_expressions" class="function"><a href="../generator.html#Generator.op_expressions">op_expressions</a></dd> |