[SQL] Dynamic Query for System functions - now()

2003-11-10 Thread Kumar
Dear Friends,   I am using PostgreSQL 7.3.4 Server on RH Linux 7.2. I am trying to generate a dynamic query to fetch the next month interval.   select now()+ interval'1 month';  -- This is working fine.   I wanna dynamically assign the interval number. i,e --> select now()+ interval'n month'

Re: [SQL] Dynamic Query for System functions - now()

2003-11-10 Thread Christoph Haller
> > Dear Friends, > > I am using PostgreSQL 7.3.4 Server on RH Linux 7.2. I am trying to generate= > a dynamic query to fetch the next month interval. > > select now()+ interval'1 month'; -- This is working fine. > > I wanna dynamically assign the interval number. i,e --> select now()+ inter=

[SQL] FOR : Structure control pb

2003-11-10 Thread Guillaume Houssay
I am using the For controle structure as follows   FOR i IN 0..23 LOOP   query   END LOOP;   The query is tested and is working OK.   When I launch the loop in psql interface, I get the error parse error at or near FOR.   As this is the first time I use this kind of struture I am probably us

Re: [SQL] Dynamic Query for System functions - now()

2003-11-10 Thread Kumar
Dear Christoph Haller, The code that u sent is not working test=> EXECUTE 'select now()+ interval\'' ||to_char(3,'9')|| 'month\''; ERROR: parser: parse error at or near "'select now()+ interval\''" at character 9 test=> Also I tried just to run the now() function with a dynamic query, I got the

Re: [SQL] FOR : Structure control pb

2003-11-10 Thread Richard Huxton
On Monday 10 November 2003 11:24, Guillaume Houssay wrote: > I am using the For controle structure as follows > > FOR i IN 0..23 LOOP > > query > > END LOOP; > > The query is tested and is working OK. > > When I launch the loop in psql interface, I get the error parse error at or > near FOR. The F

Re: [SQL] Dynamic Query for System functions - now()

2003-11-10 Thread Achilleus Mantzios
Kumar, why dont you try prepare fooplan2(int4) as select now() + ($1||' month')::interval; execute fooplan2(12); O kyrios Kumar egrapse stis Nov 10, 2003 : > Dear Christoph Haller, > > The code that u sent is not working > test=> EXECUTE 'select now()+ interval\'' ||to_char(3,'9')|| 'month\''

Re: [SQL] Dynamic Query for System functions - now()

2003-11-10 Thread Christoph Haller
I like Achilleus' proposal for its elegance, just in case you are interested in the old-school plpgsql way: create or replace function future_date(int) returns timestamp as 'declare future_dat timestamp; future_off text; begin future_dat := ''now'' ; future_off := $1::text; future_off := future_

Re: [SQL] help me...

2003-11-10 Thread Yasir Malik
That's what I said! :) Yasir On Sun, 9 Nov 2003, Christopher Browne wrote: > Date: Sun, 09 Nov 2003 21:59:14 -0500 > From: Christopher Browne <[EMAIL PROTECTED]> > To: [EMAIL PROTECTED] > Subject: Re: [SQL] help me... > > The world rejoiced as [EMAIL PROTECTED] (ron_tabada) wrote: > > Hello every

Re: [SQL] Dynamic Query for System functions - now()

2003-11-10 Thread George Weaver
Kumar, What about this: EXECUTE 'select now()+ interval \' || to_char(3,\'9\') || \'month\' '; George - Original Message - From: "Kumar" <[EMAIL PROTECTED]> To: "Christoph Haller" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Monday, November 10, 2003 5:57 AM Subject: Re: [SQL] Dyn

Re: [SQL] Dynamic Query for System functions - now()

2003-11-10 Thread Stephan Szabo
On Mon, 10 Nov 2003, Kumar wrote: > select now()+ interval'1 month'; -- This is working fine. > > I wanna dynamically assign the interval number. i,e --> select now()+ > interval'n month'; If n is an integer, I'd suggest something like select now() + n * interval '1 month'; rather than messing

Re: [SQL] transaction processing after error in statement

