Skip site navigation (1) Skip section navigation (2)

RE: Iterations in a SELECT

From: "Robby Slaughter" <webmaster(at)robbyslaughter(dot)com>
To: "Scott Muir" <wsmuir(at)islandnet(dot)com>, <pgsql-novice(at)postgresql(dot)org>
Subject: RE: Iterations in a SELECT
Date: 2001-07-18 02:38:54
Message-ID: EPEHLKLEHAHLONFOKNHNCEPLDCAA.webmaster@robbyslaughter.com (view raw or flat)
Thread:
Lists: pgsql-novice
Scott,

>I'm trying to put together a select where a list dates is compared to a
>period to identify dates which aren't in the list...

Sounds like you are trying to find out what values are not in a list of
other values.
Here's my example which you can adapt (if it's what you're trying to do).
Two tables,
test and test2, each with an integer column called val and val2
respectively:

select * from test;
  val
  ---
   1
   2
   3
   5
   6
   3

select * from test2;
  val2
  ----
   3
   4

Then you do a quick subselect and...

   select * from test where val not in ((select val2 from test2));

   Result is:
     val
    -----
      1
      2
      5
      6

Is that what you're hoping to do?

I can't think of anyway to do a select and genrate a list from x to y.
Wow, that's a great one!

Hope this helps,

-Robby





I could just create a list of days in a table (like 20 years worth) and then
compare it, but I'm wondering if there is a trick where one could get
results like this

select (for i := 1 to 5) as number;

or

select i as number from for(i,1,5);

and get something like

number
------
1
2
3
4
5

Any suggestions?
Thanks
Scott.


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

http://www.postgresql.org/users-lounge/docs/faq.html


In response to

Responses

pgsql-novice by date

Next:From: Scott MuirDate: 2001-07-18 02:49:36
Subject: RE: Iterations in a SELECT
Previous:From: Scott MuirDate: 2001-07-18 02:07:33
Subject: Iterations in a SELECT

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group