Re: Using \copy to populate a table - Mailing list pgsql-general

From Adrian Klaver
Subject Re: Using \copy to populate a table
Date
Msg-id 18ef99ab-f4c1-44a5-b78a-35c261993017@aklaver.com
Whole thread Raw
In response to Using \copy to populate a table  (rob stone <floriparob@tpg.com.au>)
List 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.klaver@aklaver.com



pgsql-general by date:

Previous
From: Francisco Olarte
Date:
Subject: Re: Using \copy to populate a table
Next
From: Adrian Klaver
Date:
Subject: Re: Does included columns part of the PK