[SQL] Login information in system tables

2004-03-08 Thread Daniel Doorduin
Hi,

I was wondering if it is possible to query the sytem tables to get an
overview of user logins in psql. I've searched the documentation but I can't
find a system table that stores login information, but I might have
overlooked something...

With regards,

Daniel Doorduin


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

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


Re: [SQL] Login information in system tables

2004-03-08 Thread Radu-Adrian Popescu
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Daniel Doorduin wrote:

| Hi,
|
| I was wondering if it is possible to query the sytem tables to get
| an overview of user logins in psql.
Check out the pg_user table.

Regards,
- --
Radu-Adrian Popescu
CSA, DBA, Developer
Aldratech Ltd.
+40213212243
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFATGvDVZmwYru5w6ERAlJ7AJ9RLaEkboJ+YNuwEcmur/OXnhlB2ACgoXum
GEy4Lun4Gtmi3FJkWFby5T8=
=4JRJ
-END PGP SIGNATURE-


---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster


[SQL] Simple SQL question

2004-03-08 Thread Daniel Henrique Alves Lima
   Hello, everybody.

   I've a simple question about SQL usage but i don't know even i can 
formulate this question. Well, i will try :
   I've a teacher_course table with columns cd_course, cd_teacher => 
teacher_course(cd_teacher,cd_course) and i've a set of pairs that 
contains the values for these columns, like {(1,2),(23,11),(563,341),...}.
   Is there a way to build a query to select rows that matchs these 
pairs ? Like a "in" extension (or something else) :

select * from teacher_course where (cd_course,cd_teacher) in 
((1,2),(23,11),(563,341))

?

   I would appreciate any help. Thanks in advance.

---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
   (send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])


[SQL] Functional index and string concatenation

2004-03-08 Thread Daniel Henrique Alves Lima
   Is there a way to create a "functional index" over a string 
concatenation of two columns ?

   Thanks.

---(end of broadcast)---
TIP 6: Have you searched our list archives?
  http://archives.postgresql.org


Re: [SQL] Functional index and string concatenation

2004-03-08 Thread Edmund Bacon
On Mon, 2004-03-08 at 08:19, Daniel Henrique Alves Lima wrote:
> Is there a way to create a "functional index" over a string 
> concatenation of two columns ?
> 
> Thanks.
> 
Like this?

test=# create table strtable (x int, str1 text, str2 text);
CREATE TABLE
test=# create index str_idx on strtable( textcat(str1, str2) );
CREATE INDEX
test=# 

-- 
Edmund Bacon <[EMAIL PROTECTED]>


---(end of broadcast)---
TIP 7: don't forget to increase your free space map settings


Re: [SQL] Functional index and string concatenation

2004-03-08 Thread Tom Lane
Edmund Bacon <[EMAIL PROTECTED]> writes:
> On Mon, 2004-03-08 at 08:19, Daniel Henrique Alves Lima wrote:
>> Is there a way to create a "functional index" over a string 
>> concatenation of two columns ?

> test=# create index str_idx on strtable( textcat(str1, str2) );

As of 7.4 you can do it more directly:

create index str_idx on strtable( (str1 || str2) );

The disadvantage of the textcat() locution is that the planner will only
match it up to queries that also say textcat().

regards, tom lane

---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


[SQL] Trying to make efficient "all vendors who can provide all items"

2004-03-08 Thread terry
My mind is drawing a blank.  Please consider:
TABLE 1: items: list of items in catalog
item_id  |  item_description

TABLE 2: vendors: list of vendors who provide 1 or more items
vendor_id |  vendor_name

TABLE 3: item_vendors: record existence indicates vendor can provide item
item_id  |  vendor_id


QUESTION:
I have a list of say 5 items, and I want to find all vendors who can provide
ALL 5 items

Solution 1:
SELECT vendor_id
FROM vendors
WHERE EXISTS (SELECT 1 FROM item_vendors WHERE vendors.vendor_id =
item_vendors.vendor_id AND item_id = 'item_1')
  AND EXISTS (SELECT 1 FROM item_vendors WHERE vendors.vendor_id =
item_vendors.vendor_id AND item_id = 'item_2')
  AND EXISTS (SELECT 1 FROM item_vendors WHERE vendors.vendor_id =
item_vendors.vendor_id AND item_id = 'item_3')
  AND EXISTS (SELECT 1 FROM item_vendors WHERE vendors.vendor_id =
item_vendors.vendor_id AND item_id = 'item_4')
  AND EXISTS (SELECT 1 FROM item_vendors WHERE vendors.vendor_id =
item_vendors.vendor_id AND item_id = 'item_5')

Solution 2:
SELECT vendors.vendor_id
FROM vendors, items AS item_1, items AS item_2, items AS item_3, items AS
item_4, items AS item_5
WHERE items_1.vendor_id = vendors.vendor_id AND items_1.item_id = 'item_1'
  AND items_2.vendor_id = vendors.vendor_id AND items_2.item_id = 'item_2'
  AND items_3.vendor_id = vendors.vendor_id AND items_2.item_id = 'item_3'
  AND items_4.vendor_id = vendors.vendor_id AND items_2.item_id = 'item_4'
  AND items_5.vendor_id = vendors.vendor_id AND items_2.item_id = 'item_5'

Yep, both my solutions are pretty ugly, especially in situations where my
list of items that need to be provided grow large.

There must be a better way.  Can anyone help me with this?

Thanks



Terry Fielder
Manager Software Development and Deployment
Great Gulf Homes / Ashton Woods Homes
[EMAIL PROTECTED]
Fax: (416) 441-9085


---(end of broadcast)---
TIP 9: the planner will ignore your desire to choose an index scan if your
  joining column's datatypes do not match


Re: [SQL] Functional index and string concatenation

2004-03-08 Thread Richard Huxton
On Monday 08 March 2004 16:02, Daniel Henrique Alves Lima wrote:
> Yes, i was searching for the name of equivalent function to "||"
> operator...
>
> Now, i've got a new problem: I need to concat three values (two
> column values and a sepator constant). But from documentation: " The
> function in the index definition can take more than one argument, but
> they must be table columns, not constants" and "there cannot be
> multicolumn indexes that contain function calls".
>
> Maybe i should to create a new pgsql function.

Yes - a wrapper function is the standard solution. I don't think you need to 
do this in 7.4 though.

-- 
  Richard Huxton
  Archonet Ltd

---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
  subscribe-nomail command to [EMAIL PROTECTED] so that your
  message can get through to the mailing list cleanly


Re: [SQL] Trying to make efficient "all vendors who can provide all items"

2004-03-08 Thread terry
Thanks for your response.

If I understand your proposal, it is a way of getting vendors who can
provide me with all the items in the items table.

But the situation I have is items table could have 100k items, and I want
all vendors who can provide a specific list of say 20 items.

Do I misunderstand your query?

Terry Fielder
Manager Software Development and Deployment
Great Gulf Homes / Ashton Woods Homes
[EMAIL PROTECTED]
Fax: (416) 441-9085


