Sha256: f743c188a2483452342cd4e4ff4427452451a6f4d2a9e02c1cfcb96645d025cd

Contents?: true

Size: 504 Bytes

Versions: 9

Compression:

Stored size: 504 Bytes

Contents

WITH RECURSIVE t AS (
  SELECT MIN(<%= @column_name %>) AS <%= @column_name %>
  FROM <%= @table_name %>
  UNION ALL
  SELECT (
    SELECT MIN(<%= @column_name %>) FROM <%= @table_name %>
    WHERE <%= @column_name %> > t.<%= @column_name %>)
  FROM t WHERE t.<%= @column_name %> IS NOT NULL
)
SELECT <%= @column_name %> FROM t WHERE <%= @column_name %> IS NOT NULL
<% if @with_nulls %>
  UNION ALL
  SELECT NULL WHERE EXISTS(SELECT 1 FROM <%= @table_name %> WHERE <%= @column_name %> IS NULL)
<% end %>

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
sql_query-0.7.4 examples/distinct_values.sql.erb
sql_query-0.7.3 examples/distinct_values.sql.erb
sql_query-0.7.2 examples/distinct_values.sql.erb
sql_query-0.7.1 examples/distinct_values.sql.erb
sql_query-0.7.0 examples/distinct_values.sql.erb
sql_query-0.6.0 examples/distinct_values.sql.erb
sql_query-0.5.0 examples/distinct_values.sql.erb
sql_query-0.4.0 examples/distinct_values.sql.erb
sql_query-0.3.0 examples/distinct_values.sql.erb