Re: [HACKERS] pg_dump Add dumping of comments on index columns

2009-08-07 Thread Brendan Jurd
2009/8/8 Bruce Momjian :
> Just to verify, this patch was about comments on composite columns, not
> about dumping comments on index columns (as the subject states), right?
> We do have a TODO for index column comments:

Correct.

If you scroll up a couple of messages [1] you'll see that I added that
TODO after I reviewed the patch.

Cheers,
BJ

[1] 37ed240d0907212253peaab8abtf8fd58fbde44c...@mail.gmail.com

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_dump Add dumping of comments on index columns

2009-08-07 Thread Bruce Momjian
Tom Lane wrote:
> Brendan Jurd  writes:
> > I've also done an initial review of the patch.  Everything looks sane
> > and the patch works as advertised.  I made a couple of minor tweaks
> > for code-style and comment consistency, and my version 3 is attached.
> 
> > I'm marking this patch Ready for Committer.
> 
> Applied with minor revisions --- mostly, it leaked memory in the case
> of no comments, and the query wasn't very schema-safe.

Just to verify, this patch was about comments on composite columns, not
about dumping comments on index columns (as the subject states), right? 
We do have a TODO for index column comments:

Forbid COMMENT on columns of an index

Postgres currently allows comments to be placed on the columns of an
index, but pg_dump doesn't handle them and the column names themselves
are implementation-dependent. 

-- 
  Bruce Momjian  http://momjian.us
  EnterpriseDB http://enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_dump Add dumping of comments on index columns

2009-07-23 Thread Tom Lane
Brendan Jurd  writes:
> I've also done an initial review of the patch.  Everything looks sane
> and the patch works as advertised.  I made a couple of minor tweaks
> for code-style and comment consistency, and my version 3 is attached.

> I'm marking this patch Ready for Committer.

Applied with minor revisions --- mostly, it leaked memory in the case
of no comments, and the query wasn't very schema-safe.

regards, tom lane

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_dump Add dumping of comments on index columns

2009-07-21 Thread Brendan Jurd
2009/7/14 Jaime Casanova :
> On Thu, Mar 26, 2009 at 2:39 AM, higepon wrote:
>> Here is a patch for pg_dump "Commenting on a composite-type column".
>> This patch is for Todo item named "Add dumping of comments on index
>> columns and composite type columns".
>
> this one looks good to me, the only adjust i made to the patch is
> change the name for the function that dump the comments from the
> composite types columns for: dumpCompositeTypeColsComment that seems
> more clearer to me...
>
> the patch works just fine...
>

Oops.  I picked this patch up from the commitfest queue because it was
still marked as "Needs Review", not realising that Jaime had already
done an initial review of the patch.

Seems like this one should have been "Ready for Committer", but no matter.

I've also done an initial review of the patch.  Everything looks sane
and the patch works as advertised.  I made a couple of minor tweaks
for code-style and comment consistency, and my version 3 is attached.

I'm marking this patch Ready for Committer.

I've also added a TODO item "forbid COMMENT on columns of an index",
per Tom's comments upthread.

Cheers,
BJ


pg_dump_composite_type_v3.patch
Description: Binary data

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_dump Add dumping of comments on index columns

2009-07-14 Thread higepon
Jaime Casanova wrote:

> this one looks good to me, the only adjust i made to the patch is

Thank you for your review!

---
Taro Minowa(Higepon)

http://www.monaos.org/
http://code.google.com/p/mosh-scheme/   


On Tue, Jul 14, 2009 at 4:34 PM, Jaime
Casanova wrote:
> On Thu, Mar 26, 2009 at 2:39 AM, higepon wrote:
>> Hi.
>>
>> Here is a patch for pg_dump "Commenting on a composite-type column".
>> This patch is for Todo item named "Add dumping of comments on index
>> columns and composite type columns".
>
> this one looks good to me, the only adjust i made to the patch is
> change the name for the function that dump the comments from the
> composite types columns for: dumpCompositeTypeColsComment that seems
> more clearer to me...
>
> the patch works just fine...
>
> --
> Atentamente,
> Jaime Casanova
> Soporte y capacitación de PostgreSQL
> Asesoría y desarrollo de sistemas
> Guayaquil - Ecuador
> Cel. +59387171157
>

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_dump Add dumping of comments on index columns

2009-07-14 Thread Jaime Casanova
On Thu, Mar 26, 2009 at 2:39 AM, higepon wrote:
> Hi.
>
> Here is a patch for pg_dump "Commenting on a composite-type column".
> This patch is for Todo item named "Add dumping of comments on index
> columns and composite type columns".

this one looks good to me, the only adjust i made to the patch is
change the name for the function that dump the comments from the
composite types columns for: dumpCompositeTypeColsComment that seems
more clearer to me...

the patch works just fine...

-- 
Atentamente,
Jaime Casanova
Soporte y capacitación de PostgreSQL
Asesoría y desarrollo de sistemas
Guayaquil - Ecuador
Cel. +59387171157
Index: src/bin/pg_dump/pg_dump.c
===
RCS file: /home/postgres/pgrepo/pgsql/src/bin/pg_dump/pg_dump.c,v
retrieving revision 1.540
diff -c -r1.540 pg_dump.c
*** src/bin/pg_dump/pg_dump.c	2 Jul 2009 21:34:32 -	1.540
--- src/bin/pg_dump/pg_dump.c	14 Jul 2009 07:22:38 -
***
*** 133,138 
--- 133,139 
  static void dumpEnumType(Archive *fout, TypeInfo *tinfo);
  static void dumpDomain(Archive *fout, TypeInfo *tinfo);
  static void dumpCompositeType(Archive *fout, TypeInfo *tinfo);
+ static void dumpCompositeTypeColsComment(Archive *fout, TypeInfo *tinfo);
  static void dumpShellType(Archive *fout, ShellTypeInfo *stinfo);
  static void dumpProcLang(Archive *fout, ProcLangInfo *plang);
  static void dumpFunc(Archive *fout, FuncInfo *finfo);
***
*** 6708,6716 
--- 6709,6818 
  	destroyPQExpBuffer(q);
  	destroyPQExpBuffer(delq);
  	destroyPQExpBuffer(query);
+ 
+  	/* Dump column comments */
+  	dumpCompositeTypeColsComment(fout, tinfo);
  }
  
  /*
+  * dumpCompositeTypeColsComment
+  *	  writes out to fout the comments on
+  *	  columns of composite type
+  */
+ static void
+ dumpCompositeTypeColsComment(Archive *fout, TypeInfo *tinfo)
+ {
+ 	CommentItem *comments;
+ 	int ncomments;
+ 	PGresult *res;
+ 	PQExpBuffer query;
+ 	PQExpBuffer attrquery = createPQExpBuffer();
+ 	PQExpBuffer target;
+ 	Oid colTableOid;
+ 	int i;
+ 	int ntups;
+ 	int i_attname;
+ 	int i_attnum;
+ 
+ 	appendPQExpBuffer(attrquery,
+ 	  "SELECT pg_class.tableoid, "
+ 	  "   pg_attribute.attname, "
+ 	  "pg_attribute.attnum "
+ 	  "FROM pg_class, pg_attribute "
+ 	  "WHERE pg_class.oid = '%u' and pg_class.oid = pg_attribute.attrelid "
+ 	  "ORDER BY pg_attribute.attnum "
+ 	  , tinfo->typrelid);
+ 
+ 	/* Fetch column's attname */
+ 	res = PQexec(g_conn, attrquery->data);
+ 	check_sql_result(res, g_conn, attrquery->data, PGRES_TUPLES_OK);
+ 	ntups = PQntuples(res);
+ 	if (ntups < 1)
+ 	{
+ 		write_msg(NULL, "query returned no rows: %s\n", attrquery->data);
+ 		exit_nicely();
+ 	}
+ 	colTableOid = atooid(PQgetvalue(res, 0, PQfnumber(res, "tableoid")));
+ 
+ 	/* Search for comments associated with relation, using table */
+ 	ncomments = findComments(fout,
+ 			 colTableOid,
+ 			 tinfo->typrelid,
+ 			 &comments);
+ 
+ 	/* If comments exist, build COMMENT ON statements */
+ 	if (ncomments <= 0)
+ 		return;
+ 
+ 	query = createPQExpBuffer();
+ 	target = createPQExpBuffer();
+ 
+ 	i_attnum = PQfnumber(res, "attnum");
+ 	i_attname = PQfnumber(res, "attname");
+ 	while (ncomments > 0)
+ 	{
+ 		const char *descr = comments->descr;
+ 		/* Just to be safe */
+ 		const char *attname = "unknown";
+ 		for (i = 0; i < ntups; i++)
+ 		{
+ 			if (atoi(PQgetvalue(res, i, i_attnum)) == comments->objsubid)
+ 			{
+ attname = PQgetvalue(res, i, i_attname);
+ break;
+ 			}
+ 		}
+ 		resetPQExpBuffer(target);
+ 		appendPQExpBuffer(target, "COLUMN %s.",
+ 		  fmtId(tinfo->dobj.name));
+ 		appendPQExpBuffer(target, "%s",
+ 		  fmtId(attname));
+ 		
+ 		resetPQExpBuffer(query);
+ 		appendPQExpBuffer(query, "COMMENT ON %s IS ", target->data);
+ 		appendStringLiteralAH(query, descr, fout);
+ 		appendPQExpBuffer(query, ";\n");
+ 
+ 		ArchiveEntry(fout, nilCatalogId, createDumpId(),
+ 	 target->data,
+ 	 tinfo->dobj.namespace->dobj.name,
+ 	 NULL,
+ 	 tinfo->rolname,
+ 	 false, "COMMENT", SECTION_NONE, query->data, "", NULL,
+ 	 &(tinfo->dobj.dumpId), 1,
+ 	 NULL, NULL);
+ 
+ 		comments++;
+ 		ncomments--;
+ 	}
+ 	destroyPQExpBuffer(attrquery);
+ 	destroyPQExpBuffer(query);
+ 	destroyPQExpBuffer(target);
+ 	PQclear(res);
+ }
+ 
+ 
+ /*
   * dumpShellType
   *	  writes out to fout the queries to create a shell type
   *

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_dump Add dumping of comments on index columns

2009-03-26 Thread higepon
Hi.

> Since we are about to go to beta, it may be that no one is up for
> reviewing it right now.  But I've added it to the CommitFest page for
> the next CommitFest.

Thank you.
I wait until the next CommitFest.

-
Taro Minowa(Higepon)

http://www.monaos.org/
http://code.google.com/p/mosh-scheme/

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_dump Add dumping of comments on index columns

2009-03-26 Thread Robert Haas
> Would someone please review this?

Since we are about to go to beta, it may be that no one is up for
reviewing it right now.  But I've added it to the CommitFest page for
the next CommitFest.

http://wiki.postgresql.org/wiki/CommitFest_2009-First

...Robert

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_dump Add dumping of comments on index columns

2009-03-26 Thread higepon
Hi.

Here is a patch for pg_dump "Commenting on a composite-type column".
This patch is for Todo item named "Add dumping of comments on index
columns and composite type columns".
As Tom Lane said, this patch is not for dumping "comments on index columns",
but only for "comment on composite-type column".

With this patch, pg_dump can dump comments on composite-type column.

 --
 -- Name: COLUMN bar.b1; Type: COMMENT; Schema: public; Owner: taro
 --

 COMMENT ON COLUMN bar.b1 IS 'column of a composite type b1';


 --
 -- Name: COLUMN bar.b3; Type: COMMENT; Schema: public; Owner: taro
 --

 COMMENT ON COLUMN bar.b3 IS 'column of a composite type b3';

Would someone please review this?

Cheers.

-
Taro Minowa(Higepon)

Cybozu Labs, Inc.

http://www.monaos.org/
http://code.google.com/p/mosh-scheme/


On Tue, Mar 24, 2009 at 11:56 PM, Tom Lane  wrote:
> Bruce Momjian  writes:
>> Wow, I have no idea what that means.  I am wondering if we should just
>> remove this TODO item.  We don't even support comments on indexed
>> columns, so why would pg_dump need to dump it?
>
> The system will let you do it, both cases:
>
> regression=# create type foo as (f1 int, f2 text);
> CREATE TYPE
> regression=# comment on column foo.f2 is 'column of a composite type';
> COMMENT
> regression=# create table tt (f1 int primary key);
> NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "tt_pkey" for 
> table "tt"
> CREATE TABLE
> regression=# comment on column tt_pkey.f1 is 'column of an index';
> COMMENT
>
> and pg_dump fails to dump both cases.
>
> Commenting on a composite-type column seems reasonable.  I'm less happy
> about the other because it depends on the names assigned to index
> columns, which are implementation artifacts.  I'd rather see us forbid
> the case.
>
>                        regards, tom lane
>


pg_dump_composite_type_v1.patch
Description: Binary data

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_dump Add dumping of comments on index columns

2009-03-24 Thread Tom Lane
Bruce Momjian  writes:
> Wow, I have no idea what that means.  I am wondering if we should just
> remove this TODO item.  We don't even support comments on indexed
> columns, so why would pg_dump need to dump it?

The system will let you do it, both cases:

regression=# create type foo as (f1 int, f2 text);
CREATE TYPE
regression=# comment on column foo.f2 is 'column of a composite type';
COMMENT
regression=# create table tt (f1 int primary key);
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "tt_pkey" for 
table "tt"
CREATE TABLE
regression=# comment on column tt_pkey.f1 is 'column of an index';
COMMENT

and pg_dump fails to dump both cases.

Commenting on a composite-type column seems reasonable.  I'm less happy
about the other because it depends on the names assigned to index
columns, which are implementation artifacts.  I'd rather see us forbid
the case.

regards, tom lane

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_dump Add dumping of comments on index columns

2009-03-24 Thread higepon
Hi.

> Wow, I have no idea what that means.  I am wondering if we should just
> remove this TODO item.  We don't even support comments on indexed
> columns, so why would pg_dump need to dump it?

Oh I see.
But we still can comment on indexed columns like following on 8.3.7,
is it unsupported feature?

 create table person (social_no integer, name text, age integer, uri
text, PRIMARY KEY  (social_no));
 create index person_age on person using BTREE (age);
 comment on column person_age.age IS 'hello index person_age.age';

And we can find the comment in pg_description table.

> Do we support comments on composite types 

If we do, I will also write a patch for it.

Cheers.

-
Taro Minowa(Higepon)

http://www.monaos.org/
http://code.google.com/p/mosh-scheme/   


On Tue, Mar 24, 2009 at 11:10 PM, Bruce Momjian  wrote:
> higepon wrote:
>> Hi.
>> I found a TODO item "Add dumping of comments on index columns and
>> composite type columns" for pg_dump
>> and want to write a patch for it.
>>
>> But I'm not sure if I understand the problem correctly.
>> Does "Add dumping of comments on index columns" mean that
>> pg_dump should dump out COMMENT statements like following?
>>
>>  COMMENT ON COLUMN some_index.index_column1 IS 'Hello column1';
>>
>> Can anybody give me some advice on this?
>
> Wow, I have no idea what that means.  I am wondering if we should just
> remove this TODO item.  We don't even support comments on indexed
> columns, so why would pg_dump need to dump it?
>
> The full text is:
>
>        Add dumping of comments on index columns and composite type columns
>
> Do we support comments on composite types?
>
> This item first appeared on the TODO list in Postgres 8.0.
>
> --
>  Bruce Momjian          http://momjian.us
>  EnterpriseDB                             http://enterprisedb.com
>
>  + If your life is a hard drive, Christ can be your backup. +
>

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] pg_dump Add dumping of comments on index columns

2009-03-24 Thread Bruce Momjian
higepon wrote:
> Hi.
> I found a TODO item "Add dumping of comments on index columns and
> composite type columns" for pg_dump
> and want to write a patch for it.
> 
> But I'm not sure if I understand the problem correctly.
> Does "Add dumping of comments on index columns" mean that
> pg_dump should dump out COMMENT statements like following?
> 
>  COMMENT ON COLUMN some_index.index_column1 IS 'Hello column1';
> 
> Can anybody give me some advice on this?

Wow, I have no idea what that means.  I am wondering if we should just
remove this TODO item.  We don't even support comments on indexed
columns, so why would pg_dump need to dump it?

The full text is:

Add dumping of comments on index columns and composite type columns 

Do we support comments on composite types?

This item first appeared on the TODO list in Postgres 8.0.

-- 
  Bruce Momjian  http://momjian.us
  EnterpriseDB http://enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


[HACKERS] pg_dump Add dumping of comments on index columns

2009-03-23 Thread higepon
Hi.
I found a TODO item "Add dumping of comments on index columns and
composite type columns" for pg_dump
and want to write a patch for it.

But I'm not sure if I understand the problem correctly.
Does "Add dumping of comments on index columns" mean that
pg_dump should dump out COMMENT statements like following?

 COMMENT ON COLUMN some_index.index_column1 IS 'Hello column1';

Can anybody give me some advice on this?

Best regards,

-
Taro Minowa(Higepon)

http://www.monaos.org/
http://code.google.com/p/mosh-scheme/

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


[HACKERS] pg_dump Add dumping of comments on index columns

2009-03-23 Thread higepon
Hi.
I found a TODO item "Add dumping of comments on index columns and
composite type columns" for pg_dump
and want to write a patch for it.

But I'm not sure if I understand the problem correctly.
Does "Add dumping of comments on index columns" mean that
pg_dump should dump out COMMENT statements like following?

 COMMENT ON COLUMN some_index.index_column1 IS 'Hello column1';

Can anybody give me some advice on this?

Best regards,

-
Taro Minowa(Higepon)

http://www.monaos.org/
http://code.google.com/p/mosh-scheme/

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers