Re: [PATCHES] ruleutils with pretty-print option

2003-07-31 Thread Andreas Pflug
Tom Lane wrote:

Applied with some editorializing.  In particular, I don't believe the
original did the right thing with (a - (b - c)).
	

Oops, missed that case...
But now, we have (a + ( b + c)) again.
A patch that removes parentheses for + and * is appended.
Regards,
Andfdsa
---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
   (send unregister YourEmailAddressHere to [EMAIL PROTECTED])


[Fwd: Re: [PATCHES] ruleutils with pretty-print option]

2003-07-31 Thread Andreas Pflug
Now the patch is *really* appended :-)

Tom Lane wrote:

Applied with some editorializing.  In particular, I don't believe the
original did the right thing with (a - (b - c)).
	

Oops, missed that case...
But now, we have (a + ( b + c)) again.
A patch that removes parentheses for + and * is appended.
Regards,
Andfdsa

Index: backend/utils/adt/ruleutils.c
===
RCS file: /projects/cvsroot/pgsql-server/src/backend/utils/adt/ruleutils.c,v
retrieving revision 1.147
diff -c -r1.147 ruleutils.c
*** backend/utils/adt/ruleutils.c   30 Jul 2003 22:56:23 -  1.147
--- backend/utils/adt/ruleutils.c   31 Jul 2003 09:32:15 -
***
*** 2547,2552 
--- 2547,2559 
if (node == (Node *) lfirst(((OpExpr *) 
parentNode)-args))
return true;
  
+   /*
+  * Exception: for * and +, ordering doesn't matter
+  */
+   if ((*op == '+'  *parentOp == '+') ||
+   (*op == '*'  *parentOp == '*'))
+   return true;
+ 
return false;
}
  /* else do the same stuff as for T_SubLink et al. */

---(end of broadcast)---
TIP 7: don't forget to increase your free space map settings


Re: [Fwd: Re: [PATCHES] ruleutils with pretty-print option]

2003-07-31 Thread Andreas Pflug
Tom Lane wrote:

Now the patch is *really* appended :-)
   

And rejected.  

Ok, the ckeck for node being the first child already does the trick for 
standard l-t-r evaluation.

You cannot assume that an operator is commutative or
associative just because it has a name you think ought to be.
(For a counter-example, it's well known that floating-point addition
is not associative.)
Well, to me it's not well-known that floating-point addition is not 
associative, do I need to re-learn my math?

More: if the tree structure for ops of equal precedence looks like
a + (b + c), then it's a near certainty that the user wrote those
parentheses.  Why would you think that removing them is pretty-printing?
In this case the user really wrote the parentheses, so they should be shown.
This stuff is all about guessing what the original definition looked 
like, if we just had the source sigh...
I had a conversation with Bruce about embedded comments, and we found 
that the idea of (mis-)using nodes for this seems to be not viable. 
Still seeking for a way to preserve more-or-less the original user's 
definition.

Regards,
Andreas
---(end of broadcast)---
TIP 9: the planner will ignore your desire to choose an index scan if your
 joining column's datatypes do not match


Re: [Fwd: Re: [PATCHES] ruleutils with pretty-print option]

2003-07-31 Thread Tom Lane
Andreas Pflug [EMAIL PROTECTED] writes:
 Now the patch is *really* appended :-)

And rejected.  You cannot assume that an operator is commutative or
associative just because it has a name you think ought to be.
(For a counter-example, it's well known that floating-point addition
is not associative.)

More: if the tree structure for ops of equal precedence looks like
a + (b + c), then it's a near certainty that the user wrote those
parentheses.  Why would you think that removing them is pretty-printing?

regards, tom lane

---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


Re: [Fwd: Re: [PATCHES] ruleutils with pretty-print option]

2003-07-31 Thread Andreas Pflug
Tom Lane wrote:

Andreas Pflug [EMAIL PROTECTED] writes:
 

Well, to me it's not well-known that floating-point addition is not 
associative, do I need to re-learn my math?
   

regression=# select (1.0::float8 + (-1.0::float8)) + 1.0e-20::float8;
?column?
--
   1e-20
(1 row)
regression=# select 1.0::float8 + ((-1.0::float8) + 1.0e-20::float8);
?column?
--
   0
(1 row)
 

Hi Tom,

I already suspected an example like this. Obviously in a pure math 
world, the second example is wrong, caused by implicite rounding. 
Fortunately, if omitting the float8 casts numeric is used, delivering 
ultimate precision.

Just for curiousity: on MSSQL2000, the first will deliver 
9.95E-21, and if the type decimal(30,25) is used both give 
0.000.  Even better, CAST(  CAST(1E-20 AS DECIMAL(30,25)  AS 
FLOAT) is 0.0 :-

Oracle 9.2 will calculate correctly with float down to 1.0e-40. 

Regards,
Andreas
---(end of broadcast)---
TIP 6: Have you searched our list archives?
  http://archives.postgresql.org


Re: [Fwd: Re: [PATCHES] ruleutils with pretty-print option]

2003-07-31 Thread Manfred Koizar
On Thu, 31 Jul 2003 16:30:17 +0200, Andreas Pflug
[EMAIL PROTECTED] wrote:
Well, to me it's not well-known that floating-point addition is not 
associative

This is a case of theory vs. practice mismatch:  In theory addition is
associative, in practice there is only limited storage available for a
floating-point number.  Let's do an example with 3 significant decimal
digits:

a = 1000internal representation: 1.00e3
b =1internal representation: 1.00e0
a + b = 1.001e3

which cannot be represented in our system, so it is rounded to 1.00e3
and we get

a + b = 1000
a + b + b + b + b + b + b + b + b + b + b = 1000

when evaluated left to right, but

a + (b + b + b + b + b + b + b + b + b + b) = 
1.00e3 + 1.00e1 = 1.01e3 = 1001

Servus
 Manfred

---(end of broadcast)---
TIP 6: Have you searched our list archives?

   http://archives.postgresql.org


Re: [PATCHES] ruleutils with pretty-print option

2003-07-31 Thread Bruce Momjian
Tom Lane wrote:
 Bruce Momjian [EMAIL PROTECTED] writes:
  I didn't like the functions ending in _ext.  I renamed them to _pp for
  pretty print.  Patch attached and applied.
 
 Seems to be shy a catversion bump; since you have just made an
 incompatible change in the internal-function-names array, one is needed.
 
 But I disagree with your opinion anyway --- _ext for extended made
 perfect sense to me, especially for the get_indexdef one which adds more
 than just prettyprint functionality.

OK. I never did the commit, so I will just discard the patch.

Thanks.

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  [EMAIL PROTECTED]   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073

---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send unregister YourEmailAddressHere to [EMAIL PROTECTED])


Re: [Fwd: Re: [PATCHES] ruleutils with pretty-print option]

2003-07-31 Thread Tom Lane
Andreas Pflug [EMAIL PROTECTED] writes:
 Well, to me it's not well-known that floating-point addition is not 
 associative, do I need to re-learn my math?

regression=# select (1.0::float8 + (-1.0::float8)) + 1.0e-20::float8;
 ?column?
--
1e-20
(1 row)

regression=# select 1.0::float8 + ((-1.0::float8) + 1.0e-20::float8);
 ?column?
--
0
(1 row)


regards, tom lane

---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faqs/FAQ.html


Re: [PATCHES] ruleutils with pretty-print option

2003-07-31 Thread Bruce Momjian

Would you send over the patch --- it was missing.

---

Andreas Pflug wrote:
 Tom Lane wrote:
 
 
 Applied with some editorializing.  In particular, I don't believe the
 original did the right thing with (a - (b - c)).
 
  
 
 
 Oops, missed that case...
 But now, we have (a + ( b + c)) again.
 A patch that removes parentheses for + and * is appended.
 
 Regards,
 Andfdsa
 
 
 ---(end of broadcast)---
 TIP 2: you can get off all lists at once with the unregister command
 (send unregister YourEmailAddressHere to [EMAIL PROTECTED])
 

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  [EMAIL PROTECTED]   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073

---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faqs/FAQ.html


Re: [PATCHES] ruleutils with pretty-print option

2003-07-30 Thread Bruce Momjian

I didn't like the functions ending in _ext.  I renamed them to _pp for
pretty print.  Patch attached and applied.

---

Tom Lane wrote:
 Andreas Pflug [EMAIL PROTECTED] writes:
  I recoded the stuff as Tom recommended, leaving the non-pretty version 
  function names as they used to be, inventing new pg_get__ext 
  functions for the extended stuff, and pushing the code down into 
  pg_get__worker functions when needed. We now need the additional 
  prototype include patch from builtins.h.
 
 Applied with some editorializing.  In particular, I don't believe the
 original did the right thing with (a - (b - c)).
 
   regards, tom lane
 
 ---(end of broadcast)---
 TIP 4: Don't 'kill -9' the postmaster
 

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  [EMAIL PROTECTED]   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073
Index: src/backend/utils/adt/ruleutils.c
===
RCS file: /cvsroot/pgsql-server/src/backend/utils/adt/ruleutils.c,v
retrieving revision 1.147
diff -c -c -r1.147 ruleutils.c
*** src/backend/utils/adt/ruleutils.c   30 Jul 2003 22:56:23 -  1.147
--- src/backend/utils/adt/ruleutils.c   31 Jul 2003 04:48:35 -
***
*** 228,234 
  
  
  Datum
