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;
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.
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.
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.
The PostgreSQL BETWEEN condition will return the records where expression is within the range of value1 and value2 (inclusive).
SELECT *
FROM generate_series(1, 6) num
https://www.postgresql.org/docs/current/functions-srf.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With