Postgres and Ruby

Hi I’m very new to Ruby on Rails. I’ve tried to create a very simple
test application on postgres database. I’ve installed

gem install postgres-pr

driver. My database table name is players. My model file in ruby is
named player.rb

when I go to


I can see the list of the table

when I want to add new record


I’m receiving this error :

RuntimeError: ERROR C55000 Mcurrval of sequence “players_id_seq” is
not yet defined in this session Fsequence.c L639 Rcurrval_oid: SELECT

I know this is error from database. When I tired to do
SELECT currval(‘players_id_seq’) on database i’ve received the same
error. After nextval (‘playe…’) and than SELECT
currval(‘players_id_seq’) currval returned good value.

I really want to stay on postgres database. Do any1 know what is wrong
or how to fix this when i want to use ActiveRecord for adding new
records to the database ?

Many thanks …

btw : editing of the record is working fine too

Try this SQL, it might work. It resets the sequence number in a
table. Can be obviously modified to work on any table with a regular
unique non-null incrementing primary-key ‘id’

SELECT setval(‘players_id_seq’, (SELECT MAX(id) FROM players)+1);

Strictly speaking, you not need the “+1”, as nextval() will increment
it. The “+1” will actually create a hole in the sequence - which of
course may or may not be if importance to your application.

16 nov 2007 kl. 15.55 skrev fredistic:


i made it like this.

class PlayersController < ApplicationController

def initialize
sql = ActiveRecord::Base.connection();
sql.execute(“SELECT setval(‘players_id_seq’, (SELECT MAX(id) FROM

def list


if it’s not entirely correct let me know plz.

I am new to Ruby on Rails and am trying to run a very simple example
using also postgres database.
I also have the problem when trying to add\create.
My controller is very basic:

class MyuserController < ApplicationController
scaffold :myuser

i get the following error:
RuntimeError: ERROR C42P01 Mrelation “myusers_id_seq” does not exist
Fnamespace.c L200 RRangeVarGetRelid: SELECT currval(‘myusers_id_seq’)

Have you found a solution to your problem?

On Nov 17, 9:14 pm, Jozef N. [email protected]

Jozef N. wrote:

have you created an sequencer ?

Indeed. It sounds like the id column is defined as an integer instead of
a serial.

Roderick van Domburg

have you created an sequencer ?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs