From c828ec88205a232a9789f157d8cf9c3d82f85152 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Sun, 18 Aug 2002 09:36:26 +0000 Subject: Make pg_dump output more portable and more pleasing to look at. The -n and -N options were removed. Quoting is now smart enough to supply quotes if and only if necessary. Numerical types are now printed without quotes, except in cases of special values such as NaN. Boolean values printed as true and false. Most string literals now do not escape whitespace characters (newlines, etc.) for portability. SET SESSION AUTHORIZATION argument is a string literal, to follow SQL. Made commands output by pg_dump use consistent spacing and indentation. --- src/backend/utils/adt/ruleutils.c | 41 +++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) (limited to 'src/backend/utils/adt/ruleutils.c') diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index ec711e9959f..0f5d0fca86b 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -3,7 +3,7 @@ * back to source text * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.116 2002/08/16 23:01:19 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.117 2002/08/18 09:36:25 petere Exp $ * * This software is copyrighted by Jan Wieck - Hamburg. * @@ -2529,14 +2529,42 @@ get_const_expr(Const *constval, deparse_context *context) { case INT2OID: case INT4OID: - case OIDOID: /* int types */ + case INT8OID: + case OIDOID: case FLOAT4OID: - case FLOAT8OID: /* float types */ - /* These types are printed without quotes */ - appendStringInfo(buf, extval); + case FLOAT8OID: + case NUMERICOID: + { + /* + * These types are printed without quotes unless they + * contain values that aren't accepted by the scanner + * unquoted (e.g., 'NaN'). Note that strtod() and friends + * might accept NaN, so we can't use that to test. + * + * In reality we only need to defend against infinity and + * NaN, so we need not get too crazy about pattern + * matching here. + */ + if (strspn(extval, "0123456789 +-eE.") == strlen(extval)) + appendStringInfo(buf, extval); + else + appendStringInfo(buf, "'%s'", extval); + } + break; + + case BITOID: + case VARBITOID: + appendStringInfo(buf, "B'%s'", extval); break; - default: + case BOOLOID: + if (strcmp(extval, "t")==0) + appendStringInfo(buf, "true"); + else + appendStringInfo(buf, "false"); + break; + + default: /* * We must quote any funny characters in the constant's * representation. XXX Any MULTIBYTE considerations here? @@ -2564,6 +2592,7 @@ get_const_expr(Const *constval, deparse_context *context) switch (constval->consttype) { + case BOOLOID: case INT4OID: case FLOAT8OID: case UNKNOWNOID: -- cgit v1.2.3