IWETHEY v. 0.3.0 | TODO
1,095 registered users | 1 active user | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New So does 'DEFERRABLE' not work in postgres?
I've got a constriant between two fields in one table.

\n            Column            |  Type   |                           Modifiers                            \n------------------------------+---------+----------------------------------------------------------------\n cv_entry_id                  | bigint  | not null default nextval('cv_entry_cv_entry_id_seq'::regclass)\noriginal_book_id             | bigint  | \n


with constraint:

"translation_references_book" FOREIGN KEY (original_book_id) REFERENCES cv_entry(cv_entry_id) DEFERRABLE

I'm inside a transaction, I insert a record for the translation before inserting the record for the book and I get a constraint violation. I thought deferred constraints were not to be checked until commit?

I have executed 'set constraints all deferred'.

For now I've dropped that particular constraint and checked it with
select original_book_id from cv_entry where original_book_id is not null and original_book_id not in (select cv_entry_id from cv_entry);

it comes out clean - so this looks like a (VERY ANNOYING) but in PG's constraints checking - I have version 8.1.

Or am I missing something?



[link|http://www.blackbagops.net|Black Bag Operations Log]

[link|http://www.objectiveclips.com|Artificial Intelligence]

[link|http://www.badpage.info/seaside/html|Scrutinizer]
New Possibly not a bug:
[link|http://www.postgresql.org/docs/8.1/interactive/sql-createtable.html|http://www.postgresq...-createtable.html]
Referential actions other than the NO ACTION check cannot be deferred, even if the constraint is declared deferrable.


and
NO ACTION

Produce an error indicating that the deletion or update would create a foreign key constraint violation. If the constraint is deferred, this error will be produced at constraint check time if there still exist any referencing rows. This is the default action.


You might try INITIALLY DEFERRED instead.

The functionality has been in there since 7.4 at least, so I doubt that it isn't working.
Regards,

-scott anderson

"Welcome to Rivendell, Mr. Anderson..."
New The naming convention is a bug in itself
I have googled away and cannot find anywhere a coherent explanation of the differences or semantic benefits between choosing initially deferred and deferrable. So I've simply declared them all deferrable.

I'll changed them to initially deferred and see.



[link|http://www.blackbagops.net|Black Bag Operations Log]

[link|http://www.objectiveclips.com|Artificial Intelligence]

[link|http://www.badpage.info/seaside/html|Scrutinizer]
New Removes the need for SET CONSTRAINTS
As far as I can tell. You're right, it's not their best documented feature.
Regards,

-scott anderson

"Welcome to Rivendell, Mr. Anderson..."
New Initially Deferred seems to be doing the right thing -thx
This is really getting to be nice development environment - I've added schema comparison/migration features to glorp in squeak and now I just change the object model and it syncs it on demand - with warnings for non-empty tables when dropping and options to merge dropped non-empty columns to other columns. Doing the inverse sync from tables to objects should take all of a couple hours giving round tripping in two directions.

Rails, shmails.



[link|http://www.blackbagops.net|Black Bag Operations Log]

[link|http://www.objectiveclips.com|Artificial Intelligence]

[link|http://www.badpage.info/seaside/html|Scrutinizer]
New Re: Initially Deferred seems to be doing the right thing -th
I reckon the SET CONSTRAINTS wasn't working for some reason, then.
Regards,

-scott anderson

"Welcome to Rivendell, Mr. Anderson..."
     So does 'DEFERRABLE' not work in postgres? - (tuberculosis) - (5)
         Possibly not a bug: - (admin) - (4)
             The naming convention is a bug in itself - (tuberculosis) - (3)
                 Removes the need for SET CONSTRAINTS - (admin) - (2)
                     Initially Deferred seems to be doing the right thing -thx - (tuberculosis) - (1)
                         Re: Initially Deferred seems to be doing the right thing -th - (admin)

Who left that on the floor?
84 ms