5CESNJJQPZDHWDKA2C46FZO5VYDDHTC2ENZS6ZSIZM767IQPZ52AC Y4CGGXO7OJRSU36XZRIUVTGX73BXSKUY566ZWXIFO3UP7Y6JXXUQC OJD2AWBJJRUXYVF5BBYWSRRIE5A7LKJDL6YQCQZ3APEBIB6GATFAC QQAJ5O5EW6ASWLXQ627Y2F6YGMYKCM4WS37LTZYOMNPPFDPMNBUAC EGNRBQUMOZHAF5B7KCMTAPMB4H3USK4MK33Q6T5V26D6HOJNW6LQC E4HFJ4L4PAGV7R7EXVG2B2CWDGGW7XWU4D37VURZ66HZ3ILHCFUAC 63VXWIHIAKGK7J4VTNRUAG2V32N2QUSWFELB6GD34S54FGRWAPCQC Y6HOXJX6YHDL2Y3L53QZFA4LHKXXS6WAG4TZGBKQGMT35VQLAN3QC 72DUSPYXB64ECTFQWWD7XSY4YJUNRCFZT22AS4BDRIIUZP33CZGAC NBGKNI25T2AKNWDH5Z6U6JDUHLQPNRL6GQFF5VS37OOHONSP4CKQC NJ233BBUD2WBHKNEWPO5JWQTECTGR5F43NYTSNOZ5J3K22U5C47QC NDMM44EV2XD5RP7J4Q25ZX52LUP7WOMTKO3C2PDXW7IWFEVWUW6QC 5RSETDN4QCQLU7Z55EFXSW27CBEW6HD2MVD2MKB6WDBXIKXFHKNQC ZBUC3VBT42SDAG42OCUX7MTT6GNPX2GEGWU2QIUYAY4NMX33IGLAC GQ2TJSGOGNH4PKDNN5ZWITLOE6YNAWO6TCBCQV4SN7ZRWEB6IZ5AC NAAQ2HMF7NXGJDRPXATVAGGZWL5MAIQWF4K5S23VFYBPOPZUXJZAC HVXAGQL3ODR3M46AQSASGGNFWSLYUNAHDIBN5DS4IGC4FHTT5JMAC NF2TA3BN5FXWG6LFHHI3IDBVRPMLVRNUUZBE3NWIBASMSKEQPC4QC 76HUJPOPXCN2NMOWLI6JOY7HR35EL4IBHMES3DBJVCFZRKKPGQSAC species species not null,strain_id integer references strain on delete set null,
species species,blend boolean not null,strain_id integer references strain on delete restrict,check (blend and species is not null and strain_id is null ornot blend and (species is null) != (strain_id is null)),
create or replace function ios_product_id(_producer text, _brand text, _display_name text, _joined_name citext, _type product_type, _species species, _strain citext, _description text, _show boolean, _terpenes citext[], _dosage decimal, out _product_id integer) as $$
create or replace function ios_product_id(_producer text, _brand text, _display_name text, _joined_name citext, _type product_type, _species species, _blend boolean, _strain citext, _description text, _show boolean, _terpenes citext[], _dosage decimal, out _product_id integer) as $$
species,(select strain.display_name from strain where strain.strain_id = product.strain_id),--aggregate first, then join https://stackoverflow.com/a/27626358 use subquery since small selection
coalesce(product.species, strain.species),blend,strain.display_name,
coalesce((select json_agg(destination) from product_image where product_image.product_id = product.product_id), '[]'),
coalesce((select json_agg(destination) from product_image where product_image.product_id = product.product_id), '[]'),--aggregate first, then join https://stackoverflow.com/a/27626358 use subquery since small selection