Re: Problemas para realizar update

From: Jaime Casanova <jaime(at)2ndquadrant(dot)com>
To: Paola Alejandra de Montserrat Cordero Bon <paola(dot)cordero(dot)b(at)gmail(dot)com>
Cc: POSTGRES <pgsql-es-ayuda(at)postgresql(dot)org>
Subject: Re: Problemas para realizar update
Date: 2015-06-30 02:56:34
Message-ID: CAJKUy5gMuoXA0dQGyzrGS5y3EDHw=VCmxkcWa+1OZ-bQf-ndOg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

2015-06-29 17:58 GMT-05:00 Paola Alejandra de Montserrat Cordero Bon
<paola(dot)cordero(dot)b(at)gmail(dot)com>:
> Buenas noches comunidad, les pido ayuda sobre una operación de
> actualización. Tengo dos tablas, tabla 1, tabla 2, tienen en común varias
> variables, quedando fuera cuatro que estan en la segunda tabla (tabla 2).
> Hice una tercera tabla, tabla 3, donde le cargue la información completa de
> la tabla 1, quedando pendiente actualizar con las variables no comunes de la
> tabla 2.
>
> Use los siguientes comandos:
>
> Para insertar los datos en común: insert into tabla_3 (variable1, ...
> variable_n) select variable1, ... variable_n from tabla_1 TODO Bien acá...
>
> Para actualizar estos usando el siguiente comando: update tabla_3 set
> (variable1, variable2, variable3, variable4) = (variable1, variable2,
> variable3, variable4 from tabla_2 where tabla_2.variable1 =
> tabla_3.variable1)
>

UPDATE tabla_3
SET variable_1 = tabla_2.variable_1,
variable_2 = tabla_2.variable_2,
...
variable_n = tabla_2.variable_n
FROM tabla_2
WHERE tabla_2.variable_1 = tabla_3.variable_1;

fijate en el FROM, aunque lo que quieres hacer debería ser lo
correcto postgres aun no lo implementa y por eso existe la posibilidad
*NO* estandar de usar la clausula FROM en el UPDATE.

en la versión 9.5 me parece que se podrá hacer como se debería.

--
Jaime Casanova www.2ndQuadrant.com
Professional PostgreSQL: Soporte 24x7 y capacitación

-
Enviado a la lista de correo pgsql-es-ayuda (pgsql-es-ayuda(at)postgresql(dot)org)
Para cambiar tu suscripcin:
http://www.postgresql.org/mailpref/pgsql-es-ayuda

In response to

Responses

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Kernel 2015-06-30 15:39:06 Re: pg_dump del servidor esclavo
Previous Message Paola Alejandra de Montserrat Cordero Bon 2015-06-29 22:58:46 Problemas para realizar update