* by PostgreSQL
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.429 2006/02/12 06:11:51 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.430 2006/02/21 18:01:32 tgl Exp $
*
*-------------------------------------------------------------------------
*/
Oid typsendoid;
Oid typanalyzeoid;
char *typdelim;
- char *typdefault;
char *typbyval;
char *typalign;
char *typstorage;
+ char *typdefault;
+ bool typdefault_is_literal = false;
/* Set proper schema search path so regproc references list correctly */
selectSourceSchema(tinfo->dobj.namespace->dobj.name);
"typreceive::pg_catalog.oid as typreceiveoid, "
"typsend::pg_catalog.oid as typsendoid, "
"typanalyze::pg_catalog.oid as typanalyzeoid, "
- "typdelim, typdefault, typbyval, typalign, "
- "typstorage "
+ "typdelim, typbyval, typalign, typstorage, "
+ "pg_catalog.pg_get_expr(typdefaultbin, 'pg_catalog.pg_type'::pg_catalog.regclass) as typdefaultbin, typdefault "
"FROM pg_catalog.pg_type "
"WHERE oid = '%u'::pg_catalog.oid",
tinfo->dobj.catId.oid);
"typreceive::pg_catalog.oid as typreceiveoid, "
"typsend::pg_catalog.oid as typsendoid, "
"0 as typanalyzeoid, "
- "typdelim, typdefault, typbyval, typalign, "
- "typstorage "
+ "typdelim, typbyval, typalign, typstorage, "
+ "pg_catalog.pg_get_expr(typdefaultbin, 'pg_catalog.pg_type'::pg_catalog.regclass) as typdefaultbin, typdefault "
"FROM pg_catalog.pg_type "
"WHERE oid = '%u'::pg_catalog.oid",
tinfo->dobj.catId.oid);
"typoutput::pg_catalog.oid as typoutputoid, "
"0 as typreceiveoid, 0 as typsendoid, "
"0 as typanalyzeoid, "
- "typdelim, typdefault, typbyval, typalign, "
- "typstorage "
+ "typdelim, typbyval, typalign, typstorage, "
+ "pg_catalog.pg_get_expr(typdefaultbin, 'pg_catalog.pg_type'::pg_catalog.regclass) as typdefaultbin, typdefault "
"FROM pg_catalog.pg_type "
"WHERE oid = '%u'::pg_catalog.oid",
tinfo->dobj.catId.oid);
}
- else if (fout->remoteVersion >= 70100)
+ else if (fout->remoteVersion >= 70200)
{
/*
* Note: although pre-7.3 catalogs contain typreceive and typsend,
"typoutput::oid as typoutputoid, "
"0 as typreceiveoid, 0 as typsendoid, "
"0 as typanalyzeoid, "
- "typdelim, typdefault, typbyval, typalign, "
- "typstorage "
+ "typdelim, typbyval, typalign, typstorage, "
+ "NULL as typdefaultbin, typdefault "
+ "FROM pg_type "
+ "WHERE oid = '%u'::oid",
+ tinfo->dobj.catId.oid);
+ }
+ else if (fout->remoteVersion >= 70100)
+ {
+ /*
+ * Ignore pre-7.2 typdefault; the field exists but has an unusable
+ * representation.
+ */
+ appendPQExpBuffer(query, "SELECT typlen, "
+ "typinput, typoutput, "
+ "'-' as typreceive, '-' as typsend, "
+ "'-' as typanalyze, "
+ "typinput::oid as typinputoid, "
+ "typoutput::oid as typoutputoid, "
+ "0 as typreceiveoid, 0 as typsendoid, "
+ "0 as typanalyzeoid, "
+ "typdelim, typbyval, typalign, typstorage, "
+ "NULL as typdefaultbin, NULL as typdefault "
"FROM pg_type "
"WHERE oid = '%u'::oid",
tinfo->dobj.catId.oid);
"typoutput::oid as typoutputoid, "
"0 as typreceiveoid, 0 as typsendoid, "
"0 as typanalyzeoid, "
- "typdelim, typdefault, typbyval, typalign, "
- "'p'::char as typstorage "
+ "typdelim, typbyval, typalign, "
+ "'p'::char as typstorage, "
+ "NULL as typdefaultbin, NULL as typdefault "
"FROM pg_type "
"WHERE oid = '%u'::oid",
tinfo->dobj.catId.oid);
typsendoid = atooid(PQgetvalue(res, 0, PQfnumber(res, "typsendoid")));
typanalyzeoid = atooid(PQgetvalue(res, 0, PQfnumber(res, "typanalyzeoid")));
typdelim = PQgetvalue(res, 0, PQfnumber(res, "typdelim"));
- if (PQgetisnull(res, 0, PQfnumber(res, "typdefault")))
- typdefault = NULL;
- else
- typdefault = PQgetvalue(res, 0, PQfnumber(res, "typdefault"));
typbyval = PQgetvalue(res, 0, PQfnumber(res, "typbyval"));
typalign = PQgetvalue(res, 0, PQfnumber(res, "typalign"));
typstorage = PQgetvalue(res, 0, PQfnumber(res, "typstorage"));
+ if (!PQgetisnull(res, 0, PQfnumber(res, "typdefaultbin")))
+ typdefault = PQgetvalue(res, 0, PQfnumber(res, "typdefaultbin"));
+ else if (!PQgetisnull(res, 0, PQfnumber(res, "typdefault")))
+ {
+ typdefault = PQgetvalue(res, 0, PQfnumber(res, "typdefault"));
+ typdefault_is_literal = true; /* it needs quotes */
+ }
+ else
+ typdefault = NULL;
/*
* DROP must be fully qualified in case same name appears in pg_catalog
if (typdefault != NULL)
{
appendPQExpBuffer(q, ",\n DEFAULT = ");
- appendStringLiteral(q, typdefault, true);
+ if (typdefault_is_literal)
+ appendStringLiteral(q, typdefault, true);
+ else
+ appendPQExpBufferStr(q, typdefault);
}
if (tinfo->isArray)
char *typnotnull;
char *typdefn;
char *typdefault;
+ bool typdefault_is_literal = false;
/* Set proper schema search path so type references list correctly */
selectSourceSchema(tinfo->dobj.namespace->dobj.name);
/* We assume here that remoteVersion must be at least 70300 */
appendPQExpBuffer(query, "SELECT typnotnull, "
"pg_catalog.format_type(typbasetype, typtypmod) as typdefn, "
- "typdefault "
+ "pg_catalog.pg_get_expr(typdefaultbin, 'pg_catalog.pg_type'::pg_catalog.regclass) as typdefaultbin, typdefault "
"FROM pg_catalog.pg_type "
"WHERE oid = '%u'::pg_catalog.oid",
tinfo->dobj.catId.oid);
typnotnull = PQgetvalue(res, 0, PQfnumber(res, "typnotnull"));
typdefn = PQgetvalue(res, 0, PQfnumber(res, "typdefn"));
- if (PQgetisnull(res, 0, PQfnumber(res, "typdefault")))
- typdefault = NULL;
- else
+ if (!PQgetisnull(res, 0, PQfnumber(res, "typdefaultbin")))
+ typdefault = PQgetvalue(res, 0, PQfnumber(res, "typdefaultbin"));
+ else if (!PQgetisnull(res, 0, PQfnumber(res, "typdefault")))
+ {
typdefault = PQgetvalue(res, 0, PQfnumber(res, "typdefault"));
+ typdefault_is_literal = true; /* it needs quotes */
+ }
+ else
+ typdefault = NULL;
appendPQExpBuffer(q,
"CREATE DOMAIN %s AS %s",
if (typnotnull[0] == 't')
appendPQExpBuffer(q, " NOT NULL");
- if (typdefault)
- appendPQExpBuffer(q, " DEFAULT %s", typdefault);
+ if (typdefault != NULL)
+ {
+ appendPQExpBuffer(q, " DEFAULT ");
+ if (typdefault_is_literal)
+ appendStringLiteral(q, typdefault, true);
+ else
+ appendPQExpBufferStr(q, typdefault);
+ }
PQclear(res);