aleatorio acotado en postgres

From: Jose Mercedes Venegas Acevedo <jvenegasperu(at)gmail(dot)com>
To: Ayuda <pgsql-es-ayuda(at)postgresql(dot)org>
Subject: aleatorio acotado en postgres
Date: 2012-12-06 19:49:20
Message-ID: CA+KjtGeYn4+uf-owstyMb=b7JHV356+6wsw2+4h2z1pU3UvXpw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

buen dia a todos tengo este inconveniente en mi sistema estoy haciendo
varias operaciones dentro del begin commit

lo que estoy haciendo es generando grafico de sectores y los pinto con un
color aleatorio
como ven en la linea 2 al final debo introducir el campo color que debe
tener esta forma
ejemplo:
190 200 150
como se ve en la linea 3 hago esto enviando 3 variables de php $r $g $b con
espacios sin embargo dependiendo de las lineas 2 y 3

en la las lineas 6 y 7 debo volver a poner un color sin embargo aqui ya no
es un registro sino n registros asi que debo colocar un numero aleatorio
para pintar de diferentes colores cada registro
sin embargo debo asegurarme que los 3 numeros ingresados con espacios esten
entre 0 y 255 que son los valores validos para rgb alguien puede darme una
idea como podria hacer esto?

1 $query = 'BEGIN; ';

2 $query .= 'insert into maestro_distribucion
(usuario,fh_inicio,fh_fin,estado,glosa,fecha_inicio,fecha_fin,hora_ini,hora_fin,the_geom,color
) ';
3 $query .= "values
('$usuario','$fh_ini','$fh_fin',3,'$red','$fechaIni','$fechaFin','$horaIni','$horaFin',st_geomfromtext('SRID=32717;POLYGON((".$coords."))'),'$r
$g $b');";

4 $query .= 'insert into detalle_distribucion
(id_mdistribucion,id_suministro,the_geom) ';
5 $query .= "select currval('maestro_distribucion_id_seq'),l.id,l.the_geom
from cat_lote l where
st_contains(st_geomfromtext('SRID=32717;POLYGON((".$coords."))'),l.the_geom);
";

6 $query .= 'INSERT INTO maestro_distribucion
(usuario,fh_inicio,fh_fin,the_geom,estado,glosa,fecha_inicio,fecha_fin,hora_ini,hora_fin,anio,color)
';
7 $query .= 'select
m2.usuario,m2.fh_inicio,m2.fh_fin,ST_Difference(m2.the_geom,m1.the_geom),2,m2.glosa,m2.fecha_inicio,m2.fecha_fin,m2.hora_ini,m2.hora_fin,m2.anio
';
8 $query .= 'from maestro_distribucion m1,maestro_distribucion m2 ';
9 $query .= "where st_intersects(m1.the_geom,m2.the_geom) and m1.estado =
3 and m2.estado != 3;";

10 $query .= 'insert into detalle_distribucion
(id_mdistribucion,id_suministro) ';
11 $query .= 'select m.id,l.id from cat_lote l,maestro_distribucion m where
st_contains(m.the_geom,l.the_geom) and m.estado = 2; ';

12 $query .= 'update maestro_distribucion set estado = 0 ';
13 $query .= 'FROM (SELECT m2.id FROM maestro_distribucion
m1,maestro_distribucion m2 ';
14 $query .= 'WHERE m1.estado = 2 and m2.estado = 1 and
st_contains(m2.the_geom,m1.the_geom)) as bb ';
15 $query .= 'WHERE bb.id = maestro_distribucion.id; ';

16 $query .= 'update maestro_distribucion set estado = 1 where estado = 2
or estado = 3; ';

17 $query .= "COMMIT;";

--
José Mercedes Venegas Acevedo
cel: Mov. 949808846

mails: jvenegasperu(at)php(dot)net
jvenegasperu(at)gmail(dot)com

PHP Spanish Docs translator member.
http://www.php.net/manual/es/index.php

Responses

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Guillermo E. Villanueva 2012-12-07 00:09:05 error humano gravísimo
Previous Message Frank 2012-12-06 16:07:45 Re: aleatorio acotado en postgres