! pg_get_ruledef_ext(PG_FUNCTION_ARGS)
  {
Oid ruleoid = PG_GETARG_OID(0);
boolpretty = PG_GETARG_BOOL(1);
--- 228,234 
  
  
  Datum
! pg_get_ruledef_pp(PG_FUNCTION_ARGS)
  {
Oid ruleoid = PG_GETARG_OID(0);
boolpretty = PG_GETARG_BOOL(1);
***
*** 337,343 
  
  
  Datum
! pg_get_viewdef_ext(PG_FUNCTION_ARGS)
  {
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
--- 337,343 
  
  
  Datum
! pg_get_viewdef_pp(PG_FUNCTION_ARGS)
  {
/* By OID */
Oid viewoid = PG_GETARG_OID(0);
***
*** 369,375 
  
  
  Datum
! pg_get_viewdef_name_ext(PG_FUNCTION_ARGS)
  {
/* By qualified name */
text   *viewname = PG_GETARG_TEXT_P(0);
--- 369,375 
  
  
  Datum
! pg_get_viewdef_name_pp(PG_FUNCTION_ARGS)
  {
/* By qualified name */
text   *viewname = PG_GETARG_TEXT_P(0);
***
*** 630,636 
  }
  
  Datum
! pg_get_indexdef_ext(PG_FUNCTION_ARGS)
  {
Oid indexrelid = PG_GETARG_OID(0);
int32   colno = PG_GETARG_INT32(1);
--- 630,636 
  }
  
  Datum
! pg_get_indexdef_pp(PG_FUNCTION_ARGS)
  {
Oid indexrelid = PG_GETARG_OID(0);
int32   colno = PG_GETARG_INT32(1);
***
*** 856,862 
  }
  
  Datum
! pg_get_constraintdef_ext(PG_FUNCTION_ARGS)
  {
Oid constraintId = PG_GETARG_OID(0);
boolpretty = PG_GETARG_BOOL(1);
--- 856,862 
  }
  
  Datum
! pg_get_constraintdef_pp(PG_FUNCTION_ARGS)
  {
Oid constraintId = PG_GETARG_OID(0);
boolpretty = PG_GETARG_BOOL(1);
***
*** 1175,1181 
  }
  
  Datum
! pg_get_expr_ext(PG_FUNCTION_ARGS)
  {
text*expr = PG_GETARG_TEXT_P(0);
Oid relid = PG_GETARG_OID(1);
--- 1175,1181 
  }
  
  Datum
! pg_get_expr_pp(PG_FUNCTION_ARGS)
  {
text*expr = PG_GETARG_TEXT_P(0);
Oid relid = PG_GETARG_OID(1);
Index: src/include/catalog/pg_proc.h
===
RCS file: /cvsroot/pgsql-server/src/include/catalog/pg_proc.h,v
retrieving revision 1.310
diff -c -c -r1.310 pg_proc.h
*** src/include/catalog/pg_proc.h   30 Jul 2003 22:56:24 -  1.310
--- src/include/catalog/pg_proc.h   31 Jul 2003 04:48:40 -
***
*** 3406,3422 
  DESCR(I/O);
  
  /* System-view support functions with pretty-print option */
! DATA(insert OID = 2504 (  pg_get_ruledef PGNSP PGUID 12 f f t f s 2 25 26 
16  pg_get_ruledef_ext - _null_ ));
  DESCR(source text of a rule with pretty-print option);
! DATA(insert OID = 2505 (  pg_get_viewdef PGNSP PGUID 12 f f t f s 2 25 25 
16  pg_get_viewdef_name_ext - _null_ ));
  DESCR(select statement of a view with pretty-print option);
! DATA(insert OID = 2506 (  pg_get_viewdef PGNSP PGUID 12 f f t f s 2 25 26 
16  pg_get_viewdef_ext - _null_ ));
  DESCR(select statement of a view with pretty-print option);
! DATA(insert OID = 2507 (  pg_get_indexdefPGNSP PGUID 12 f f t f s 3 25 26 
23 16  pg_get_indexdef_ext - _null_ ));
  DESCR(index description (full create statement or single expression) with 
pretty-print option);
! DATA(insert OID = 2508 (  pg_get_constraintdef PGNSP 

Re: [PATCHES] ruleutils with pretty-print option

2003-07-30 Thread Bruce Momjian

Patch applied, modified by Tom and myself.

---

Andreas Pflug wrote:
 Bruce Momjian wrote:
 
 Andreas, looks good, but I need a diff -c, context diff.
 
   
 
 Hi Bruce,
 I intentionally only attached only non-context diffs because the patch 
 is about 50 % size of the original file. Now, here's the same as context 
 diff.
 
 Regards,
 Andreas

 Index: pg_proc.h
 ===
 RCS file: /projects/cvsroot/pgsql-server/src/include/catalog/pg_proc.h,v
 retrieving revision 1.309
 diff -c -r1.309 pg_proc.h
 *** pg_proc.h 1 Jul 2003 00:04:38 -   1.309
 --- pg_proc.h 22 Jul 2003 12:52:07 -
 ***
 *** 3405,3410 
 --- 3405,3424 
   DATA(insert OID = 2503 (  anyarray_sendPGNSP PGUID 12 f f t f s 1 
 17 2277  anyarray_send - _null_ ));
   DESCR(I/O);
   
 + /* System-view support functions with pretty-print option */
 + DATA(insert OID = 2504 (  pg_get_ruledef   PGNSP PGUID 12 f f t f s 2 25 26 
 16  pg_get_ruledef - _null_ ));
 + DESCR(source text of a rule with pretty-print option);
 + DATA(insert OID = 2505 (  pg_get_viewdef   PGNSP PGUID 12 f f t f s 2 25 25 
 16  pg_get_viewdef_name - _null_ ));
 + DESCR(select statement of a view with pretty-print option);
 + DATA(insert OID = 2506 (  pg_get_viewdef   PGNSP PGUID 12 f f t f s 2 25 26 
 16  pg_get_viewdef - _null_ ));
 + DESCR(select statement of a view with pretty-print option);
 + DATA(insert OID = 2507 (  pg_get_indexdef  PGNSP PGUID 12 f f t f s 3 25 26 
 23 16  pg_get_indexdef - _null_ ));
 + DESCR(index description (full create statement or single expression) with 
 pretty-print option);
 + DATA(insert OID = 2508 (  pg_get_constraintdef PGNSP PGUID 12 f f t f s 2 25 26 
 16  pg_get_constraintdef - _null_ ));
 + DESCR(constraint description with pretty-print option);
 + DATA(insert OID = 2509 (  pg_get_expr  PGNSP PGUID 12 f f t f s 3 
 25 25 26 16 pg_get_expr - _null_ ));
 + DESCR(deparse an encoded expression with pretty-print option);
 + 
   
   /*
* Symbolic values for provolatile column: these indicate whether the result

 Index: ruleutils.c
 ===
 RCS file: /projects/cvsroot/pgsql-server/src/backend/utils/adt/ruleutils.c,v
 retrieving revision 1.145
 diff -c -r1.145 ruleutils.c
 *** ruleutils.c   4 Jul 2003 02:51:34 -   1.145
 --- ruleutils.c   22 Jul 2003 12:54:10 -
 ***
 *** 71,76 
 --- 71,95 
   #include utils/lsyscache.h
   
   
 + /**
 +  * Pretty formatting constants
 +  **/
 + 
 + /* Indent counts */
 + #define PRETTYINDENT_STD8
 + #define PRETTYINDENT_JOIN  13
 + #define PRETTYINDENT_JOIN_ON(PRETTYINDENT_JOIN-PRETTYINDENT_STD)
 + #define PRETTYINDENT_VAR4
 + 
 + /* Pretty flags */
 + #define PRETTYFLAG_PAREN1
 + #define PRETTYFLAG_INDENT   2
 + 
 + /* macro to test if pretty action needed */
 + #define PRETTY_PAREN(context)   (context-prettyFlags  PRETTYFLAG_PAREN)
 + #define PRETTY_INDENT(context)  (context-prettyFlags  PRETTYFLAG_INDENT)
 + 
 + 
   /* --
* Local data types
* --
 ***
 *** 81,86 
 --- 100,107 
   {
   StringInfo  buf;/* output buffer to append to */
   List   *namespaces; /* List of deparse_namespace nodes */
 + int prettyFlags;/* enabling/disabling of 
 pretty-print functions */
 + int indentLevel;/* for prettyPrint, current space 
 indents are counted */
   boolvarprefix;  /* TRUE to print prefixes on Vars */
   } deparse_context;
   
 ***
 *** 123,135 
* as a parameter, and append their text output to its contents.
* --
*/
 ! static text *pg_do_getviewdef(Oid viewoid);
   static void decompile_column_index_array(Datum column_index_array, Oid relId,
StringInfo buf);
 ! static void make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc);
 ! static void make_viewdef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc);
   static void get_query_def(Query *query, StringInfo buf, List *parentnamespace,
 !   TupleDesc resultDesc);
   static void get_select_query_def(Query *query, deparse_context *context,
TupleDesc resultDesc);
   static void get_insert_query_def(Query *query, deparse_context *context);
 --- 144,162 
* as a parameter, and append their text output to its contents.
* --
*/
 ! static char *get_simple_binary_op_name(OpExpr *expr);
 ! static void appendStringInfoSpace(StringInfo buf, int count);
 ! static void appendContextKeyword(deparse_context 

Re: [PATCHES] ruleutils with pretty-print option

2003-07-28 Thread Andreas Pflug
Tom Lane wrote:

Andreas Pflug [EMAIL PROTECTED] writes:
 

+ 	int prettyFlags = !PG_ARGISNULL(1)  PG_GETARG_BOOL(1) ? PRETTYFLAG_PAREN|PRETTYFLAG_INDENT : 0;
   

Since the pg_proc entries are all marked strict, it's unnecessary for
you to write any ARGISNULL checks.
Yeah you're right, it's a remainder of the previous solution. it was 
late at night... But it won't do any harm either.

Regards,
Andreas
---(end of broadcast)---
TIP 6: Have you searched our list archives?
  http://archives.postgresql.org


Re: [PATCHES] ruleutils with pretty-print option

2003-07-27 Thread Tom Lane
Bruce Momjian [EMAIL PROTECTED] writes:
 Are these illustrating a problem with the function definition, or is it
 happening because it is the first time we are calling the same function
 with one and more than one parameter?

The function definition is broken.  While it could be fixed (by
explicitly testing fcinfo-nargs, rather than assuming positions
beyond nargs are valid) I am not willing to remove the opr_sanity
check that is complaining.  Accordingly, a better solution would be
to make two C-code wrapper functions, one for the single-parameter
and one for the two-parameter case of each function.

regards, tom lane

---(end of broadcast)---
TIP 9: the planner will ignore your desire to choose an index scan if your
  joining column's datatypes do not match


Re: [PATCHES] ruleutils with pretty-print option

2003-07-27 Thread Bruce Momjian
Tom Lane wrote:
 Bruce Momjian [EMAIL PROTECTED] writes:
  Are these illustrating a problem with the function definition, or is it
  happening because it is the first time we are calling the same function
  with one and more than one parameter?
 
 The function definition is broken.  While it could be fixed (by
 explicitly testing fcinfo-nargs, rather than assuming positions
 beyond nargs are valid) I am not willing to remove the opr_sanity
 check that is complaining.  Accordingly, a better solution would be
 to make two C-code wrapper functions, one for the single-parameter
 and one for the two-parameter case of each function.

Tom, how do I pass PG_FUNCTION_ARGS to another function, while adding a
new parameter?  Would it be better to declare SQL functions to call new
functions with a prettyprint parameter of false?

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  [EMAIL PROTECTED]   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073

---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send unregister YourEmailAddressHere to [EMAIL PROTECTED])


Re: [PATCHES] ruleutils with pretty-print option

2003-07-27 Thread Tom Lane
Bruce Momjian [EMAIL PROTECTED] writes:
 Tom, how do I pass PG_FUNCTION_ARGS to another function, while adding a
 new parameter?

I wouldn't.  Do the PG_GETARGS in the wrapper, and have the called
function take a normal C parameter list.

regards, tom lane

---(end of broadcast)---
TIP 9: the planner will ignore your desire to choose an index scan if your
  joining column's datatypes do not match


Re: [PATCHES] ruleutils with pretty-print option

2003-07-27 Thread Bruce Momjian
Tom Lane wrote:
 Bruce Momjian [EMAIL PROTECTED] writes:
  Tom, how do I pass PG_FUNCTION_ARGS to another function, while adding a
  new parameter?
 
 I wouldn't.  Do the PG_GETARGS in the wrapper, and have the called
 function take a normal C parameter list.

So I need to wrappers for each function, one that pulls the pretty print
option, and another that doesn't, and they both call a normal C function?

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  [EMAIL PROTECTED]   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073

---(end of broadcast)---
TIP 9: the planner will ignore your desire to choose an index scan if your
  joining column's datatypes do not match


Re: [PATCHES] ruleutils with pretty-print option

2003-07-27 Thread Andreas Pflug
Bruce Momjian wrote:

Tom Lane wrote:
 

Bruce Momjian [EMAIL PROTECTED] writes:
   

Tom, how do I pass PG_FUNCTION_ARGS to another function, while adding a
new parameter?
 

I wouldn't.  Do the PG_GETARGS in the wrapper, and have the called
function take a normal C parameter list.
   

So I need to wrappers for each function, one that pulls the pretty print
option, and another that doesn't, and they both call a normal C function?
 

Hi Bruce,

sorry for my late reply, I was out for a day.

I wasn't aware of that regression test checking the arg count of the 
functions. I wanted to keep the impact on the source tree as small as 
possible, so I implemented that kind of overloaded functions.

I clearly understand that Tom doesn't like to weaken the check, because 
in most cases a regression failure really is a coding problem.

I recoded the stuff as Tom recommended, leaving the non-pretty version 
function names as they used to be, inventing new pg_get__ext 
functions for the extended stuff, and pushing the code down into 
pg_get__worker functions when needed. We now need the additional 
prototype include patch from builtins.h.

All-new stuff attached, diff'ed against the current cvs.

Regards,
Andreas


Index: include/catalog/pg_proc.h
===
RCS file: /projects/cvsroot/pgsql-server/src/include/catalog/pg_proc.h,v
retrieving revision 1.309
diff -c -r1.309 pg_proc.h
*** include/catalog/pg_proc.h   1 Jul 2003 00:04:38 -   1.309
--- include/catalog/pg_proc.h   27 Jul 2003 23:40:49 -
***
*** 3405,3410 
--- 3405,3424 
  DATA(insert OID = 2503 (  anyarray_send  PGNSP PGUID 12 f f t f s 1 
17 2277  anyarray_send - _null_ ));
  DESCR(I/O);
  
+ /* System-view support functions with pretty-print option */
+ DATA(insert OID = 2504 (  pg_get_ruledef PGNSP PGUID 12 f f t f s 2 25 26 
16  pg_get_ruledef_ext - _null_ ));
+ DESCR(source text of a rule with pretty-print option);
+ DATA(insert OID = 2505 (  pg_get_viewdef PGNSP PGUID 12 f f t f s 2 25 25 
16  pg_get_viewdef_name_ext - _null_ ));
+ DESCR(select statement of a view with pretty-print option);
+ DATA(insert OID = 2506 (  pg_get_viewdef PGNSP PGUID 12 f f t f s 2 25 26 
16  pg_get_viewdef_ext - _null_ ));
+ DESCR(select statement of a view with pretty-print option);
+ DATA(insert OID = 2507 (  pg_get_indexdefPGNSP PGUID 12 f f t f s 3 25 26 
23 16  pg_get_indexdef_ext - _null_ ));
+ DESCR(index description (full create statement or single expression) with 
pretty-print option);
+ DATA(insert OID = 2508 (  pg_get_constraintdef PGNSP PGUID 12 f f t f s 2 25 26 16 
 pg_get_constraintdef_ext - _null_ ));
+ DESCR(constraint description with pretty-print option);
+ DATA(insert OID = 2509 (  pg_get_exprPGNSP PGUID 12 f f t f s 3 25 25 
26 16 pg_get_expr_ext - _null_ ));
+ DESCR(deparse an encoded expression with pretty-print option);
+ 
  
  /*
   * Symbolic values for provolatile column: these indicate whether the result
Index: include/utils/builtins.h
===
RCS file: /projects/cvsroot/pgsql-server/src/include/utils/builtins.h,v
retrieving revision 1.223
diff -c -r1.223 builtins.h
*** include/utils/builtins.h27 Jun 2003 00:33:26 -  1.223
--- include/utils/builtins.h27 Jul 2003 23:41:58 -
***
*** 441,453 
--- 441,459 
  
  /* ruleutils.c */
  extern Datum pg_get_ruledef(PG_FUNCTION_ARGS);
+ extern Datum pg_get_ruledef_ext(PG_FUNCTION_ARGS);
  extern Datum pg_get_viewdef(PG_FUNCTION_ARGS);
+ extern Datum pg_get_viewdef_ext(PG_FUNCTION_ARGS);
  extern Datum pg_get_viewdef_name(PG_FUNCTION_ARGS);
+ extern Datum pg_get_viewdef_name_ext(PG_FUNCTION_ARGS);
  extern Datum pg_get_indexdef(PG_FUNCTION_ARGS);
+ extern Datum pg_get_indexdef_ext(PG_FUNCTION_ARGS);
  extern Datum pg_get_triggerdef(PG_FUNCTION_ARGS);
  extern Datum pg_get_constraintdef(PG_FUNCTION_ARGS);
+ extern Datum pg_get_constraintdef_ext(PG_FUNCTION_ARGS);
  extern Datum pg_get_userbyid(PG_FUNCTION_ARGS);
  extern Datum pg_get_expr(PG_FUNCTION_ARGS);
+ extern Datum pg_get_expr_ext(PG_FUNCTION_ARGS);
  extern char *deparse_expression(Node *expr, List *dpcontext,
   bool forceprefix, bool showimplicit);
  extern List *deparse_context_for(const char *aliasname, Oid relid);
Index: backend/utils/adt/ruleutils.c
===
RCS file: /projects/cvsroot/pgsql-server/src/backend/utils/adt/ruleutils.c,v
retrieving revision 1.146
diff -c -r1.146 ruleutils.c
*** backend/utils/adt/ruleutils.c   27 Jul 2003 04:53:09 -  1.146
--- backend/utils/adt/ruleutils.c   27 Jul 2003 23:42:40 -
***
*** 71,76 
--- 71,95 
  #include utils/lsyscache.h
  
  
+ /**
+  * Pretty formatting constants
+  

Re: [PATCHES] ruleutils with pretty-print option

2003-07-22 Thread Andreas Pflug
Bruce Momjian wrote:

Andreas, looks good, but I need a diff -c, context diff.

 

Hi Bruce,
I intentionally only attached only non-context diffs because the patch 
is about 50 % size of the original file. Now, here's the same as context 
diff.

Regards,
Andreas
Index: pg_proc.h
===
RCS file: /projects/cvsroot/pgsql-server/src/include/catalog/pg_proc.h,v
retrieving revision 1.309
diff -c -r1.309 pg_proc.h
*** pg_proc.h   1 Jul 2003 00:04:38 -   1.309
--- pg_proc.h   22 Jul 2003 12:52:07 -
***
*** 3405,3410 
--- 3405,3424 
  DATA(insert OID = 2503 (  anyarray_send  PGNSP PGUID 12 f f t f s 1 
17 2277  anyarray_send - _null_ ));
  DESCR(I/O);
  
+ /* System-view support functions with pretty-print option */
+ DATA(insert OID = 2504 (  pg_get_ruledef PGNSP PGUID 12 f f t f s 2 25 26 
16  pg_get_ruledef - _null_ ));
+ DESCR(source text of a rule with pretty-print option);
+ DATA(insert OID = 2505 (  pg_get_viewdef PGNSP PGUID 12 f f t f s 2 25 25 
16  pg_get_viewdef_name - _null_ ));
+ DESCR(select statement of a view with pretty-print option);
+ DATA(insert OID = 2506 (  pg_get_viewdef PGNSP PGUID 12 f f t f s 2 25 26 
16  pg_get_viewdef - _null_ ));
+ DESCR(select statement of a view with pretty-print option);
+ DATA(insert OID = 2507 (  pg_get_indexdefPGNSP PGUID 12 f f t f s 3 25 26 
23 16  pg_get_indexdef - _null_ ));
+ DESCR(index description (full create statement or single expression) with 
pretty-print option);
+ DATA(insert OID = 2508 (  pg_get_constraintdef PGNSP PGUID 12 f f t f s 2 25 26 16 
 pg_get_constraintdef - _null_ ));
+ DESCR(constraint description with pretty-print option);
+ DATA(insert OID = 2509 (  pg_get_exprPGNSP PGUID 12 f f t f s 3 25 25 
26 16 pg_get_expr - _null_ ));
+ DESCR(deparse an encoded expression with pretty-print option);
+ 
  
  /*
   * Symbolic values for provolatile column: these indicate whether the result
Index: ruleutils.c
===
RCS file: /projects/cvsroot/pgsql-server/src/backend/utils/adt/ruleutils.c,v
retrieving revision 1.145
diff -c -r1.145 ruleutils.c
*** ruleutils.c 4 Jul 2003 02:51:34 -   1.145
--- ruleutils.c 22 Jul 2003 12:54:10 -
***
*** 71,76 
--- 71,95 
  #include utils/lsyscache.h
  
  
+ /**
+  * Pretty formatting constants
+  **/
+ 
+ /* Indent counts */
+ #define PRETTYINDENT_STD8
+ #define PRETTYINDENT_JOIN  13
+ #define PRETTYINDENT_JOIN_ON(PRETTYINDENT_JOIN-PRETTYINDENT_STD)
+ #define PRETTYINDENT_VAR4
+ 
+ /* Pretty flags */
+ #define PRETTYFLAG_PAREN1
+ #define PRETTYFLAG_INDENT   2
+ 
+ /* macro to test if pretty action needed */
+ #define PRETTY_PAREN(context)   (context-prettyFlags  PRETTYFLAG_PAREN)
+ #define PRETTY_INDENT(context)  (context-prettyFlags  PRETTYFLAG_INDENT)
+ 
+ 
  /* --
   * Local data types
   * --
***
*** 81,86 
--- 100,107 
  {
StringInfo  buf;/* output buffer to append to */
List   *namespaces; /* List of deparse_namespace nodes */
+ int prettyFlags;/* enabling/disabling of 
pretty-print functions */
+ int indentLevel;/* for prettyPrint, current space 
indents are counted */
boolvarprefix;  /* TRUE to print prefixes on Vars */
  } deparse_context;
  
***
*** 123,135 
   * as a parameter, and append their text output to its contents.
   * --
   */
! static text *pg_do_getviewdef(Oid viewoid);
  static void decompile_column_index_array(Datum column_index_array, Oid relId,
 StringInfo buf);
! static void make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc);
! static void make_viewdef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc);
  static void get_query_def(Query *query, StringInfo buf, List *parentnamespace,
! TupleDesc resultDesc);
  static void get_select_query_def(Query *query, deparse_context *context,
 TupleDesc resultDesc);
  static void get_insert_query_def(Query *query, deparse_context *context);
--- 144,162 
   * as a parameter, and append their text output to its contents.
   * --
   */
! static char *get_simple_binary_op_name(OpExpr *expr);
! static void appendStringInfoSpace(StringInfo buf, int count);
! static void appendContextKeyword(deparse_context *context, char *str, int 
indentBefore, int indentAfter, int indentPlus);
! static char *deparse_expression_pretty(Node *expr, List *dpcontext,
! bool forceprefix, bool showimplicit, int prettyFlags, int 
startIndent);
! static bool 

Re: [PATCHES] ruleutils with pretty-print option

2003-07-22 Thread Bruce Momjian

Your patch has been added to the PostgreSQL unapplied patches list at:

http://momjian.postgresql.org/cgi-bin/pgpatches

I will try to apply it within the next 48 hours.

---


Andreas Pflug wrote:
 Bruce Momjian wrote:
 
 Andreas, looks good, but I need a diff -c, context diff.
 
   
 
 Hi Bruce,
 I intentionally only attached only non-context diffs because the patch 
 is about 50 % size of the original file. Now, here's the same as context 
 diff.
 
 Regards,
 Andreas

 Index: pg_proc.h
 ===
 RCS file: /projects/cvsroot/pgsql-server/src/include/catalog/pg_proc.h,v
 retrieving revision 1.309
 diff -c -r1.309 pg_proc.h
 *** pg_proc.h 1 Jul 2003 00:04:38 -   1.309
 --- pg_proc.h 22 Jul 2003 12:52:07 -
 ***
 *** 3405,3410 
 --- 3405,3424 
   DATA(insert OID = 2503 (  anyarray_sendPGNSP PGUID 12 f f t f s 1 
 17 2277  anyarray_send - _null_ ));
   DESCR(I/O);
   
 + /* System-view support functions with pretty-print option */
 + DATA(insert OID = 2504 (  pg_get_ruledef   PGNSP PGUID 12 f f t f s 2 25 26 
 16  pg_get_ruledef - _null_ ));
 + DESCR(source text of a rule with pretty-print option);
 + DATA(insert OID = 2505 (  pg_get_viewdef   PGNSP PGUID 12 f f t f s 2 25 25 
 16  pg_get_viewdef_name - _null_ ));
 + DESCR(select statement of a view with pretty-print option);
 + DATA(insert OID = 2506 (  pg_get_viewdef   PGNSP PGUID 12 f f t f s 2 25 26 
 16  pg_get_viewdef - _null_ ));
 + DESCR(select statement of a view with pretty-print option);
 + DATA(insert OID = 2507 (  pg_get_indexdef  PGNSP PGUID 12 f f t f s 3 25 26 
 23 16  pg_get_indexdef - _null_ ));
 + DESCR(index description (full create statement or single expression) with 
 pretty-print option);
 + DATA(insert OID = 2508 (  pg_get_constraintdef PGNSP PGUID 12 f f t f s 2 25 26 
 16  pg_get_constraintdef - _null_ ));
 + DESCR(constraint description with pretty-print option);
 + DATA(insert OID = 2509 (  pg_get_expr  PGNSP PGUID 12 f f t f s 3 
 25 25 26 16 pg_get_expr - _null_ ));
 + DESCR(deparse an encoded expression with pretty-print option);
 + 
   
   /*
* Symbolic values for provolatile column: these indicate whether the result

 Index: ruleutils.c
 ===
 RCS file: /projects/cvsroot/pgsql-server/src/backend/utils/adt/ruleutils.c,v
 retrieving revision 1.145
 diff -c -r1.145 ruleutils.c
 *** ruleutils.c   4 Jul 2003 02:51:34 -   1.145
 --- ruleutils.c   22 Jul 2003 12:54:10 -
 ***
 *** 71,76 
 --- 71,95 
   #include utils/lsyscache.h
   
   
 + /**
 +  * Pretty formatting constants
 +  **/
 + 
 + /* Indent counts */
 + #define PRETTYINDENT_STD8
 + #define PRETTYINDENT_JOIN  13
 + #define PRETTYINDENT_JOIN_ON(PRETTYINDENT_JOIN-PRETTYINDENT_STD)
 + #define PRETTYINDENT_VAR4
 + 
 + /* Pretty flags */
 + #define PRETTYFLAG_PAREN1
 + #define PRETTYFLAG_INDENT   2
 + 
 + /* macro to test if pretty action needed */
 + #define PRETTY_PAREN(context)   (context-prettyFlags  PRETTYFLAG_PAREN)
 + #define PRETTY_INDENT(context)  (context-prettyFlags  PRETTYFLAG_INDENT)
 + 
 + 
   /* --
* Local data types
* --
 ***
 *** 81,86 
 --- 100,107 
   {
   StringInfo  buf;/* output buffer to append to */
   List   *namespaces; /* List of deparse_namespace nodes */
 + int prettyFlags;/* enabling/disabling of 
 pretty-print functions */
 + int indentLevel;/* for prettyPrint, current space 
 indents are counted */
   boolvarprefix;  /* TRUE to print prefixes on Vars */
   } deparse_context;
   
 ***
 *** 123,135 
* as a parameter, and append their text output to its contents.
* --
*/
 ! static text *pg_do_getviewdef(Oid viewoid);
   static void decompile_column_index_array(Datum column_index_array, Oid relId,
StringInfo buf);
 ! static void make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc);
 ! static void make_viewdef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc);
   static void get_query_def(Query *query, StringInfo buf, List *parentnamespace,
 !   TupleDesc resultDesc);
   static void get_select_query_def(Query *query, deparse_context *context,
TupleDesc resultDesc);
   static void get_insert_query_def(Query *query, deparse_context *context);
 --- 144,162 
