Fórum alterar o tipo de dado #452308
17/08/2013
0
desde já agradeço...
Adenilson
Curtir tópico
+ 0Posts
17/08/2013
Roniere Almeida
[url]http://postgresql.1045698.n5.nabble.com/Duvida-tipo-de-dados-td2024411.html[/url]
Gostei + 0
20/08/2013
Jair N.
desde já agradeço...
Bom Dia bem a algum tempo atrás fiz esse procedimento
=====================================================================
POSTGRESQL : ALTERANDO A ORDEM DOS CAMPOS...
=====================================================================
CREATE OR REPLACE VIEW vw_cml_campos AS
SELECT pg_type.typname AS tabela
, pg_attribute.attnum AS ordem
, pg_attribute.attname AS campo
, pg_description.description AS descricao
, pg_description_table.description AS descricao_tabela
FROM pg_attribute
INNER JOIN pg_type
ON (pg_type.typrelid = pg_attribute.attrelid)
INNER JOIN pg_namespace
ON (pg_namespace.oid = pg_type.typnamespace)
LEFT JOIN pg_description
ON (pg_description.objoid = pg_attribute.attrelid)
AND (pg_description.objsubid = pg_attribute.attnum)
LEFT JOIN pg_description pg_description_table
ON (pg_description_table.objoid = pg_type.typrelid)
AND (pg_description_table.objsubid = pg_type.typelem)
WHERE (pg_type.typtype = 'c')
AND (pg_attribute.attstattarget = -1)
AND (pg_namespace.nspname = 'public')
ORDER BY pg_type.typname
, pg_attribute.attnum;
-- Selecionando a tabela...
SELECT pg_attribute.attnum
, pg_attribute.attname
FROM pg_attribute
INNER JOIN pg_type
ON (pg_type.typrelid = pg_attribute.attrelid)
WHERE (pg_type.typname = 'cml_aux_tipos') -- nome da tabela para pesquisa
AND (pg_attribute.attstattarget = -1)
-- Alterando o valor...
UPDATE pg_attribute
SET attnum = 5 -- quantidade de posições posteriores
FROM pg_type
WHERE (pg_type.typrelid = pg_attribute.attrelid)
AND (pg_type.typname = 'cml_aux_tipos') -- nome da tabela para pesquisa
AND (pg_attribute.attname = 'int_cod_usuario') -- nome do campo para pesquisa
AND (pg_attribute.attstattarget = -1)
Gostei + 0
05/07/2014
Ronaldo Lanhellas
1- Crie uma nova coluna auxiliar com o novo tipo;
2 - Copie os dados da antiga para a nova
3 - delete a antiga
4 - mude o nome da antiga para nova;
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)