1

Given the following base table, which implements a sort of Entity-Attribute-Value table

CREATE OR REPLACE TABLE dipendenti_detail (
    id_dipendente int(10) unsigned DEFAULT 0,
    id_azienda int(10) unsigned NOT NULL DEFAULT 1,
    id_sede int(10) unsigned NOT NULL DEFAULT 1,
    revisione_documento int(10) unsigned NOT NULL DEFAULT 0,
    campo varchar(255) NOT NULL DEFAULT '',
    valore varchar(255) DEFAULT NULL,
    PRIMARY KEY (id_dipendente,id_azienda,id_sede,revisione_documento,campo)
) ENGINE=InnoDB;

And the following example data:

id_dipendente id_azienda id_sede revisione_documento campo valore
187 2 98 0 ID Ente Esterno
187 2 98 0 ID Ruolo 1
187 2 98 0 Qualifica Amministrativo - Collaboratore di Amministrazione
187 2 98 0 Ruolo Dipendente
187 2 98 0 test
188 2 98 0 ID Ente Esterno
188 2 98 0 ID Ruolo 1
188 2 98 0 Qualifica Amministrativo - Collaboratore di Amministrazione
188 2 98 0 Ruolo Dipendente
189 2 98 0 ID Ente Esterno
189 2 98 0 ID Ruolo 1
189 2 98 0 Qualifica Amministrativo - Collaboratore di Amministrazione
189 2 98 0 Ruolo Dipendente
190 2 98 0 ID Ente Esterno
190 2 98 0 ID Ruolo 1
190 2 98 0 Qualifica Amministrativo - Collaboratore di Amministrazione
190 2 98 0 Ruolo Dipendente
191 2 98 0 ID Ente Esterno
191 2 98 0 ID Ruolo 1
191 2 98 0 Qualifica Ricercatore - Primo Ricercatore
191 2 98 0 Ruolo Dipendente
192 2 98 0 ID Ente Esterno 335
192 2 98 0 ID Ruolo 2
192 2 98 0 Qualifica Prof. Ordinario
192 2 98 0 Ruolo Associato
193 2 98 0 ID Ente Esterno
193 2 98 0 ID Ruolo 1
193 2 98 0 Qualifica Ricercatore - Ricercatore
193 2 98 0 Ruolo Dipendente
194 2 98 0 ID Ente Esterno 335
194 2 98 0 ID Ruolo 2
194 2 98 0 Qualifica Prof. Ordinario
194 2 98 0 Ruolo Associato
195 2 98 0 ID Ente Esterno 335
195 2 98 0 ID Ruolo 2
195 2 98 0 Qualifica Prof. Associato
195 2 98 0 Ruolo Associato

I tried creating a PIVOT table using the CONNECT engine:

CREATE OR REPLACE TABLE dipendenti_detail_pivot
ENGINE=CONNECT
TABLE_TYPE=PIVOT
TABNAME=dipendenti_detail
OPTION_LIST='user=connect,PivotCol=campo,FncCol=valore,Function=MAX';

The table is created correctly; however, when I select from it, I get an unexpected result:

id_dipendente id_azienda id_sede revisione_documento ID Ente Esterno ID Ruolo Qualifica Ruolo test ICE in caso di emergenza Contatto di Emergenza tel familiare
187 2 98 0
187 2 98 0 1
187 2 98 0 Amministrativo - Collaboratore di Amministrazione
187 2 98 0 Dipendente
187 2 98 0
187 2 98 0 9a125ef2-24ec-4f57-97a6-76365b490bce
188 2 98 0
188 2 98 0 1
188 2 98 0 Amministrativo - Collaboratore di Amministrazione
188 2 98 0 Dipendente
188 2 98 0 9becc99d-3b41-4276-89fc-4dbbb1cd6b4e

Here you can see that, while I would have expected a single for for each (id_dipendente, id_azienda, id_sede, revisione_documento) 4-tuple, instead I get one row for each detail field.

Did I create the PIVOT table with the wrong definition, or is it an error in the CONNECT engine itself?

I am currently using MariaDB 10.6.12 on Ubuntu 22.04.

EDIT:

Given that the original table structure does not actually need aggregation, I also tried to define the PIVOT table as:

CREATE OR REPLACE TABLE dipendenti_detail_pivot
ENGINE=CONNECT
TABLE_TYPE=PIVOT
TABNAME=dipendenti_detail
OPTION_LIST='user=connect,PivotCol=campo,FncCol=valore,GroupBy=1';

But when I select from it, the result is the same.

Matteo Tassinari
  • 187
  • 2
  • 16

0 Answers0