> -Original Message-
> From: Jeremy Semeiks [mailto:[EMAIL PROTECTED]
> Sent: Monday, March 08, 2004 2:07 PM
> To: [EMAIL PROTECTED]
> Cc: [EMAIL PROTECTED]
> Subject: Re: [SQL] Trying to make efficient "all vendors who
> can provide
> all items"
>
>
> On Mon, Mar 08, 2004 at 11:02:13AM -0500,
> [EMAIL PROTECTED] wrote:
> > My mind is drawing a blank.  Please consider:
> > TABLE 1: items: list of items in catalog
> > item_id  |  item_description
> >
> > TABLE 2: vendors: list of vendors who provide 1 or more items
> > vendor_id |  vendor_name
> >
> > TABLE 3: item_vendors: record existence indicates vendor
> can provide item
> > item_id  |  vendor_id
> >
> >
> > QUESTION:
> > I have a list of say 5 items, and I want to find all
> vendors who can provide
> > ALL 5 items
> [...]
> > Yep, both my solutions are pretty ugly, especially in
> situations where my
> > list of items that need to be provided grow large.
> >
> > There must be a better way.  Can anyone help me with this?
>
> You could use some subselects:
>
> select vendor_id from
> (select vendor_id, count(*) as ct from item_vendors group by
> vendor_id) vict
> where ct = (select count(*) from items);
>
> I haven't tested this.
>
> - Jeremy
>


---(end of broadcast)---
TIP 8: explain analyze is your friend


Re: [SQL] Trying to make efficient "all vendors who can provide all items"

2004-03-08 Thread Matt Chatterley
Hmm. My PGSQL knowledge is rusty, so this may be slightly microsoftified..

How about just:

SELECT V.VendorID, V.VendorName, COUNT(IV.ItemID)
FROM Vendor V
INNER JOIN Item_Vendor IV ON IV.VendorID = V.VendorID AND IV.ItemID IN (1,
2, 3, 4, 5)
GROUP BY V.VendorID, V.VendorName
HAVING COUNT(IV.ItemID) = 5

Alternatively, you could repeatedly inner join onto Item_vendor, but this is
no 'nicer' than either of your previous solutions:

SELECT V.VendorID, V.VendorName
FROM Vendor V
INNER JOIN Item_Vendor IV1 ON IV1.VendorID = V.VendorID AND IV1.ItemID = 1
INNER JOIN Item_Vendor IV2 ON IV2.VendorID = V.VendorID AND IV2.ItemID = 2
INNER JOIN Item_Vendor IV3 ON IV3.VendorID = V.VendorID AND IV3.ItemID = 3
INNER JOIN Item_Vendor IV4 ON IV4.VendorID = V.VendorID AND IV4.ItemID = 4
INNER JOIN Item_Vendor IV5 ON IV5.VendorID = V.VendorID AND IV5.ItemID = 5


Does that help at all, or am I barking up the wrong tree? :)


Regards,


Matt.

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of [EMAIL PROTECTED]
Sent: 08 March 2004 19:23
To: 'Jeremy Semeiks'
Cc: [EMAIL PROTECTED]
Subject: Re: [SQL] Trying to make efficient "all vendors who can provide all
items"

Thanks for your response.

If I understand your proposal, it is a way of getting vendors who can
provide me with all the items in the items table.

But the situation I have is items table could have 100k items, and I want
all vendors who can provide a specific list of say 20 items.

Do I misunderstand your query?

Terry Fielder
Manager Software Development and Deployment
Great Gulf Homes / Ashton Woods Homes
[EMAIL PROTECTED]
Fax: (416) 441-9085


> -Original Message-
> From: Jeremy Semeiks [mailto:[EMAIL PROTECTED]
> Sent: Monday, March 08, 2004 2:07 PM
> To: [EMAIL PROTECTED]
> Cc: [EMAIL PROTECTED]
> Subject: Re: [SQL] Trying to make efficient "all vendors who
> can provide
> all items"
>
>
> On Mon, Mar 08, 2004 at 11:02:13AM -0500,
> [EMAIL PROTECTED] wrote:
> > My mind is drawing a blank.  Please consider:
> > TABLE 1: items: list of items in catalog
> > item_id  |  item_description
> >
> > TABLE 2: vendors: list of vendors who provide 1 or more items
> > vendor_id |  vendor_name
> >
> > TABLE 3: item_vendors: record existence indicates vendor
> can provide item
> > item_id  |  vendor_id
> >
> >
> > QUESTION:
> > I have a list of say 5 items, and I want to find all
> vendors who can provide
> > ALL 5 items
> [...]
> > Yep, both my solutions are pretty ugly, especially in
> situations where my
> > list of items that need to be provided grow large.
> >
> > There must be a better way.  Can anyone help me with this?
>
> You could use some subselects:
>
> select vendor_id from
> (select vendor_id, count(*) as ct from item_vendors group by
> vendor_id) vict
> where ct = (select count(*) from items);
>
> I haven't tested this.
>
> - Jeremy
>


---(end of broadcast)---
TIP 8: explain analyze is your friend



---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


Re: [SQL] Trying to make efficient "all vendors who can provide all items"

2004-03-08 Thread terry
That's pretty nifty code.  It certainly looks nicer, and looks like it would
work providing vendor_id&item_id is the pk of item_vendors (and it is).  I
will let you know if it runs any faster...

Thanks

Terry Fielder
Manager Software Development and Deployment
Great Gulf Homes / Ashton Woods Homes
[EMAIL PROTECTED]
Fax: (416) 441-9085


> -Original Message-
> From: Matt Chatterley [mailto:[EMAIL PROTECTED]
> Sent: Monday, March 08, 2004 3:41 PM
> To: [EMAIL PROTECTED]
> Cc: [EMAIL PROTECTED]
> Subject: RE: [SQL] Trying to make efficient "all vendors who
> can provide
> all items"
>
>
> Hmm. My PGSQL knowledge is rusty, so this may be slightly
> microsoftified..
>
> How about just:
>
> SELECT V.VendorID, V.VendorName, COUNT(IV.ItemID)
> FROM Vendor V
> INNER JOIN Item_Vendor IV ON IV.VendorID = V.VendorID AND
> IV.ItemID IN (1,
> 2, 3, 4, 5)
> GROUP BY V.VendorID, V.VendorName
> HAVING COUNT(IV.ItemID) = 5
>


---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])


Re: [SQL] Trying to make efficient "all vendors who can provide all items"

2004-03-08 Thread Christopher Browne
Clinging to sanity, [EMAIL PROTECTED] mumbled into her beard:
> My mind is drawing a blank.  Please consider:
> TABLE 1: items: list of items in catalog
> item_id  |  item_description
>
> TABLE 2: vendors: list of vendors who provide 1 or more items
> vendor_id |  vendor_name
>
> TABLE 3: item_vendors: record existence indicates vendor can provide item
> item_id  |  vendor_id
>
>
> QUESTION:
> I have a list of say 5 items, and I want to find all vendors who can provide
> ALL 5 items
>
> Solution 1:
> SELECT vendor_id
> FROM vendors
> WHERE EXISTS (SELECT 1 FROM item_vendors WHERE vendors.vendor_id =
> item_vendors.vendor_id AND item_id = 'item_1')
>   AND EXISTS (SELECT 1 FROM item_vendors WHERE vendors.vendor_id =
> item_vendors.vendor_id AND item_id = 'item_2')
>   AND EXISTS (SELECT 1 FROM item_vendors WHERE vendors.vendor_id =
> item_vendors.vendor_id AND item_id = 'item_3')
>   AND EXISTS (SELECT 1 FROM item_vendors WHERE vendors.vendor_id =
> item_vendors.vendor_id AND item_id = 'item_4')
>   AND EXISTS (SELECT 1 FROM item_vendors WHERE vendors.vendor_id =
> item_vendors.vendor_id AND item_id = 'item_5')
>
> Solution 2:
> SELECT vendors.vendor_id
> FROM vendors, items AS item_1, items AS item_2, items AS item_3, items AS
> item_4, items AS item_5
> WHERE items_1.vendor_id = vendors.vendor_id AND items_1.item_id = 'item_1'
>   AND items_2.vendor_id = vendors.vendor_id AND items_2.item_id = 'item_2'
>   AND items_3.vendor_id = vendors.vendor_id AND items_2.item_id = 'item_3'
>   AND items_4.vendor_id = vendors.vendor_id AND items_2.item_id = 'item_4'
>   AND items_5.vendor_id = vendors.vendor_id AND items_2.item_id = 'item_5'
>
> Yep, both my solutions are pretty ugly, especially in situations where my
> list of items that need to be provided grow large.
>
> There must be a better way.  Can anyone help me with this?

