Re: problem inserting with sequence - Mailing list pgsql-general

From Richard Huxton
Subject Re: problem inserting with sequence
Date
Msg-id 42E8D721.3020203@archonet.com
Whole thread Raw
In response to problem inserting with sequence  (germ germ <super_code_monkey@yahoo.com>)
List pgsql-general
germ germ wrote:
> I have been trying to figure out why I can't insert
> into a table and I think it has something to do with
> the sequnce.
>
> I am able to use able to properly insert into the
> table using the the shell, but I am not able to insert
> using a php script:
>
> INSERT INTO requests (time_stamp, req_num,
> recommended_by) VALUES (now(),
> nextval('requests_req_num_seq'), 'foo');
>
> Here is the schema I'm using:
> DROP SEQUENCE requests_req_num_seq;
> DROP TABLE requests;
>
> CREATE SEQUENCE requests_req_num_seq INCREMENT BY 1
> START WITH 1000;
>
> CREATE TABLE requests (
>     time_stamp         timestamp    PRIMARY KEY DEFAULT 'now',
>     req_num            integer        DEFAULT
> nextval('acq_requests_req_num_seq') NOT NULL,
>     recommended_by        varchar(35)    NOT NULL
> );
> GRANT ALL ON requests TO wwwrun, postgres;

Check you server logs and it should tell you why. Actually, check the
error code in your PHP and it should tell you why.

My immediate guess - you haven't granted permission to the sequence for
user "wwwrun".

--
   Richard Huxton
   Archonet Ltd

pgsql-general by date:

Previous
From: Kilian Hagemann
Date:
Subject: Re: Backup and restore from 7.4.1 to latest, crossing
Next
From: Ezequiel Tolnay
Date:
Subject: pg_get_serial_sequence and inheritance