2009/6/23 Rubens José Rodrigues <[email protected]>

>  Opa salve galera!
>
>
>
> Deparei-me com uma dúvida, estamos adaptando mais um módulo (que funciona
> em Oracle) no PostgreSQL e tentei sem sucesso o uso de aliases em comandos
> update, relendo a documentação vi que é possivel, mas na prática devo estar
> errando em algo, será que podem me ajudar?
>
>
>
> Cenário:
>
> PostgreSQL 8.3.7 on x86_64-pc-linux-gnu, compiled by GCC gcc-4.3.real
> (Ubuntu 4.3.2-1ubuntu11) 4.3.2
>
>
>
> Base > 1T em UTF8.
>
>
>
>
>
> Manual 8.3 [1]
>
> UPDATE -- update rows of a table
>
> *Synopsis*
>
> UPDATE [ ONLY ] *table* [ [ AS ] *alias* ]
>
>     SET { *column* = { *expression* | DEFAULT } |
>
>           ( *column* [, ...] ) = ( { *expression* | DEFAULT } [, ...] ) }
> [, ...]
>
>     [ FROM *fromlist* ]
>
>     [ WHERE *condition* | WHERE CURRENT OF *cursor_name* ]
>
>     [ RETURNING * | *output_expression* [ AS *output_name* ] [, ...] ]
>
> *Parameters*
>
> *Table*
>
> The name (optionally schema-qualified) of the table to update.
>
> * *
>
> *Alias*
>
> A substitute name for the target table. When an alias is provided, it
> completely hides the actual name of the table. For example, given UPDATE foo
> AS f, the remainder of the UPDATEstatement must refer to this table
> as f not foo.
>
>
>
>
>
> *Tentativa:*
>
> * *
>
> *Update foo a set a.coluna = (select count(1) from outratabela where
> codfoo=a.codfoo);*
>

Faz assim:

*update foo set coluna = outratabela.coluna from outratabela where *outratabela.
*codfoo=foo.codfoo


*

[],

-- 
Marcelo Costa
www.marcelocosta.net
-------------------------------------------------
“Os muito poderosos e os muito estúpidos possuem uma coisa em comum. Ao
invés de alterarem as suas visões para se ajustarem aos fatos do mundo, eles
alteram os fatos para ajustá-los às suas visões.”,

Doctor Who.
_______________________________________________
pgbr-geral mailing list
[email protected]
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral

Responder a