2003-11-10 Thread Stephan Szabo
On Mon, 10 Nov 2003, Holger Jakobs wrote: > Hi Stephan, > > On 9 Nov, Stephan Szabo wrote: > > On Fri, 7 Nov 2003 [EMAIL PROTECTED] wrote: > > > >> Whenever an error occurs within the transaction, PostgreSQL puts the > >> whole transaction in an *ABORT* state, so that there is no difference > >>

Re: [SQL]

2003-11-10 Thread Louise Cofield
You will have to use a WHERE clause or a JOIN in query three, so you will have to include some field, such as itemno, in the result sets of both query1 and query2 on which you can join with where or join. Such as: Select query1.sumofqty as sum1, query2.sumofqty as sum2, query1.sumofqty - query2.s

Re: [SQL] transaction processing after error in statement

2003-11-10 Thread Holger Jakobs
Hi Stephan, On 9 Nov, Stephan Szabo wrote: > On Fri, 7 Nov 2003 [EMAIL PROTECTED] wrote: > >> Whenever an error occurs within the transaction, PostgreSQL puts the >> whole transaction in an *ABORT* state, so that there is no difference >> at all between COMMITing or ROLLBACKing it. Even commands

Re: [SQL] help me...

2003-11-10 Thread Yasir Malik
Hi, I'm usually wrong, but you can create a view for Query1 and Query2. That is do create view Query1 [your query for query1]; create view Query2 [your query for query2]; Then what you are doing should work. Regards, Yasir On Sat, 8 Nov 2003, [iso-8859-1] ron_tabada wrote: > Date: Sat, 8 Nov 20

[SQL] FOR : control structure

2003-11-10 Thread Guillaume Houssay
I am using the For controle structure as follows   FOR i IN 0..23 LOOP   query   END LOOP;   The query is tested and is working OK.   When I launch the loop in psql interface, I get the error parse error at or near FOR.   As this is the first time I use this kind of struture I am probably usi

Re: [SQL] transaction processing after error in statement

2003-11-10 Thread Jan Wieck
Holger Jakobs wrote: Hi Stephan, On 9 Nov, Stephan Szabo wrote: On Fri, 7 Nov 2003 [EMAIL PROTECTED] wrote: Whenever an error occurs within the transaction, PostgreSQL puts the whole transaction in an *ABORT* state, so that there is no difference at all between COMMITing or ROLLBACKing it. Even

Re: [SQL] transaction processing after error in statement

2003-11-10 Thread Rod Taylor
> be recovered either. When committing a transaction the effects of all > operations that did not fail will be made permanent. This is how > transaction processing is described in the literature. I would be interested in reading that (URLs please) as I didn't see anything in the spec that was inte

Re: [SQL] Dynamic Query for System functions - now()

2003-11-10 Thread Gaetano Mendola
Kumar wrote: Dear Friends, I am using PostgreSQL 7.3.4 Server on RH Linux 7.2. I am trying to generate a dynamic query to fetch the next month interval. select now()+ interval'1 month'; -- This is working fine. I wanna dynamically assign the interval number. i,e --> select now()+ interval

Re: [SQL] transaction processing after error in statement

2003-11-10 Thread Rajesh Kumar Mallah
Rod Taylor wrote: be recovered either. When committing a transaction the effects of all operations that did not fail will be made permanent. This is how transaction processing is described in the literature. I would be interested in reading that (URLs please) as I didn't see

Re: [SQL] transaction processing after error in statement

2003-11-10 Thread Rod Taylor
> Although i am not aware of the roots of this discussion but would like > to > comment at this point . > > When we work with sequences an aborted transaction does have > a permanent effect on the last value of sequence. Is this behaviour > not a violation of above defination of transaction ? I

[SQL] Is there a more elegant way to write this query?...

2003-11-10 Thread Nick Fankhauser
Hi- I'm suffering from a performance problem, but when I look at my query, I'm not convinced that there isn't a better way to handle this in SQL. -So I'm seeking advice here before I go to the performance list. I have three tables- case, actor and actor_case_assignment. As the names imply, actor

