sqllist-comprehensionsqlanywhere

How to generate a list of number in SQL as it was a list of comprehension?


In my case, using sql anywhere (sybase).

Something similar to haskell. [1..100].

I don't know how to generate a random simple list of 1 up to 100.

I only could do it doing:

select 1
union 
select 2
union
select 3

Google did not provide any sample, I suspect this feature does not exist.


Solution

  • SQL Anywhere contains an sa_rowgenerator stored procedure, which can be used for this purpose. For example:

    select row_num from sa_rowgenerator( 1, 100 )
    

    returns a result set of 100 rows from 1 to 100 inclusive. A link to the documentation (for version 12.0.1) is here.

    Disclaimer: I work for SAP/Sybase in the SQL Anywhere engineering.