Ruby Forum Nitro > invalid format for pg sequence query - SELECT nextval('"ogsimpletest"_oid_seq')

Posted by Reid Thompson (Guest)
on 17.12.2007 15:25
(Received via mailing list)
>From current repo...
Looks like the select for the sequence has double quotes that shouldn't 
be there

rthompso@raker ~ $ ruby simplePG.rb
 INFO: Og uses the Postgresql store.
DEBUG: Og manageable classes: [SimpleTest]
DEBUG: CREATE TABLE "ogsimpletest" ("date" text, "ts" text, "oid" serial 
PRIMARY KEY) WITHOUT OIDS
DEBUG: SELECT * FROM "ogsimpletest" LIMIT 1
DEBUG: SELECT nextval('"ogsimpletest"_oid_seq')
ERROR: DB error ERROR:  invalid name syntax
, [SELECT nextval('"ogsimpletest"_oid_seq')]
ERROR: 
/home/rthompso/src/repo.nitroproject.org/script/lib/../../og/lib/og/adapter/postgresql.rb:119:in 
`exec'
/home/rthompso/src/repo.nitroproject.org/script/lib/../../og/lib/og/adapter/postgresql.rb:119:in 
`query_statement'
/home/rthompso/src/repo.nitroproject.org/script/lib/../../og/lib/og/store/sql.rb:572:in 
`query'
/home/rthompso/src/repo.nitroproject.org/script/lib/../../og/lib/og/adapter/postgresql.rb:152:in 
`insert'
/home/rthompso/src/repo.nitroproject.org/script/lib/../../og/lib/og/store/sql.rb:102:in 
`og_insert'
/home/rthompso/src/repo.nitroproject.org/script/lib/../../og/lib/og/store.rb:94:in 
`save'
/home/rthompso/src/repo.nitroproject.org/script/lib/../../og/lib/og/model.rb:69:in 
`save'
/home/rthompso/src/repo.nitroproject.org/script/lib/../../og/lib/og/manager.rb:118:in 
`with_store'
/home/rthompso/src/repo.nitroproject.org/script/lib/../../og/lib/og/model.rb:68:in 
`save'
simplePG.rb:36
/home/rthompso/src/repo.nitroproject.org/script/lib/../../og/lib/og/store/sql.rb:615:in 
`handle_sql_exception': Og::StoreException (Og::StoreException)
  from 
/home/rthompso/src/repo.nitroproject.org/script/lib/../../og/lib/og/store/sql.rb:575:in 
`query'
  from 
/home/rthompso/src/repo.nitroproject.org/script/lib/../../og/lib/og/adapter/postgresql.rb:152:in 
`insert'
  from 
/home/rthompso/src/repo.nitroproject.org/script/lib/../../og/lib/og/store/sql.rb:102:in 
`og_insert'
  from 
/home/rthompso/src/repo.nitroproject.org/script/lib/../../og/lib/og/store.rb:94:in 
`save'
  from 
/home/rthompso/src/repo.nitroproject.org/script/lib/../../og/lib/og/model.rb:69:in 
`save'
  from 
/home/rthompso/src/repo.nitroproject.org/script/lib/../../og/lib/og/manager.rb:118:in 
`with_store'
  from 
/home/rthompso/src/repo.nitroproject.org/script/lib/../../og/lib/og/model.rb:68:in 
`save'
  from simplePG.rb:36
Posted by George Moschovitis (Guest)
on 17.12.2007 20:18
(Received via mailing list)
can someone with pg provide a fix for this?

-g.
Posted by Bill Kelly (Guest)
on 18.12.2007 00:55
(Received via mailing list)
From: George Moschovitis
>
> can someone with pg provide a fix for this?

I'm not sure what the ideal fix is.  But for what it's worth,
I'm still using the simplistic fix I posted here back in July:

  def enchant(klass, manager)
    super

    pk = klass.primary_key

    seq = "#{klass::OGTABLE}_#{pk}_seq"
    seq.tr!('"', '')  # %%BWK 070827 -- added this kludge to strip 
quotes from table name

    pkann = klass.ann(pk)

    unless pkann[:sequence]
      if pkann[:sql] =~ /SERIAL/i
        klass.ann(pk, {:sequence => seq})
      else
        klass.ann(pk, {:sequence => false})
      end
    end
  end


^^^^ I just strip the quotes wholesale.


Regards,

Bill
Posted by Reid Thompson (Guest)
on 18.12.2007 02:54
(Received via mailing list)
Bill Kelly wrote:
>     seq = "#{klass::OGTABLE}_#{pk}_seq"
>     seq.tr!('"', '')  # %%BWK 070827 -- added this kludge to strip quotes from table name
> 

> 
> ^^^^ I just strip the quotes wholesale.
> 

Thanks,
i now remember seeing the original post --

It looks like the code may have been written to account for
(from the the PostgreSQL docs )
  '...Quoting an identifier also makes it case-sensitive, whereas 
unquoted names
are always folded to lower case. For example, the identifiers FOO, foo, 
and
"foo" are considered the same by PostgreSQL, but "Foo" and "FOO" are 
different
from these three and each other. (The folding of unquoted names to lower 
case in
PostgreSQL is incompatible with the SQL standard, which says that 
unquoted names
should be folded to upper case. Thus, foo should be equivalent to "FOO" 
not
"foo" according to the standard. If you want to write portable 
applications you
are advised to always quote a particular name or never quote it.)...'

( I'm thinking specifically the last line ).
In general, PostgreSQL forces the user to remember/manage this.