-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver-sql.txt
3303 lines (2469 loc) · 99.3 KB
/
server-sql.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--
-- PostgreSQL database dump
--
-- Dumped from database version 12.3
-- Dumped by pg_dump version 12.3
-- Started on 2020-12-01 16:19:40
SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;
--
-- TOC entry 9 (class 2615 OID 33405)
-- Name: store; Type: SCHEMA; Schema: -; Owner: postgres
--
CREATE SCHEMA store;
ALTER SCHEMA store OWNER TO postgres;
--
-- TOC entry 301 (class 1255 OID 33862)
-- Name: alluserinformation(); Type: FUNCTION; Schema: public; Owner: postgres
--
CREATE FUNCTION public.alluserinformation() RETURNS TABLE(userid integer, fname character varying, lname character varying, mobno character varying, dob date, gender character, emailid character varying, userdiscount character varying, addrid integer, addrline1 character varying, addrline2 character varying, addrline3 character varying, city character varying, state character varying, pincode character varying, country character varying)
LANGUAGE plpgsql
AS $$
BEGIN
RETURN QUERY
select a.user_id,a.user_fname, a.user_lname, a.user_mobileno,
a.user_dob,a.user_gender,a.user_emailaddr, a.user_discount,
b.addr_id,b.addr_line1,b.addr_line2,b.addr_line3,
b.addr_city, b.addr_state, b.addr_pincode, b.addr_country
from users a
left join user_address b ON b.user_id = a.user_id
where a.user_typecode = 'c' and b.addr_datetill is null;
END
$$;
ALTER FUNCTION public.alluserinformation() OWNER TO postgres;
--
-- TOC entry 302 (class 1255 OID 33871)
-- Name: fnadminproductselect(); Type: FUNCTION; Schema: public; Owner: postgres
--
CREATE FUNCTION public.fnadminproductselect() RETURNS TABLE(prodid integer, prodcategory character varying, prodname character varying, proddesc text, qty bigint, trending boolean, latest boolean)
LANGUAGE plpgsql
AS $$
BEGIN
RETURN QUERY
with cte_productgetdetails as (
select a.prod_category, b.prod_subcateg_id
, c.prod_id, c.prod_name, c.prod_desc, c.prod_trending, c.prod_latest from
product_sub_category b inner join product_category a on b.prod_category_id =a.prod_category_id
inner join product c on b.prod_subcateg_id = c.prod_subcateg_id
where c.prod_datetill is null
)
select prod_id, prod_category, prod_name
, prod_desc , sum(pd.prod_qty) as Qty, ct.prod_trending, ct.prod_latest from product_details pd
inner join cte_productgetdetails ct using (prod_id)
inner join ref_colour rc on pd.prod_colour = rc.colour_id
inner join ref_size rs on pd.prod_size = rs.size_id
group by prod_id,prod_category, prod_name, prod_desc,ct.prod_trending, ct.prod_latest;
-- RETURN QUERY
-- SELECT b.prod_id,c.prod_category, a.prod_name,a.prod_desc, b.prod_inr_price,
-- b.prod_usd_price, d.colour_value, e.size_value,b.prod_qty FROM product_sub_category a
-- INNER JOIN product b ON a.prod_subcateg_id = b.prod_subcateg_id
-- INNER JOIN product_category c ON a.prod_category_id = c.prod_category_id
-- LEFT JOIN ref_colour d ON d.colour_id = b.prod_colour
-- LEFT JOIN ref_size e ON e.size_id = b.prod_size
-- ORDER BY b.prod_id;
END
$$;
ALTER FUNCTION public.fnadminproductselect() OWNER TO postgres;
--
-- TOC entry 294 (class 1255 OID 33894)
-- Name: fncheckcoupon(character varying); Type: FUNCTION; Schema: public; Owner: postgres
--
CREATE FUNCTION public.fncheckcoupon(_couponcode character varying) RETURNS TABLE(cp_id integer, cp_code character varying, cp_value character varying)
LANGUAGE plpgsql
AS $$
DECLARE
_couponvalue VARCHAR(20);
BEGIN
IF EXISTS (SELECT 1 from coupon where LOWER(coupon.coupon_code) = LOWER(_couponcode) and coupon_datetill is null) THEN
RETURN QUERY
select coupon.coupon_id, coupon.coupon_code, coupon.coupon_value from coupon where LOWER(coupon.coupon_code) = LOWER(_couponcode);
ELSE
raise exception 'Invalid Coupon Code';
END IF;
END;
$$;
ALTER FUNCTION public.fncheckcoupon(_couponcode character varying) OWNER TO postgres;
--
-- TOC entry 299 (class 1255 OID 42109)
-- Name: fncheckifuseremailexists(character varying); Type: FUNCTION; Schema: public; Owner: postgres
--
CREATE FUNCTION public.fncheckifuseremailexists(_useremail character varying) RETURNS TABLE(user_id integer)
LANGUAGE plpgsql
AS $$
BEGIN
RETURN QUERY
select users.user_id
from users
where user_emailaddr = _userEmail;
END
$$;
ALTER FUNCTION public.fncheckifuseremailexists(_useremail character varying) OWNER TO postgres;
--
-- TOC entry 256 (class 1255 OID 16827)
-- Name: fncolourselect(); Type: FUNCTION; Schema: public; Owner: postgres
--
CREATE FUNCTION public.fncolourselect() RETURNS TABLE(col_id integer, col_code character varying, col_value character varying)
LANGUAGE plpgsql
AS $$
BEGIN
RETURN QUERY
SELECT colour_id, colour_code, colour_value from ref_colour
WHERE colour_datetill is null;
END
$$;
ALTER FUNCTION public.fncolourselect() OWNER TO postgres;
--
-- TOC entry 258 (class 1255 OID 16860)
-- Name: fncouponselect(); Type: FUNCTION; Schema: public; Owner: postgres
--
CREATE FUNCTION public.fncouponselect() RETURNS TABLE(cp_id integer, cp_code character varying, cp_value character varying)
LANGUAGE plpgsql
AS $$
BEGIN
RETURN QUERY
SELECT coupon_id, coupon_code, coupon_value FROM coupon
WHERE coupon_datetill is null;
END
$$;
ALTER FUNCTION public.fncouponselect() OWNER TO postgres;
--
-- TOC entry 309 (class 1255 OID 42096)
-- Name: fngetlatesttrendingproduct(integer); Type: FUNCTION; Schema: public; Owner: postgres
--
CREATE FUNCTION public.fngetlatesttrendingproduct(i integer) RETURNS TABLE(prod_id integer, prod_categ_name character varying, prod_name character varying, prod_inr_price numeric, prod_usd_price numeric, productdetailid integer, prod_img_name character varying, prod_img_path text)
LANGUAGE plpgsql
AS $$
BEGIN
IF i = 1 THEN ---- LATEST
RETURN QUERY
select a.prod_id,pc.prod_category, a.prod_name,
pd.prod_inr_price, pd.prod_usd_price,pd.pd_id,
b.prod_img_name, b.prod_img_path from public.product a
join public.product_sub_category ps on ps.prod_subcateg_id = a.prod_subcateg_id
join public.product_category pc on pc.prod_category_id = ps.prod_category_id
left join public.product_image b on a.prod_id=b.prod_id
left join public.product_details pd on a.prod_id = pd.prod_id
where a.prod_id in (select pd.prod_id from product_details pd)
and a.prod_datetill is null
and a.prod_latest = true
and pd.pd_id = (select pds.pd_id from public.product_details pds where pds.prod_id = a.prod_id LIMIT 1)
and b.prod_img_name = (select pi.prod_img_name from public.product_image pi where pi.prod_id=a.prod_id LIMIT 1)
LIMIT 12;
ELSEIF i = 2 THEN ---- TRENDING
RETURN QUERY
select a.prod_id ,pc.prod_category,a.prod_name,
pd.prod_inr_price, pd.prod_usd_price,pd.pd_id,
b.prod_img_name, b.prod_img_path from public.product a
join public.product_sub_category ps on ps.prod_subcateg_id = a.prod_subcateg_id
join public.product_category pc on pc.prod_category_id = ps.prod_category_id
left join public.product_image b on a.prod_id=b.prod_id
left join public.product_details pd on a.prod_id = pd.prod_id
where a.prod_id in (select pd.prod_id from product_details pd)
and a.prod_datetill is null
and a.prod_trending = true
and pd.pd_id = (select pds.pd_id from public.product_details pds where pds.prod_id = a.prod_id LIMIT 1)
and b.prod_img_name = (select pi.prod_img_name from public.product_image pi where pi.prod_id=a.prod_id LIMIT 1)
LIMIT 12;
END IF;
END;
$$;
ALTER FUNCTION public.fngetlatesttrendingproduct(i integer) OWNER TO postgres;
--
-- TOC entry 257 (class 1255 OID 16851)
-- Name: fnprodsubcategselect(); Type: FUNCTION; Schema: public; Owner: postgres
--
CREATE FUNCTION public.fnprodsubcategselect() RETURNS TABLE(ps_id integer, cat_name character varying, cat_id integer, ps_name character varying, ps_desc text)
LANGUAGE plpgsql
AS $$
BEGIN
RETURN QUERY
SELECT a.prod_subcateg_id, b.prod_category, b.prod_category_id, a.prod_name, a.prod_desc FROM product_sub_category a
INNER JOIN product_category b ON a.prod_category_id = b.prod_category_id;
END
$$;
ALTER FUNCTION public.fnprodsubcategselect() OWNER TO postgres;
--
-- TOC entry 310 (class 1255 OID 42101)
-- Name: fnproductlistselect(text, text, text, text, text, text); Type: FUNCTION; Schema: public; Owner: postgres
--
CREATE FUNCTION public.fnproductlistselect(_colour text DEFAULT NULL::text, _size text DEFAULT NULL::text, _price text DEFAULT NULL::text, _prodcategid text DEFAULT NULL::text, _subcategid text DEFAULT NULL::text, _prodname text DEFAULT NULL::text) RETURNS TABLE(prodid integer, prodcategory character varying, prodsubcategory character varying, prodname character varying, proddesc text, inrprice numeric, usdprice numeric, proddetailid integer, colour character varying, size character varying, qty integer, prodimgpath text, prodimgname character varying)
LANGUAGE plpgsql
AS $_$
DECLARE
_sql TEXT := 'SELECT b.prod_id, c.prod_category,a.prod_name, b.prod_name,b.prod_desc, pd.prod_inr_price,
pd.prod_usd_price, pd.pd_id, d.colour_value, e.size_value,pd.prod_qty,f.prod_img_path,f.prod_img_name FROM product_sub_category a
INNER JOIN product b ON a.prod_subcateg_id = b.prod_subcateg_id
INNER JOIN product_category c ON a.prod_category_id = c.prod_category_id
INNER JOIN product_details pd ON b.prod_id = pd.prod_id
LEFT JOIN ref_colour d ON d.colour_id = pd.prod_colour
LEFT JOIN ref_size e ON e.size_id = pd.prod_size
LEFT JOIN product_image f ON b.prod_id = f.prod_id ';
-- WHERE
-- f.prod_img_path = (select prod_img_path from product_image where prod_id= b.prod_id LIMIT 1)';
--WHERE 1=1 ';
_where TEXT;
BEGIN
_where = CONCAT_WS(' AND '
-- , CASE WHEN _colour IS NOT NULL THEN '('||_colour||')' END
, 'f.prod_img_path = (select prod_img_path from product_image where prod_id= b.prod_id LIMIT 1)'
, CASE WHEN _colour IS NOT NULL THEN 'd.colour_id in ' ||_colour||' ' END
, CASE WHEN _size IS NOT NULL THEN 'e.size_id in ' || _size||' ' END
, CASE WHEN _prodcategid IS NOT NULL THEN 'c.prod_category_id in '|| _prodcategid END
, CASE WHEN _subcategid IS NOT NULL THEN 'a.prod_subcateg_id in '||_subcategid||' ' END
, CASE WHEN _price IS NOT NULL THEN _price END||' '
, CASE WHEN _prodname IS NOT NULL THEN 'lower(b.prod_name) like lower(''%'||_prodname||'%'') ' END||' ');
IF _where <> '' THEN
_sql :=_sql ||' where '|| _where ||' order by b.prod_id';
--_sql :=_sql || _where ||' order by b.prod_id';
ELSE
_sql := _sql ||' order by b.prod_id';
END IF;
RETURN QUERY
EXECUTE _sql
USING $1,$2,$3,$4,$5,$6;
END
$_$;
ALTER FUNCTION public.fnproductlistselect(_colour text, _size text, _price text, _prodcategid text, _subcategid text, _prodname text) OWNER TO postgres;
--
-- TOC entry 283 (class 1255 OID 33277)
-- Name: fnproductselectfilter(integer, integer, integer); Type: FUNCTION; Schema: public; Owner: postgres
--
CREATE FUNCTION public.fnproductselectfilter(_cid integer DEFAULT NULL::integer, _sid integer DEFAULT NULL::integer, _pcid integer DEFAULT NULL::integer) RETURNS TABLE(prodid integer, prodcategory character varying, prodname character varying, proddesc text, inrprice numeric, usdprice numeric, colour character varying, size character varying, qty integer, prodimgpath text)
LANGUAGE plpgsql
AS $_$
DECLARE
_sql TEXT := 'SELECT b.prod_id, a.prod_name, b.prod_name ,a.prod_desc, b.prod_inr_price,
b.prod_usd_price, d.colour_value, e.size_value,b.prod_qty
,f.prod_img_path
FROM product_sub_category a
INNER JOIN product b ON a.prod_subcateg_id = b.prod_subcateg_id
INNER JOIN product_category c ON a.prod_category_id = c.prod_category_id
LEFT JOIN ref_colour d ON d.colour_id = b.prod_colour
LEFT JOIN ref_size e ON e.size_id = b.prod_size
LEFT JOIN product_image f ON b.prod_id = f.prod_id WHERE
b.prod_datetill is null and
f.prod_img_path = (select prod_img_path from product_image where prod_id= b.prod_id LIMIT 1) '
;
-- WHERE 1=1 ';
_where TEXT;
BEGIN
_where = CONCAT_WS('AND'
, CASE WHEN _cid IS NOT NULL THEN ' d.colour_id=$1 ' END
, CASE WHEN _sid IS NOT NULL THEN ' e.size_id = $2 ' END
, CASE WHEN _pcid IS NOT NULL THEN ' c.prod_category_id = $3 ' END);
IF _where <> '' THEN
--_sql :=_sql ||'where '|| _where ||'order by b.prod_id';
_sql :=_sql ||'and'|| _where ||'order by b.prod_id';
ELSE
_sql := _sql ||'order by b.prod_id';
END IF;
RETURN QUERY
EXECUTE _sql
USING $1,$2,$3;
END
$_$;
ALTER FUNCTION public.fnproductselectfilter(_cid integer, _sid integer, _pcid integer) OWNER TO postgres;
--
-- TOC entry 306 (class 1255 OID 42078)
-- Name: fnrelatedproduct(integer, integer); Type: FUNCTION; Schema: public; Owner: postgres
--
CREATE FUNCTION public.fnrelatedproduct(_subcategid integer, _productid integer) RETURNS TABLE(prodid integer, prod_categ_name character varying, prodname character varying, productdetailid integer, prodinrprice numeric, produsdprice numeric, prodimgname character varying, prodimgpath text)
LANGUAGE plpgsql
AS $$
BEGIN
RETURN QUERY
select * FROM ( SELECT DISTINCT ON (prod.prod_id) prod.prod_id,pc.prod_category , prod.prod_name
,pd.pd_id, pd.prod_inr_price, pd.prod_usd_price
, pi.prod_img_name, pi.prod_img_path
from product prod
inner join product_sub_category psc on prod.prod_subcateg_id = psc.prod_subcateg_id
inner join product_category pc on pc.prod_category_id = psc.prod_category_id
inner join product_details pd on prod.prod_id = pd.prod_id
inner join product_image pi on prod.prod_id = pi.prod_id
where prod.prod_subcateg_id = _subcategid AND prod.prod_datetill is null AND prod.prod_id != _productid
and pd.prod_inr_price = (select pdp.prod_inr_price from product_details pdp where pdp.prod_id = prod.prod_id limit 1)
and pi.prod_img_name = (select pim.prod_img_name from product_image pim where pim.prod_id=prod.prod_id LIMIT 1)) AS product
order by random() limit 8;
END;
$$;
ALTER FUNCTION public.fnrelatedproduct(_subcategid integer, _productid integer) OWNER TO postgres;
--
-- TOC entry 290 (class 1255 OID 33404)
-- Name: fnsingleproductselect(integer); Type: FUNCTION; Schema: public; Owner: postgres
--
CREATE FUNCTION public.fnsingleproductselect(_prod_id integer) RETURNS TABLE(prodid integer, prodcategory character varying, prodname character varying, proddesc text, proddetailid text, inrprice text, usdprice text, colour text, colourid text, size text, sizeid text, qty text, subcategoryid integer, imagename text, imagepath text)
LANGUAGE plpgsql
AS $$
BEGIN
RETURN QUERY
with cte_productgetdetails as (
select a.prod_category, b.prod_subcateg_id
, c.prod_id, c.prod_name, c.prod_desc from
product_sub_category b
inner join product_category a on b.prod_category_id =a.prod_category_id
inner join product c on b.prod_subcateg_id = c.prod_subcateg_id
where prod_id = _prod_id
),
cte_productimage as(
select prod_id
, string_agg(pi.prod_img_name,',' ) Images
, string_agg(pi.prod_img_path,',' ) ImagePath
from product_image pi where prod_id = _prod_id group by prod_id
)
select pd.prod_id
, ct.prod_category, ct.prod_name, ct.prod_desc
, string_agg(CAST (pd.pd_id as CHARACTER VARYING),',' order by pd.pd_id) Product_Detail_Id
, string_agg(pd.prod_inr_price::CHARACTER VARYING,',' order by pd.pd_id) INR_Price
, string_agg(pd.prod_usd_price::CHARACTER VARYING,',' order by pd.pd_id) USD_Price
, string_agg(rc.colour_value,',' order by pd.pd_id) Colour
, string_agg(CAST (rc.colour_id as CHARACTER VARYING),',' order by pd.pd_id) Colour_Id
, string_agg(rs.size_value,',' order by pd.pd_id) Size
, string_agg(CAST (rs.size_id as CHARACTER VARYING),',' order by pd.pd_id) Size_Id
, string_agg(pd.prod_qty::CHARACTER VARYING,',' order by pd.pd_id) Qty
, ct.prod_subcateg_id
, cpi.Images
, cpi.ImagePath
from product_details pd
inner join cte_productgetdetails ct using (prod_id)
left join cte_productimage cpi on pd.prod_id= cpi.prod_id
inner join ref_colour rc on pd.prod_colour = rc.colour_id
inner join ref_size rs on pd.prod_size = rs.size_id
where pd.prod_id = _prod_id
group by pd.prod_id, ct.prod_category, ct.prod_name, ct.prod_desc, ct.prod_subcateg_id, cpi.Images,cpi.ImagePath;
-- SELECT b.prod_id,c.prod_category, b.prod_name,b.prod_desc, b.prod_inr_price,
-- b.prod_usd_price, d.colour_value, e.size_value,b.prod_qty, b.prod_subcateg_id,
-- b.prod_size, b.prod_colour, string_agg(f.prod_img_name, ', '),string_agg(f.prod_img_path, ', ')
-- FROM product_sub_category a
-- INNER JOIN product b ON a.prod_subcateg_id = b.prod_subcateg_id
-- INNER JOIN product_category c ON a.prod_category_id = c.prod_category_id
-- LEFT JOIN ref_colour d ON d.colour_id = b.prod_colour
-- LEFT JOIN ref_size e ON e.size_id = b.prod_size
-- LEFT JOIN product_image f ON f.prod_id = b.prod_id
-- WHERE b.prod_id = _prod_id AND b.prod_datetill is null
-- GROUP BY b.prod_id,c.prod_category, b.prod_name,a.prod_desc, b.prod_inr_price,
-- b.prod_usd_price, d.colour_value, e.size_value,b.prod_qty, b.prod_subcateg_id,
-- b.prod_size, b.prod_colour;
END
$$;
ALTER FUNCTION public.fnsingleproductselect(_prod_id integer) OWNER TO postgres;
--
-- TOC entry 278 (class 1255 OID 16852)
-- Name: fnsizeselect(); Type: FUNCTION; Schema: public; Owner: postgres
--
CREATE FUNCTION public.fnsizeselect() RETURNS TABLE(s_id integer, s_code character varying, s_value character varying, prod_category integer, prod_categoryname character varying)
LANGUAGE plpgsql
AS $$
BEGIN
RETURN QUERY
SELECT size_id, size_code, size_value, a.prod_category_id,b.prod_category from ref_size a
inner join product_category b on a.prod_category_id = b.prod_category_id
WHERE a.size_datetill is null;
END
$$;
ALTER FUNCTION public.fnsizeselect() OWNER TO postgres;
--
-- TOC entry 308 (class 1255 OID 42117)
-- Name: getuseridpassword(text); Type: FUNCTION; Schema: public; Owner: postgres
--
CREATE FUNCTION public.getuseridpassword(_email text) RETURNS TABLE(userid integer, userpassword text, usertype character)
LANGUAGE plpgsql
AS $_$
BEGIN
RETURN QUERY
select user_id, user_password, user_typecode
from users
where user_emailaddr =$1;
END
$_$;
ALTER FUNCTION public.getuseridpassword(_email text) OWNER TO postgres;
--
-- TOC entry 275 (class 1255 OID 16646)
-- Name: passwordchange(integer); Type: FUNCTION; Schema: public; Owner: postgres
--
CREATE FUNCTION public.passwordchange(_userid integer) RETURNS TABLE(user_password text)
LANGUAGE plpgsql
AS $_$
BEGIN
RETURN QUERY
select user_password
from users
where user_id =$1;
END
$_$;
ALTER FUNCTION public.passwordchange(_userid integer) OWNER TO postgres;
--
-- TOC entry 303 (class 1255 OID 33863)
-- Name: personalinfoselect(integer); Type: FUNCTION; Schema: public; Owner: postgres
--
CREATE FUNCTION public.personalinfoselect(_userid integer) RETURNS TABLE(userid integer, fname character varying, lname character varying, mobno character varying, dob date, gender character, emailid character varying, discount character varying, addrid integer, addrline1 character varying, addrline2 character varying, addrline3 character varying, city character varying, state character varying, pincode character varying, country character varying)
LANGUAGE plpgsql
AS $_$
BEGIN
RETURN QUERY
select a.user_id,a.user_fname, a.user_lname, a.user_mobileno,
a.user_dob,a.user_gender,a.user_emailaddr, a.user_discount,b.addr_id,b.addr_line1,b.addr_line2,b.addr_line3,
b.addr_city, b.addr_state, b.addr_pincode, b.addr_country
from users a
left join user_address b ON b.user_id = a.user_id
where a.user_id= $1 and b.addr_datetill is null;
END
$_$;
ALTER FUNCTION public.personalinfoselect(_userid integer) OWNER TO postgres;
--
-- TOC entry 314 (class 1255 OID 42153)
-- Name: spaddressinsertupdatedelete(integer, integer, integer, character, character varying, character varying, character varying, character varying, character varying, character varying, character varying, numeric); Type: PROCEDURE; Schema: public; Owner: postgres
--
CREATE PROCEDURE public.spaddressinsertupdatedelete(_ser integer, _userid integer, _addrserial integer, _typecode character, _line1 character varying, _line2 character varying, _line3 character varying, _city character varying, _state character varying, _pincode character varying, _country character varying, INOUT _addressid numeric DEFAULT NULL::numeric)
LANGUAGE plpgsql
AS $$
begin
if _ser =1 then
insert into user_address (user_id, addr_serial, addr_type_code, addr_line1, addr_line2, addr_line3,
addr_city, addr_state, addr_pincode,addr_country, addr_datetimecreated)
values (_userid, _addrserial, _typecode, _line1, _line2, _line3, _city, _state, _pincode,
_country, now()) returning addr_id into _addressId;
end if;
if _ser=2 then --Update address
update user_address
set addr_datetill = now()
where user_id=_userid;
insert into user_address (user_id, addr_serial, addr_type_code, addr_line1, addr_line2, addr_line3,
addr_city, addr_state, addr_pincode,addr_country, addr_datetimecreated)
values (_userid, _addrserial, _typecode, _line1, _line2, _line3, _city, _state, _pincode,
_country, now()) returning addr_id into _addressId;
end if;
end
$$;
ALTER PROCEDURE public.spaddressinsertupdatedelete(_ser integer, _userid integer, _addrserial integer, _typecode character, _line1 character varying, _line2 character varying, _line3 character varying, _city character varying, _state character varying, _pincode character varying, _country character varying, INOUT _addressid numeric) OWNER TO postgres;
--
-- TOC entry 261 (class 1255 OID 16834)
-- Name: spcolourinsertupdatedelete(integer, character varying, character varying, integer); Type: PROCEDURE; Schema: public; Owner: postgres
--
CREATE PROCEDURE public.spcolourinsertupdatedelete(_ser integer, _code character varying, _value character varying, _cid integer DEFAULT NULL::integer)
LANGUAGE plpgsql
AS $$
BEGIN
IF _ser =1 THEN --Insert Block
INSERT INTO ref_colour
VALUES(_code, _value);
ELSEIF _ser =2 THEN
UPDATE ref_colour
SET colour_code = _code,
colour_value = _value
WHERE colour_id = _cid;
ELSEIF _ser = 3 THEN --- DELETE
UPDATE ref_colour SET colour_datetill=now()
WHERE colour_id = _cid;
END IF;
END
$$;
ALTER PROCEDURE public.spcolourinsertupdatedelete(_ser integer, _code character varying, _value character varying, _cid integer) OWNER TO postgres;
--
-- TOC entry 280 (class 1255 OID 16861)
-- Name: spcouponinsertupdatedelete(integer, character varying, character varying, integer); Type: PROCEDURE; Schema: public; Owner: postgres
--
CREATE PROCEDURE public.spcouponinsertupdatedelete(_ser integer, _cp_code character varying, _cp_value character varying, INOUT _cp_id integer DEFAULT NULL::integer)
LANGUAGE plpgsql
AS $$
BEGIN
CASE _ser
WHEN 1 THEN --- INSERT
INSERT INTO coupon
(coupon_code, coupon_value)
VALUES (_cp_code , _cp_value );
WHEN 2 THEN --- UPDATE
UPDATE coupon
SET (coupon_code, coupon_value)
=(_cp_code , _cp_value)
WHERE coupon_id = _cp_id;
WHEN 3 THEN --- DELETE
UPDATE coupon
SET coupon_datetill = now()
WHERE coupon_id = _cp_id;
ELSE
RAISE EXCEPTION 'Unexpected Serial Value: %', _ser;
END CASE;
END
$$;
ALTER PROCEDURE public.spcouponinsertupdatedelete(_ser integer, _cp_code character varying, _cp_value character varying, INOUT _cp_id integer) OWNER TO postgres;
--
-- TOC entry 282 (class 1255 OID 33264)
-- Name: spimageinsertupdatedelete(integer, integer, character varying, text, character varying, text, character varying, text, character varying, text, character varying, text, integer, text[]); Type: PROCEDURE; Schema: public; Owner: postgres
--
CREATE PROCEDURE public.spimageinsertupdatedelete(_ser integer, _prodid integer, _name1 character varying DEFAULT NULL::character varying, _img1path text DEFAULT NULL::text, _name2 character varying DEFAULT NULL::character varying, _img2path text DEFAULT NULL::text, _name3 character varying DEFAULT NULL::character varying, _img3path text DEFAULT NULL::text, _name4 character varying DEFAULT NULL::character varying, _img4path text DEFAULT NULL::text, _name5 character varying DEFAULT NULL::character varying, _img5path text DEFAULT NULL::text, _imgid integer DEFAULT NULL::integer, _imgpaths text[] DEFAULT NULL::text[])
LANGUAGE plpgsql
AS $_$
DECLARE
_sql TEXT := 'INSERT INTO product_image (prod_id, prod_img_name, prod_img_path)
VALUES ($2,$3,$4)';
_val text;
BEGIN
IF _ser = 1 THEN -- insert
-- INSERT INTO product_image (prod_id, prod_img_name, prod_img_path)
-- VALUES (_prodid,_name1, _imgpath1),(_prodid, _name2, _imgpath2),(_prodid, _name3, _imgpath3),
-- (_prodid, _name4, _imgpath4),(_prodid, _name5, _imgpath5);
_val = CONCAT (
CASE WHEN _name2 IS NOT NULL THEN ',($2,$5,$6)' END,
CASE WHEN _name3 IS NOT NULL THEN ',($2,$7,$8)' END,
CASE WHEN _name4 IS NOT NULL THEN ',($2,$9,$10)' END,
CASE WHEN _name5 IS NOT NULL THEN ',($2,$11,$12)' END
);
IF _val <> '' THEN
_sql := _sql || _val ||';';
ELSE
_sql := _sql || ';';
END IF;
EXECUTE _sql
USING _ser,_prodid,_name1,_img1path,_name2,_img2path,
_name3, _img3path, _name4, _img4path, _name5, _img5path;
ELSEIF _ser = 2 THEN --update
UPDATE product_image set
prod_img_name = _name1,
prod_img_path = _img1path
where prod_img_id = _imgid;
ELSEIF _ser = 3 THEN --DELETE
DELETE FROM product_image WHERE prod_img_path =ANY(ARRAY[_imgpaths]);
END IF;
END
$_$;
ALTER PROCEDURE public.spimageinsertupdatedelete(_ser integer, _prodid integer, _name1 character varying, _img1path text, _name2 character varying, _img2path text, _name3 character varying, _img3path text, _name4 character varying, _img4path text, _name5 character varying, _img5path text, _imgid integer, _imgpaths text[]) OWNER TO postgres;
--
-- TOC entry 277 (class 1255 OID 16829)
-- Name: spprodsubcateginsertupdatedelete(integer, integer, character varying, text, integer); Type: PROCEDURE; Schema: public; Owner: postgres
--
CREATE PROCEDURE public.spprodsubcateginsertupdatedelete(_ser integer, _pcid integer, _name character varying, _desc text, _psid integer DEFAULT NULL::integer)
LANGUAGE plpgsql
AS $$
BEGIN
IF _ser=1 THEN -- INSERT
INSERT INTO product_sub_category (prod_category_id, prod_name, prod_desc)
VALUES (_pcid, _name, _desc);
ELSEIF _ser=2 THEN --UPDATE
UPDATE product_sub_category SET
prod_category_id = _pcid,
prod_name = _name,
prod_desc = _desc
where prod_subcateg_id = _psid;
ELSEIF _ser=3 THEN --DELETE
IF EXISTS (SELECT 1 FROM product_sub_category a
INNER JOIN product b on a.prod_subcateg_id = b.prod_subcateg_id
WHERE a.prod_subcateg_id = _psid) THEN
BEGIN
RAISE NOTICE 'There are products under this category! Delete them first.';
END;
ELSE
BEGIN
DELETE FROM product_sub_category
WHERE prod_subcateg_id = _psid;
END;
END IF;
END IF;
END
$$;
ALTER PROCEDURE public.spprodsubcateginsertupdatedelete(_ser integer, _pcid integer, _name character varying, _desc text, _psid integer) OWNER TO postgres;
--
-- TOC entry 276 (class 1255 OID 16781)
-- Name: spprodtypeinsertupdatedelete(integer, integer, character varying, text); Type: PROCEDURE; Schema: public; Owner: postgres
--
CREATE PROCEDURE public.spprodtypeinsertupdatedelete(_ser integer, _categoryid integer, _name character varying, _desc text)
LANGUAGE plpgsql
AS $$
BEGIN
IF _ser=1 THEN
INSERT INTO product_sub_category (prod_category_id,prod_name,prod_desc)
VALUES (_categoryid, _name, _desc);
ELSEIF _ser= 2 THEN
UPDATE product_sub_category
SET prod_name=_name,
prod_desc=_desc
WHERE prod_subcateg_id = _subcateg_id;
END IF;
END
$$;
ALTER PROCEDURE public.spprodtypeinsertupdatedelete(_ser integer, _categoryid integer, _name character varying, _desc text) OWNER TO postgres;
--
-- TOC entry 260 (class 1255 OID 16782)
-- Name: spproductcategoryinsertupdatedelete(integer, character varying); Type: PROCEDURE; Schema: public; Owner: postgres
--
CREATE PROCEDURE public.spproductcategoryinsertupdatedelete(_ser integer, _categoryname character varying)
LANGUAGE plpgsql
AS $$
BEGIN
IF _ser =1 THEN
INSERT INTO product_category (prod_category)
VALUES(_categoryName);
END IF;
END
$$;
ALTER PROCEDURE public.spproductcategoryinsertupdatedelete(_ser integer, _categoryname character varying) OWNER TO postgres;
--
-- TOC entry 281 (class 1255 OID 33323)
-- Name: spproductdetails_add(text); Type: PROCEDURE; Schema: public; Owner: postgres
--
CREATE PROCEDURE public.spproductdetails_add(_prod_details text)
LANGUAGE plpgsql
AS $_$
DECLARE
_sql TEXT := 'INSERT INTO product_details (prod_id,prod_inr_price,prod_usd_price,prod_size,prod_colour,prod_qty) VALUES';
BEGIN
if _prod_details is null then
RAISE EXCEPTION 'Product details not added';
END IF;
_sql := _sql || _prod_details;
EXECUTE _sql
USING $1;
END
$_$;
ALTER PROCEDURE public.spproductdetails_add(_prod_details text) OWNER TO postgres;
--
-- TOC entry 285 (class 1255 OID 33369)
-- Name: spproductdetails_delete(integer); Type: PROCEDURE; Schema: public; Owner: postgres
--
CREATE PROCEDURE public.spproductdetails_delete(_pd_id integer)
LANGUAGE plpgsql
AS $$
BEGIN
DELETE
FROM public.product_details
WHERE pd_id = _pd_id;
END
$$;
ALTER PROCEDURE public.spproductdetails_delete(_pd_id integer) OWNER TO postgres;
--
-- TOC entry 307 (class 1255 OID 42116)
-- Name: spproductdetails_price_update(integer, numeric, numeric); Type: PROCEDURE; Schema: public; Owner: postgres
--
CREATE PROCEDURE public.spproductdetails_price_update(_prod_id integer, _inrprice numeric, _usdprice numeric)
LANGUAGE plpgsql
AS $$
BEGIN
UPDATE product_details
SET (prod_inr_price, prod_usd_price)
=(_inrprice , _usdprice)
WHERE prod_id = _prod_id;
END
$$;
ALTER PROCEDURE public.spproductdetails_price_update(_prod_id integer, _inrprice numeric, _usdprice numeric) OWNER TO postgres;
--
-- TOC entry 284 (class 1255 OID 33320)
-- Name: spproductdetails_update(integer, numeric, numeric, integer, integer, integer); Type: PROCEDURE; Schema: public; Owner: postgres
--
CREATE PROCEDURE public.spproductdetails_update(_pd_id integer, _inrprice numeric, _usdprice numeric, _colour integer, _size integer, _qty integer)
LANGUAGE plpgsql
AS $$
BEGIN
UPDATE product_details
SET (prod_inr_price, prod_usd_price, prod_colour, prod_size, prod_qty)
=(_inrprice , _usdprice , _colour , _size , _qty)
WHERE pd_id = _pd_id;
END
$$;
ALTER PROCEDURE public.spproductdetails_update(_pd_id integer, _inrprice numeric, _usdprice numeric, _colour integer, _size integer, _qty integer) OWNER TO postgres;
--
-- TOC entry 304 (class 1255 OID 33873)
-- Name: spproductinsertupdatedelete(integer, integer, character varying, text, boolean, boolean, integer); Type: PROCEDURE; Schema: public; Owner: postgres
--
CREATE PROCEDURE public.spproductinsertupdatedelete(_ser integer, _subcategid integer, _name character varying, _desc text, _latest boolean DEFAULT false, _trending boolean DEFAULT false, INOUT _prod_id integer DEFAULT NULL::integer)
LANGUAGE plpgsql
AS $$
BEGIN
CASE _ser
WHEN 1 THEN -- INSERT
INSERT INTO product
(prod_subcateg_id, prod_name, prod_desc,prod_datetimeinserted)
VALUES (_subcategid, _name, _desc,now() )
RETURNING prod_id
INTO _prod_id;
WHEN 2 THEN -- UPDATE
UPDATE product
SET (prod_subcateg_id,prod_name, prod_desc)
= (_subcategid, _name , _desc)
WHERE prod_id = _prod_id;
WHEN 3 THEN -- soft-DELETE
UPDATE product
SET prod_datetill = now()
WHERE prod_id = _prod_id;
WHEN 4 THEN -- UPDATE latest and trending
UPDATE product
SET (prod_latest, prod_trending)
= (_latest,_trending)
WHERE prod_id = _prod_id;
ELSE
RAISE EXCEPTION 'Unexpected _ser value: %', _ser;
END CASE;
END
$$;
ALTER PROCEDURE public.spproductinsertupdatedelete(_ser integer, _subcategid integer, _name character varying, _desc text, _latest boolean, _trending boolean, INOUT _prod_id integer) OWNER TO postgres;
--
-- TOC entry 298 (class 1255 OID 42105)
-- Name: spresetpassword(character varying, text); Type: PROCEDURE; Schema: public; Owner: postgres
--
CREATE PROCEDURE public.spresetpassword(_email character varying, _pwd text)
LANGUAGE plpgsql
AS $$
BEGIN
UPDATE users SET user_password = _pwd WHERE user_emailaddr = _email;
END
$$;
ALTER PROCEDURE public.spresetpassword(_email character varying, _pwd text) OWNER TO postgres;
--
-- TOC entry 279 (class 1255 OID 16848)
-- Name: spsizeinsertupdatedelete(integer, integer, character varying, character varying, integer); Type: PROCEDURE; Schema: public; Owner: postgres
--
CREATE PROCEDURE public.spsizeinsertupdatedelete(_ser integer, _pcid integer, _code character varying, _value character varying, _sid integer DEFAULT NULL::integer)
LANGUAGE plpgsql
AS $$
BEGIN
CASE _ser
WHEN 1 THEN --- INSERT
INSERT INTO ref_size
(prod_category_id, size_code, size_value)
VALUES(_pcid ,_code , _value);