On Tuesday 12 January 2010 01:06:22 Takahiro Itagaki wrote:
> Psql shows too many parentheses when it prints triggers with WHEN clause.
>
> postgres=# \d t1
>       Table "public.t1"
>  Column |  Type   | Modifiers
> --------+---------+-----------
>  c1     | integer |
> Triggers:
>     mytrig AFTER UPDATE ON t1 FOR EACH ROW
>     WHEN ((old.c1 <> new.c1)) EXECUTE PROCEDURE myfunc()
>           ^                ^
>
> The attached patch eliminates unneeded parentheses by using
> pg_get_triggerdef(pretty = true) in psql.
>
> Triggers:
>     mytrig AFTER UPDATE ON t1 FOR EACH ROW
>     WHEN (old.c1 <> new.c1) EXECUTE PROCEDURE myfunc()
>
> <snip>

        Greetings,

        I tried to apply this patch to the latest version of PostgreSQL in git 
(bbfc96e).  Some of the patch did not apply.  Please 
find attached the output from patch.  The full path of the ruleutils.c.rej is 
src/backend/utils/adt/ruleutils.c.rej

        Thanks,

        --bts
Hmm...  Looks like a new-style context diff to me...
The text leading up to this was:
--------------------------
|diff -cprN head/src/backend/utils/adt/ruleutils.c 
work/src/backend/utils/adt/ruleutils.c
|*** head/src/backend/utils/adt/ruleutils.c     2010-01-04 09:10:26.638773000 
+0900
|--- work/src/backend/utils/adt/ruleutils.c     2010-01-12 17:51:27.595666819 
+0900
--------------------------
Patching file src/backend/utils/adt/ruleutils.c using Plan A...
Hunk #1 failed at 518.
Hunk #2 failed at 572.
Hunk #3 succeeded at 636.
2 out of 3 hunks failed--saving rejects to src/backend/utils/adt/ruleutils.c.rej
Hmm...  The next patch looks like a new-style context diff to me...
The text leading up to this was:
--------------------------
|diff -cprN head/src/bin/psql/describe.c work/src/bin/psql/describe.c
|*** head/src/bin/psql/describe.c       2010-01-04 09:10:26.638773000 +0900
|--- work/src/bin/psql/describe.c       2010-01-12 17:51:27.597646243 +0900
--------------------------
Patching file src/bin/psql/describe.c using Plan A...
Hunk #1 succeeded at 1854 with fuzz 2.
Hmm...  The next patch looks like a new-style context diff to me...
The text leading up to this was:
--------------------------
|diff -cprN head/src/test/regress/expected/triggers.out 
work/src/test/regress/expected/triggers.out
|*** head/src/test/regress/expected/triggers.out        2009-11-24 
10:04:57.883822000 +0900
|--- work/src/test/regress/expected/triggers.out        2010-01-12 
17:53:21.142635393 +0900
--------------------------
Patching file src/test/regress/expected/triggers.out using Plan A...
Hunk #1 succeeded at 375.
Hunk #2 succeeded at 387.
Hunk #3 succeeded at 416.
Hmm...  The next patch looks like a new-style context diff to me...
The text leading up to this was:
--------------------------
|diff -cprN head/src/test/regress/sql/triggers.sql 
work/src/test/regress/sql/triggers.sql
|*** head/src/test/regress/sql/triggers.sql     2009-11-24 10:04:57.883822000 
+0900
|--- work/src/test/regress/sql/triggers.sql     2010-01-12 17:51:27.597646243 
+0900
--------------------------
Patching file src/test/regress/sql/triggers.sql using Plan A...
Hunk #1 succeeded at 304.
done
***************
*** 518,527 ****
  	initStringInfo(&buf);
  
  	tgname = NameStr(trigrec->tgname);
! 	appendStringInfo(&buf, "CREATE %sTRIGGER %s",
! 					 trigrec->tgisconstraint ? "CONSTRAINT " : "",
  					 quote_identifier(tgname));
- 	appendStringInfoString(&buf, pretty ? "\n    " : " ");
  
  	if (TRIGGER_FOR_BEFORE(trigrec->tgtype))
  		appendStringInfo(&buf, "BEFORE");
--- 518,526 ----
  	initStringInfo(&buf);
  
  	tgname = NameStr(trigrec->tgname);
! 	appendStringInfo(&buf, "CREATE %sTRIGGER %s ",
! 					 trigrec->tgisconstraint ? "CONSTRAINT" : "",
  					 quote_identifier(tgname));
  
  	if (TRIGGER_FOR_BEFORE(trigrec->tgtype))
  		appendStringInfo(&buf, "BEFORE");
***************
*** 573,605 ****
  			appendStringInfo(&buf, " TRUNCATE");
  		findx++;
  	}
! 	appendStringInfo(&buf, " ON %s",
  					 generate_relation_name(trigrec->tgrelid, NIL));
- 	appendStringInfoString(&buf, pretty ? "\n    " : " ");
  
  	if (trigrec->tgisconstraint)
  	{
  		if (OidIsValid(trigrec->tgconstrrelid))
! 		{
! 			appendStringInfo(&buf, "FROM %s",
  							 generate_relation_name(trigrec->tgconstrrelid, NIL));
- 			appendStringInfoString(&buf, pretty ? "\n    " : " ");
- 		}
  		if (!trigrec->tgdeferrable)
  			appendStringInfo(&buf, "NOT ");
  		appendStringInfo(&buf, "DEFERRABLE INITIALLY ");
  		if (trigrec->tginitdeferred)
! 			appendStringInfo(&buf, "DEFERRED");
  		else
! 			appendStringInfo(&buf, "IMMEDIATE");
! 		appendStringInfoString(&buf, pretty ? "\n    " : " ");
  	}
  
  	if (TRIGGER_FOR_ROW(trigrec->tgtype))
! 		appendStringInfo(&buf, "FOR EACH ROW");
  	else
! 		appendStringInfo(&buf, "FOR EACH STATEMENT");
! 	appendStringInfoString(&buf, pretty ? "\n    " : " ");
  
  	/* If the trigger has a WHEN qualification, add that */
  	value = fastgetattr(ht_trig, Anum_pg_trigger_tgqual,
--- 572,598 ----
  			appendStringInfo(&buf, " TRUNCATE");
  		findx++;
  	}
! 	appendStringInfo(&buf, " ON %s ",
  					 generate_relation_name(trigrec->tgrelid, NIL));
  
  	if (trigrec->tgisconstraint)
  	{
  		if (OidIsValid(trigrec->tgconstrrelid))
! 			appendStringInfo(&buf, "FROM %s ",
  							 generate_relation_name(trigrec->tgconstrrelid, NIL));
  		if (!trigrec->tgdeferrable)
  			appendStringInfo(&buf, "NOT ");
  		appendStringInfo(&buf, "DEFERRABLE INITIALLY ");
  		if (trigrec->tginitdeferred)
! 			appendStringInfo(&buf, "DEFERRED ");
  		else
! 			appendStringInfo(&buf, "IMMEDIATE ");
  	}
  
  	if (TRIGGER_FOR_ROW(trigrec->tgtype))
! 		appendStringInfo(&buf, "FOR EACH ROW ");
  	else
! 		appendStringInfo(&buf, "FOR EACH STATEMENT ");
  
  	/* If the trigger has a WHEN qualification, add that */
  	value = fastgetattr(ht_trig, Anum_pg_trigger_tgqual,
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to