Re: [SQL] Bucketing Row Data in columns

2009-06-25 Thread Oliveiros Cristina
l) Getting the counts takes half the time, making the flattened report takes half the time. Oliveiros Cristina wrote: Hello, Sandeep, I am not sure if this is what you want. I came up with this query SELECT * FROM (SELECT user_id,SUM(amount) as day1 FROM t1 WHERE create_timestamp = '2

Re: [SQL] Bucketing Row Data in columns

2009-06-25 Thread Oliveiros Cristina
Hello, Sandeep, I am not sure if this is what you want. I came up with this query SELECT * FROM (SELECT user_id,SUM(amount) as day1 FROM t1 WHERE create_timestamp = '2009-1-1' GROUP BY "user_id") a NATURAL FULL JOIN (SELECT user_id,SUM(amount) as day2 FROM t1 WHERE create_timestamp = '2009-1-

Re: [SQL] Composite primary keys

2009-06-23 Thread Oliveiros Cristina
Howdy! When you say that pg accepts "this" silently instead of complaining what are you referring to exactly? First Insert? Why wouldn't it work after all ? What will happen is that when you try to insert a new record without specifying the id column you'll get an error informing that primar

Re: [SQL] Obtaining a limited number of records from a long query

2009-05-25 Thread Oliveiros Cristina
al Message - From: "Ivan Sergio Borgonovo" To: Sent: Monday, May 25, 2009 3:13 PM Subject: Re: [SQL] Obtaining a limited number of records from a long query On Mon, 25 May 2009 14:55:54 +0100 "Oliveiros Cristina" wrote: Thanks a million, Andy. It's precis

Re: [SQL] Obtaining a limited number of records from a long query

2009-05-25 Thread Oliveiros Cristina
Thanks a million, Andy. It's precisely what I needed, Indeed! Best, Oliveiros - Original Message - From: "Andy Shellam" To: "Oliveiros Cristina" Cc: Sent: Monday, May 25, 2009 2:45 PM Subject: Re: [SQL] Obtaining a limited number of records from a l

[SQL] Obtaining a limited number of records from a long query

2009-05-25 Thread Oliveiros Cristina
Dear List, Is there any way to force a query to return just a few records? For ex, returning just the first ten rows from a long ORDER BY query ? And then, eventually, obtaining the remaining records at a later time, or in background? Thanks in advance for your help, Best, Oliveiros

Re: [SQL] Need help combining 2 tables together

2009-05-22 Thread Oliveiros Cristina
I guess this is pretty much the same as doing SELECT message.id,topic.topic,message.message FROM topics JOIN messages ON topics.id = message.topic ORDER BY message.ID Ain't I right? Best, Oliveiros - Original Message - From: James Kitambara To: Richard Ekblom Cc: pgsql-s

[SQL] performance question

2009-05-08 Thread Oliveiros Cristina
Hi, All Suppose you have a query like this SELECT * FROM t_sitesresumebydate a JOIN t_triple_association c ON "IDSiteResume" = "IDResume" WHERE "dtDate" BETWEEN '2009-2-1' AND '2009-2-3' AND "IDHitsAccount" = 378284 With this time interval it completes in less than a second. If I add one da

[SQL] Re: [SQL] Relatorio da composiçao de FKs e PKs

2009-03-19 Thread Oliveiros Cristina
Escreve a tua dúvida em inglês, por favor, isto é uma lista de mailing em ingles. He wants to do a report with the composition of each foreign key and primary key, not just their names. He wants to know where postgres keeps that in catalog. Best, Oliveiros - Original Message - From

Re: [SQL] uso de dblink en php

2009-03-05 Thread Oliveiros Cristina
Escribe tu duda en ingles, por favor Saludos, Oliveiros - Original Message - From: Jhonny Velasquez c. To: pgsql-sql@postgresql.org ; pgsql-...@postgresql.org Sent: Thursday, March 05, 2009 3:50 PM Subject: [SQL] uso de dblink en php hola a todos estoy programando en

Re: [SQL] Grass Root Protectionism

2009-02-09 Thread Oliveiros Cristina
Just follow Google's motto "Don't be evil" :-) We are all engineers from the same field, so Let's all be friends Best, Oliveiros - Original Message - From: Boycott Tech Forums To: pgsql-sql@postgresql.org Sent: Sunday, February 08, 2009 6:40 AM Subject: [SQL] Grass Root Prote

Re: [SQL] I need some magical advice

2009-01-29 Thread Oliveiros Cristina
(status_id = 0) GROUP BY name HAVING (COUNT(*) > 1)) d ON d.name = c.name GROUP BY (c.name) ) b ON a.name = b.name AND (a.status_id <> b.estado OR b.oldest <> a.c_date) WHERE a.status_id = 0 ) - Original Message - From: "Andreas" To: "PostgresSQL list&qu

