Re: SQL state: 22P02 Error during a COPY FROM a CSV file

From: Richard Huxton <dev(at)archonet(dot)com>
To: Sherman Brown <ardcsb(at)earthlink(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: SQL state: 22P02 Error during a COPY FROM a CSV file
Date: 2009-01-08 16:37:11
Message-ID: 49662BB7.9020000@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Sherman Brown wrote:
> CREATE TABLE mp3.songs
> (
> "Name" character varying[] NOT NULL,
> "Artist" character varying[] NOT NULL,
> "Composer" character varying[],
> "Album" character varying[] NOT NULL,
...

> Here are the first 4 lines from my CSV file:
> Name,Artist,Composer,Album,Grouping,Genre,Size,Time,Disc Number,Disc Count,Track Number,Track Count,Year,Date Modified,Date Added,Bit Rate,Sample Rate,Volume Adjustment,Kind,Equalizer,Comments,Play Count,Last Played,Skip Count,Last Skipped,My Rating,Location
> Talking About,Susan Tedeschi,"Susan Tedeschi, Doyle Bramhall II & Derek Trucks",Back To The River,,Blues,4175697,263,1,1,1,11,2008,1/1/2009 16:38,1/1/2009 16:38,128,44100,,AAC audio file,,,1,1/1/2009 16:47,,,,C:\Documents and Settings\SB\My Documents\My Music\iTunes\iTunes Music\Susan Tedeschi\Back To The River\01 Talking About.m4a

> Here is the error I am getting:
>
> ERROR: array value must start with "{" or dimension information
> CONTEXT: COPY songs, line 2, column Name: "Talking About"

The problem is that you've defined your "name" column as being an array
of varchar values. That's not what you're providing.

=> CREATE TABLE mp3s (track_name text[]);
CREATE TABLE
=> INSERT INTO mp3s (track_name) VALUES ( '{"first item", "second item"}' );
INSERT 0 1

See the manual: data-types, arrays for more details.

--
Richard Huxton
Archonet Ltd

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2009-01-08 16:49:38 Re: SQL state: 22P02 Error during a COPY FROM a CSV file
Previous Message Mohamed 2009-01-08 16:33:08 Re: to_tsquery, plainto_... avoiding bad input, injections. Is there a builtin function for this ? Escaping?