Re: Using \copy to populate a table

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: rob stone <floriparob(at)tpg(dot)com(dot)au>, PostGreSQL MailingList <pgsql-general(at)postgresql(dot)org>
Subject: Re: Using \copy to populate a table
Date: 2026-03-15 15:30:44
Message-ID: 18ef99ab-f4c1-44a5-b78a-35c261993017@aklaver.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 3/15/26 12:11 AM, rob stone wrote:
> psql (18.3 (Debian 18.3-1+b1))
> Type "help" for help.
>
> Debian OS is forky.
>
> When setting up a new development database, the following occurred:-
>

> How do we fix this? Alter all the nulls to zeroes in the file or write
> a program to dissect the file and create individual insert statements?

CSV is a text format and in:

C|0|pageloader|||null|null|null|null|t|f|f|0

the null values are the string 'null' which indeed is not a valid syntax
for a smallint.

>
> Has anybody else had this problem and if so what was the solution?

Do you have control over whatever creates the file?

An option is to create a staging table that is has all string fields,
import into it and then do clean up before moving to final table.

>
> Thanks,
> Rob
>
>

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2026-03-15 15:34:13 Re: Does included columns part of the PK
Previous Message Francisco Olarte 2026-03-15 09:50:33 Re: Using \copy to populate a table