Re: pg_dump doesn't dump binary compatible casts - Mailing list pgsql-hackers
From | Jan Wieck |
---|---|
Subject | Re: pg_dump doesn't dump binary compatible casts |
Date | |
Msg-id | 3F75B0BE.40700@Yahoo.com Whole thread Raw |
In response to | Re: pg_dump doesn't dump binary compatible casts (Tom Lane <tgl@sss.pgh.pa.us>) |
Responses |
Re: pg_dump doesn't dump binary compatible casts
|
List | pgsql-hackers |
Tom Lane wrote: > Jan Wieck <JanWieck@Yahoo.com> writes: >> That eliminated, a cast should be dumped if one or more of the three >> objects (source, target and function) are not builtin AND all the >> non-builtin objects belong to namespaces included in the dump. > > Where "builtin" is defined as "belongs to pg_catalog schema", you mean? > I think that works for me ... Okay, I have more precisely defined "builtin" as "belongs to a schema who's name starts with pg_", as that is how we distinguish what namespaces get dumped in the first place. The patch is applied to 7.4 according to being a bug. The same patch would cleanly apply to 7.3.4 as well, so my question is do we want to backpatch? Jan -- #======================================================================# # It's easier to get forgiveness for being wrong than for being right. # # Let's break this rule - forgive me. # #================================================== JanWieck@Yahoo.com # diff -crN ../src.orig/bin/pg_dump/pg_dump.c ./bin/pg_dump/pg_dump.c *** ../src.orig/bin/pg_dump/pg_dump.c Tue Sep 23 10:10:31 2003 --- ./bin/pg_dump/pg_dump.c Sat Sep 27 10:18:55 2003 *************** *** 3912,3917 **** --- 3912,3918 ---- PQExpBuffer query = createPQExpBuffer(); PQExpBuffer defqry = createPQExpBuffer(); PQExpBuffer delqry = createPQExpBuffer(); + PQExpBuffer castsig = createPQExpBuffer(); int ntups; int i; *************** *** 3941,3956 **** char *castcontext = PQgetvalue(res, i, 4); int fidx = -1; const char *((*deps)[]); if (strcmp(castfunc, "0") != 0) fidx = findFuncByOid(finfo, numFuncs, castfunc); /* ! * We treat the cast as being in the namespace of the underlying ! * function. This doesn't handle binary compatible casts. Where ! * should those go? */ ! if (fidx < 0 || !finfo[fidx].pronamespace->dump) continue; /* Make a dependency to ensure function is dumped first */ --- 3942,3992 ---- char *castcontext = PQgetvalue(res, i, 4); int fidx = -1; const char *((*deps)[]); + int source_idx; + int target_idx; if (strcmp(castfunc, "0") != 0) fidx = findFuncByOid(finfo, numFuncs, castfunc); /* ! * As per discussion we dump casts if one or more of the underlying ! * objects (the conversion function and the two data types) are not ! * builtin AND if all of the non-builtin objects namespaces are ! * included in the dump. Builtin meaning, the namespace name does ! * not start with "pg_". */ ! source_idx = findTypeByOid(tinfo, numTypes, castsource); ! target_idx = findTypeByOid(tinfo, numTypes, casttarget); ! ! /* ! * Skip this cast if all objects are from pg_ ! */ ! if ((fidx < 0 || strncmp(finfo[fidx].pronamespace->nspname, "pg_", 3) == 0) && ! strncmp(tinfo[source_idx].typnamespace->nspname, "pg_", 3) == 0 && ! strncmp(tinfo[target_idx].typnamespace->nspname, "pg_", 3) == 0) ! continue; ! ! /* ! * Skip cast if function isn't from pg_ and that namespace is ! * not dumped. ! */ ! if (fidx >= 0 && ! strncmp(finfo[fidx].pronamespace->nspname, "pg_", 3) != 0 && ! !finfo[fidx].pronamespace->dump) ! continue; ! ! /* ! * Same for the Source type ! */ ! if (strncmp(tinfo[source_idx].typnamespace->nspname, "pg_", 3) != 0 && ! !tinfo[source_idx].typnamespace->dump) ! continue; ! ! /* ! * and the target type. ! */ ! if (strncmp(tinfo[target_idx].typnamespace->nspname, "pg_", 3) != 0 && ! !tinfo[target_idx].typnamespace->dump) continue; /* Make a dependency to ensure function is dumped first */ *************** *** 3966,3971 **** --- 4002,4008 ---- resetPQExpBuffer(defqry); resetPQExpBuffer(delqry); + resetPQExpBuffer(castsig); appendPQExpBuffer(delqry, "DROP CAST (%s AS %s);\n", getFormattedTypeName(castsource, zeroAsNone), *************** *** 3987,3995 **** appendPQExpBuffer(defqry, " AS IMPLICIT"); appendPQExpBuffer(defqry, ";\n"); ArchiveEntry(fout, castoid, ! format_function_signature(&finfo[fidx], false), ! finfo[fidx].pronamespace->nspname, "", "CAST", deps, defqry->data, delqry->data, NULL, NULL, NULL); --- 4024,4036 ---- appendPQExpBuffer(defqry, " AS IMPLICIT"); appendPQExpBuffer(defqry, ";\n"); + appendPQExpBuffer(castsig, "CAST (%s AS %s)", + getFormattedTypeName(castsource, zeroAsNone), + getFormattedTypeName(casttarget, zeroAsNone)); + ArchiveEntry(fout, castoid, ! castsig->data, ! tinfo[source_idx].typnamespace->nspname, "", "CAST", deps, defqry->data, delqry->data, NULL, NULL, NULL); *************** *** 4000,4005 **** --- 4041,4047 ---- destroyPQExpBuffer(query); destroyPQExpBuffer(defqry); destroyPQExpBuffer(delqry); + destroyPQExpBuffer(castsig); }
pgsql-hackers by date: