Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make a range in postgres

How can I make a range in a select in PostgreSQL? I'd like to have this result:

num
---
1
2
3
4
5
6

From a query like:

SELECT range(1,6) AS num;
like image 709
Yuri Kaszubowski Lopes Avatar asked Mar 25 '10 13:03

Yuri Kaszubowski Lopes


People also ask

What is range in PostgreSQL?

Range types are a unique feature of PostgreSQL, managing two dimensions of data in a single column, and allowing advanced processing. The main example is the daterange data type, which stores as a single value a lower and an upper bound of the range as a single value.

How do I create an interval in PostgreSQL?

In PostgreSQL, the make_interval() function creates an interval from years, months, weeks, days, hours, minutes and seconds fields. You provide the years, months, weeks, days, hours, minutes and/or seconds fields, and it will return an interval in the interval data type.

What is $$ in Postgres?

In PostgreSQL, the dollar-quoted string constants ($$) is used in user-defined functions and stored procedures. In PostgreSQL, you use single quotes for a string constant like this: select 'String constant'; When a string constant contains a single quote ('), you need to escape it by doubling up the single quote.

Is between inclusive in PostgreSQL?

The PostgreSQL BETWEEN condition will return the records where expression is within the range of value1 and value2 (inclusive).


1 Answers

SELECT  *
FROM    generate_series(1, 6) num

https://www.postgresql.org/docs/current/functions-srf.html

like image 179
Quassnoi Avatar answered Oct 09 '22 20:10

Quassnoi