12
12
* by PostgreSQL
13
13
*
14
14
* IDENTIFICATION
15
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.429 2006/02/12 06:11:51 momjian Exp $
15
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.430 2006/02/21 18:01:32 tgl Exp $
16
16
*
17
17
*-------------------------------------------------------------------------
18
18
*/
@@ -4690,10 +4690,11 @@ dumpBaseType(Archive *fout, TypeInfo *tinfo)
4690
4690
Oid typsendoid ;
4691
4691
Oid typanalyzeoid ;
4692
4692
char * typdelim ;
4693
- char * typdefault ;
4694
4693
char * typbyval ;
4695
4694
char * typalign ;
4696
4695
char * typstorage ;
4696
+ char * typdefault ;
4697
+ bool typdefault_is_literal = false;
4697
4698
4698
4699
/* Set proper schema search path so regproc references list correctly */
4699
4700
selectSourceSchema (tinfo -> dobj .namespace -> dobj .name );
@@ -4709,8 +4710,8 @@ dumpBaseType(Archive *fout, TypeInfo *tinfo)
4709
4710
"typreceive::pg_catalog.oid as typreceiveoid, "
4710
4711
"typsend::pg_catalog.oid as typsendoid, "
4711
4712
"typanalyze::pg_catalog.oid as typanalyzeoid, "
4712
- "typdelim, typdefault, typbyval, typalign, "
4713
- "typstorage "
4713
+ "typdelim, typbyval, typalign, typstorage , "
4714
+ "pg_catalog.pg_get_expr(typdefaultbin, 'pg_catalog.pg_type'::pg_catalog.regclass) as typdefaultbin, typdefault "
4714
4715
"FROM pg_catalog.pg_type "
4715
4716
"WHERE oid = '%u'::pg_catalog.oid" ,
4716
4717
tinfo -> dobj .catId .oid );
@@ -4725,8 +4726,8 @@ dumpBaseType(Archive *fout, TypeInfo *tinfo)
4725
4726
"typreceive::pg_catalog.oid as typreceiveoid, "
4726
4727
"typsend::pg_catalog.oid as typsendoid, "
4727
4728
"0 as typanalyzeoid, "
4728
- "typdelim, typdefault, typbyval, typalign, "
4729
- "typstorage "
4729
+ "typdelim, typbyval, typalign, typstorage , "
4730
+ "pg_catalog.pg_get_expr(typdefaultbin, 'pg_catalog.pg_type'::pg_catalog.regclass) as typdefaultbin, typdefault "
4730
4731
"FROM pg_catalog.pg_type "
4731
4732
"WHERE oid = '%u'::pg_catalog.oid" ,
4732
4733
tinfo -> dobj .catId .oid );
@@ -4741,13 +4742,13 @@ dumpBaseType(Archive *fout, TypeInfo *tinfo)
4741
4742
"typoutput::pg_catalog.oid as typoutputoid, "
4742
4743
"0 as typreceiveoid, 0 as typsendoid, "
4743
4744
"0 as typanalyzeoid, "
4744
- "typdelim, typdefault, typbyval, typalign, "
4745
- "typstorage "
4745
+ "typdelim, typbyval, typalign, typstorage , "
4746
+ "pg_catalog.pg_get_expr(typdefaultbin, 'pg_catalog.pg_type'::pg_catalog.regclass) as typdefaultbin, typdefault "
4746
4747
"FROM pg_catalog.pg_type "
4747
4748
"WHERE oid = '%u'::pg_catalog.oid" ,
4748
4749
tinfo -> dobj .catId .oid );
4749
4750
}
4750
- else if (fout -> remoteVersion >= 70100 )
4751
+ else if (fout -> remoteVersion >= 70200 )
4751
4752
{
4752
4753
/*
4753
4754
* Note: although pre-7.3 catalogs contain typreceive and typsend,
@@ -4761,8 +4762,28 @@ dumpBaseType(Archive *fout, TypeInfo *tinfo)
4761
4762
"typoutput::oid as typoutputoid, "
4762
4763
"0 as typreceiveoid, 0 as typsendoid, "
4763
4764
"0 as typanalyzeoid, "
4764
- "typdelim, typdefault, typbyval, typalign, "
4765
- "typstorage "
4765
+ "typdelim, typbyval, typalign, typstorage, "
4766
+ "NULL as typdefaultbin, typdefault "
4767
+ "FROM pg_type "
4768
+ "WHERE oid = '%u'::oid" ,
4769
+ tinfo -> dobj .catId .oid );
4770
+ }
4771
+ else if (fout -> remoteVersion >= 70100 )
4772
+ {
4773
+ /*
4774
+ * Ignore pre-7.2 typdefault; the field exists but has an unusable
4775
+ * representation.
4776
+ */
4777
+ appendPQExpBuffer (query , "SELECT typlen, "
4778
+ "typinput, typoutput, "
4779
+ "'-' as typreceive, '-' as typsend, "
4780
+ "'-' as typanalyze, "
4781
+ "typinput::oid as typinputoid, "
4782
+ "typoutput::oid as typoutputoid, "
4783
+ "0 as typreceiveoid, 0 as typsendoid, "
4784
+ "0 as typanalyzeoid, "
4785
+ "typdelim, typbyval, typalign, typstorage, "
4786
+ "NULL as typdefaultbin, NULL as typdefault "
4766
4787
"FROM pg_type "
4767
4788
"WHERE oid = '%u'::oid" ,
4768
4789
tinfo -> dobj .catId .oid );
@@ -4777,8 +4798,9 @@ dumpBaseType(Archive *fout, TypeInfo *tinfo)
4777
4798
"typoutput::oid as typoutputoid, "
4778
4799
"0 as typreceiveoid, 0 as typsendoid, "
4779
4800
"0 as typanalyzeoid, "
4780
- "typdelim, typdefault, typbyval, typalign, "
4781
- "'p'::char as typstorage "
4801
+ "typdelim, typbyval, typalign, "
4802
+ "'p'::char as typstorage, "
4803
+ "NULL as typdefaultbin, NULL as typdefault "
4782
4804
"FROM pg_type "
4783
4805
"WHERE oid = '%u'::oid" ,
4784
4806
tinfo -> dobj .catId .oid );
@@ -4808,13 +4830,18 @@ dumpBaseType(Archive *fout, TypeInfo *tinfo)
4808
4830
typsendoid = atooid (PQgetvalue (res , 0 , PQfnumber (res , "typsendoid" )));
4809
4831
typanalyzeoid = atooid (PQgetvalue (res , 0 , PQfnumber (res , "typanalyzeoid" )));
4810
4832
typdelim = PQgetvalue (res , 0 , PQfnumber (res , "typdelim" ));
4811
- if (PQgetisnull (res , 0 , PQfnumber (res , "typdefault" )))
4812
- typdefault = NULL ;
4813
- else
4814
- typdefault = PQgetvalue (res , 0 , PQfnumber (res , "typdefault" ));
4815
4833
typbyval = PQgetvalue (res , 0 , PQfnumber (res , "typbyval" ));
4816
4834
typalign = PQgetvalue (res , 0 , PQfnumber (res , "typalign" ));
4817
4835
typstorage = PQgetvalue (res , 0 , PQfnumber (res , "typstorage" ));
4836
+ if (!PQgetisnull (res , 0 , PQfnumber (res , "typdefaultbin" )))
4837
+ typdefault = PQgetvalue (res , 0 , PQfnumber (res , "typdefaultbin" ));
4838
+ else if (!PQgetisnull (res , 0 , PQfnumber (res , "typdefault" )))
4839
+ {
4840
+ typdefault = PQgetvalue (res , 0 , PQfnumber (res , "typdefault" ));
4841
+ typdefault_is_literal = true; /* it needs quotes */
4842
+ }
4843
+ else
4844
+ typdefault = NULL ;
4818
4845
4819
4846
/*
4820
4847
* DROP must be fully qualified in case same name appears in pg_catalog
@@ -4854,7 +4881,10 @@ dumpBaseType(Archive *fout, TypeInfo *tinfo)
4854
4881
if (typdefault != NULL )
4855
4882
{
4856
4883
appendPQExpBuffer (q , ",\n DEFAULT = " );
4857
- appendStringLiteral (q , typdefault , true);
4884
+ if (typdefault_is_literal )
4885
+ appendStringLiteral (q , typdefault , true);
4886
+ else
4887
+ appendPQExpBufferStr (q , typdefault );
4858
4888
}
4859
4889
4860
4890
if (tinfo -> isArray )
@@ -4936,6 +4966,7 @@ dumpDomain(Archive *fout, TypeInfo *tinfo)
4936
4966
char * typnotnull ;
4937
4967
char * typdefn ;
4938
4968
char * typdefault ;
4969
+ bool typdefault_is_literal = false;
4939
4970
4940
4971
/* Set proper schema search path so type references list correctly */
4941
4972
selectSourceSchema (tinfo -> dobj .namespace -> dobj .name );
@@ -4944,7 +4975,7 @@ dumpDomain(Archive *fout, TypeInfo *tinfo)
4944
4975
/* We assume here that remoteVersion must be at least 70300 */
4945
4976
appendPQExpBuffer (query , "SELECT typnotnull, "
4946
4977
"pg_catalog.format_type(typbasetype, typtypmod) as typdefn, "
4947
- "typdefault "
4978
+ "pg_catalog.pg_get_expr(typdefaultbin, 'pg_catalog.pg_type'::pg_catalog.regclass) as typdefaultbin, typdefault "
4948
4979
"FROM pg_catalog.pg_type "
4949
4980
"WHERE oid = '%u'::pg_catalog.oid" ,
4950
4981
tinfo -> dobj .catId .oid );
@@ -4963,10 +4994,15 @@ dumpDomain(Archive *fout, TypeInfo *tinfo)
4963
4994
4964
4995
typnotnull = PQgetvalue (res , 0 , PQfnumber (res , "typnotnull" ));
4965
4996
typdefn = PQgetvalue (res , 0 , PQfnumber (res , "typdefn" ));
4966
- if (PQgetisnull (res , 0 , PQfnumber (res , "typdefault" )))
4967
- typdefault = NULL ;
4968
- else
4997
+ if (!PQgetisnull (res , 0 , PQfnumber (res , "typdefaultbin" )))
4998
+ typdefault = PQgetvalue (res , 0 , PQfnumber (res , "typdefaultbin" ));
4999
+ else if (!PQgetisnull (res , 0 , PQfnumber (res , "typdefault" )))
5000
+ {
4969
5001
typdefault = PQgetvalue (res , 0 , PQfnumber (res , "typdefault" ));
5002
+ typdefault_is_literal = true; /* it needs quotes */
5003
+ }
5004
+ else
5005
+ typdefault = NULL ;
4970
5006
4971
5007
appendPQExpBuffer (q ,
4972
5008
"CREATE DOMAIN %s AS %s" ,
@@ -4976,8 +5012,14 @@ dumpDomain(Archive *fout, TypeInfo *tinfo)
4976
5012
if (typnotnull [0 ] == 't' )
4977
5013
appendPQExpBuffer (q , " NOT NULL" );
4978
5014
4979
- if (typdefault )
4980
- appendPQExpBuffer (q , " DEFAULT %s" , typdefault );
5015
+ if (typdefault != NULL )
5016
+ {
5017
+ appendPQExpBuffer (q , " DEFAULT " );
5018
+ if (typdefault_is_literal )
5019
+ appendStringLiteral (q , typdefault , true);
5020
+ else
5021
+ appendPQExpBufferStr (q , typdefault );
5022
+ }
4981
5023
4982
5024
PQclear (res );
4983
5025
0 commit comments