Skip to main content

Send feedback

Tell us what works and what could be better. We read every submission.

Send feedback

Tell us what works and what could be better. We read every submission.

A

adewes

@adewes·20 public vizzes

Loading thumbnail…

Sometimes you just need an SQL table filled with some natural numbers. Here's a simple & brute-force solution that will work on ANY SQL dialect. It returns a table with an arbitrary number of natural numbers, provided this number is equal to 10.000... I used this on ExaSOL, where most Oracle / MSSQL magic does not work.

This example shows a SQL table named `natural_numbers` containing a single column `n` with integer values. The brute-force solution generates a sequence of natural numbers from 1 to 10000 by explicitly listing every value in a single `INSERT INTO` statement, making it compatible with any SQL dialect, including Exasol, where common alternatives like Oracle's `CONNECT BY` or MSSQL's `WITH` recursion may not work. The table is created with a simple `CREATE TABLE` statement followed by an exhaustive `VALUES` list, providing a straightforward, if verbose, method for generating a range of natural numbers without relying on dialect-specific features. The visualization highlights the impracticality of this approach for large ranges, while demonstrating a universal fallback technique.**Title:** Brute-Force Natural Numbers Table for Any SQL Dialect **Description:** This example demonstrates a remarkably simple, albeit verbose, SQL approach to generating a table of natural numbers from 1 to 10,000. Instead of relying on dialect-specific functions or recursive CTEs—which often fail on platforms like ExaSOL—the author manually constructs the table using a single `INSERT` statement with 10,000 explicit value tuples. The result is a portable, dependency-free way to create a numbers table, though it requires copying a very long list of values. A humorous take on a common developer need, this gist highlights the trade-off between universal compatibility and brute-force practicality. **Files:** - `natural_numbers.sql` — contains the full `CREATE TABLE` and `INSERT` statements to generate the sequence.This example from adewes showcases a delightfully pragmatic SQL workaround: generating a sequence of natural numbers in ExaSOL, where common recursive or procedural methods aren't available. The `natural_numbers.sql` file uses a purely brute-force approach, explicitly inserting values from 1 to 10,000 with a single `INSERT` statement. While verbose, this solution is guaranteed to run on virtually any SQL dialect, making it a useful fallback when more elegant methods fail. The visualization gallery entry would emphasize this as a humorous yet functional illustration of SQL portability constraints and creative problem-solving—a "sometimes you just need" workaround that trades elegance for universal compatibility.

Aug 23, 2013