Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w1fe4-000VFH-2B for pgsql-general@arkaria.postgresql.org; Sun, 15 Mar 2026 07:12:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w1fe3-003lvG-1a for pgsql-general@arkaria.postgresql.org; Sun, 15 Mar 2026 07:12:16 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w1fe2-003lv8-0z for pgsql-general@lists.postgresql.org; Sun, 15 Mar 2026 07:12:15 +0000 Received: from omr-01.pc5.atmailcloud.com ([103.150.252.152]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1w1fdz-00000000EYx-0c18 for pgsql-general@postgresql.org; Sun, 15 Mar 2026 07:12:14 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tpg.com.au; s=202309; h=MIME-Version:Content-Type:Date:To:From:Subject:Message-ID; bh=78aKH6nbGf6Se3/0CI07ZPHWkhZcdjezOrFI46Zbblk=; b=Khv/P0ZZHU8P5RTHiAy+J2IDhv BRnCDVFWi0nSA7MU/qQKymIxe/O3pxlgjw3hTOoffuBj8ulHD/V+Ck8TcZQJyr7e5vk2XtL4hGs95 te/EOsPK7gCiIDZjZCDBXjFyK7ImByLgRJcekdRoH35o9+kS1iCmIvp6G4JSb882qcbguKKL06TIb s3WgSnujj+xphd4MLic34hOMWAiUsddD0IVdG4X+VOEPtY/t6wSUB+kcTA8pVowZBgPe1aGLLsDQx 9AbSO1AbWQG0IueyBRk41nx/Vz4v3tSasJlA5zz4/UHbsgvUjbLN89T8a2KPcwY6lniNR6mxd/zg1 ijltjsjg==; Received: from cmr-kakadu02.internal.pc5.atmailcloud.com (cmr-kakadu02.internal.pc5.atmailcloud.com [192.168.1.4]) by omr-01.pc5.atmailcloud.com (Exim/cmr-kakadu02.i-0c9cfa5e504c0c8a0) with ESMTPS (envelope-from ) id 1w1fdu-00000001U9K-14Qv for ; Sun, 15 Mar 2026 07:12:06 +0000 Received: from 124-148-217-142.tpgi.com.au ([124.148.217.142] helo=[192.168.1.103]) by cmr-kakadu02.i-0c9cfa5e504c0c8a0 with esmtpsa (envelope-from ) id 1w1fdq-0000000BTUM-39zv for pgsql-general@postgresql.org; Sun, 15 Mar 2026 07:12:04 +0000 Message-ID: <43388977a1cdbde81043c690b41e0647e9b95a2b.camel@tpg.com.au> Subject: Using \copy to populate a table From: rob stone To: PostGreSQL MailingList Date: Sun, 15 Mar 2026 18:11:59 +1100 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.56.2-8 MIME-Version: 1.0 X-Atmail-Id: floriparob@tpg.com.au X-atmailcloud-spam-action: X-AVAS-Report: RCVD_TLS_ALL(0.00) FROM_HAS_DN(0.00) FROM_EQ_ENVFROM(0.00) UNKNOWN_SENDER(0.50) CLOUDMARK_NOT_SPAM(-10.00) TO_MATCH_ENVRCPT_ALL(0.00) TO_DN_ALL(0.00) MIME_GOOD(-0.10) MID_RHS_MATCH_FROM(0.00) RCVD_VIA_SMTP_AUTH(0.00) ARC_NA(0.00) ASN(0.00) RCVD_COUNT_ONE(0.00) MIME_TRACE(0.00) CYREN_UNKNOWN(0.00) FREEMAIL_FROM(0.00) RCPT_COUNT_ONE(0.00) FREEMAIL_ENVFROM(0.00) X-atmailcloud-route: unknown List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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:- applntestdb=3D> \copy forms_table (item_type, navgn_refn, html_name, table_key, navgn_bar, rows_page, forward_to, second_to, tertiary_to, active_item, super_only, system_admin, inserted_by) from '/home/postgres/loadfiles/formstable.txt' header delimiter '|'; ERROR: invalid input syntax for type smallint: "null" CONTEXT: COPY forms_table, line 2, column rows_page: "null" applntestdb=3D> This is what is on line 2 of the file:- C|0|pageloader|||null|null|null|null|t|f|f|0 The test below was simplified to just choose one SMALLINT column.=20 applntestdb=3D> insert into forms_table (item_type, navgn_refn, html_name, rows_page, active_item, inserted_by) values ('C', 0, 'pageloader', null, TRUE, 0); INSERT 0 1 applntestdb=3D> delete from forms_table where item_type =3D 'C'; DELETE 1 applntestdb=3D> insert into forms_table (item_type, navgn_refn, html_name, rows_page, active_item, inserted_by) values ('C', 0, 'pageloader', '', TRUE, 0); ERROR: invalid input syntax for type smallint: "" LINE 2: inserted_by) values ('C', 0, 'pageloader', '', TRUE, 0) ^ =20 So, psql is quite happy to insert null into a column defined as smallint, but when you use the \copy mechanism to populate a table it pulls an error. 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? Has anybody else had this problem and if so what was the solution? Thanks, Rob