[SQL] can someone explain confusing array indexing nomenclature

2007-02-14 Thread chrisj

given the following table:

protocal2=> select * from sal_emp ;
 name  |  pay_by_quarter   | schedule
---+---+---
 Bill  | {1,1,1,1} |
{{meeting,lunch},{training,presentation}}
 Carol | {2,25000,25000,25000} |
{{breakfast,consulting},{meeting,lunch}}
(2 rows)

why do the following two queries yield different results??

protocal2=> SELECT schedule[1][2] FROM sal_emp WHERE name = 'Bill';
 schedule
--
 lunch
(1 row)

protocal2=> SELECT schedule[1:1][2] FROM sal_emp WHERE name = 'Bill';
 schedule
---
 {{meeting,lunch}}
(1 row)

-- 
View this message in context: 
http://www.nabble.com/can-someone-explain-confusing-array-indexing-nomenclature-tf3229165.html#a8971770
Sent from the PostgreSQL - sql mailing list archive at Nabble.com.


---(end of broadcast)---
TIP 1: 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


[SQL] problem with join

2007-02-14 Thread Edward W. Rouse
I have 2 tables that look like this:
 
table1  table2
-   
value1 | value2 value1 | value3 | value4
-   
one| a  one| a  | jim
one| b  one| d  | bob
one| c  two| d  | bill
many   | d  two| f  | sue
many   | e  three  | d  | mary
some   | f  three  | f  | jane
 
my query is like this:
 
select b.value1, value2, count(value4)
from table1 as a join table2 as b on (a.value2 = b.value3)
where (a.value1 in ('one', 'two', 'three', 'many') or a.value2 = 'f')
and b.value1 in ('one', 'two', 'three')
group by b.value1, value2 
order by b.value1, value2;
 
I get back correct results EXCEPT I don't get back empty counts.
 
The results that I need from the tables above should look like this:
 
one, a, 1
one, b, 0
one, c, 0
one, d, 1
one, e, 0
one, f, 0
two, d, 1 
two, e, 0 
two, f, 1
three, d, 1 
three, e, 0 
three, f, 1
 
What I get are all of the rows with counts, but none of the rows where
the count would be 0. I understand why this query works that way, but I
need to find away to resolve the many to one relations that are 
backwards in this case. Can anyone come up with a query that will 
include the results that have counts of 0?
 
I tried using coalesce(count(value4)) and case count(value4) = 0
with no luck. I tried left and right joins and the right join gave me 
the same results while the left join gave me rows like:
 
many, d, 3
 
I'm beginning to wonder if this is even possible. 
 
 
 
Ed


Re: [SQL] Regaring posting a query

2007-02-14 Thread Phillip Smith
Exactly the same way as you posted this message - include your query, and
what you question is and we'll see what we can do.

 

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of sahaanaa subha
Sent: Wednesday, 14 February 2007 17:45
To: pgsql-sql@postgresql.org
Subject: [SQL] Regaring posting a query

 

Dear sir,

 I would like to know how to post my queres in postgres mailing list and how
to view the answers.

Thanks & Regards

subha.N


 

  _  

I use Kify Mail - http://email.kify.com - Get your Kify Mail Account Today -
Its Free, Fast, Easy, Secure & Spam-Free.



***Confidentiality and Privilege Notice***

The material contained in this message is privileged and confidential to
the addressee.  If you are not the addressee indicated in this message or
responsible for delivery of the message to such person, you may not copy
or deliver this message to anyone, and you should destroy it and kindly
notify the sender by reply email.

Information in this message that does not relate to the official business
of Weatherbeeta must be treated as neither given nor endorsed by Weatherbeeta.
Weatherbeeta, its employees, contractors or associates shall not be liable
for direct, indirect or consequential loss arising from transmission of this
message or any attachments



Re: [SQL] problem with join

2007-02-14 Thread Bruno Wolff III
On Wed, Feb 14, 2007 at 17:21:44 -0500,
  "Edward W. Rouse" <[EMAIL PROTECTED]> wrote:
>  
> I tried using coalesce(count(value4)) and case count(value4) = 0
> with no luck. I tried left and right joins and the right join gave me 
> the same results while the left join gave me rows like:

That is because neither side of the join had all combinations of numbers
and letters. One approach would be to cross join a table with 'one', 'two',
and 'three' with one with 'a', 'b', 'c', 'd', 'e', and 'f'. And then
left join the query above to it.

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