I'd suggest putting in another table containing the items that you
want to check against...

create table list_items (
  item_id text not null unique
);
insert into list_items (item_id) values ('item_1');
insert into list_items (item_id) values ('item_2');
insert into list_items (item_id) values ('item_3');
insert into list_items (item_id) values ('item_4');
insert into list_items (item_id) values ('item_5');

select v.vendor_id, v.vendor_name from
vendors v,
(select vendor_id, count(*) from
   list_items l, item_vendors iv where
   iv.item_id = l.item_id
   group by vendor_id
   having count(*) = 5) as vendors_sat
where v.vendor_id = vendors_sat.vendor_id;

Extend it to 20, and the query only need change "5" to "20"...
-- 
If this was helpful,  rate me
http://www.ntlug.org/~cbbrowne/unix.html
Rules of the Evil Overlord #56.  "My Legions of Terror will be trained
in basic marksmanship. Any who  cannot learn to hit a man-sized target
at 10 meters will be used for target practice."


---(end of broadcast)---
TIP 6: Have you searched our list archives?

   http://archives.postgresql.org


Re: [SQL] Simple SQL question

2004-03-08 Thread Daniel Henrique Alves Lima
Thank you, Jeremy.

I've built a function that returns a string from (cd_teacher, cd_course) 
and i've create a functional index over this function, like :

create index teacher_course_idx on teacher_course 
(build_unique_2p(cd_teacher,cd_course));
select * from teacher_course where build_unique_2p(cd_teacher,cd_course) 
in ('1:2','23:11','563','341');

Is it possible to use "array cast" over cd_teacher and cd_course (just 
an idea, i don't known the sintaxe), like:

select * from teachar_course where cast((cd_teacher,cd_course) as array) 
in ('{1,2}','{23,11}','{563,341}');

?

I'm using postgreSQL 7.34

Thanks !!!

Jeremy Semeiks wrote:

You could use a subselect of unions:

select * from teacher_course where (cd_course, cd_teacher) in
(select 1, 2 union select 23, 11 union select 563, 341)
Maybe there's a more concise way, though.

- Jeremy

 



---(end of broadcast)---
TIP 9: the planner will ignore your desire to choose an index scan if your
 joining column's datatypes do not match


[SQL] ANALYZE error

2004-03-08 Thread David Witham
Hi all,

I run a cron job at 2am every night to do an ANALYZE on my whole database:

su - postgres -c 'echo analyze | /usr/bin/psql buns | grep -v ANALYZE'

Its a batch oriented database so there is no user activity on it at this time. The 
only other job that could be running is a vacuum I run at 1am but I don't think it 
would take an hour to run. Occasionally I get this error message from the analyze job:

ERROR:  simple_heap_update: tuple concurrently updated

What does this mean and should I do anything about it?

Thanks,

David Witham
Telephony Platforms Architect
Unidial
Australia


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

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


Re: [SQL] ANALYZE error

2004-03-08 Thread Tom Lane
"David Witham" <[EMAIL PROTECTED]> writes:
> Occasionally I get this error message from the analyze job:
> ERROR:  simple_heap_update: tuple concurrently updated
> What does this mean and should I do anything about it?

You can get this if two ANALYZEs run in parallel for the same table;
whichever one tries to update pg_statistic second fails with the above
error.  It's moderately annoying, but not dangerous.

regards, tom lane

---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])


Re: [SQL] ANALYZE error

2004-03-08 Thread Iain
>>The only other job that could be running is a vacuum I run at 1am but I
don't think it would take an hour to run.

