Johan Dahlin wrote: > Oleg Broytmann wrote: > >> On Thu, Jan 05, 2006 at 04:01:17PM -0600, Tim Edwards wrote: >> >>> So I created a view of it in Postgres. But now I can't seem to create >>> an object wrapper for it. SqlObject complains that the view doesn't >>> have a primary key. I saw a thread about views and primary keys, but >>> it didn't seem to help me. >> >> >> SQLObject-mapped tables must have a single-column primary key of >> int or >> str type. > > > It doesn't seem possible to add constraints on views in postgresql. > At least I couldn't figure out a way of doing that. > > Do you have an example of this?
I don't see what constraints have to do withit. You need to construct your
view to generate a primary key.
CREATE VIEW Foo AS
SELECT Bar.id || '.' || Baz.id, Bar.whatever, Baz.whatever
FROM Bar, Baz
WHERE Bar.id = Baz.id
How you generate the primary key will depend on your view. You might find
you have a naturally UNIQUE column in the view, or you might need to use a
complex expression using COALESCE to handle NULLs. PostgreSQL won't enforce
the uniqueness, so you have to guarantee it yourself.
--
Stuart Bishop <[EMAIL PROTECTED]>
http://www.stuartbishop.net/
signature.asc
Description: OpenPGP digital signature
