pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
sub selects
4+ messages / 4 participants
[nested] [flat]

* sub selects
@ 2002-01-23 18:07 Jodi Kanter <jkanter@virginia.edu>
  2002-01-23 19:05 ` Re: sub selects Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 4+ messages in thread

From: Jodi Kanter @ 2002-01-23 18:07 UTC (permalink / raw)
  To: pgsql-admin

I hope this is not too confusing..... I left my column names and table names as is but you should get the idea...

I am doing the following:

select usf_fk from am_spots where ams_pk in ((select min(ams_pk) from am_spots where am_fk>135),(select max(ams_pk) from am_spots where am_fk>135);

It works fine but I originally tried this:

select usf_fk from am_spots where ams_pk in (select min(ams_pk), max(ams_pk) from am_spots where am_fk>135);

I received an error saying that my subselect has too many fields. Did I use the wrong syntax or is it just a postgres rule that you can't pull more than one field back in a sub select?

Also, I need to now embed this entire select statement into another select statement such as:

select spot_identifier from al_spots where als_pk in (SELECT STATMENT ABOVE)

Can I do this? Is there any easier way that I cannot see? Any suggestions would be appreciated.
Thanks
Jodi

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: sub selects
  2002-01-23 18:07 sub selects Jodi Kanter <jkanter@virginia.edu>
@ 2002-01-23 19:05 ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 4+ messages in thread

From: Tom Lane @ 2002-01-23 19:05 UTC (permalink / raw)
  To: Jodi Kanter <jkanter@virginia.edu>; +Cc: pgsql-admin

Jodi Kanter <jkanter@virginia.edu> writes:
> select usf_fk from am_spots where ams_pk in (select min(ams_pk), max(ams_pk=
> ) from am_spots where am_fk>135);

> I received an error saying that my subselect has too many fields. Did I use=
>  the wrong syntax or is it just a postgres rule that you can't pull more th=
> an one field back in a sub select?

It's an SQL92 rule: if you are doing "foo IN (subselect)" then the
subselect must return one column to compare to foo.  You are confusing
this case with "foo IN (scalar expression, scalar expression, ...)"
which is actually quite a different construct.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Sub SELECTS
@ 2002-09-25 14:27 Waruna Geekiyanage <waruna@nirmani.com>
  2002-09-27 16:15 ` Re: Sub SELECTS Stephan Szabo <sszabo@megazone23.bigpanda.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Waruna Geekiyanage @ 2002-09-25 14:27 UTC (permalink / raw)
  To: pgsql-admin

I have a select query with 2 sub selects.
When I run that query CPU usage goes to 98% for postgres.
Does sub selects eat more resources and slower the queries?
Is there any alternatives to sub selects?

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Sub SELECTS
  2002-09-25 14:27 Sub SELECTS Waruna Geekiyanage <waruna@nirmani.com>
@ 2002-09-27 16:15 ` Stephan Szabo <sszabo@megazone23.bigpanda.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Stephan Szabo @ 2002-09-27 16:15 UTC (permalink / raw)
  To: Waruna Geekiyanage <waruna@nirmani.com>; +Cc: pgsql-admin


On Wed, 25 Sep 2002, Waruna Geekiyanage wrote:

> I have a select query with 2 sub selects.
> When I run that query CPU usage goes to 98% for postgres.
> Does sub selects eat more resources and slower the queries?
> Is there any alternatives to sub selects?

It depends on what you're doing.  The query and table schema
would be useful.





^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2002-09-27 16:15 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-01-23 18:07 sub selects Jodi Kanter <jkanter@virginia.edu>
2002-01-23 19:05 ` Tom Lane <tgl@sss.pgh.pa.us>
2002-09-25 14:27 Sub SELECTS Waruna Geekiyanage <waruna@nirmani.com>
2002-09-27 16:15 ` Re: Sub SELECTS Stephan Szabo <sszabo@megazone23.bigpanda.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox