Unix Technical Forum

Re: [GENERAL] DB insert Error

This is a discussion on Re: [GENERAL] DB insert Error within the pgsql Novice forums, part of the PostgreSQL category; --> On Tue, Aug 15, 2006 at 11:55:58PM -0400, Jasbinder Bali wrote: > I'm using ECPG and trying to do ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Novice

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-17-2008, 10:06 PM
Michael Fuhr
 
Posts: n/a
Default Re: [GENERAL] DB insert Error

On Tue, Aug 15, 2006 at 11:55:58PM -0400, Jasbinder Bali wrote:
> I'm using ECPG and trying to do follwoing insert in one of the talbes.
>
> insert into raw_email ( id , raw_email ) values ( 1 , :ch);
>
> ch is an array and defined as follows:
>
> EXEC SQL BEGIN DECLARE SECTION;
> char ch[MSG_LEN];
> EXEC SQL END DECLARE SECTION;
>
> contents of array ch is actually a parsed raw email that i've attached
> herewith.
>
> I get the following error when the insert statement is hit:
>
> [2446]: ECPGexecute line 97: Error: ERROR: array value must start with "{"
> or dimension information.


What's the table definition for raw_email? Based on the error it
looks like one of the columns you're inserting is defined as an
array. I'm guessing you did something like this:

CREATE TABLE raw_email (
id integer,
raw_email char[]
);

When you should have done this:

CREATE TABLE raw_email (
id integer,
raw_email text -- or varchar
);

Is my guess correct?

--
Michael Fuhr

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-17-2008, 10:06 PM
Jasbinder Bali
 
Posts: n/a
Default Re: [GENERAL] DB insert Error

table definition of raw_email table is as follows

CREATE TABLE raw_email (
id int4 NOT NULL,
raw_email varchar[],
parsed_flag bool NOT NULL DEFAULT false,
CONSTRAINT pk_rawemail PRIMARY KEY (id)
)
WITHOUT OIDS;

i have very much declared raw_email field as varchar and not char

~Jas



On 8/16/06, Michael Fuhr <mike@fuhr.org> wrote:
>
> On Tue, Aug 15, 2006 at 11:55:58PM -0400, Jasbinder Bali wrote:
> > I'm using ECPG and trying to do follwoing insert in one of the talbes.
> >
> > insert into raw_email ( id , raw_email ) values ( 1 , :ch);
> >
> > ch is an array and defined as follows:
> >
> > EXEC SQL BEGIN DECLARE SECTION;
> > char ch[MSG_LEN];
> > EXEC SQL END DECLARE SECTION;
> >
> > contents of array ch is actually a parsed raw email that i've attached
> > herewith.
> >
> > I get the following error when the insert statement is hit:
> >
> > [2446]: ECPGexecute line 97: Error: ERROR: array value must start with

> "{"
> > or dimension information.

>
> What's the table definition for raw_email? Based on the error it
> looks like one of the columns you're inserting is defined as an
> array. I'm guessing you did something like this:
>
> CREATE TABLE raw_email (
> id integer,
> raw_email char[]
> );
>
> When you should have done this:
>
> CREATE TABLE raw_email (
> id integer,
> raw_email text -- or varchar
> );
>
> Is my guess correct?
>
> --
> Michael Fuhr
>


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-17-2008, 10:06 PM
Michael Fuhr
 
Posts: n/a
Default Re: [GENERAL] DB insert Error

On Wed, Aug 16, 2006 at 12:38:42AM -0400, Jasbinder Bali wrote:
> table definition of raw_email table is as follows
>
> CREATE TABLE raw_email (
> id int4 NOT NULL,
> raw_email varchar[],
> parsed_flag bool NOT NULL DEFAULT false,
> CONSTRAINT pk_rawemail PRIMARY KEY (id)
> )
> WITHOUT OIDS;
>
> i have very much declared raw_email field as varchar and not char


It's not the varchar-vs-char distinction that matters; it's the
fact that raw_email is declared as array, so it expects a certain
input syntax. Example:

test=> INSERT INTO raw_email (id, raw_email) VALUES (1, 'test');
ERROR: array value must start with "{" or dimension information
test=> INSERT INTO raw_email (id, raw_email) VALUES (1, '{test}');
INSERT 0 1

Are you sure you want raw_email to be an array instead of a simple
varchar column? Are you handling the contents as array elements
(e.g., one element per line) or is the whole considered a single
piece of data?

--
Michael Fuhr

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-17-2008, 10:07 PM
Jasbinder Bali
 
Posts: n/a
Default Re: [GENERAL] DB insert Error

This is how the array is formed in my C code
-------------------------------------------------------------------------------------------
FILE *fp;

while(!feof(fp))
{ch[i]=fgetc(fp);
if(ch[i]=='\n') lines++; i++; }
ch[i-1]='\0';
fclose(fp);
------------------------------------------------------------------------------
and then am inserting ch as a whole in the varchar column in the database.

Do you want me to append a leading '{' and a trailing '}' to ch??

~Jas


On 8/16/06, Michael Fuhr <mike@fuhr.org> wrote:
>
> On Wed, Aug 16, 2006 at 12:38:42AM -0400, Jasbinder Bali wrote:
> > table definition of raw_email table is as follows
> >
> > CREATE TABLE raw_email (
> > id int4 NOT NULL,
> > raw_email varchar[],
> > parsed_flag bool NOT NULL DEFAULT false,
> > CONSTRAINT pk_rawemail PRIMARY KEY (id)
> > )
> > WITHOUT OIDS;
> >
> > i have very much declared raw_email field as varchar and not char

>
> It's not the varchar-vs-char distinction that matters; it's the
> fact that raw_email is declared as array, so it expects a certain
> input syntax. Example:
>
> test=> INSERT INTO raw_email (id, raw_email) VALUES (1, 'test');
> ERROR: array value must start with "{" or dimension information
> test=> INSERT INTO raw_email (id, raw_email) VALUES (1, '{test}');
> INSERT 0 1
>
> Are you sure you want raw_email to be an array instead of a simple
> varchar column? Are you handling the contents as array elements
> (e.g., one element per line) or is the whole considered a single
> piece of data?
>
> --
> Michael Fuhr
>


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-17-2008, 10:07 PM
Michael Fuhr
 
Posts: n/a
Default Re: [GENERAL] DB insert Error

On Wed, Aug 16, 2006 at 01:20:08AM -0400, Jasbinder Bali wrote:
> This is how the array is formed in my C code
> -------------------------------------------------------------------------------------------
> FILE *fp;
>
> while(!feof(fp))
> {ch[i]=fgetc(fp);
> if(ch[i]=='\n') lines++; i++; }
> ch[i-1]='\0';
> fclose(fp);
> ------------------------------------------------------------------------------
> and then am inserting ch as a whole in the varchar column in the database.
>
> Do you want me to append a leading '{' and a trailing '}' to ch??


Do you intend to handle the data as an array in SQL? If not then
the raw_email column should be declared as varchar or text instead
of varchar[]. In that case your C code won't need to change.

--
Michael Fuhr

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-17-2008, 10:07 PM
Jasbinder Bali
 
Posts: n/a
Default Re: [GENERAL] DB insert Error

I changed the datatype from varchar[] to varchar
ECPGdebug(1,stderr) says
[2998]: ECPGexecute line 97 Ok: INSERT 0 1

Its not inserting any record even though sqlcode is 0.

~Jas


On 8/16/06, Michael Fuhr <mike@fuhr.org> wrote:
>
> On Wed, Aug 16, 2006 at 01:20:08AM -0400, Jasbinder Bali wrote:
> > This is how the array is formed in my C code
> >

> -------------------------------------------------------------------------------------------
> > FILE *fp;
> >
> > while(!feof(fp))
> > {ch[i]=fgetc(fp);
> > if(ch[i]=='\n') lines++; i++; }
> > ch[i-1]='\0';
> > fclose(fp);
> >

> ------------------------------------------------------------------------------
> > and then am inserting ch as a whole in the varchar column in the

> database.
> >
> > Do you want me to append a leading '{' and a trailing '}' to ch??

>
> Do you intend to handle the data as an array in SQL? If not then
> the raw_email column should be declared as varchar or text instead
> of varchar[]. In that case your C code won't need to change.
>
> --
> Michael Fuhr
>


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-17-2008, 10:07 PM
Jasbinder Bali
 
Posts: n/a
Default Re: [GENERAL] DB insert Error

Also,
My insert statement is

EXEC SQL INSERT INTO raw_email (id,raw_email) VALUES (1,:ch);




On 8/16/06, Michael Fuhr <mike@fuhr.org> wrote:
>
> On Wed, Aug 16, 2006 at 01:20:08AM -0400, Jasbinder Bali wrote:
> > This is how the array is formed in my C code
> >

> -------------------------------------------------------------------------------------------
> > FILE *fp;
> >
> > while(!feof(fp))
> > {ch[i]=fgetc(fp);
> > if(ch[i]=='\n') lines++; i++; }
> > ch[i-1]='\0';
> > fclose(fp);
> >

> ------------------------------------------------------------------------------
> > and then am inserting ch as a whole in the varchar column in the

> database.
> >
> > Do you want me to append a leading '{' and a trailing '}' to ch??

>
> Do you intend to handle the data as an array in SQL? If not then
> the raw_email column should be declared as varchar or text instead
> of varchar[]. In that case your C code won't need to change.
>
> --
> Michael Fuhr
>


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 04-17-2008, 10:07 PM
Michael Fuhr
 
Posts: n/a
Default Re: [GENERAL] DB insert Error

On Wed, Aug 16, 2006 at 01:46:30AM -0400, Jasbinder Bali wrote:
> I changed the datatype from varchar[] to varchar
> ECPGdebug(1,stderr) says
> [2998]: ECPGexecute line 97 Ok: INSERT 0 1
>
> Its not inserting any record even though sqlcode is 0.


Are you committing the transaction? See the bottom of the
following page:

http://www.postgresql.org/docs/8.1/i...-commands.html

"In the default mode, statements are committed only when EXEC SQL
COMMIT is issued."

--
Michael Fuhr

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 11:33 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com