[SQL] update from multiple rows
hi (B I have some trouble updating a table like this one : (B date | data_raw | data_sys (B 12-01 | 5 | 4.5 (B 13-01 | 6 | 6 (B 14-01 | 7 | 8 (B (BI would like to update the 'data_sys' row by computing values of multiple (B'data_raw' values. I mean for example : (B data_sys(13-01) = (data_raw['12-01'] + data_raw['13-01'] + (Bdata_raw['14-01'] )/3; (B (BI thought of a function that fetch the 3 data_raw rows for each rows (Bbut it was obviously too much slow... (B (BIs there a more efficient way to achieve this ? (BThanks in advance.. This could help me very much.. (B (BEtienne Adam (B (B_ $BL5NA%a!<%k$J$i$d$C$Q$j(B $B!V(BMSN Hotmail$B!W(B http://www.hotmail.com/ (B (B (B---(end of broadcast)--- (BTIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]
[SQL] Question about a select
Hi, I have a table with this columns: machine, date and area. Now i need a view with machine an week, calculated from date, and sum(area), where date between CURRENT_DATE and now+N days. Okay, this is not the problem, it works fine. (the original table and the view is more complex) The problem is, i need also rows for machine and week with no entrys in the table. For this rows the sum(area) shold be NULL ore 0. In other words: for every machine i need M rows, and M must be constant. Regards & Thx, Andreas -- Diese Message wurde erstellt mit freundlicher Unterstützung eines freilau- fenden Pinguins aus artgerechter Freilandhaltung. Er ist garantiert frei von Micro$oft'schen Viren. (#97922 http://counter.li.org) GPG 7F4584DA Was, Sie wissen nicht, wo Kaufbach ist? Hier: N 51.05082°, E 13.56889° ;-) ---(end of broadcast)--- TIP 8: explain analyze is your friend
Re: [SQL] update from multiple rows
On Sat, Jan 22, 2005 at 12:51:20PM +, adam etienne wrote: > > I have some trouble updating a table like this one : > date | data_raw | data_sys > 12-01 | 5 | 4.5 > 13-01 | 6 | 6 > 14-01 | 7 | 8 > > I would like to update the 'data_sys' row by computing values of multiple > 'data_raw' values. I mean for example : > data_sys(13-01) = (data_raw['12-01'] + data_raw['13-01'] + > data_raw['14-01'] )/3; Is there a reason to maintain data_sys in the table? Could you use a view instead? A view could do self joins (join the table against itself) and perform the necessary calculations on the fly when you make a query. That could be expensive if you select large data sets, but for small slices of data it might suffice. Another possibility might be to use a trigger to recalculate data_sys when records are inserted, updated, or deleted. You'd still have to do a potentially expensive one-time update of the entire table, but future updates would then touch only the rows that depend on the data being inserted, updated, or deleted, and the calculated values would always be current. Using a trigger would require some care, however, to avoid cascading updates that are unnecessary or that could result in infinite recursion. -- Michael Fuhr http://www.fuhr.org/~mfuhr/ ---(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
[SQL] editors with colum positioning for debugging?
Hi I am doing my work in windows attached to a postgres server on linux fedora core3. I have been using pgadminIII and amd am trying the demo of EMS. My question is I dont see an easy way to find an error. Typical error text is syntax error at or near "trans" at character 825 But determining character 825 is a little slow by hand. Any of you guru's have some ideas you use (I am sure you dont get the number of errors I am). By the way my issues were caused by SELinux not being turned off, I turned it off and re-did my postgres rpm and all is well (no pg_user error). I was also able to add the view that had given me the row too large error. Joel Fradkin Wazagua, Inc. 2520 Trailmate Dr Sarasota, Florida 34243 Tel. 941-753-7111 ext 305 [EMAIL PROTECTED] www.wazagua.com Powered by Wazagua Providing you with the latest Web-based technology & advanced tools. © 2004. WAZAGUA, Inc. All rights reserved. WAZAGUA, Inc This email message is for the use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and delete and destroy all copies of the original message, including attachments. ---(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] editors with colum positioning for debugging?
"Joel Fradkin" <[EMAIL PROTECTED]> writes: > My question is I dont see an easy way to find an error. > Typical error text is syntax error at or near "trans" at character 825 > But determining character 825 is a little slow by hand. PG 8.0 produces more useful output. A trivial example: regression=# select regression-#1/0 as a, regression-#1/ as b, regression-#1/2 as c; ERROR: syntax error at or near "as" at character 27 LINE 3:1/ as b, ^ regression=# regards, tom lane ---(end of broadcast)--- TIP 8: explain analyze is your friend
Re: [SQL] editors with colum positioning for debugging?
Very cool (I tried to get 8 on fedora, but think I was missing it somehow.). I also noticed if I run in EMS (course I need to buy it)it positions me on the error if I am in the editor not the builder. I am a little afraid of using 8 as it is brand new, and this will be on a production machine. I could use 8 for development and 7 for production I guess. Joel Fradkin Wazagua, Inc. 2520 Trailmate Dr Sarasota, Florida 34243 Tel. 941-753-7111 ext 305 [EMAIL PROTECTED] www.wazagua.com Powered by Wazagua Providing you with the latest Web-based technology & advanced tools. C 2004. WAZAGUA, Inc. All rights reserved. WAZAGUA, Inc This email message is for the use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and delete and destroy all copies of the original message, including attachments. -Original Message- From: Tom Lane [mailto:[EMAIL PROTECTED] Sent: Saturday, January 22, 2005 5:21 PM To: Joel Fradkin Cc: pgsql-sql@postgresql.org Subject: Re: [SQL] editors with colum positioning for debugging? "Joel Fradkin" <[EMAIL PROTECTED]> writes: > My question is I don't see an easy way to find an error. > Typical error text is syntax error at or near "trans" at character 825 > But determining character 825 is a little slow by hand. PG 8.0 produces more useful output. A trivial example: regression=# select regression-#1/0 as a, regression-#1/ as b, regression-#1/2 as c; ERROR: syntax error at or near "as" at character 27 LINE 3:1/ as b, ^ regression=# regards, tom lane ---(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] editors with colum positioning for debugging?
On Jan 22, 2005, at 5:12 PM, Joel Fradkin wrote: My question is I don’t see an easy way to find an error. Typical error text is syntax error at or near "trans" at character 825 But determining character 825 is a little slow by hand. In pgEdit you can use the "Goto Point" command to jump to a specific offset in the file. I hope to have something better in the near future to automatically move the cursor for you when an error is detected. John DeSoi, Ph.D. http://pgedit.com/ Power Tools for PostgreSQL ---(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