It should be easy. I want to get the nextval sequence ... this is not the default ... this is not the primary key ... this is not the foreign key. In rare cases, I need a serial number for a user-supplied value.
I tried the following:
@nextid = ActiveRecord::Base.connection.execute("SELECT nextval('xscrpt_id_seq')")
and I will return:
#<PG::Result:0x007fe668a854e8 @connection=#<PG::Connection:0x00000003aeff30>>
And using
@nextid[0]["nextval"]
I can get the correct value, but this does not seem to be the correct way to solve the problem. I searched, I read "Pro Active Record", which said it was used:
M_script.find_by_sql("SELECT nextval('xscript_id_seq')")
but it didn’t work.
Any hints on the right path (Rails) for getting the next value from the sequence in the ROR will be greatly appreciated!
source share