...
WITH parameters AS
(SELECT
'law,ref' AS location_code_filter -- enter a locatiON location code; if left blank, the query will get all locations except for 'serv,remo'
)
SELECT distinct
ipd.instance_id,
ipd.instance_hrid,
instext.title,
ll.location_name,
he.call_number,
ipd.physical_description,
CASE
WHEN substring (ipd.physical_description,'\d{1,4}') IS NOT NULL
AND (ipd.physical_descriptiON description LIKE '%page%' OR ipd.physical_descriptiON description LIKE '%p.%' OR ipd.physical_descriptiON description LIKE '%leaves%' OR ipd.physical_descriptiON description LIKE '% l.%')
THEN substring (ipd.physical_description,'\d{1,4}')::INT
ELSE NULL
END AS page_count_estimate,
ipd.physical_description_ordinality
...