Re: [PATCHES] Reference by output in : \d table_name

2008-04-16 Thread kenneth d'souza

Hi Brendan,
 
I thought you were referring to the spaces sourrounding the word FOREIGN KEY 
on the last line and hence my explaination was out of place.I am glad that you 
have corrected the indentation to 4 spaces. Those were unintentional at 2 
spaces from myside.
However,Why does the word FOREIGN KEY appear in the last line of your output. 
My original patch had the output like this.
Referenced by:  bar_foo_fkey IN public.bar(foo) REFERENCES foo(a)
The keyword FOREIGN KEY was removed by me as it would further cause a 
confusion.
Secondly, since the table foo is altered with an addition of a new column 
bar, it doesn't display in your output. Please double check.
My output is looking like this: 
testdb=# \d foo  Table public.foo Column |  Type   | 
Modifiers+-+--- a  | integer | not null bar| 
integer | not null/* Brendan--this line is missing in your 
output */Indexes:foo_pkey PRIMARY KEY, btree (a)Foreign-key constraints:  
  foo_bar_fkey FOREIGN KEY (bar) REFERENCES bar(a)Referenced by:  
bar_foo_fkey IN public.bar(foo) REFERENCES foo(a)
/* please ignore the 2 space indent, I am still using my orignal patch. I will 
correct it later */
Thanks,Kenneth Date: Mon, 14 Apr 2008 11:04:35 -0400 From: [EMAIL PROTECTED] 
To: [EMAIL PROTECTED] CC: [EMAIL PROTECTED]; [EMAIL PROTECTED]; 
pgsql-patches@postgresql.org Subject: Re: [PATCHES] Reference by output in : 
\d table_name  Brendan Jurd escribió:   Yeah, that's what I figured. The 
patch I attached to my previous  email should fix it up.  Applied, thanks. 
 --  Alvaro Herrera http://www.CommandPrompt.com/ PostgreSQL Replication, 
Consulting, Custom Development, 24x7 support
_
Fashion Channel : Want to know what’s the latest in the fashion world ? You 
have it all here on MSN Fashion.
http://lifestyle.in.msn.com/

Re: [PATCHES] Reference by output in : \d table_name

2008-04-14 Thread kenneth d'souza

Hi Brendan, 
Your observation is correct.
 
The indentation is deliberate. The reason is that the (result7,i,3) starts with 
the word FOREIGN KEY . I am using the details that follow after this blurb. 
All other keywords which are searched in usingpos = strstr(indexdef,  KEYWORD 
) , the KEYWORD are embedded somewhere in between in the output. Hence 
indentation given is that of four spaces considering the final output that it 
is desired.
 
Thanks,
Kenneth
 
_
Tried the new MSN Messenger? It’s cool! Download now.
http://messenger.msn.com/Download/Default.aspx?mkt=en-in

[PATCHES] Reference by output in : \d table_name

2008-03-02 Thread kenneth d'souza

With reference to the post 
http://archives.postgresql.org/pgsql-patches/2008-02/msg00104.phpand as stated 
by -hackers and -patchers, I am submitting the diff -c output as an attachment. 
Thanks, Kenneth 
_
Tried the new MSN Messenger? It’s cool! Download now.
http://messenger.msn.com/Download/Default.aspx?mkt=en-inIndex: describe.c
===
RCS file: /projects/cvsroot/pgsql/src/bin/psql/describe.c,v
retrieving revision 1.164
diff -c -r1.164 describe.c
*** describe.c  1 Jan 2008 19:45:56 -   1.164
--- describe.c  3 Mar 2008 04:10:55 -
***
*** 1106,1117 
   *result3 = NULL,
   *result4 = NULL,
   *result5 = NULL,
!  *result6 = NULL;
int check_count = 0,
index_count = 0,
foreignkey_count = 0,
rule_count = 0,
trigger_count = 0,
inherits_count = 0;
int count_footers = 0;
  
--- 1106,1119 
   *result3 = NULL,
   *result4 = NULL,
   *result5 = NULL,
!  *result6 = NULL,
!  *result7 = NULL;
int check_count = 0,
index_count = 0,
foreignkey_count = 0,
rule_count = 0,
trigger_count = 0,
+   referenceby_count = 0,
inherits_count = 0;
int count_footers = 0;
  
***
*** 1244,1251 
else
inherits_count = PQntuples(result6);
  
!   footers = pg_malloc_zero((index_count + check_count + 
rule_count + trigger_count + foreignkey_count + inherits_count + 7 + 1)
!* 
sizeof(*footers));
  
/* print indexes */
if (index_count  0)
--- 1246,1268 
else
inherits_count = PQntuples(result6);
  
!   /* reference_by count */
! 
! printfPQExpBuffer(buf,SELECT 
c.conname,n.nspname,p2.relname,pg_catalog.pg_get_constraintdef(c.oid, true)\n
!   FROM pg_catalog.pg_class p, 
pg_catalog.pg_constraint c,  pg_catalog.pg_class p2 \n
!   ,pg_catalog.pg_namespace n WHERE p.oid 
= '%s' AND c.confrelid = '%s'\n 
!   AND c.conrelid = p2.oid AND n.oid 
=p2.relnamespace, oid,oid);
! 
! result7 = PSQLexec(buf.data, false);
! if (!result7)
! goto error_return;
! else
! referenceby_count = PQntuples(result7);
! 
! 
! footers = pg_malloc_zero((index_count + check_count + 
rule_count + trigger_count + foreignkey_count + inherits_count + 
referenceby_count +  7 + 1) * sizeof(*footers));
! 
! 
  
/* print indexes */
if (index_count  0)
***
*** 1481,1486 
--- 1498,1529 
}
}
  
+   /* print reference count details */
+ if (referenceby_count  0)
+ {
+ printfPQExpBuffer(buf, _(Refrenced by :));
+ footers[count_footers++] = pg_strdup(buf.data);
+ for (i = 0; i  referenceby_count; i++)
+ {
+ const char *refbydef;
+ const char *usingpos;
+ printfPQExpBuffer(buf, _(  \%s\ IN 
%s.%s),
+
PQgetvalue(result7,i,0),
+  
PQgetvalue(result7,i,1),
+  
PQgetvalue(result7,i,2));
+ 
+ /* Everything after FOREIGN KEY  is echoed 
verbatim */
+ refbydef = PQgetvalue(result7, i, 3);
+ usingpos = strstr(refbydef, FOREIGN KEY );
+ if (usingpos)
+ refbydef = usingpos + 12;
+ appendPQExpBuffer(buf, %s,refbydef);
+ 
+  

[PATCHES] Reference by output in : \d table_name

2008-02-24 Thread kenneth d'souza

Hi,
 
Refering to this request http://momjian.us/mhonarc/patches_hold/msg00022.htmlI 
have created a patch. The output doesn't exaclty match with what is stated here 
http://momjian.us/mhonarc/patches_hold/msg00023.html. 
However, it does tell the required details in a similar format.
 
Comments?
 
 
Thanks,
Kenneth
osdb_pgarch=# \d htest   Table public.htestColumn| Type   
   | Modifiers--+---+--- new_id   | integer 
  | not null test_name| character(20) | test_cust_id | integer   
|Indexes:htest_pkey PRIMARY KEY,  btree (new_id)Foreign-key constraints:  
  htest_test_cust_id_fkey FOREIGN KEY (test_cust_id) REFERENCES 
customers(customer_id)Refrenced by :  htest_child_ctest_cust_id_fkey IN 
public.htest_child(ctest_cust_id) REFERENCES htest(new_id)  
htest_child1_ctest_cust_id_fkey IN public.htest_child1(ctest_cust_id) 
REFERENCES htest(new_id)
 
 
diff describe.c_orig describe.c1109c1109,1110  
*result6 = NULL;---  *result6 = NULL, 
 *result7 = NULL;1114a1116 
refof_count = 0,1247,1248c1249,1265   footers = 
pg_malloc_zero((index_count + check_count + rule_count + trigger_count + 
foreignkey_count + inherits_count + 7 + 1) 
   * sizeof(*footers));---   /* 
reference_by count */ printfPQExpBuffer(buf,SELECT 
c.conname,n.nspname,p2.relname,pg_catalog.pg_get_constraintdef(c.oid, true)\n 
  FROM pg_catalog.pg_class p, 
pg_catalog.pg_constraint c,  pg_catalog.pg_class p2 \n
   ,pg_catalog.pg_namespace n WHERE p.oid = '%s' AND c.confrelid = 
'%s'\n   AND c.conrelid = p2.oid AND 
n.oid =p2.relnamespace, oid,oid); result7 = 
PSQLexec(buf.data, false); if (!result7)  
   goto error_return; else 
refof_count = PQntuples(result7); footers = 
pg_malloc_zero((index_count + check_count + rule_count + trigger_count + 
foreignkey_count + inherits_count + refof_count +  7 + 1) * 
sizeof(*footers));1483a1501,1526   /* print reference count 
details */ if (refof_count  0) {
 printfPQExpBuffer(buf, _(Refrenced by :)); 
footers[count_footers++] = pg_strdup(buf.data); 
for (i = 0; i  refof_count; i++) {   
  const char *refbydef; const char 
*usingpos; printfPQExpBuffer(buf, _(  \%s\ 
IN %s.%s),
PQgetvalue(result7,i,0),   
   PQgetvalue(result7,i,1),
  PQgetvalue(result7,i,2));   
  /* Everything after FOREIGN KEY  is echoed verbatim */ 
refbydef = PQgetvalue(result7, i, 3);  
   usingpos = strstr(refbydef, FOREIGN KEY );
 if (usingpos) refbydef = usingpos + 
12; appendPQExpBuffer(buf, %s,refbydef);  
   footers[count_footers++] = pg_strdup(buf.data); 
}  }
 
_
Tried the new MSN Messenger? It’s cool! Download now.
http://messenger.msn.com/Download/Default.aspx?mkt=en-in