Re: [SQL] I need some magical advice

2009-01-29 Thread Oliveiros Cristina
Andreas, Does your table has any field that can be used as primary key? Any "ID" field? Best, Oliveiros - Original Message - From: "Andreas" To: Sent: Thursday, January 29, 2009 11:56 AM Subject: [SQL] I need some magical advice Hi, I'd like to update some records in a table.

Re: [SQL] Best way to "and" from a one-to-many joined table?

2008-12-10 Thread Oliveiros Cristina
*How can I get an AND search (people with Dark Hair AND who are President)?* The two joins didn't work? Or were they too slow ? Best, Oliveiros 2008/12/10 Bryce Nesbitt <[EMAIL PROTECTED]> > > > Milan Oparnica wrote: > > This is how I do it, and it runs fast: > > select p.* > > from test_people

Re: [SQL] Best way to "and" from a one-to-many joined table?

2008-12-05 Thread Oliveiros Cristina
8Dark Hair > 8USA President > 10Dark Hair > \. > > CREATE TABLE test_people ( > people_id integer DEFAULT nextval('test_sequence'::regclass) NOT NULL, > person_name text > ); > COPY test_people (people_id, person_name) FROM stdin; > 8O

Re: [SQL] Best way to "and" from a one-to-many joined table?

2008-12-05 Thread Oliveiros Cristina
Howdy, Bryce Could you please try this out and tell me if it gave what you want. Best, Oliveiros SELECT person_name FROM test_people p JOIN test_attributes a ON ((a.people_id = p.people_id) AND (a."attribute" = @firstAttr)) JOIN test_attributes b ON ((b."people_id" = p."people_id") AND (b."attri

Re: [SQL] function - string ends with

2008-11-21 Thread Oliveiros Cristina
If I understand what you need, I guess this clause does work. WHERE string LIKE '%substring' Best, Oliveiros - Original Message - From: Kevin Duffy To: pgsql-sql@postgresql.org Sent: Friday, November 21, 2008 4:30 PM Subject: [SQL] function - string ends with Hello All

Re: [SQL] Subsorting GROUP BY data

2008-11-10 Thread Oliveiros Cristina
If it is to Group the items by cat field then select the ID where the num is the highest in group, You could maybe try SELECT a.ID, b.Cat,b.Num FROM my_table a JOIN ( SELECT cat, MAX(num) as maximo FROM my_table GROUP_BY cat) b ON a.Cat = b.Cat AND a.Num = b.maximo; It 'll probably give what y

Re: [SQL] Subqueries

2008-10-30 Thread Oliveiros Cristina
alias v not visible in sub-query? - Original Message - From: Pascal Tufenkji To: pgsql-sql@postgresql.org Sent: Thursday, October 30, 2008 12:17 PM Subject: [SQL] Subqueries Hello, I don't understand the following error. Can anyone help me plz Thx Pascal

Re: [SQL] Performing intersection without intersect operator

2008-10-28 Thread Oliveiros Cristina
Howdy, Nacef, Try this, SELECT a.userid FROM orders a JOIN orders b USING (userid) WHERE a.productid = 1 AND b.productid = 2 Best, Oliveiros - Original Message - From: Nacef LABIDI To: pgsql-sql@postgresql.org Sent: Tuesday, October 28, 2008 11:14 AM Subject: [SQL] Perfo

Re: [SQL] grouping/clustering query

2008-10-24 Thread Oliveiros Cristina
Your script is handy, Steve. Spontaneously, This seems to be an array type problem, something I just have vague notions about. I'll take a look at this, http://www.postgresql.org/docs/8.3/static/arrays.html to see if something occurs... Best, Oliveiros - Original Message - From:

Re: [SQL] Postgres-sql-php

2008-10-23 Thread Oliveiros Cristina
I guess you can change a little the query to your needs. The problem is pretty much the same... I've used c3 column in equality, but if this column has repeated values, just choose any column or combination of columns which is unique. Best, Oliveiros SELECT a.c1,a.c2,b.c3,b.c4,a.c5,b.c6 FROM ( SE

Re: [SQL] Postgres-sql-php

2008-10-23 Thread Oliveiros Cristina
Just add two conditions on the previous query A particularity of this approach is that the non-null record will always appear with the first child in alphabetical order. But, according to what you explain, I guess it is OK, and if it doesn't it is easily changed. :-) Also I've changed the first c

Re: [SQL] Postgres-sql-php

2008-10-23 Thread Oliveiros Cristina
Howdy, Zied. The query below outputs the results as you want, but I suspect you have a more general situation you want to solve. If you have more than one father, say "manuel", you would want something like this ? num father child age 1 joe bruce14 lei

Re: [SQL] Search fields in multiple tables

2008-10-16 Thread Oliveiros Cristina
Howdy, Raju. Could you please provide a more concrete example of what you need? What information would you like your query to return exactly? An ordered set of records? Ordered by rank...? Please give an example of a search operation and intended result Best, Oliveiros - Original Messag

Re: [SQL] sequence number in a result

2008-10-09 Thread Oliveiros Cristina
Sorry, Lance By mistake I posted my own things, which I was using to "adapt" to your situation. :-) Please kindly ignore everything below my signature :p Best, Oliveiros - Original Message - From: Oliveiros Cristina To: Campbell, Lance ; pgsql-sql@postgresql.org Sent

Re: [SQL] sequence number in a result

2008-10-09 Thread Oliveiros Cristina
Howdy, Lance. I had that problem about a year ago, and AFAIK there is no solution, at least not in SQL Standard. What I did was something like SELECT a,b,c,count(y.a) as order FROM t1 x , t1 y WHERE ((x.a > y.a) OR (x.a = y.a AND x.ID <= y.ID)) -- Use here whatever you have as primary key

Re: [SQL] For each key, find row with highest value of other field

2008-10-03 Thread Oliveiros Cristina
Howdy, Raju Do you want somethin like this? Not sure if I fully understood your requests... SELECT "Key",MAX(Date) FROM t_yourTable WHERE Value LIKE 'foo' GROUP BY Key ; Best, Oliveiros - Original Message - From: "Raj Mathur" <[EMAIL PROTECTED]> To: Sent: Friday, October 03, 2008 7

Re: [SQL] optimizing a query over tree-like structure

2008-09-30 Thread Oliveiros Cristina
ver-filter-by-N FROM ( (ownership join N on ownership.N = N.dbid) union (ownership join mm_N2R on ownership.R = mm_N2R.right join N on mm_N2R.left = N.dbid ) OR ) ... and should i bundle the filtering-by-N/Employment in every of above union-members? On Tuesday 30 September 2008 15:21:09 Oliveir

Re: [SQL] optimizing a query over tree-like structure

2008-09-30 Thread Oliveiros Cristina
Hi, Svil I 'd like to first fully understand the background of your problem before figurin out if I can be of any help (or not). You have a tree, of which N is the root, is this correct? Then, what are the next sublevel? F, P and R? If so, why is R linked to a sibling (F) ? And the next one? O

Re: [SQL] Finding sequential records

2008-09-26 Thread Oliveiros Cristina
Howdy, Steve. SELECT id FROM dummy a NATURAL JOIN ( SELECT fkey_id,name FROM dummy GROUP BY fkey_id,name HAVING COUNT(*) > 1 AND SUM(id) = (MAX(id) + MIN(id)) * (MAX(id) - MIN(id) + 1) / 2 ) b ORDER BY id; The GROUP BY clause is to associate records that have the same fkey_id and name The COUNT(

Re: [SQL] Finding sequential records

2008-09-26 Thread Oliveiros Cristina
Can this be what you need? Best, Oliveiros SELECT id FROM dummy a NATURAL JOIN ( SELECT fkey_id,name FROM dummy GROUP BY fkey_id,name HAVING COUNT(*) > 1 AND SUM(id) = (MAX(id) + MIN(id)) * (MAX(id) - MIN(id) + 1) / 2 ) b ORDER BY id; - Original Message - From: "Steve Midgley" <[E

Re: [SQL] exclusion query

2008-09-25 Thread Oliveiros Cristina
Hi, Louis-David, I guess you already have your problem solved, but just for the sake of curiosity, another way to do it might be to tweak a little your original query, I've written on Capitals the things I've added. Should you need to exclude more than one event you can add the conditions to t

[SQL] Question on partitioning

2008-08-21 Thread Oliveiros Cristina
Hello , All. I am not sure if this is the right mailing list to place this question. If it doesn't, please kindly redirect me to the right list. I have a giant table with about 10,6 million records. Queries on it are usually slow, and if I try to do something more elaborate like an INNER JOIN w

Re: [SQL] Join question

2008-08-19 Thread Oliveiros Cristina
To: pgsql-sql@postgresql.org Sent: Tuesday, August 19, 2008 2:36 PM Subject: Re: [SQL] Join question I thought of that, but it does violate table constraints. Edward W. Rouse From: Oliveiros Cristina [mailto:[EMAIL PROTECTED] Sent: Monday, August 18, 2008 2:00 PM To:

Re: [SQL] Join question

2008-08-18 Thread Oliveiros Cristina
I don't understand your count(total) expression... It doesnt work, because apparently you dont have any "total" column... Apparently, you meant count(color) The problem is that you are grouping by a.org,a.user and on table "a" u actually dont have any "null" users... Well, if it is to include

Re: [SQL] column names with - and (

2008-07-29 Thread Oliveiros Cristina
You can enclose the names in quotes, then the characters are allowed Sorry to mislead you :p Best, Oliveiros - Original Message - From: Oliveiros Cristina To: maria s ; Osvaldo Rosario Kussama ; pgsql-sql@postgresql.org ; Pavel Stehule ; Ivan Sergio Borgonovo Sent: Tuesday

Re: [SQL] column names with - and (

2008-07-29 Thread Oliveiros Cristina
Maria, The minus, open bracket and close bracket are illegal as identifier names http://www.postgresql.org/docs/8.3/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS Best, Oliveiros - Original Message - From: maria s To: Osvaldo Rosario Kussama ; pgsql-sql@postgresql.org ;

Re: [SQL] Accessing array datatype

2008-07-28 Thread Oliveiros Cristina
I can fetch the elements as I wish. But I don't know is there any other way to get the data. Thank you for your reply. Maria On Mon, Jul 28, 2008 at 12:56 PM, Oliveiros Cristina <[EMAIL PROTECTED]> wrote: Maria, You mean your array has a variable size, which yo

Re: [SQL] Accessing array datatype

2008-07-28 Thread Oliveiros Cristina
Maria, You mean your array has a variable size, which you need to know in order to properly construct a query? Dunno much about arrays, but here http://www.postgresql.org/docs/8.3/static/arrays.html is said that array_upper( your_array, 1 ) returns the upper bound of the array... Can this be

Re: [SQL] How to GROUP results BY month

2008-07-18 Thread Oliveiros Cristina
July 16, 2008, 5:39 AM am Tue, dem 15.07.2008, um 18:15:07 -0700 mailte Mark Roberts folgendes: > > On Tue, 2008-07-15 at 14:31 +0200, A. Kretschmer wrote: > > am Tue, dem 15.07.2008, um 13:12:39 +0100 mailte Oliveiros Cristina folgendes: > > > Howdy, all, > > > > &

Re: [SQL] How to GROUP results BY month

2008-07-17 Thread Oliveiros Cristina
e: am Tue, dem 15.07.2008, um 18:15:07 -0700 mailte Mark Roberts folgendes: > > On Tue, 2008-07-15 at 14:31 +0200, A. Kretschmer wrote: > > am Tue, dem 15.07.2008, um 13:12:39 +0100 mailte Oliveiros Cristina folgendes: > > > Howdy, all, > > > > > > I have a problem

[SQL] How to GROUP results BY month

2008-07-15 Thread Oliveiros Cristina
Howdy, all, I have a problem. I have a table which one of the fields is of type date. I need to obtain the totals of the other fields in a by-month basis IS there any easy way to do this using the GROUP BY or any other construct? Thanks in advance for your kind help Best, Oliveiros -- Sent

Re: [SQL] This SQL works under Mysql, not Postgresql.

2008-01-25 Thread Oliveiros Cristina
Neither have I. The LEFT JOIN I know is something like SELECT ... FROM table1 LEFT OUTER JOIN table2 ON Try using this construct Best, Oliveiros - Original Message - From: "Scott Marlowe" <[EMAIL PROTECTED]> To: "acec acec" <[EMAIL PROTECTED]> Cc: Sent: Friday, January 25, 2008

Re: [SQL] Obtaining the primary key of the record just inserted

2007-11-08 Thread Oliveiros Cristina
It worked perfectly. Thanks a million, Scott. Best, Oliveiros - Original Message - From: "Scott Marlowe" <[EMAIL PROTECTED]> To: "Oliveiros Cristina" <[EMAIL PROTECTED]> Cc: Sent: Thursday, November 08, 2007 6:03 PM Subject: Re: [SQL] Obtaining th

[SQL] Obtaining the primary key of the record just inserted

2007-11-08 Thread Oliveiros Cristina
Hello, All, I have the need to know the primary key assigned to a record I've just INSERTed . Is there an easy way to solve this ? Similar to SQLServer's SELECT scope_identity() ; ? Any help deeply appreciated Best, Oliveiros

Re: [SQL] JOIN

2007-06-05 Thread Oliveiros Cristina
,date FROM my_table WHERE date=ANY(dates) GROUP BY theme,receiver,date ; But I don't know, do you need to include the column "dates" on output ? Best, Oliveiros From: Loredana Curugiu To: Oliveiros Cristina ; [EMAIL PROTECTED] ; pgsql-sql@postgresql.org Sent: Tuesd

Re: [SQL] JOIN

2007-06-05 Thread Oliveiros Cristina
On 6/5/07, Oliveiros Cristina < [EMAIL PROTECTED]> wrote: Hey, Loredana. Hi Oliveiros! Nice to "see" you again! Please advice me, you need to sum for a certain pair (Theme, receiver) the number that appears on count for every record whose date is in

Re: [SQL] JOIN

2007-06-05 Thread Oliveiros Cristina
bout the result Best, Oliveiros 2007/6/5, Loredana Curugiu <[EMAIL PROTECTED]>: On 6/5/07, Loredana Curugiu <[EMAIL PROTECTED]> wrote: > > > > On 6/5/07, Oliveiros Cristina < [EMAIL PROTECTED]> wrote: > > > > Hey, Loredana. > > > Hi Oliveiros!

Re: [SQL] JOIN

2007-06-05 Thread Oliveiros Cristina
Hey, Loredana. Please advice me, you need to sum for a certain pair (Theme, receiver) the number that appears on count for every record whose date is in dates column, is this correct? But in what record's dates column? On all of them? Or just the dates column of the records that have that (Theme