Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7914959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:17:41+00:00 2026-06-03T14:17:41+00:00

In PostgreSQL, I created a new table and assigned a new sequence to the

  • 0

In PostgreSQL, I created a new table and assigned a new sequence to the id column. If I insert a record from the PostgreSQL console it works but when I try to import a record from from Rails, it raises an exception that it is unable to find the associated sequence.

Here is the table:

\d+ user_messages;
                                                  Table "public.user_messages"
   Column    |            Type             |                         Modifiers                          | Storage  | Description 
-------------+-----------------------------+------------------------------------------------------------+----------+-------------
 id          | integer                     | not null default nextval('new_user_messages_id'::regclass) | plain    | 

But when I try to get the sequence with the SQL query which Rails uses, it returns NULL:

select pg_catalog.pg_get_serial_sequence('user_messages', 'id');
 pg_get_serial_sequence 
------------------------

(1 row)

The error being raised by Rails is:

UserMessage.import [UserMessage.new]
NoMethodError: undefined method `split' for nil:NilClass
    from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:910:in `default_sequence_name'

This problem only occurs when I use the ActiveRecord extension for importing bulk records, single records get saved through ActiveRecord.

How do I fix it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T14:17:44+00:00Added an answer on June 3, 2026 at 2:17 pm

    I think your problem is that you set all this up by hand rather than by using a serial column. When you use a serial column, PostgreSQL will create the sequence, set up the appropriate default value, and ensure that the sequence is owned by the table and column in question. From the fine manual:

    pg_get_serial_sequence(table_name, column_name)
    get name of the sequence that a serial or bigserial column uses

    But you’re not using serial or bigserial so pg_get_serial_sequence won’t help.

    You can remedy this by doing:

    alter sequence new_user_messages_id owned by user_messages.id
    

    I’m not sure if this is a complete solution and someone (hi Erwin) will probably fill in the missing bits.

    You can save yourself some trouble here by using serial as the data type of your id column. That will create and hook up the sequence for you.

    For example:

    => create sequence seq_test_id;
    => create table seq_test (id integer not null default nextval('seq_test_id'::regclass));
    => select pg_catalog.pg_get_serial_sequence('seq_test','id');
     pg_get_serial_sequence 
    ------------------------
    
    (1 row)
    => alter sequence seq_test_id owned by seq_test.id;
    => select pg_catalog.pg_get_serial_sequence('seq_test','id');
     pg_get_serial_sequence 
    ------------------------
     public.seq_test_id
    (1 row)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I accidentaly created a table in PostgreSQL which contains, in its name, some double
I have created a table in postgreSQL. I want to look at the SQL
How can I find the table creation time in PostgreSQL? Example: If I created
I am new to PostgreSQL and I try to get my head around it.
I have created a new schema in my PostgreSQl database with psql: CREATE SCHEMA
I'm new to PostgreSQL. I have tables like: CREATE TABLE Person ( ID SERIAL
I created a table Abc in the public schema of my postgresql database. According
I have a table being created in a PostgreSQL ( version 9 ) database
I created a databse with four tables in pgAdmin. It was coded in PostgreSQL.
Apparently there is a database postgres that is created by default on each postgresql

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.