Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

227
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda