Re: [PATCHES] fori stmt with by keyword was:(Re: [HACKERS] for statement,
Patch applied. Thanks. --- Jaime Casanova wrote: On 5/30/06, Bruce Momjian pgman@candle.pha.pa.us wrote: I went to test this patch and got the attached regression failures. Please repair and resubmit. Thanks. did it. sorry for the delay, i was busy this week. -- Atentamente, Jaime Casanova Programming today is a race between software engineers striving to build bigger and better idiot-proof programs and the universe trying to produce bigger and better idiots. So far, the universe is winning. Richard Cook [ Attachment, skipping... ] ---(end of broadcast)--- TIP 9: In versions below 8.0, the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match -- Bruce Momjian http://candle.pha.pa.us EnterpriseDBhttp://www.enterprisedb.com + If your life is a hard drive, Christ can be your backup. + ---(end of broadcast)--- TIP 4: Have you searched our list archives? http://archives.postgresql.org
Re: [PATCHES] fori stmt with by keyword was:(Re: [HACKERS] for statement,
On 5/30/06, Bruce Momjian pgman@candle.pha.pa.us wrote: I went to test this patch and got the attached regression failures. Please repair and resubmit. Thanks. did it. sorry for the delay, i was busy this week. -- Atentamente, Jaime Casanova Programming today is a race between software engineers striving to build bigger and better idiot-proof programs and the universe trying to produce bigger and better idiots. So far, the universe is winning. Richard Cook fori.patch Description: Binary data ---(end of broadcast)--- TIP 9: In versions below 8.0, the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match
Re: [PATCHES] fori stmt with by keyword was:(Re: [HACKERS] for statement,
I went to test this patch and got the attached regression failures. Please repair and resubmit. Thanks. --- Jaime Casanova wrote: On 4/30/06, Jaime Casanova [EMAIL PROTECTED] wrote: On 4/29/06, Andrew Dunstan [EMAIL PROTECTED] wrote: Tom Lane wrote: Jaime Casanova [EMAIL PROTECTED] writes: there is a chance to add a STEP clause to the FOR statement in plpgsql? This is not free: it'd require making STEP a reserved word (at least within plpgsql) which is contrary to spec. I think you need to make a pretty good case why the value of the feature outweighs breaking applications that have perfectly-legally used step as an identifier. This isn't available in PL/SQL, is it? That doesn't mean we shouldn't do it, of course, but it might lessen any perceived imperative. Maybe using BY instad of STEP as the keyword would make it easier, since its occurrence in SQL makes it less likely to be used as a variable. cheers andrew Hi, i make a little patch using BY instead of STEP per Tom's complaint and Andrew's suggestion. the patch is ready, at least it seems to me... also i have added some lines to the docs... let me know what your decision is about this... -- regards, Jaime Casanova Programming today is a race between software engineers striving to build bigger and better idiot-proof programs and the universe trying to produce bigger and better idiots. So far, the universe is winning. Richard Cook -- Bruce Momjian http://candle.pha.pa.us EnterpriseDBhttp://www.enterprisedb.com + If your life is a hard drive, Christ can be your backup. + *** ./expected/plpgsql.out Tue May 30 07:58:19 2006 --- ./results/plpgsql.out Tue May 30 08:13:52 2006 *** *** 1466,1474 --- 1466,1482 -- ethernet interface into the wall and patch it to the hub. -- insert into Hub values ('base.hub1', 'Patchfield PF0_1 hub', 16); + ERROR: syntax error at or near ¤ + LINE 1: ¤JäH¯#¤F + ^ + QUERY: ¤JäH¯#¤F + CONTEXT: PL/pgSQL function tg_hub_adjustslots line 9 at for with integer loopvar + PL/pgSQL function tg_hub_a line 6 at assignment insert into System values ('orion', 'PC'); insert into IFace values ('IF', 'orion', 'eth0', 'WS.002.1b'); update PSlot set slotlink = 'HS.base.hub1.1' where slotname = 'PS.base.b2'; + ERROR: HS.base.hub1.1 does not exist + CONTEXT: PL/pgSQL function tg_slotlink_a line 16 at assignment -- -- Now we take a look at the patchfield -- *** *** 1482,1488 PF0_1 | PS.base.a5 | WS.001.3a in room 001 - - | - PF0_1 | PS.base.a6 | WS.001.3b in room 001 - - | - PF0_1 | PS.base.b1 | WS.002.1a in room 002 - Phone PH.hc002 (Hicom standard) | PS.base.ta5 - Phone line -103 ! PF0_1 | PS.base.b2 | WS.002.1b in room 002 - orion IF eth0 (PC) | Patchfield PF0_1 hub slot 1 PF0_1 | PS.base.b3 | WS.002.2a in room 002 - Phone PH.hc003 (Hicom standard) | PS.base.tb2 - Phone line -106 PF0_1 | PS.base.b4 | WS.002.2b in room 002 - - | - PF0_1 | PS.base.b5 | WS.002.3a in room 002 - - | - --- 1490,1496 PF0_1 | PS.base.a5 | WS.001.3a in room 001 - - | - PF0_1 | PS.base.a6 | WS.001.3b in room 001 - - | - PF0_1 | PS.base.b1 | WS.002.1a in room 002 - Phone PH.hc002 (Hicom standard) | PS.base.ta5 - Phone line -103 ! PF0_1 | PS.base.b2 | WS.002.1b in room 002 - orion IF eth0 (PC) | - PF0_1 | PS.base.b3 | WS.002.2a in room 002 - Phone PH.hc003 (Hicom standard) | PS.base.tb2 - Phone line -106 PF0_1 | PS.base.b4 | WS.002.2b in room 002 - - | - PF0_1 | PS.base.b5 | WS.002.3a in room 002 - - | - *** *** 1530,1540 ERROR: illegal slotlink beginning with XX CONTEXT: PL/pgSQL function tg_slotlink_a line 16 at assignment insert into HSlot values ('HS', 'base.hub1', 1, ''); ! ERROR: duplicate key violates unique constraint hslot_name insert into HSlot values ('HS', 'base.hub1', 20, ''); ERROR: no manual manipulation of HSlot delete from HSlot; - ERROR: no manual manipulation of HSlot insert into IFace values ('IF', 'notthere', 'eth0', ''); ERROR: system notthere does not exist insert into IFace values ('IF', 'orion', 'ethernet_interface_name_too_long', ''); --- 1538,1547 ERROR: illegal slotlink beginning with XX CONTEXT: PL/pgSQL function tg_slotlink_a line 16 at assignment insert into HSlot
Re: [PATCHES] fori stmt with by keyword was:(Re: [HACKERS] for statement, adding a STEP clause?)
On 4/30/06, Jaime Casanova [EMAIL PROTECTED] wrote: On 4/29/06, Andrew Dunstan [EMAIL PROTECTED] wrote: Tom Lane wrote: Jaime Casanova [EMAIL PROTECTED] writes: there is a chance to add a STEP clause to the FOR statement in plpgsql? This is not free: it'd require making STEP a reserved word (at least within plpgsql) which is contrary to spec. I think you need to make a pretty good case why the value of the feature outweighs breaking applications that have perfectly-legally used step as an identifier. This isn't available in PL/SQL, is it? That doesn't mean we shouldn't do it, of course, but it might lessen any perceived imperative. Maybe using BY instad of STEP as the keyword would make it easier, since its occurrence in SQL makes it less likely to be used as a variable. cheers andrew Hi, i make a little patch using BY instead of STEP per Tom's complaint and Andrew's suggestion. the patch is ready, at least it seems to me... also i have added some lines to the docs... let me know what your decision is about this... -- regards, Jaime Casanova Programming today is a race between software engineers striving to build bigger and better idiot-proof programs and the universe trying to produce bigger and better idiots. So far, the universe is winning. Richard Cook diff -rcEib pgsql-8.2dev/doc/src/sgml/plpgsql.sgml pgsql-8.2fori/doc/src/sgml/plpgsql.sgml *** pgsql-8.2dev/doc/src/sgml/plpgsql.sgml 2006-05-01 08:49:20.0 -0500 --- pgsql-8.2fori/doc/src/sgml/plpgsql.sgml 2006-05-05 17:31:36.0 -0500 *** *** 1960,1966 synopsis optional lt;lt;replaceablelabel/replaceablegt;gt; /optional ! FOR replaceablename/replaceable IN optional REVERSE /optional replaceableexpression/replaceable .. replaceableexpression/replaceable LOOP replaceablestatements/replaceable END LOOP optional replaceablelabel/replaceable /optional; /synopsis --- 1960,1966 synopsis optional lt;lt;replaceablelabel/replaceablegt;gt; /optional ! FOR replaceablename/replaceable IN optional REVERSE /optional replaceableexpression/replaceable .. replaceableexpression/replaceable optional BY replaceableexpression/replaceable /optional LOOP replaceablestatements/replaceable END LOOP optional replaceablelabel/replaceable /optional; /synopsis *** *** 1973,1980 definition of the variable name is ignored within the loop). The two expressions giving the lower and upper bound of the range are evaluated once when entering ! the loop. The iteration step is normally 1, but is -1 when literalREVERSE/ is ! specified. /para para --- 1973,1982 definition of the variable name is ignored within the loop). The two expressions giving the lower and upper bound of the range are evaluated once when entering ! the loop. If the literalBY/ clause isn't specified the iteration ! step is 1 otherwise it's the value specified in the literalBY/ ! clause. If literalREVERSE/ is specified then the step value is ! considered negative. /para para *** *** 1988,1993 --- 1990,2000 FOR i IN REVERSE 10..1 LOOP -- some computations here END LOOP; + + FOR i IN REVERSE 10..1 BY 2 LOOP + -- some computations here + RAISE NOTICE 'i is %', i; + END LOOP; /programlisting /para diff -rcEib pgsql-8.2dev/src/pl/plpgsql/src/gram.y pgsql-8.2fori/src/pl/plpgsql/src/gram.y *** pgsql-8.2dev/src/pl/plpgsql/src/gram.y 2006-05-01 08:49:39.0 -0500 --- pgsql-8.2fori/src/pl/plpgsql/src/gram.y 2006-05-05 17:42:08.0 -0500 *** *** 143,148 --- 143,149 %token K_ALIAS %token K_ASSIGN %token K_BEGIN + %token K_BY %token K_CLOSE %token K_CONSTANT %token K_CONTINUE *** *** 930,935 --- 931,937 { /* Saw .., so it must be an integer loop */ PLpgSQL_expr *expr2; + PLpgSQL_expr *expr_by; PLpgSQL_var *fvar; PLpgSQL_stmt_fori *new; char*varname; *** *** 937,943 /* First expression is well-formed */ check_sql_expr(expr1-query); ! expr2 = plpgsql_read_expression(K_LOOP, LOOP); /* should have had a single variable name */ plpgsql_error_lineno = $2.lineno; --- 939,968 /* First expression is well-formed */ check_sql_expr(expr1-query); ! ! expr2 = read_sql_construct(K_BY, ! K_LOOP, ! LOOP, ! SELECT , ! true, ! false, ! tok); ! ! if (tok == K_BY) ! expr_by = plpgsql_read_expression(K_LOOP, LOOP); ! else ! { ! /* ! * If there is no BY clause we will assume 1 !
[PATCHES] fori stmt with by keyword was:(Re: [HACKERS] for statement, adding a STEP clause?)
On 4/29/06, Andrew Dunstan [EMAIL PROTECTED] wrote: Tom Lane wrote: Jaime Casanova [EMAIL PROTECTED] writes: there is a chance to add a STEP clause to the FOR statement in plpgsql? This is not free: it'd require making STEP a reserved word (at least within plpgsql) which is contrary to spec. I think you need to make a pretty good case why the value of the feature outweighs breaking applications that have perfectly-legally used step as an identifier. This isn't available in PL/SQL, is it? That doesn't mean we shouldn't do it, of course, but it might lessen any perceived imperative. Maybe using BY instad of STEP as the keyword would make it easier, since its occurrence in SQL makes it less likely to be used as a variable. cheers andrew Hi, i make a little patch using BY instead of STEP per Tom's complaint and Andrew's suggestion. the patch is not ready yet because i can't figure out how to make the BY optional and that is mandatory because backward compatibility... the problem is how to manage it in gram.y perhaps someone with more expertise in gram.y can make suggestions? also, you can review the patch and say if it will be added if i can solve the optional BY problem... then i can start working in fixing the docs -- regards, Jaime Casanova What they (MySQL) lose in usability, they gain back in benchmarks, and that's all that matters: getting the wrong answer really fast. Randal L. Schwartz diff -rciEb pgsql-8.2dev/src/pl/plpgsql/src/gram.y pgsql-8.2fori/src/pl/plpgsql/src/gram.y *** pgsql-8.2dev/src/pl/plpgsql/src/gram.y 2006-04-30 09:45:12.0 -0500 --- pgsql-8.2fori/src/pl/plpgsql/src/gram.y 2006-04-30 09:49:05.0 -0500 *** *** 143,148 --- 143,149 %token K_ALIAS %token K_ASSIGN %token K_BEGIN + %token K_BY %token K_CLOSE %token K_CONSTANT %token K_CONTINUE *** *** 930,935 --- 931,937 { /* Saw .., so it must be an integer loop */ PLpgSQL_expr *expr2; + PLpgSQL_expr *expr_by; PLpgSQL_var *fvar; PLpgSQL_stmt_fori *new; char*varname; *** *** 937,943 /* First expression is well-formed */ check_sql_expr(expr1-query); ! expr2 = plpgsql_read_expression(K_LOOP, LOOP); /* should have had a single variable name */ plpgsql_error_lineno = $2.lineno; --- 939,951 /* First expression is well-formed */ check_sql_expr(expr1-query); ! expr2 = read_sql_construct(K_BY, K_LOOP, ! BY|LOOP, ! SELECT , true, ! false, tok); ! ! if (tok = K_BY) ! expr_by = plpgsql_read_expression(K_LOOP, LOOP); /* should have had a single variable name */ plpgsql_error_lineno = $2.lineno; *** *** 965,970 --- 973,979 new-reverse = reverse; new-lower = expr1; new-upper = expr2; + new-by = expr_by; $$ = (PLpgSQL_stmt *) new; } diff -rciEb pgsql-8.2dev/src/pl/plpgsql/src/pl_exec.c pgsql-8.2fori/src/pl/plpgsql/src/pl_exec.c *** pgsql-8.2dev/src/pl/plpgsql/src/pl_exec.c 2006-04-30 09:45:12.0 -0500 --- pgsql-8.2fori/src/pl/plpgsql/src/pl_exec.c 2006-04-30 09:49:54.0 -0500 *** *** 1346,1352 /* -- * exec_stmt_fori Iterate an integer variable ! * from a lower to an upper value. * Loop can be left with exit. * -- */ --- 1346,1353 /* -- * exec_stmt_fori Iterate an integer variable ! * from a lower to an upper value ! * incrementing or decrementing in BY value * Loop can be left with exit. * -- */ *** *** 1355,1360 --- 1356,1362 { PLpgSQL_var *var; Datum value; + Datum by_value; Oid valtype; bool isnull; bool found = false; *** *** 1393,1398 --- 1395,1414 exec_eval_cleanup(estate); /* + * Get the by value + */ + by_value = exec_eval_expr(estate, stmt-by, isnull, valtype); + by_value = exec_cast_value(by_value, valtype, var-datatype-typoid, + (var-datatype-typinput), + var-datatype-typioparam, + var-datatype-atttypmod, isnull); + + /* If there is no BY, then we assume 1 */ + if (isnull) + by_value = (Datum) 1; + exec_eval_cleanup(estate); + + /* * Now do the loop */ for (;;) *** *** 1468,1476 * Increase/decrease loop var */ if (stmt-reverse) ! var-value--; else ! var-value++; } /* --- 1484,1492 * Increase/decrease loop var */ if (stmt-reverse) ! var-value -= by_value; else ! var-value += by_value; } /* diff -rciEb pgsql-8.2dev/src/pl/plpgsql/src/plpgsql.h pgsql-8.2fori/src/pl/plpgsql/src/plpgsql.h ***