@@ -7944,24 +7944,50 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo)
7944
7944
int ntups ;
7945
7945
int i_attname ;
7946
7946
int i_atttypdefn ;
7947
+ int i_attcollation ;
7947
7948
int i_typrelid ;
7948
7949
int i ;
7949
7950
7950
7951
/* Set proper schema search path so type references list correctly */
7951
7952
selectSourceSchema (tyinfo -> dobj .namespace -> dobj .name );
7952
7953
7953
7954
/* 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
+ }
7965
7991
7966
7992
res = PQexec (g_conn ,query -> data );
7967
7993
check_sql_result (res ,g_conn ,query -> data ,PGRES_TUPLES_OK );
@@ -7970,6 +7996,7 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo)
7970
7996
7971
7997
i_attname = PQfnumber (res ,"attname" );
7972
7998
i_atttypdefn = PQfnumber (res ,"atttypdefn" );
7999
+ i_attcollation = PQfnumber (res ,"attcollation" );
7973
8000
i_typrelid = PQfnumber (res ,"typrelid" );
7974
8001
7975
8002
if (binary_upgrade )
@@ -7987,11 +8014,30 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo)
7987
8014
{
7988
8015
char * attname ;
7989
8016
char * atttypdefn ;
8017
+ Oid attcollation ;
7990
8018
7991
8019
attname = PQgetvalue (res ,i ,i_attname );
7992
8020
atttypdefn = PQgetvalue (res ,i ,i_atttypdefn );
8021
+ attcollation = atooid (PQgetvalue (res ,i ,i_attcollation ));
7993
8022
7994
8023
appendPQExpBuffer (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
+
7995
8041
if (i < ntups - 1 )
7996
8042
appendPQExpBuffer (q ,"," );
7997
8043
}