-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path03_db_inmobiliaria_DML_INSERTS_FUNCTIONS.sql
13705 lines (7785 loc) · 412 KB
/
03_db_inmobiliaria_DML_INSERTS_FUNCTIONS.sql
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
/* ----------------------------
* ------ INMOBILIARIA---------
* ----------------------------
*
*
* ========= DML INSERTS FUNCTIONS=============
*/
-- -------------
-- ---Tablas----
-- -------------
-- logs_inserts
drop function if exists listado_logs_inserts() cascade;
-- oficinas
drop function if exists listado_oficinas() cascade;
drop function if exists descripcion_oficinas() cascade;
drop function if exists insertar_registro_oficinas() cascade;
drop function if exists insertar_registros_oficinas() cascade;
-- oficinas_detalles
drop function if exists listado_oficinas_detalles() cascade;
drop function if exists descripcion_oficinas_detalles() cascade;
drop function if exists insertar_registro_oficinas_detalles() cascade;
drop function if exists insertar_registros_oficinas_detalles() cascade;
-- empleados
drop function if exists listado_empleados() cascade;
drop function if exists descripcion_empleados() cascade;
drop function if exists insertar_registro_empleados() cascade;
drop function if exists insertar_registros_empleados() cascade;
-- propietarios_inmuebles
drop function if exists listado_propietarios_inmuebles() cascade;
drop function if exists descripcion_propietarios_inmuebles() cascade;
drop function if exists insertar_registro_propietarios_inmuebles() cascade;
drop function if exists insertar_registros_propietarios_inmuebles() cascade;
-- inmuebles_descripciones
drop function if exists listado_inmuebles_descripciones() cascade;
drop function if exists descripcion_inmuebles_descripciones() cascade;
drop function if exists insertar_registro_inmuebles_descripciones() cascade;
drop function if exists insertar_registros_inmuebles_descripciones() cascade;
-- inmuebles_medidas
drop function if exists listado_inmuebles_medidas() cascade;
drop function if exists descripcion_inmuebles_medidas() cascade;
drop function if exists insertar_registro_inmuebles_medidas() cascade;
drop function if exists insertar_registros_inmuebles_medidas() cascade;
-- inmuebles
drop function if exists listado_inmuebles() cascade;
drop function if exists descripcion_inmuebles() cascade;
drop function if exists insertar_registro_inmuebles() cascade;
drop function if exists insertar_registros_inmuebles() cascade;
-- inmuebles_marketing
drop function if exists listado_inmuebles_marketing() cascade;
drop function if exists descripcion_inmuebles_marketing() cascade;
drop function if exists insertar_registro_inmuebles_marketing() cascade;
drop function if exists insertar_registros_inmuebles_marketing() cascade;
-- inspecciones_inmuebles
drop function if exists listado_inspecciones_inmuebles() cascade;
drop function if exists descripcion_inspecciones_inmuebles() cascade;
drop function if exists insertar_registro_inspecciones_inmuebles() cascade;
drop function if exists insertar_registros_inspecciones_inmuebles() cascade;
-- citas_inmuebles
drop function if exists listado_citas_inmuebles() cascade;
drop function if exists descripcion_citas_inmuebles() cascade;
drop function if exists insertar_registro_citas_inmuebles() cascade;
drop function if exists insertar_registros_citas_inmuebles() cascade;
-- gerentes
drop function if exists listado_gerentes() cascade;
drop function if exists descripcion_gerentes() cascade;
drop function if exists insertar_registro_gerentes() cascade;
drop function if exists insertar_registros_gerentes() cascade;
-- administradores
drop function if exists listado_administradores() cascade;
drop function if exists descripcion_administradores() cascade;
drop function if exists insertar_registro_administradores() cascade;
drop function if exists insertar_registros_administradores() cascade;
-- vendedores
drop function if exists listado_vendedores() cascade;
drop function if exists descripcion_vendedores() cascade;
drop function if exists insertar_registro_vendedores() cascade;
drop function if exists insertar_registros_vendedores() cascade;
-- ventas
drop function if exists listado_ventas() cascade;
drop function if exists descripcion_ventas() cascade;
drop function if exists insertar_registro_ventas() cascade;
drop function if exists insertar_registros_ventas() cascade;
-- compradores
drop function if exists listado_compradores() cascade;
drop function if exists descripcion_compradores() cascade;
drop function if exists insertar_registro_compradores() cascade;
drop function if exists insertar_registros_compradores() cascade;
-- facturas
drop function if exists listado_facturas() cascade;
drop function if exists descripcion_facturas() cascade;
drop function if exists insertar_registro_facturas() cascade;
drop function if exists insertar_registros_facturas() cascade;
-- facturas_detalles
drop function if exists listado_facturas_detalles() cascade;
drop function if exists descripcion_facturas_detalles() cascade;
drop function if exists insertar_registro_facturas_detalles() cascade;
drop function if exists insertar_registros_facturas_detalles() cascade;
-- ---------------------------------------------------------------------------
-- ---------------------------------------------------------------------------
-- =================================
-- ======= TABLA OFICINAS ===========
-- ==================================
select * from oficinas;
select column_name, data_type, is_nullable from
information_schema.columns where table_name = 'oficinas';
-- =======================================================================
-- ----------- SELECT DE TODOS LOS REGISTROS DE LA TABLA OFICINAS -------
-- =======================================================================
drop function if exists listado_oficinas();
create or replace function listado_oficinas() returns setof oficinas as $$
declare
registro_actual_oficinas RECORD;
begin
for registro_actual_oficinas in (select * from oficinas) loop
return next registro_actual_oficinas;-- Por cada iteracion se guarda el registro completo
end loop;
return;
end;
$$ language plpgsql;
-- -----------------------------------------------------------------------------
-- --------------------------------------------------------------------------------
-- ===========================================================
-- ----------- SELECT DESCRIPCION DE LA TABLA OFICINAS -------
-- ===========================================================
create or replace function descripcion_oficinas(out campo varchar, out tip_dato varchar, out nuleable varchar)
returns setof RECORD as $$
declare
registro_actual RECORD;
begin
for registro_actual in (select column_name, data_type, is_nullable from
information_schema.columns where table_name = 'oficinas') loop
campo := registro_actual.column_name;
tip_dato := registro_actual.data_type;
nuleable := registro_actual.is_nullable;
return next;-- Por cada iteracion se guarda el registro completo
end loop;
return;
end;
$$ language plpgsql;
-- -----------------------------------------------------------------------------
-- --------------------------------------------------------------------------------
-- =======================================================================
-- ----------- SELECT DE TODOS LOS REGISTROS DE LA TABLA LOGS_INSERTS -------
-- =======================================================================
create or replace function listado_logs_inserts() returns setof logs_inserts as $$
declare
registro_actual_logs_inserts RECORD;
begin
for registro_actual_logs_inserts in (select * from logs_inserts) loop
return next registro_actual_logs_inserts;-- Por cada iteracion se guarda el registro completo
end loop;
return;
end;
$$ language plpgsql;
-- --------------------------------------------------------------------------------
-- ---------------------------------------------------------------------------------
/*
-- =======================================================================
-- ----------- SELECT DE ALGUNOS REGISTROS DE LA TABLA OFICINAS -------
-- =======================================================================
create or replace function listado_oficinas( out id int, out nombre varchar , out direccion varchar, out nro_telefono varchar
, out email varchar) returns setof RECORD as $$
declare
registro_actual RECORD;
begin
for registro_actual in (select * from oficinas) loop
id := registro_actual.id;
nombre := registro_actual.nombre;
direccion := registro_actual.direccion;
nro_telefono := registro_actual.nro_telefono;
email := registro_actual.email;
return next;-- Por cada iteracion se guarda el registro completo
end loop;
return;
end;
$$ language plpgsql;
*/
-- ---------------------------------------------------------------------
-- --------------------------------------------------------------------
-- =======================================================================
-- ----------- INSERCION DE 1 REGISTRO TABLA OFICINAS ------------
-- =======================================================================
select listado_oficinas();
create or replace function insertar_registro_oficinas(
nombre_input varchar, dir_input varchar, nro_tel_input varchar, email_input varchar
) returns void as $$
declare
-- TABLA OFICINAS
-- Comprobamos que exista un id y cual es el ultimo
id_last_of_check boolean;
id_last_of int;
-- Nos aseguramos que no exista un registro repetido ademas del check de la db
nombre_of_check boolean := exists(select nombre from oficinas where nombre = nombre_input);
direccion_of_check boolean := exists(select direccion from oficinas where direccion = dir_input);
-- TABLA LOGS_INSERTS
uuid_registro_of uuid;
nombre_tabla_of varchar := 'oficinas';
accion_of varchar := 'insert';
fecha_of date ;
hora_of time ;
usuario_of varchar;
usuario_sesion_of varchar;
db_of varchar;
db_version_of varchar;
begin
if(
(nombre_of_check = true) or (direccion_of_check = true)
) then
raise exception '===== NO SE PUEDE INGRESAR UN REGISTRO REPETIDO ===== '
using hint= '------- REVISAR NOMBRE Y DIRECCION DE LA OFICINA -------';
elsif (
((nombre_of_check = false) and (direccion_of_check = false))
and (nombre_input <> '')
and (dir_input <> '')
and (nro_tel_input <> '')
and (email_input <> '')
) then
raise notice '';
raise notice '----------------------------------------------';
raise notice '-- Inserción de Registro Tabla "oficinas" --';
raise notice '----------------------------------------------';
--------------------------------------- INSERCION REGISTRO ----------------------------------------
insert into oficinas(nombre, direccion, nro_telefono, email) values
(nombre_input , dir_input , nro_tel_input , email_input);
--------------------------------------- FIN INSERCION REGISTRO ----------------------------------------
--------------------------------------- ÚLTIMO ID ----------------------------------------
id_last_of_check := exists(select id from oficinas);
-- Comprobacion id
if (id_last_of_check = true) then
id_last_of := (select max(id) from oficinas);
else
id_last_of := 0;
end if;
--------------------------------------- FIN ÚLTIMO ID ----------------------------------------
raise notice '';
raise notice '';
raise notice '-- Registro de Inserción --';
raise notice '';
raise notice 'ID : %' , id_last_of;
raise notice 'Nombre : %', nombre_input;
raise notice 'Dirección : %', dir_input;
raise notice 'Nro Telefono : %', nro_tel_input;
raise notice 'Email : %', email_input;
raise notice ' ';
raise notice 'ok!';
raise notice ' ';
raise notice '';
raise notice '----------------------------------------------';
raise notice '-- Inserción de Registro Tabla "logs_inserts" --';
raise notice '----------------------------------------------';
--------------------------------------- INSERCION REGISTRO ----------------------------------------
insert into logs_inserts(id_registro, nombre_tabla , accion) values
(id_last_of , nombre_tabla_of, accion_of);
--------------------------------------- FIN INSERCION REGISTRO ----------------------------------------
-- Traemos los valores del Registro Insertado
uuid_registro_of := (select uuid_registro from logs_inserts
where (id_registro = id_last_of) and (nombre_tabla = 'oficinas'));
fecha_of := (select fecha from logs_inserts
where (id_registro = id_last_of) and (nombre_tabla = 'oficinas'));
hora_of := (select hora from logs_inserts
where (id_registro = id_last_of) and (nombre_tabla = 'oficinas'));
usuario_of := (select usuario from logs_inserts
where (id_registro = id_last_of) and (nombre_tabla = 'oficinas'));
usuario_sesion_of := (select usuario_sesion from logs_inserts
where (id_registro = id_last_of) and (nombre_tabla = 'oficinas'));
db_of := (select db from logs_inserts
where (id_registro = id_last_of) and (nombre_tabla = 'oficinas'));
db_version_of := (select db_version from logs_inserts
where (id_registro = id_last_of) and (nombre_tabla = 'oficinas'));
raise notice '';
raise notice '';
raise notice '-- Registro de Inserción --';
raise notice '';
raise notice 'ID Registro: %' , id_last_of;
raise notice 'UUID Registro : %', uuid_registro_of;
raise notice 'Tabla : %', nombre_tabla_of;
raise notice 'Acción : %', accion_of;
raise notice 'Fecha : %', fecha_of;
raise notice 'Hora : %', hora_of;
raise notice 'Usuario : %', usuario_of;
raise notice 'Sesión de Usuario : %', usuario_sesion_of;
raise notice 'DB : %', db_of;
raise notice 'Versión DB : %', db_version_of;
raise notice ' ';
raise notice 'ok!';
raise notice ' ';
else
raise exception '===== SE DEBEN AGREGAR TODOS LOS VALORES DEL REGISTRO PARA LA FUNCIÓN insertar_registro_oficinas() ====='
using hint = '------- insertar_registros_oficinas(nombre varchar, direccion varchar, nro_telefono varchar, email varchar); ------- ';
end if;
end;
$$ language plpgsql;
-- ----------------------------------------------------------------------------
-- --------------------------------------------------------------------------
-- =======================================================================
-- ----------- INSERCION DE 2 REGISTROS TABLA OFICINAS ------------
-- =======================================================================
create or replace function insertar_registros_oficinas(
nombre_input_01 varchar, dir_input_01 varchar, nro_tel_input_01 varchar, email_input_01 varchar
,nombre_input_02 varchar, dir_input_02 varchar, nro_tel_input_02 varchar, email_input_02 varchar
) returns void as $$
declare
-- TABLA OFICINAS
-- Comprobamos que exista un id y cual es el ultimo
id_last_of_check boolean;
id_last_of int;
-- Nos aseguramos que no se inserten registros repetidos en la db ademas del check de la db
nombre_of_check_01 boolean := exists(select nombre from oficinas where nombre = nombre_input_01);
nombre_of_check_02 boolean := exists(select nombre from oficinas where nombre = nombre_input_02);
direccion_of_check_01 boolean := exists(select direccion from oficinas where direccion = dir_input_01);
direccion_of_check_02 boolean := exists(select direccion from oficinas where direccion = dir_input_02);
-- TABLA LOGS_INSERTS
uuid_registro_of uuid;
nombre_tabla_of varchar := 'oficinas';
accion_of varchar := 'insert';
fecha_of date ;
hora_of time ;
usuario_of varchar;
usuario_sesion_of varchar;
db_of varchar;
db_version_of varchar;
begin
if(
((nombre_of_check_01 = true) and (direccion_of_check_01 = true))
or
((nombre_of_check_02 = true) and (direccion_of_check_02 = true))
or
(dir_input_01 = dir_input_02)
) then
raise exception '===== NO SE PUEDE INGRESAR UN REGISTRO REPETIDO ===== '
using hint= '------- REVISAR NOMBRES Y DIRECCIONES DE LA OFICINA -------';
elsif (
(direccion_of_check_01 = false) and (direccion_of_check_02 = false)
and
((nombre_input_01 <> '') and (dir_input_01 <> '') and (nro_tel_input_01 <> '') and (email_input_01 <> ''))
and
((nombre_input_02 <> '') and (dir_input_02 <> '') and (nro_tel_input_02 <> '') and (email_input_02 <> ''))
) then
-- ================================================================
-- ===================== PRIMER REGISTRO =========================
-- ================================================================
-- -------------------------------------------------------------------------------------
-- ------------------------- TABLA OFICINAS 1ER REGISTRO -------------------------------
raise notice '';
raise notice '----------------------------------------------';
raise notice '-- Inserción de 2 Registros Tabla "oficinas" --';
raise notice '----------------------------------------------';
--------------------------------------- INSERCION 1ER REGISTRO ----------------------------------------
insert into oficinas (nombre, direccion, nro_telefono, email) values
(nombre_input_01 , dir_input_01 , nro_tel_input_01 , email_input_01);
--------------------------------------- FIN INSERCION 1ER REGISTRO ----------------------------------------
--------------------------------------- ÚLTIMO ID ----------------------------------------
id_last_of_check := exists(select id from oficinas);
-- Comprobacion id
if (id_last_of_check = true) then
id_last_of := (select max(id) from oficinas);
else
id_last_of := 0;
end if;
--------------------------------------- FIN ÚLTIMO ID ----------------------------------------
raise notice '';
raise notice '';
raise notice '-- Registro de Inserción Tabla "oficinas" Número 1--';
raise notice '';
raise notice 'Id : %', id_last_of;
raise notice 'Nombre : %', nombre_input_01;
raise notice 'Dirección : %', dir_input_01;
raise notice 'Nro Telefono : %', nro_tel_input_01;
raise notice 'Email : %', email_input_01;
raise notice ' ';
raise notice 'ok!';
raise notice ' ';
-- ------------------------- FIN TABLA OFICINAS 1ER REGISTRO -------------------------------
-- -------------------------------------------------------------------------------------
-- -------------------------------------------------------------------------------------
-- ------------------------- TABLA LOGS_INSERTS 1ER REGISTRO -------------------------------
raise notice '';
raise notice '----------------------------------------------';
raise notice '-- Inserción 1er Registro Tabla "logs_inserts" --';
raise notice '----------------------------------------------';
insert into logs_inserts(id_registro, nombre_tabla , accion) values
(id_last_of , nombre_tabla_of, accion_of);
--------------------------------------- FIN INSERCION REGISTRO ----------------------------------------
-- Traemos los valores del Registro Insertado
uuid_registro_of := (select uuid_registro from logs_inserts
where (id_registro = id_last_of) and (nombre_tabla = 'oficinas'));
fecha_of := (select fecha from logs_inserts
where (id_registro = id_last_of) and (nombre_tabla = 'oficinas'));
hora_of := (select hora from logs_inserts
where (id_registro = id_last_of) and (nombre_tabla = 'oficinas'));
usuario_of := (select usuario from logs_inserts
where (id_registro = id_last_of) and (nombre_tabla = 'oficinas'));
usuario_sesion_of := (select usuario_sesion from logs_inserts
where (id_registro = id_last_of) and (nombre_tabla = 'oficinas'));
db_of := (select db from logs_inserts
where (id_registro = id_last_of) and (nombre_tabla = 'oficinas'));
db_version_of := (select db_version from logs_inserts
where (id_registro = id_last_of) and (nombre_tabla = 'oficinas'));
raise notice '';
raise notice '';
raise notice '-- Registro de Inserción --';
raise notice '';
raise notice 'ID Registro: %' , id_last_of;
raise notice 'UUID Registro : %', uuid_registro_of;
raise notice 'Tabla : %', nombre_tabla_of;
raise notice 'Acción : %', accion_of;
raise notice 'Fecha : %', fecha_of;
raise notice 'Hora : %', hora_of;
raise notice 'Usuario : %', usuario_of;
raise notice 'Sesión de Usuario : %', usuario_sesion_of;
raise notice 'DB : %', db_of;
raise notice 'Versión DB : %', db_version_of;
raise notice ' ';
raise notice 'ok!';
raise notice ' ';
-- ------------------------- FIN TABLA LOGS_INSERTS 1ER REGISTRO -------------------------------
-- -------------------------------------------------------------------------------------
-- ----------------------------------------------------------------
-- --------------------- SEGUNDO REGISTRO -------------------------
-- ----------------------------------------------------------------
-- -------------------------------------------------------------------------------------
-- ------------------------- TABLA OFICINAS 2DO REGISTRO -------------------------------
--------------------------------------- INSERCION 2DO REGISTRO ----------------------------------------
insert into oficinas (nombre, direccion, nro_telefono, email) values
(nombre_input_02 , dir_input_02 , nro_tel_input_02 , email_input_02);
--------------------------------------- FIN INSERCION 2DO REGISTRO ----------------------------------------
--------------------------------------- ÚLTIMO ID ----------------------------------------
id_last_of_check := exists(select id from oficinas);
-- Comprobacion id
if (id_last_of_check = true) then
id_last_of := (select max(id) from oficinas);
else
id_last_of := 0;
end if;
--------------------------------------- FIN ÚLTIMO ID ----------------------------------------
raise notice '';
raise notice '';
raise notice '-- Registro de Inserción Tabla "oficinas" Número 2--';
raise notice '';
raise notice 'Id: %', id_last_of;
raise notice 'Nombre : %', nombre_input_02;
raise notice 'Dirección : %', dir_input_02;
raise notice 'Nro Telefono : %', nro_tel_input_02;
raise notice 'Email : %', email_input_02;
raise notice ' ';
raise notice 'ok!';
raise notice ' ';
-- -------------------------------------------------------------------------------------
-- ------------------------- FIN TABLA OFICINAS 2DO REGISTRO -------------------------------
-- -------------------------------------------------------------------------------------
-- -------------------------------------------------------------------------------------
-- ------------------------- TABLA LOGS_INSERTS 2DO REGISTRO -------------------------------
-- -------------------------------------------------------------------------------------
raise notice '';
raise notice '----------------------------------------------';
raise notice '-- Inserción 2do Registro Tabla "logs_inserts" --';
raise notice '----------------------------------------------';
-- ------------------------------------- INSERCION REGISTRO ----------------------------------------
insert into logs_inserts(id_registro, nombre_tabla , accion) values
(id_last_of , nombre_tabla_of, accion_of);
-- ------------------------------------- FIN INSERCION REGISTRO ----------------------------------------
-- Traemos los valores del Registro Insertado
uuid_registro_of := (select uuid_registro from logs_inserts
where (id_registro = id_last_of) and (nombre_tabla = 'oficinas'));
fecha_of := (select fecha from logs_inserts
where (id_registro = id_last_of) and (nombre_tabla = 'oficinas'));
hora_of := (select hora from logs_inserts
where (id_registro = id_last_of) and (nombre_tabla = 'oficinas'));
usuario_of := (select usuario from logs_inserts
where (id_registro = id_last_of) and (nombre_tabla = 'oficinas'));
usuario_sesion_of := (select usuario_sesion from logs_inserts
where (id_registro = id_last_of) and (nombre_tabla = 'oficinas'));
db_of := (select db from logs_inserts
where (id_registro = id_last_of) and (nombre_tabla = 'oficinas'));
db_version_of := (select db_version from logs_inserts
where (id_registro = id_last_of) and (nombre_tabla = 'oficinas'));
raise notice '';
raise notice '';
raise notice '-- Registro de Inserción --';
raise notice '';
raise notice 'ID Registro: %' , id_last_of;
raise notice 'UUID Registro : %', uuid_registro_of;
raise notice 'Tabla : %', nombre_tabla_of;
raise notice 'Acción : %', accion_of;
raise notice 'Fecha : %', fecha_of;
raise notice 'Hora : %', hora_of;
raise notice 'Usuario : %', usuario_of;
raise notice 'Sesión de Usuario : %', usuario_sesion_of;
raise notice 'DB : %', db_of;
raise notice 'Versión DB : %', db_version_of;
raise notice ' ';
raise notice 'ok!';
raise notice ' ';
-- ------------------------- FIN TABLA LOGS_INSERTS 2DO REGISTRO -------------------------------
-- -------------------------------------------------------------------------------------
else
raise exception '====== SE DEBEN AGREGAR TODOS LOS VALORES DE LOS REGISTRO PARA LA FUNCIÓN insertar_registros_oficinas() ======'
using hint = '------ insertar_registros_oficinas(nombre_01 varchar, direccion_01 varchar, nro_telefono_01 varchar, email_01 varchar,nombre_02 varchar, direccion_02 varchar, nro_telefono_02 varchar, email_02 varchar); -------- ';
end if;
end;
$$ language plpgsql;
-- ----------------------------------------------------------------------------
-- -----------------------------------------------------------------------------
-- ---------------------------------------------------------------------------
-- ---------------------------------------------------------------------------
-- ================================================
-- ======= TABLA OFICINAS_DETALLES ===========
-- ================================================
select * from oficinas_detalles;
select column_name, data_type, is_nullable from
information_schema.columns where table_name = 'oficinas_detalles';
-- =================================================================================
-- ----------- SELECT DE TODOS LOS REGISTROS DE LA TABLA OFICINAS_DETALLES -------
-- ==================================================================================
create or replace function listado_oficinas_detalles() returns setof oficinas_detalles as $$
declare
registro_actual_of_det RECORD;
begin
for registro_actual_of_det in (select * from oficinas_detalles) loop
return next registro_actual_of_det;
end loop;
return;
end;
$$ language plpgsql;
-- -----------------------------------------------------------------------------
-- --------------------------------------------------------------------------------
-- ====================================================================
-- ----------- SELECT DESCRIPCION DE LA TABLA OFICINAS_DETALLES -------
-- ====================================================================
create or replace function descripcion_oficinas_detalles(out campo varchar, out tip_dato varchar, out nuleable varchar)
returns setof RECORD as $$
declare
registro_actual RECORD;
begin
for registro_actual in (select column_name, data_type, is_nullable from
information_schema.columns where table_name = 'oficinas_detalles') loop
campo := registro_actual.column_name;
tip_dato := registro_actual.data_type;
nuleable := registro_actual.is_nullable;
return next;
end loop;
return;
end;
$$ language plpgsql;
-- -----------------------------------------------------------------------------
-- -----------------------------------------------------------------------------
-- -----------------------------------------------------------------------------
-- -----------------------------------------------------------------------------
-- =======================================================================
-- ----------- INSERCION DE 1 REGISTRO TABLA OFICINAS_DETALLES ------------
-- =======================================================================
select listado_oficinas_detalles();
select descripcion_oficinas_detalles();
create or replace function insertar_registros_oficinas_detalles(
id_of_input int, loc_input varchar, tipo_of_input tipo_oficina_enum
, estado_of_input estado_oficina_enum, sup_total_input decimal
, cant_amb_input int , cant_sanit_input int , antig_input int
, sitio_web_input varchar
) returns void as $$
declare
-- TABLA oficinas_detalles
-- Comprobamos que exista un id y cual es el ultimo
id_last_of_det_check boolean;
id_last_of_det int;
-- Nos aseguramos que no exista un registro repetido ademas del check de la db
-- Comprobamos Localidad, Tipo de Oficina y Superficie Total
loc_tipo_sup_total_of_det_check boolean := exists(
select localidad, tipo_oficina , superficie_total from oficinas_detalles
where ((localidad = loc_input) and (tipo_oficina = tipo_of_input) and
(superficie_total = sup_total_input)));
-- TABLA LOGS_INSERTS
uuid_registro_of_det uuid;
nombre_tabla_of_det varchar := 'oficinas_detalles';
accion_of_det varchar := 'insert';
fecha_of_det date ;
hora_of_det time ;
usuario_of_det varchar;