nntp2http.com
Posting
Suche
Optionen
Hilfe & Kontakt

Re: [PGSQL] Bug beim Cast von Row auf Type?

Von: Bernd Nawothnig (bernd.nawothnig@t-online.de) [Profil]
Datum: 16.10.2009 03:25
Message-ID: <qkukq6xu94.ln2@bernd.nawothnig.dialin.t-online.de>
Newsgroup: de.comp.datenbanken.misc
Hallo zusammen,

Gegeben ist folgender Kontext:

#v+
CREATE TYPE t_config_row AS (
name     varchar,
"type"   varchar,
value    text,
position smallint
);

CREATE OR REPLACE FUNCTION
-- SYNOPSIS
config.compare_sections(
psource      int, -- $1
pdestination int  -- $2
)
-- END
RETURNS
-- RETURNS
boolean
-- END
AS
$body$
DECLARE
xposition int;
xname text;
xtype text;
xvalue text;
xid_1 int;
xid_2 int;
x t_config_row;
v record;
BEGIN
IF  -- number of attributes mismatch?
(SELECT count(*) FROM config.attributes WHERE section = psource) <>
(SELECT count(*) FROM config.attributes WHERE section = pdestination) OR
-- number of subsections mismatch?
(SELECT count(*) FROM config.sections WHERE section = psource) <>
(SELECT count(*) FROM config.sections WHERE section = pdestination)
THEN
RETURN FALSE;
END IF;

FOR x IN SELECT
ROW(
name,
type,
value,
"position"
)
FROM
config.attributes
WHERE
section = psource
LOOP
-- the next line should not be necessary - a pgsql bug?
x:= x.name::t_config_row;
IF x NOT IN (
SELECT
ROW(
name,
type,
value,
"position"
)
FROM
config.attributes
WHERE
section = pdestination
) THEN
RETURN FALSE;
END IF;
END LOOP;
FOR xid_1, xname IN SELECT
id,
name
FROM
config.sections
WHERE
section = psource
LOOP
IF xname IN (
SELECT
name
FROM
config.sections
WHERE
section = pdestination
) THEN
SELECT
id
INTO
xid_2
FROM
config.sections
WHERE
section = pdestination
;
RETURN config.compare_sections(xid_1, xid_2);
ELSE
RETURN FALSE;
END IF;
END LOOP;
RETURN TRUE;
END
$body$
LANGUAGE PLPGSQL STABLE;
#v-

Der Code funktioniert so, aber erst, nachdem ich diese Zeile oben

-- the next line should not be necessary - a pgsql bug?
x:= x.name::t_config_row;

eingefügt habe, die mir reichlich widersinnig erscheint erscheint.

Warum werden beim FOR x in SELECT alle Komponenten der Row in gerade
die erste Komponente von x gepackt, während es beim expliziten Cast
dann genau so funktioniert, wie man das eigentlich immer erwarten
sollte?

Bug oder feature?



Bernd

--
No time toulouse

[ Auf dieses Posting antworten ]

Antworten