473,386 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Integer ranges in PostgreSQL

Does exist a syntax in PostgreSQL for integer (INT) number ranges?

It could be useful for queries like
"SELECT * FROM table WHERE id IN (range from 1 to 20)"

Thank you!
Marco
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 22 '05 #1
2 3240
Marco Lazzeri wrote:
Does exist a syntax in PostgreSQL for integer (INT) number ranges?

It could be useful for queries like
"SELECT * FROM table WHERE id IN (range from 1 to 20)"


I believe you're looking for BETWEEN:
SELECT * FROM table WHERE id BETWEEN 1 AND 20;

That is standard SQL and not specific to PostgreSQL

Greg

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 22 '05 #2

On Fri, 16 Jan 2004, Marco Lazzeri wrote:
Does exist a syntax in PostgreSQL for integer (INT) number ranges?

It could be useful for queries like
"SELECT * FROM table WHERE id IN (range from 1 to 20)"


As already sent, BETWEEN will do this for you already for this kind
of use. However, if you need it for a join or something, you could
also write a set returning function that returns you the set of numbers.

Maybe something like the not really tested:

create or replace function range(int, int, int) returns setof int as '
declare
i int;
begin
i := $1;
while (i <= $2) loop
return next i;
i := i + $3;
end loop;
return;
end;' language 'plpgsql';
select * from range(1,20,1);

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Shailesh Humbad | last post by:
I wrote a short page as a quick reference to c++ integer data types. Any feedback welcome: http://www.somacon.com/blog/page11.php
2
by: Ben O'Steen | last post by:
Scenario: ========= Using PyGame in particular, I am trying to write an application that will run a scripted timeline of events, eg at 5.5 seconds, play xxx.mp3 and put the image of a ball on...
6
by: Ying Lu | last post by:
Hi, I have a question about alter a column's type in a postgreSQL table. For example, I have 10, 000 records in a table name "test", I'd like to change column "machineID" type from integer to...
21
by: Frederick Gotham | last post by:
I set about trying to find a portable way to set the value of UCHAR_MAX. At first, I thought the following would work: #define UCHAR_MAX ~( (unsigned char)0 ) However, it didn't work for me....
40
by: Robert Seacord | last post by:
The CERT/CC has released a beta version of a secure integer library for the C Programming Language. The library is available for download from the CERT/CC Secure Coding Initiative web page at:...
232
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
130
by: euler70 | last post by:
char and unsigned char have specific purposes: char is useful for representing characters of the basic execution character set and unsigned char is useful for representing the values of individual...
88
by: santosh | last post by:
Hello all, In K&R2 one exercise asks the reader to compute and print the limits for the basic integer types. This is trivial for unsigned types. But is it possible for signed types without...
1
by: clreed87 | last post by:
I am trying to develop a sales report coming off our postgresql server and am rumming into some problems. Basically I just want to group by the customer name and view a customers orders and sales...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.