Re: BUG #3941: Insert Error - Mailing list pgsql-bugs

From Gary Doades
Subject Re: BUG #3941: Insert Error
Date
Msg-id 47AC15DF.7050402@gpdnet.co.uk
Whole thread Raw
In response to BUG #3941: Insert Error  ("gnp yadav" <gnperumal@gmail.com>)
List pgsql-bugs
gnp yadav wrote:
> The following bug has been logged online:
>
> Bug reference:      3941
> Logged by:          gnp yadav
> Email address:      gnperumal@gmail.com
> PostgreSQL version: 8.1
> Operating system:   Ubuntu Linux
> Description:        Insert Error
> Details:
>
> CREATE TABLE sentence
> (
>   sentence_id serial NOT NULL,
>   citation_id int8 NOT NULL,
>   sen_offset int8 NOT NULL,
>   sen_length int8 NOT NULL,
>   sen_type varchar(10)[] NOT NULL,
>   CONSTRAINT sentence_id PRIMARY KEY (sentence_id),
>   CONSTRAINT citation_id FOREIGN KEY (sentence_id)
>       REFERENCES citation (citation_id) MATCH SIMPLE
>       ON UPDATE NO ACTION ON DELETE NO ACTION
> ) ;
>
> INSERT INTO sentence (sentence_id, citation_id, sen_offset, sen_length,
> sen_type) VALUES (NULL,1,2,3,asd");
>
>
> As i Got This type error frequently
>
> ERROR:  column "asd" does not exist
>
> please guide me, Advance thanks to for my teacher.

This is not a bug, at least not in Postgresql.

I'm surprised you didn't get a syntax error if that really is your
insert statement. If you use double quotes (") then you are referring to
a column name. If you want to insert a string you need to use single
quotes (').

e.g.

INSERT INTO sentence (citation_id, sen_offset, sen_length, sen_type)
VALUES (1,2,3,'asd');

However, I see you have declared sen_type as an array. Again if this was
intentional you need to specify an array value of some kind to fill it.

e.g.

INSERT INTO sentence (citation_id, sen_offset, sen_length, sen_type)
VALUES (1,2,3,'{asd}');

Notice also that sentence_id must be omitted from the insert as it is a
serial column.

I think you also need to read the manual more closely regarding arrays,
insert statements, strings and serial columns!


Cheers,
Gary.

pgsql-bugs by date:

Previous
From: Zdenek Kotala
Date:
Subject: Re: BUG #3941: Insert Error
Next
From: "Heikki Linnakangas"
Date:
Subject: Re: Re: BUG #3924: Create Database with another encoding as the encoding from postgres