Обсуждение: pg_dump && aggregate bug

Поиск
Список
Период
Сортировка

pg_dump && aggregate bug

От
Mathieu Arnold
Дата:
Hi

I have :

CREATE FUNCTION "first_cat" (text,text) RETURNS text AS 'SELECT CASE WHEN
$1 IS NULL THEN $2 ELSE $1 END' LANGUAGE 'sql';

and :

CREATE AGGREGATE first ( BASETYPE = text, SFUNC = first_cat, STYPE = text);

when I dump my database, in the dump file, the aggregate becomes :

CREATE AGGREGATE first ( BASETYPE = text, SFUNC = first_cat, STYPE = text,
INITCOND = '' );

which is *not* the same as you may imagine...

To dump my database, I use :
pg_dump -c

and I use :
PostgreSQL 7.2.1 on i386-portbld-freebsd4.5, compiled by GCC 2.95.3

I believe it lies around lines 3860 - 3864 of src/bin/pg_dump/pg_dump.c,
but I don't find what's wrong with it.

--
Mathieu Arnold

Re: pg_dump && aggregate bug

От
Tom Lane
Дата:
Mathieu Arnold <mat@mat.cc> writes:
> when I dump my database, in the dump file, the aggregate becomes :

> CREATE AGGREGATE first ( BASETYPE = text, SFUNC = first_cat, STYPE = text,
> INITCOND = '' );

Ooops.  This seems to be fixed already in current sources, but I think
a back-patch to 7.2 may be warranted.  Try this around line 1912:

        agginfo[i].aggbasetype = strdup(PQgetvalue(res, i, i_aggbasetype));
-       agginfo[i].agginitval = strdup(PQgetvalue(res, i, i_agginitval));
+       if (PQgetisnull(res, i, i_agginitval))
+           agginfo[i].agginitval = NULL;
+       else
+           agginfo[i].agginitval = strdup(PQgetvalue(res, i, i_agginitval));
        agginfo[i].usename = strdup(PQgetvalue(res, i, i_usename));

            regards, tom lane

Re: pg_dump && aggregate bug

От
Mathieu Arnold
Дата:
--On mardi 21 mai 2002 10:19 -0400 Tom Lane <tgl@sss.pgh.pa.us> wrote:

> Mathieu Arnold <mat@mat.cc> writes:
>> when I dump my database, in the dump file, the aggregate becomes :
>
>> CREATE AGGREGATE first ( BASETYPE = text, SFUNC = first_cat, STYPE =
>> text,  INITCOND = '' );
>
> Ooops.  This seems to be fixed already in current sources, but I think
> a back-patch to 7.2 may be warranted.  Try this around line 1912:
>
>         agginfo[i].aggbasetype = strdup(PQgetvalue(res, i,
> i_aggbasetype)); -       agginfo[i].agginitval = strdup(PQgetvalue(res,
> i, i_agginitval)); +       if (PQgetisnull(res, i, i_agginitval))
> +           agginfo[i].agginitval = NULL;
> +       else
> +           agginfo[i].agginitval = strdup(PQgetvalue(res, i,
> i_agginitval));         agginfo[i].usename = strdup(PQgetvalue(res, i,
> i_usename));
>
>             regards, tom lane

worked, thanks.
I wonder if it could go into a possible 7.1.2 if there is one ? :)

--
Mathieu Arnold