Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Unable to get lines from database table using composite type

ERROR: missing FROM-clause entry for table

I have composite type "design" consisting of enums (top, drawing, classic, etc.) and I need to somehow get rows from table by value from enum

So, basically, I need to process the following query:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

SELECT * 
FROM photos
WHERE nails_design.top = 'matte'

The full structure:

-- auto-generated definition
create type design as
(
    top          tops,
    volume_small volume_small,
    volume_big   volume_big,
    drawing      drawings,
    classic      classic
);

alter type design owner to postgres;

-- auto-generated definition
create type tops as enum ('matte', 'glosse');

alter type tops owner to postgres;

>Solution :

You have to do it like this:

SELECT * FROM photos WHERE (photos.nails_design).top = 'matte';

Nesting data types like that is not a good idea. Avoid composite types in table definitions, that violates the first normal form. And, as you see, it doesn’t make your queries more intuitive.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading