@@ -7944,24 +7944,50 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo)
79447944int ntups ;
79457945int i_attname ;
79467946int i_atttypdefn ;
7947+ int i_attcollation ;
79477948int i_typrelid ;
79487949int i ;
79497950
79507951/* Set proper schema search path so type references list correctly */
79517952selectSourceSchema (tyinfo -> dobj .namespace -> dobj .name );
79527953
79537954/* Fetch type specific details */
7954- /* We assume here that remoteVersion must be at least 70300 */
7955-
7956- appendPQExpBuffer (query ,"SELECT a.attname, "
7957- "pg_catalog.format_type(a.atttypid, a.atttypmod) AS atttypdefn, "
7958- "typrelid "
7959- "FROM pg_catalog.pg_type t, pg_catalog.pg_attribute a "
7960- "WHERE t.oid = '%u'::pg_catalog.oid "
7961- "AND a.attrelid = t.typrelid "
7962- "AND NOT a.attisdropped "
7963- "ORDER BY a.attnum " ,
7964- tyinfo -> dobj .catId .oid );
7955+ if (fout -> remoteVersion >=90100 )
7956+ {
7957+ /*
7958+ * attcollation is new in 9.1.Since we only want to dump COLLATE
7959+ * clauses for attributes whose collation is different from their
7960+ * type's default, we use a CASE here to suppress uninteresting
7961+ * attcollations cheaply.
7962+ */
7963+ appendPQExpBuffer (query ,"SELECT a.attname, "
7964+ "pg_catalog.format_type(a.atttypid, a.atttypmod) AS atttypdefn, "
7965+ "CASE WHEN a.attcollation <> at.typcollation "
7966+ "THEN a.attcollation ELSE 0 END AS attcollation, "
7967+ "ct.typrelid "
7968+ "FROM pg_catalog.pg_type ct, pg_catalog.pg_attribute a, "
7969+ "pg_catalog.pg_type at "
7970+ "WHERE ct.oid = '%u'::pg_catalog.oid "
7971+ "AND a.attrelid = ct.typrelid "
7972+ "AND a.atttypid = at.oid "
7973+ "AND NOT a.attisdropped "
7974+ "ORDER BY a.attnum " ,
7975+ tyinfo -> dobj .catId .oid );
7976+ }
7977+ else
7978+ {
7979+ /* We assume here that remoteVersion must be at least 70300 */
7980+ appendPQExpBuffer (query ,"SELECT a.attname, "
7981+ "pg_catalog.format_type(a.atttypid, a.atttypmod) AS atttypdefn, "
7982+ "0 AS attcollation, "
7983+ "ct.typrelid "
7984+ "FROM pg_catalog.pg_type ct, pg_catalog.pg_attribute a "
7985+ "WHERE ct.oid = '%u'::pg_catalog.oid "
7986+ "AND a.attrelid = ct.typrelid "
7987+ "AND NOT a.attisdropped "
7988+ "ORDER BY a.attnum " ,
7989+ tyinfo -> dobj .catId .oid );
7990+ }
79657991
79667992res = PQexec (g_conn ,query -> data );
79677993check_sql_result (res ,g_conn ,query -> data ,PGRES_TUPLES_OK );
@@ -7970,6 +7996,7 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo)
79707996
79717997i_attname = PQfnumber (res ,"attname" );
79727998i_atttypdefn = PQfnumber (res ,"atttypdefn" );
7999+ i_attcollation = PQfnumber (res ,"attcollation" );
79738000i_typrelid = PQfnumber (res ,"typrelid" );
79748001
79758002if (binary_upgrade )
@@ -7987,11 +8014,30 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo)
79878014{
79888015char * attname ;
79898016char * atttypdefn ;
8017+ Oid attcollation ;
79908018
79918019attname = PQgetvalue (res ,i ,i_attname );
79928020atttypdefn = PQgetvalue (res ,i ,i_atttypdefn );
8021+ attcollation = atooid (PQgetvalue (res ,i ,i_attcollation ));
79938022
79948023appendPQExpBuffer (q ,"\n\t%s %s" ,fmtId (attname ),atttypdefn );
8024+
8025+ /* Add collation if not default for the column type */
8026+ if (OidIsValid (attcollation ))
8027+ {
8028+ CollInfo * coll ;
8029+
8030+ coll = findCollationByOid (attcollation );
8031+ if (coll )
8032+ {
8033+ /* always schema-qualify, don't try to be smart */
8034+ appendPQExpBuffer (q ," COLLATE %s." ,
8035+ fmtId (coll -> dobj .namespace -> dobj .name ));
8036+ appendPQExpBuffer (q ,"%s" ,
8037+ fmtId (coll -> dobj .name ));
8038+ }
8039+ }
8040+
79958041if (i < ntups - 1 )
79968042appendPQExpBuffer (q ,"," );
79978043}