Re: [SQL] Is there a more elegant way to write this query?...

2003-11-10 Thread Eric Soroos
On Nov 10, 2003, at 1:02 PM, Nick Fankhauser wrote: Hi- I'm suffering from a performance problem, but when I look at my query, I'm not convinced that there isn't a better way to handle this in SQL. -So I'm seeking advice here before I go to the performance list. An explain analyze would help.

Re: [SQL] pg 7.4.rc1, Range query performance

2003-11-10 Thread ow
Hi, I tried CLUSTER and it did improve performance, somewhat. The query against "clustered" table performs about five (5) times better than the same table but "non-clustered". However, even after that table was clustered, the difference in performance between single record query and range query is

Re: [SQL] pg 7.4.rc1, Range query performance

2003-11-10 Thread ow
--- Stephan Szabo <[EMAIL PROTECTED]> wrote: > I'm not sure that AK_abc is the best index for check a range on a and > single values on b and c. I'd think that something like an index > on (b,c,a) would probably be better for this purpose (without doing any > testing ;) ). That would not work fo

Re: [SQL] pg 7.4.rc1, Range query performance

2003-11-10 Thread Bruce Momjian
ow wrote: > Hi, > > I tried CLUSTER and it did improve performance, somewhat. The query against > "clustered" table performs about five (5) times better than the same table but > "non-clustered". However, even after that table was clustered, the difference > in performance between single record qu

Re: [SQL] pg 7.4.rc1, Range query performance

2003-11-10 Thread Stephan Szabo
On Mon, 10 Nov 2003, ow wrote: > --- Stephan Szabo <[EMAIL PROTECTED]> wrote: > > I'm not sure that AK_abc is the best index for check a range on a and > > single values on b and c. I'd think that something like an index > > on (b,c,a) would probably be better for this purpose (without doing any

[SQL] Query Problem

2003-11-10 Thread Abdul Wahab Dahalan
Hi there! If I've a table like below. kk kj pngk vote 01 02 c 10 01 02 b 5 How do I make a query so that I can get a result like this? kk kj pngk vote 01 02 c,b 15 Any help pretty much appreciated. -

Re: [SQL] pg 7.4.rc1, Range query performance

2003-11-10 Thread ow
--- Bruce Momjian <[EMAIL PROTECTED]> wrote: > Strange 30 records takes 30x the time than one record. Can you run > ANALYZE and send us an EXPLAIN of the query to make sure it hasn't > changed? > explain analyze select * from Test where a >= '2002-06-18' and a <= '2002-07-18' and b = 5 and

Re: [SQL] Query Problem

2003-11-10 Thread Joe Conway
Abdul Wahab Dahalan wrote: If I've a table like below. kk kjpngkvote 01 02 c 10 01 02 b 5 How do I make a query so that I can get a result like this? kk kjpngkvote 01 02c,b 15 create or replace function accum_text(tex

Re: [SQL] pg 7.4.rc1, Range query performance

2003-11-10 Thread Bruce Momjian
ow wrote: > --- Bruce Momjian <[EMAIL PROTECTED]> wrote: > > Strange 30 records takes 30x the time than one record. Can you run > > ANALYZE and send us an EXPLAIN of the query to make sure it hasn't > > changed? > > > > explain analyze select * from Test > where a >= '2002-06-18' > and a <= '2

Re: [SQL] pg 7.4.rc1, Range query performance

2003-11-10 Thread Tom Lane
Bruce Momjian <[EMAIL PROTECTED]> writes: > Sorry there isn't a simple solution. But there is: make an index with the column order (b,c,a). regards, tom lane ---(end of broadcast)--- TIP 8: explain analyze is your friend

Re: [SQL] pg 7.4.rc1, Range query performance

2003-11-10 Thread Bruce Momjian
Tom Lane wrote: > Bruce Momjian <[EMAIL PROTECTED]> writes: > > Sorry there isn't a simple solution. > > But there is: make an index with the column order (b,c,a). Oh, yea, right. If he puts the columns he is doing a straight equals comparison first, the 'a' comparison will work fine. Great. -