* as a parameter, and append their text output to its contents.
* --
*/
 ! static char 

Re: [PATCHES] ruleutils with pretty-print option

2003-07-22 Thread Bruce Momjian
Andreas Pflug wrote:
 Bruce Momjian wrote:
 
 Andreas, looks good, but I need a diff -c, context diff.
 
   
 
 Hi Bruce,
 I intentionally only attached only non-context diffs because the patch 
 is about 50 % size of the original file. Now, here's the same as context 
 diff.

I understand.  I need the context diff so I am sure the lines are going
where they are supposed to go.

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  [EMAIL PROTECTED]   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073

---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send unregister YourEmailAddressHere to [EMAIL PROTECTED])


Re: [PATCHES] ruleutils with pretty-print option

2003-07-21 Thread Andreas Pflug
Hi Bruce,
so here's the complete patch against the current cvs.
Description:
The attached patches will add
  pg_get_ruledef(oid, bool)
  pg_get_viewdef(text, bool)
  pg_get_viewdef(oid, bool)
  pg_get_indexdef(oid, int4, bool)
  pg_get_constraintdef(oid, bool)
  pg_get_expr(text, oid, bool)
If the last parameter pretty-print is false, these function will 
return the same result as their original counterparts without that 
parameter. The source is based on ruleutils.c 1.145 and pg_proc 1.309, 
and should return exactly the same result as before if no pretty-print 
is selected. My tests didn't show any differences for pg_dump output 
with old or new version.

If the last parameter pretty-print is true, parentheses are checked; 
only necessary parentheses will be emitted. Additionally, line and 
indentation formatting is performed.

pg_get_indexdef has one additional parameter. The second parameter 
(int4) selects the nth expression of an index (1..indnatts). If zero, a 
complete CREATE INDEX statement is generated to obtain the previous 
behaviour.
The third is the pretty-print option as described.

example:
pg_get_indexdef(12345, 0, true)  - CREATE INDEX foo ON bar (numcol, 
length(txtcol), intcol2, (8+length(txtcol2)))
pg_get_indexdef(12345, 1, true)  - numcol
pg_get_indexdef(12345, 2, true)  - length(txtcol)
pg_get_indexdef(12345, 3, true)  - intcol2
pg_get_indexdef(12345, 4, true)  - (8+length(txtcol2))

Regards,
Andreas
Index: pg_proc.h
===
RCS file: /projects/cvsroot/pgsql-server/src/include/catalog/pg_proc.h,v
retrieving revision 1.309
diff -r1.309 pg_proc.h
3407a3408,3421
 /* System-view support functions with pretty-print option */
 DATA(insert OID = 2504 (  pg_get_ruledef PGNSP PGUID 12 f f t f s 2 25 26 
 16  pg_get_ruledef - _null_ ));
 DESCR(source text of a rule with pretty-print option);
 DATA(insert OID = 2505 (  pg_get_viewdef PGNSP PGUID 12 f f t f s 2 25 25 
 16  pg_get_viewdef_name - _null_ ));
 DESCR(select statement of a view with pretty-print option);
 DATA(insert OID = 2506 (  pg_get_viewdef PGNSP PGUID 12 f f t f s 2 25 26 
 16  pg_get_viewdef - _null_ ));
 DESCR(select statement of a view with pretty-print option);
 DATA(insert OID = 2507 (  pg_get_indexdefPGNSP PGUID 12 f f t f s 3 25 26 
 23 16  pg_get_indexdef - _null_ ));
 DESCR(index description (full create statement or single expression) with 
 pretty-print option);
 DATA(insert OID = 2508 (  pg_get_constraintdef PGNSP PGUID 12 f f t f s 2 25 26 16 
  pg_get_constraintdef - _null_ ));
 DESCR(constraint description with pretty-print option);
 DATA(insert OID = 2509 (  pg_get_exprPGNSP PGUID 12 f f t f s 3 25 25 
 26 16 pg_get_expr - _null_ ));
 DESCR(deparse an encoded expression with pretty-print option);
 
Index: ruleutils.c
===
RCS file: /projects/cvsroot/pgsql-server/src/backend/utils/adt/ruleutils.c,v
retrieving revision 1.145
diff -r1.145 ruleutils.c
73a74,92
 /**
  * Pretty formatting constants
  **/
 
 /* Indent counts */
 #define PRETTYINDENT_STD8
 #define PRETTYINDENT_JOIN  13
 #define PRETTYINDENT_JOIN_ON(PRETTYINDENT_JOIN-PRETTYINDENT_STD)
 #define PRETTYINDENT_VAR4
 
 /* Pretty flags */
 #define PRETTYFLAG_PAREN1
 #define PRETTYFLAG_INDENT   2
 
 /* macro to test if pretty action needed */
 #define PRETTY_PAREN(context)   (context-prettyFlags  PRETTYFLAG_PAREN)
 #define PRETTY_INDENT(context)  (context-prettyFlags  PRETTYFLAG_INDENT)
 
 
83a103,104
 int prettyFlags;/* enabling/disabling of 
 pretty-print functions */
 int indentLevel;/* for prettyPrint, current space 
 indents are counted */
126c147,153
 static text *pg_do_getviewdef(Oid viewoid);
---
 static char *get_simple_binary_op_name(OpExpr *expr);
 static void appendStringInfoSpace(StringInfo buf, int count);
 static void appendContextKeyword(deparse_context *context, char *str, int 
 indentBefore, int indentAfter, int indentPlus);
 static char *deparse_expression_pretty(Node *expr, List *dpcontext,
 bool forceprefix, bool showimplicit, int prettyFlags, int 
 startIndent);
 static bool isSimpleNode(Node *node, Node *parentNode, int prettyFlags);
 static text *pg_do_getviewdef(Oid viewoid, int prettyFlags);
129,130c156,157
 static void make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc);
 static void make_viewdef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc);
---
 static void make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc, int 
 prettyFlags);
 static void make_viewdef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc, int 
 prettyFlags);
132c159
 TupleDesc resultDesc);
---
 TupleDesc resultDesc, int prettyFlags, int 

Re: [PATCHES] ruleutils with pretty-print option

2003-07-21 Thread Bruce Momjian

Andreas, looks good, but I need a diff -c, context diff.

---

Andreas Pflug wrote:
 Hi Bruce,
 so here's the complete patch against the current cvs.
 
 Description:
 The attached patches will add
pg_get_ruledef(oid, bool)
pg_get_viewdef(text, bool)
pg_get_viewdef(oid, bool)
pg_get_indexdef(oid, int4, bool)
pg_get_constraintdef(oid, bool)
pg_get_expr(text, oid, bool)
 
 If the last parameter pretty-print is false, these function will 
 return the same result as their original counterparts without that 
 parameter. The source is based on ruleutils.c 1.145 and pg_proc 1.309, 
 and should return exactly the same result as before if no pretty-print 
 is selected. My tests didn't show any differences for pg_dump output 
 with old or new version.
 
 If the last parameter pretty-print is true, parentheses are checked; 
 only necessary parentheses will be emitted. Additionally, line and 
 indentation formatting is performed.
 
 pg_get_indexdef has one additional parameter. The second parameter 
 (int4) selects the nth expression of an index (1..indnatts). If zero, a 
 complete CREATE INDEX statement is generated to obtain the previous 
 behaviour.
 The third is the pretty-print option as described.
 
 example:
 pg_get_indexdef(12345, 0, true)  - CREATE INDEX foo ON bar (numcol, 
 length(txtcol), intcol2, (8+length(txtcol2)))
 pg_get_indexdef(12345, 1, true)  - numcol
 pg_get_indexdef(12345, 2, true)  - length(txtcol)
 pg_get_indexdef(12345, 3, true)  - intcol2
 pg_get_indexdef(12345, 4, true)  - (8+length(txtcol2))
 
 Regards,
 Andreas
 

 Index: pg_proc.h
 ===
 RCS file: /projects/cvsroot/pgsql-server/src/include/catalog/pg_proc.h,v
 retrieving revision 1.309
 diff -r1.309 pg_proc.h
 3407a3408,3421
  /* System-view support functions with pretty-print option */
  DATA(insert OID = 2504 (  pg_get_ruledef   PGNSP PGUID 12 f f t f s 2 25 26 
  16  pg_get_ruledef - _null_ ));
  DESCR(source text of a rule with pretty-print option);
  DATA(insert OID = 2505 (  pg_get_viewdef   PGNSP PGUID 12 f f t f s 2 25 25 
  16  pg_get_viewdef_name - _null_ ));
  DESCR(select statement of a view with pretty-print option);
  DATA(insert OID = 2506 (  pg_get_viewdef   PGNSP PGUID 12 f f t f s 2 25 26 
  16  pg_get_viewdef - _null_ ));
  DESCR(select statement of a view with pretty-print option);
  DATA(insert OID = 2507 (  pg_get_indexdef  PGNSP PGUID 12 f f t f s 3 25 26 
  23 16  pg_get_indexdef - _null_ ));
  DESCR(index description (full create statement or single expression) with 
  pretty-print option);
  DATA(insert OID = 2508 (  pg_get_constraintdef PGNSP PGUID 12 f f t f s 2 25 26 
  16  pg_get_constraintdef - _null_ ));
  DESCR(constraint description with pretty-print option);
  DATA(insert OID = 2509 (  pg_get_expr  PGNSP PGUID 12 f f t f s 3 
  25 25 26 16 pg_get_expr - _null_ ));
  DESCR(deparse an encoded expression with pretty-print option);
  

 Index: ruleutils.c
 ===
 RCS file: /projects/cvsroot/pgsql-server/src/backend/utils/adt/ruleutils.c,v
 retrieving revision 1.145
 diff -r1.145 ruleutils.c
 73a74,92
  /**
   * Pretty formatting constants
   **/
  
  /* Indent counts */
  #define PRETTYINDENT_STD8
  #define PRETTYINDENT_JOIN  13
  #define PRETTYINDENT_JOIN_ON(PRETTYINDENT_JOIN-PRETTYINDENT_STD)
  #define PRETTYINDENT_VAR4
  
  /* Pretty flags */
  #define PRETTYFLAG_PAREN1
  #define PRETTYFLAG_INDENT   2
  
  /* macro to test if pretty action needed */
  #define PRETTY_PAREN(context)   (context-prettyFlags  PRETTYFLAG_PAREN)
  #define PRETTY_INDENT(context)  (context-prettyFlags  PRETTYFLAG_INDENT)
  
  
 83a103,104
  int prettyFlags;/* enabling/disabling of 
  pretty-print functions */
  int indentLevel;/* for prettyPrint, current space 
  indents are counted */
 126c147,153
  static text *pg_do_getviewdef(Oid viewoid);
 ---
  static char *get_simple_binary_op_name(OpExpr *expr);
  static void appendStringInfoSpace(StringInfo buf, int count);
  static void appendContextKeyword(deparse_context *context, char *str, int 
  indentBefore, int indentAfter, int indentPlus);
  static char *deparse_expression_pretty(Node *expr, List *dpcontext,
bool forceprefix, bool showimplicit, int prettyFlags, int 
  startIndent);
  static bool isSimpleNode(Node *node, Node *parentNode, int prettyFlags);
  static text *pg_do_getviewdef(Oid viewoid, int prettyFlags);
 129,130c156,157
  static void make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc);
  static void make_viewdef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc);
 ---
  static void make_ruledef(StringInfo buf, 

Re: [PATCHES] ruleutils with pretty-print option

2003-07-19 Thread Bruce Momjian

Sorry I am getting to this patch late. I know you posted a newer
version, but this one has a better description.

I am uncertain if we are over-engineering the interface by having three
ways to control the output.  Is that valuable?  If it is, fine, but if
it isn't, the extra code just adds to confusion and possible bugs.

Basically, should we just have a boolean specifying pretty_print
true/false?

Comments?

---

Andreas Pflug wrote:
 The attached patches will add
 pg_get_ruledef(oid, int)
 pg_get_viewdef(text, int)
 pg_get_viewdef(oid, int)
 pg_get_indexdef(oid, int)
 pg_get_constraintdef(oid, int)
 pg_get_expr(text, oid, int)
 
 If the last parameter pretty-print is 0, these function will return 
 the same result as their original counterparts without that parameter. 
 The source is based on ruleutils.c 1.143, and should return exactly the 
 same result as before if no pretty-print is selected. My tests didn't 
 show any differences for pg_dump output with old or new version.
 
 The pretty-print parameter is evaluated bit-wise.
 
 PRETTY_PAREN  1 - Parentheses are checked; only necessary parentheses will be 
 emitted.
 
 PRETTY_INDENT 2 - pretty indentation and line formatting is performed
 
 PRETTY_OPPAREN4 - For T_BoolExpr operators, AND/OR/NOT precedence is checked, 
 for T_OpExpr +-*/% 
   precedence is checked. If precedence is identified, 
 parentheses are omitted.
   This option is only active if PRETTY_PAREN is also used.
 
 
 Regards,
 Andreas

 Index: ruleutils.c
 ===
 RCS file: /projects/cvsroot/pgsql-server/src/backend/utils/adt/ruleutils.c,v
 retrieving revision 1.143
 diff -c -r1.143 ruleutils.c
 *** ruleutils.c   29 Jun 2003 00:33:44 -  1.143
 --- ruleutils.c   29 Jun 2003 16:54:48 -
 ***
 *** 71,76 
 --- 71,97 
   #include utils/lsyscache.h
   
   
 + /**
 +  * Pretty formatting constants
 +  **/
 + 
 + /* Indent counts */
 + #define PRETTYINDENT_STD8
 + #define PRETTYINDENT_JOIN  13
 + #define PRETTYINDENT_JOIN_ON(PRETTYINDENT_JOIN-PRETTYINDENT_STD)
 + #define PRETTYINDENT_VAR4
 + 
 + /* Pretty flags */
 + #define PRETTYFLAG_PAREN1
 + #define PRETTYFLAG_INDENT   2
 + #define PRETTYFLAG_OPPAREN  4
 + 
 + /* macro to test if pretty action needed */
 + #define PRETTY_PAREN(context)   (context-prettyFlags  PRETTYFLAG_PAREN)
 + #define PRETTY_INDENT(context)  (context-prettyFlags  PRETTYFLAG_INDENT)
 + #define PRETTY_OPPAREN(context) (context-prettyFlags  PRETTYFLAG_OPPAREN)
 + 
 + 
   /* --
* Local data types
* --
 ***
 *** 81,86 
 --- 102,109 
   {
   StringInfo  buf;/* output buffer to append to */
   List   *namespaces; /* List of deparse_namespace nodes */
 + int prettyFlags;/* if non-zero, parentheses are 
 minimized. */
 + int indentLevel;/* for prettyPrint, we perform 
 indentation and line splitting */
   boolvarprefix;  /* TRUE to print prefixes on Vars */
   } deparse_context;
   
 ***
 *** 123,135 
* as a parameter, and append their text output to its contents.
* --
*/
 ! static text *pg_do_getviewdef(Oid viewoid);
   static void decompile_column_index_array(Datum column_index_array, Oid relId,
StringInfo buf);
 ! static void make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc);
 ! static void make_viewdef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc);
   static void get_query_def(Query *query, StringInfo buf, List *parentnamespace,
 !   TupleDesc resultDesc);
   static void get_select_query_def(Query *query, deparse_context *context,
TupleDesc resultDesc);
   static void get_insert_query_def(Query *query, deparse_context *context);
 --- 146,164 
* as a parameter, and append their text output to its contents.
* --
*/
 ! static char *get_simple_binary_op_name(OpExpr *expr);
 ! static void appendStringInfoSpace(StringInfo buf, int count);
 ! static void appendContextKeyword(deparse_context *context, char *str, int 
 indentBefore, int indentAfter, int indentPlus);
 ! static char *deparse_expression_pretty(Node *expr, List *dpcontext,
 !   bool forceprefix, bool showimplicit, int prettyFlags, int 
 startIndent);
 ! static bool isSimpleNode(Node *node, Node *parentNode, int prettyFlags);
 ! static text *pg_do_getviewdef(Oid viewoid, int prettyFlags);
   static void decompile_column_index_array(Datum column_index_array, Oid relId,