Skip to content

Instantly share code, notes, and snippets.

@daviddsp
Created March 5, 2019 15:35
Show Gist options
  • Select an option

  • Save daviddsp/3dc5b523698c4b61d57a54205335bacd to your computer and use it in GitHub Desktop.

Select an option

Save daviddsp/3dc5b523698c4b61d57a54205335bacd to your computer and use it in GitHub Desktop.
function PostgreSQL
create function generate () Returns Void
as
$$
CREATE VIEW jvf.view_products AS
SELECT stock.code_internal,SUM(stock.stock) AS stock,stock.object_id as id_algolia,stock.price,promo.offer as promotions,
product.name, product.master_category, product.category as category, product.sub_category as sub_category,
product.principe_active as principe_active,product.bioequivalent as bioequivalent, product.internet_sale as internet_sale,
product.prescription_type as prescription_type, product.laboratory, product.meta_description, product.image, product.keywords,
product.contraindications, product.presentation, product.composition, product.meta_title, product.warnings, product.therapeutic_action,
product.usual_dose, product.featured, product.posology, product.quantity, product.drug_interactions, product.unit_price, product.overdose,
product.side_effect, product.editable_name, product.storage_conditions, product.isp, product.shape_farmaceutic, product.important_products,
stock.pharmacy
FROM ahumada.products_price_stock as stock
LEFT JOIN public.promotions as promo
ON stock.code_internal = promo.code_internal
LEFT JOIN ahumada.products as product
ON stock.code_internal = product.code_internal
GROUP BY stock.code_internal, stock.object_id, stock.price, promo.offer, product.name, product.master_category, product.category, product.sub_category,
product.principe_active, product.bioequivalent, product.internet_sale, product.prescription_type, product.laboratory, product.meta_description,
product.image, product.keywords, product.contraindications, product.presentation, product.composition, product.meta_title, product.warnings,
product.therapeutic_action, product.usual_dose, product.featured, product.posology, product.quantity, product.drug_interactions, product.unit_price,
product.overdose, product.side_effect, product.editable_name, product.storage_conditions, product.isp, product.shape_farmaceutic, product.important_products,
stock.pharmacy;
$$
Language SQL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment