0

to tentando fazer essa query para "embaralhar" os dados da tabela. Essa mesma query funcionou no mysql, porém não to conseguindo no postgresql.

sempre recebo esse erro [Code: 0, SQL State: 42712] ERROR: table name "mytableteste" specified more than once

   UPDATE mytableteste set
  desc_nome = desc_nome.newValue,
  numr_cpf = numr_cpf.newValue,
  data_nascimento = data_nascimento.newValue,
  desc_mae = desc_mae.newValue from mytableteste
                                
  INNER JOIN (
  SELECT ROW_NUMBER() OVER (ORDER BY numg_iddoobjeto) AS rn, numg_iddoobjeto from mytableteste
) AS PKrows ON mytableteste.numg_iddoobjeto = PKrows.numg_iddoobjeto
-- repeat the following JOIN for each column you want to randomize
INNER JOIN (
  SELECT ROW_NUMBER() OVER (ORDER BY random()) AS rn, desc_nome AS newValue  from mytableteste
) AS desc_nome ON PKrows.rn = desc_nome.rn
INNER JOIN (
  SELECT ROW_NUMBER() OVER (ORDER BY random()) AS rn, numr_cpf AS newValue  from mytableteste
) AS numr_cpf ON PKrows.rn = numr_cpf.rn
INNER JOIN (
  SELECT ROW_NUMBER() OVER (ORDER BY random()) AS rn, data_nascimento AS newValue  from mytableteste
) AS data_nascimento ON PKrows.rn = data_nascimento.rn
INNER JOIN (
  SELECT ROW_NUMBER() OVER (ORDER BY random()) AS rn, desc_mae AS newValue  from mytableteste
) AS desc_mae ON PKrows.rn = desc_mae.rn

1 Resposta 1

-1

Consegui arrumar aqui

with subquery as ( select * from mytableteste

INNER JOIN ( SELECT ROW_NUMBER() OVER (ORDER BY numg_iddoobjeto) AS rn, numg_iddoobjeto as numg_iddoobjetoC from mytableteste ) AS PKrows ON mytableteste.numg_iddoobjeto = PKrows.numg_iddoobjetoC -- repeat the following JOIN for each column you want to randomize INNER JOIN ( SELECT ROW_NUMBER() OVER (ORDER BY random()) AS rn, desc_nome AS newValueNome from mytableteste ) AS desc_nome ON PKrows.rn = desc_nome.rn INNER JOIN ( SELECT ROW_NUMBER() OVER (ORDER BY random()) AS rn, numr_cpf AS newValueCPF from mytableteste ) AS numr_cpf ON PKrows.rn = numr_cpf.rn INNER JOIN ( SELECT ROW_NUMBER() OVER (ORDER BY random()) AS rn, data_nascimento AS newValueData_Nascimento from mytableteste ) AS data_nascimento ON PKrows.rn = data_nascimento.rn INNER JOIN ( SELECT ROW_NUMBER() OVER (ORDER BY random()) AS rn, desc_mae AS newValueDesc_mae from mytableteste ) AS desc_mae ON PKrows.rn = desc_mae.rn ) UPDATE mytableteste set desc_nome = subquery.newValuenome, numr_cpf = subquery.newValuecpf, data_nascimento = subquery.newValuedata_nascimento, desc_mae = subquery.newValuedesc_mae from subquery where mytableteste.numg_iddoobjeto = subquery.numg_iddoobjetoc

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .