sequence aliases?
I'm checking out Ruby on Rails and there's a tutorial
about using Postgresql views and making them
updateable
(http://wiki.rubyonrails.com/rails/pages/HowtoUsePostgresViewsAsTables).
The tutorial suggests renaming the sequence for the
table to coincide with the view so that Rails can
automatically access the sequence. I don't like this
as it may break other things. Is there a way to create
an alias or something (e.g. quotes_seq_id points to
quotes_table_seq_id), or is there a better way?
Thanks,
CSN
__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com
CSN <cool_screen_name90001@yahoo.com> writes:
I'm checking out Ruby on Rails and there's a tutorial
about using Postgresql views and making them
updateable
(http://wiki.rubyonrails.com/rails/pages/HowtoUsePostgresViewsAsTables).
The tutorial suggests renaming the sequence for the
table to coincide with the view so that Rails can
automatically access the sequence. I don't like this
as it may break other things.
Not to mention that it won't actually work --- the proposed approach
fails because PG will refuse to let you drop the original sequence.
(It has failed in every release since 7.3, so I don't put a lot of stock
in that tutorial having been tested much.) Furthermore, it's quite
likely that future releases won't let you fool with the default
expression of a serial column at all.
My advice to the Rails people would be to fix whatever it is in their
code that is assuming a particular sequence name, or indeed assuming
a sequence at all...
regards, tom lane
Tom Lane <tgl@sss.pgh.pa.us> writes:
My advice to the Rails people would be to fix whatever it is in their
code that is assuming a particular sequence name, or indeed assuming
a sequence at all...
Well how else do you find the id of the last inserted record without assuming
a sequence?
--
greg
On Sun, Nov 06, 2005 at 12:15:45AM -0500, Greg Stark wrote:
Tom Lane <tgl@sss.pgh.pa.us> writes:
My advice to the Rails people would be to fix whatever it is in their
code that is assuming a particular sequence name, or indeed assuming
a sequence at all...Well how else do you find the id of the last inserted record without assuming
a sequence?
I suppose using something like:
select currval( pg_get_serial_sequence( 'table','col' ) );
That avoids hardcoding the sequence id. Not assuming a sequences at all
may be trickier.
Have a nice day,
--
Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/
Show quoted text
Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
tool for doing 5% of the work and then sitting around waiting for someone
else to do the other 95% so you can sue them.
--- Martijn van Oosterhout <kleptog@svana.org> wrote:
On Sun, Nov 06, 2005 at 12:15:45AM -0500, Greg Stark
wrote:Tom Lane <tgl@sss.pgh.pa.us> writes:
My advice to the Rails people would be to fix
whatever it is in their
code that is assuming a particular sequence
name, or indeed assuming
a sequence at all...
Well how else do you find the id of the last
inserted record without assuming
a sequence?
I suppose using something like:
select currval( pg_get_serial_sequence(
'table','col' ) );
I like that better than the current 'table_col_seq'.
Perhaps just currval('table', 'col'). Or perhaps
tables could be made to have a default sequence (one
that's associated with the primary key).
CSN
That avoids hardcoding the sequence id. Not assuming
a sequences at all
may be trickier.Have a nice day,
--
Martijn van Oosterhout <kleptog@svana.org>
http://svana.org/kleptog/Patent. n. Genius is 5% inspiration and 95%
perspiration. A patent is a
tool for doing 5% of the work and then sitting
around waiting for someone
else to do the other 95% so you can sue them.
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com