Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

229
Visualizações
Don't copy all rows in postgres

I want to copy some data from a table to another but I dont want to copy all the rows, just a few a them (like only the first 100).

I didn't find an option in the COPY command for this. So that's only possible or not ? Thank you in advance.

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

You didn't look very hard.

https://www.postgresql.org/docs/current/static/sql-copy.html

To copy into a file just the countries whose names start with 'A':

COPY (SELECT * FROM country WHERE country_name LIKE 'A%') TO '/usr1/proj/bray/sql/a_list_countries.copy';

So you would want COPY (SELECT ... LIMIT 100).

I'm assuming you want to copy between databases or via an intermediate file or something, otherwise you just want to use INSERT ... SELECT as shown in another answer.

over 4 years ago · Santiago Trujillo Relatório

0

You can use

INSERT INTO table2(col_list) 
SELECT col_list FROM table1 WHERE condtitions ORDER BY order_col_list LIMIT X;
over 4 years ago · Santiago Trujillo Relatório

0

You can limit number of rows when you copy (SELECT ...LIMIT) to, but not COPY from. You did not find such options in docs, because there are no such.

use insert into ... select from ... limit 100 instead

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda