3

simple question I think but I can't seem to find the answer through Googling etc.

I am importing csv data into a postgresql table via psql. I can do this fine through the pgAdmin III GUI but am now using Codio Online IDE where it is all done through psql.

How can I import into the Postgresql table and skip the first 'id' auto incrementing column?

In pgAdmin it was as simple as unselecting the id column on the 'columns to import' tab.

So far I have in the SQL Query toolbox

COPY products FROM '/media/username/rails_projects/app/db/import/bdname_products.csv' DELIMITER ',' CSV; 

Alternatively, is it possible to get an output on the SQL that PgAdmin III used after you execute an Import using the menu Import command?

Thank you for your consideration.

Jay Killeen
  • 2,832
  • 6
  • 39
  • 66

1 Answers1

4

As explained in the manual, copy allows you to specify a field list to read, like this:

COPY table_name ( column_name , ... )  FROM 'filename'
fvu
  • 32,488
  • 6
  • 61
  • 79
  • oh I read that but thought differently. So it is just a matter of listing out all the columns that are in the postgresql table and excluding the id column? I'll give that a shot. – Jay Killeen Mar 04 '14 at 01:00
  • 1
    The explanation for the `column_name` optional parameter is `An optional list of columns to be copied. If no column list is specified, all columns of the table will be copied.` which is indeed less than clear if you're copying FROM a file to a table... – fvu Mar 04 '14 at 01:03