Famous last words... :-) It should be easy to check this, but I don't know
if that is a likely source of problems anyway.

If I were you I'd just do VACUUM ANALYSE in one comand. It would certainly
eliminate that as a factor.

At this stage you have no idea which table it occurs on, or if it always
happens on the same table, or at the same time, am I right? Failing any more
useful response from those with more internal knowledge you may have to
resort to collecting information and trying to isolate the problem.

It would be a good idea to give all the relevant version numbers too

regards
iain


---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
  subscribe-nomail command to [EMAIL PROTECTED] so that your
  message can get through to the mailing list cleanly


Re: [SQL] Simple SQL question

2004-03-08 Thread Iain
Just a note based on my experience, if you are going to to use IN processing
then there is a good chance that the index isn't going to be used. In some
recent tests I did, the index stopped being used after I put 3 or more items
in the IN list. You should build some representatve examples of the select
and test them using "ANALYSE SELECT ..." .I'm using 7.4.1.

The result from the select is the same, even if you don't make an index on
the function result.It's just a performance consideration. If the index
isn't used, then you don't need to create it.

regards
Iain
- Original Message - 
From: "Daniel Henrique Alves Lima" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, March 09, 2004 1:21 PM
Subject: Re: [SQL] Simple SQL question


> Thank you, Jeremy.
>
> I've built a function that returns a string from (cd_teacher, cd_course)
> and i've create a functional index over this function, like :
>
> create index teacher_course_idx on teacher_course
> (build_unique_2p(cd_teacher,cd_course));
> select * from teacher_course where build_unique_2p(cd_teacher,cd_course)
> in ('1:2','23:11','563','341');
>
> Is it possible to use "array cast" over cd_teacher and cd_course (just
> an idea, i don't known the sintaxe), like:
>
> select * from teachar_course where cast((cd_teacher,cd_course) as array)
> in ('{1,2}','{23,11}','{563,341}');
>
> ?
>
> I'm using postgreSQL 7.34
>
> Thanks !!!
>
> Jeremy Semeiks wrote:
>
> >You could use a subselect of unions:
> >
> >select * from teacher_course where (cd_course, cd_teacher) in
> >(select 1, 2 union select 23, 11 union select 563, 341)
> >
> >Maybe there's a more concise way, though.
> >
> >- Jeremy
> >
> >
> >
>
>
>
> ---(end of broadcast)---
> TIP 9: the planner will ignore your desire to choose an index scan if your
>   joining column's datatypes do not match


---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


Re: [SQL] Simple SQL question

2004-03-08 Thread Iain
Sorry, did I write "ANALYSE SELECT  "?

It's supposed to be "EXPLAIN [ANALYSE] [VERBOSE] SELECT ..."

- Original Message - 
From: "Daniel Henrique Alves Lima" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, March 09, 2004 1:21 PM
Subject: Re: [SQL] Simple SQL question


> Thank you, Jeremy.
>
> I've built a function that returns a string from (cd_teacher, cd_course)
> and i've create a functional index over this function, like :
>
> create index teacher_course_idx on teacher_course
> (build_unique_2p(cd_teacher,cd_course));
> select * from teacher_course where build_unique_2p(cd_teacher,cd_course)
> in ('1:2','23:11','563','341');
>
> Is it possible to use "array cast" over cd_teacher and cd_course (just
> an idea, i don't known the sintaxe), like:
>
> select * from teachar_course where cast((cd_teacher,cd_course) as array)
> in ('{1,2}','{23,11}','{563,341}');
>
> ?
>
> I'm using postgreSQL 7.34
>
> Thanks !!!
>
> Jeremy Semeiks wrote:
>
> >You could use a subselect of unions:
> >
> >select * from teacher_course where (cd_course, cd_teacher) in
> >(select 1, 2 union select 23, 11 union select 563, 341)
> >
> >Maybe there's a more concise way, though.
> >
> >- Jeremy
> >
> >
> >
>
>
>
> ---(end of broadcast)---
> TIP 9: the planner will ignore your desire to choose an index scan if your
>   joining column's datatypes do not match


---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])


[SQL] Help to simplify sample query

2004-03-08 Thread Daniel Henrique Alves Lima
   Hi guys, i have a new question about how to simplify a query. I have 
the tables area_course(cd_area,cd_course) and 
teacher_course(cd_teacher,cd_course) and a set of pairs of values 
{(1,2),(98,45),(11,0),...}.

   Now, i must to select the areas which courses appears in 
teacher_course and match with the set of pairs. Something like :

select cd_area from area a1 where
  exists (select * from teacher_course c2 where c2.cd_course = 
a1.cd_course and c2.cd_teacher = 1 and c2.cd_course = 2) and
  exists (select * from teacher_course c2 where c2.cd_course = 
a1.cd_course and c2.cd_teacher = 98 and c2.cd_course = 45) and
  exists (select * from teacher_course c2 where c2.cd_course = 
a1.cd_course and c2.cd_teacher = 11 and c2.cd_course = 0) and


   This is just a sample. The whole query is giant and its use other 
tables/columns. Is there a best way to write this query ?

   I don't think this is possible, but: Is there a efficient way to 
compare if the result of a query is a superset of the result of another ?



   I would appreciate any ideas/suggestions. Thanks !!!



---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


Re: [SQL] Help to simplify sample query

2004-03-08 Thread Tomasz Myrta
Dnia 2004-03-09 06:41, Użytkownik Daniel Henrique Alves Lima napisał:
   Hi guys, i have a new question about how to simplify a query. I have 
the tables area_course(cd_area,cd_course) and 
teacher_course(cd_teacher,cd_course) and a set of pairs of values 
{(1,2),(98,45),(11,0),...}.

   Now, i must to select the areas which courses appears in 
teacher_course and match with the set of pairs. Something like :

select cd_area from area a1 where
  exists (select * from teacher_course c2 where c2.cd_course = 
a1.cd_course and c2.cd_teacher = 1 and c2.cd_course = 2) and
  exists (select * from teacher_course c2 where c2.cd_course = 
a1.cd_course and c2.cd_teacher = 98 and c2.cd_course = 45) and
  exists (select * from teacher_course c2 where c2.cd_course = 
a1.cd_course and c2.cd_teacher = 11 and c2.cd_course = 0) and


   This is just a sample. The whole query is giant and its use other 
tables/columns. Is there a best way to write this query ?
Can you try this query ? :

select cd_area from area a1
 join teacher_course c2 using (cd_course)
where (cd_teacher,cd_course) in (select 1,2 union select 98,45 union 
select 11,0);

Regards,
Tomasz Myrta
---(end of broadcast)---
TIP 6: Have you searched our list archives?
  http://archives.postgresql.org


Re: [SQL] designer tool connect to PostgreSQL

2004-03-08 Thread BenLaKnet





Rekall ... 
    http://www.totalrekall.co.uk/  
      (commercial website)
    http://www.rekallrevealed.org/  
   (free sources)

for designing different RDBMS like mysql, postgresl, oracle and other
...
free with sources ... 
but packages for windows or linux are not free.

Ben

Yasir Malik a écrit :

  Well, there's phpPgAdmin. It's available at
http://phppgadmin.sourceforge.net/

Yasir

On Mon, 8 Mar 2004 [EMAIL PROTECTED] wrote:

  
  
Date: Mon, 8 Mar 2004 10:13:53 +0800
From: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Subject: [SQL] designer tool connect to PostgreSQL

Hi,

i use postgresql as my database. does anyone know the designer tool that
can connect to postgeSQL ??? meaning to say the tools
can handle design task like create table , etc . appreciate if u can give
the specific URL. thanks in advance.

  
  
---(end of broadcast)---
TIP 8: explain analyze is your friend