There is a type:

CREATE TYPE ComprositiontTransfer AS ( Id BIGINT, Name CHARACTER VARYING, COUNT BIGINT, Price NUMERIC, IdExport CHARACTER VARYING, IdImport CHARACTER VARYING ); 

In the table:

 CREATE TABLE "Transfer" ( "Id" serial NOT NULL, "Date" TIMESTAMP WITHOUT TIME zone NOT NULL, "OrgPostav" CHARACTER VARYING NOT NULL, "NameSklad" CHARACTER VARYING NOT NULL, "Сomposition" ComprositiontTransfer[] NOT NULL, "Operator" CHARACTER VARYING NOT NULL, "Total" NUMERIC, "Changed" BOOLEAN, "OneCid" CHARACTER VARYING, CONSTRAINT Transfer_pk PRIMARY KEY ("Id") ) WITH ( OIDS=FALSE ); 

How can I, for example, get all the transportation for the specified employee? (IdExport field in composite type)

  • Give an example for some two lines of data. And the irrelevant fields (except perhaps the primary key) should be thrown out altogether, for the question it is an extra volume. - D-side

1 answer 1

You can do it like this:

  SELECT id, u FROM "Transfer", unnest("Transfer"."Сomposition") u WHERE u.IdExport = '25' ; 
  • And where is your "employee"? The question does not fit in with the answer. - D-side
  • u.IdExport - this field is its ID. So I got the id of all entries in expenses - Oma
  • Oh, okay. That's what I asked for an example. The answer comes as an example. - D-side
  • Thank you for the response. - Oma