[SQL] Is it possible to only allow deletes from a table via referential integrity cascades?

2008-12-10 Thread Christopher Maier
I have two tables joined by a foreign key constraint: CREATE TABLE test_master( id SERIAL PRIMARY KEY, foo TEXT ); CREATE TABLE test_detail( id SERIAL PRIMARY KEY, master BIGINT NOT NULL REFERENCES test_master(id) ON DELETE CASCADE ON UPDATE CASCADE, bar TEXT ); Is ther

[SQL] Best way to restrict detail rows?

2008-12-08 Thread Christopher Maier
I have a "master-detail" kind of situation, as illustrated here: CREATE TABLE master( id SERIAL PRIMARY KEY, foo TEXT ); CREATE TABLE detail( id SERIAL PRIMARY KEY master BIGINT NOT NULL REFERENCES master(id), bar TEXT ); (this is a simplification, of cou

Re: [SQL] Order of trigger execution: AFTER DELETE ON EACH ROW doesn't appear to be working properly

2008-10-13 Thread Christopher Maier
On Oct 13, 2008, at 3:08 PM, Adrian Klaver wrote: -- Original message -- From: "Christopher Maier" <[EMAIL PROTECTED]> As you can see, doing a row-by-row delete works fine, but when doing a bulk delete, all the before triggers are grouped

Re: [SQL] Problem with delete trigger: how to allow only triggers to delete a row?

2008-10-13 Thread Christopher Maier
On Oct 10, 2008, at 5:16 PM, Christopher Maier wrote: On Oct 10, 2008, at 4:53 PM, Tom Lane wrote: Alvaro Herrera <[EMAIL PROTECTED]> writes: Looks like you should revoke DELETE privilege from plain users, and have your delete trigger be a security definer function. There wo

[SQL] Order of trigger execution: AFTER DELETE ON EACH ROW doesn't appear to be working properly

2008-10-13 Thread Christopher Maier
I've got a series of triggers that are responsible for maintaining deduced data in a table (background for this can be found in an earlier mailing list posting: http://archives.postgresql.org/pgsql-sql/2008-10/msg00041.php) . This problem concerns the order in which my triggers are executed.

Re: [SQL] Problem with delete trigger: how to allow only triggers to delete a row?

2008-10-10 Thread Christopher Maier
On Oct 10, 2008, at 4:53 PM, Tom Lane wrote: Alvaro Herrera <[EMAIL PROTECTED]> writes: Looks like you should revoke DELETE privilege from plain users, and have your delete trigger be a security definer function. There would be another security definer function to delete non-deduced rows wh

Re: [SQL] Problem with delete trigger: how to allow only triggers to delete a row?

2008-10-10 Thread Christopher Maier
On Oct 10, 2008, at 2:05 PM, Alvaro Herrera wrote: Looks like you should revoke DELETE privilege from plain users, and have your delete trigger be a security definer function. There would be another security definer function to delete non-deduced rows which users can call directly. Thank

Re: [SQL] Problem with delete trigger: how to allow only triggers to delete a row?

2008-10-10 Thread Christopher Maier
On Oct 10, 2008, at 1:23 PM, Adrian Klaver wrote: Could you have the the trigger examine the row to see if it meets the criteria for deletion. If it does RETURN a NON NULL value so the trigger completes, otherwise RETURN NULL to prevent the DELETE. Thanks for your reply, Adrian. This is ind

[SQL] Problem with delete trigger: how to allow only triggers to delete a row?

2008-10-10 Thread Christopher Maier
I have a table where some rows are originally entered, and others are logically deduced from original rows by triggers. For instance, if one row contains data indicating that "A < B" and another row indicates "B < C", the triggers will generate a new row indicating that "A < C". All deduc

[SQL] Case-insensitive string prefix matching with parameterized query

2008-09-03 Thread Christopher Maier
Apologies if this posts twice... I've run into issues with the listserv lately. I am implementing an autosuggest-style text input for my site, where a user can start typing the name of a thing (call it a 'Foo'), and get a list of all things whose name starts with the string the user typed.

[SQL] How can you generate a counter for ordered sets?

2007-05-19 Thread Christopher Maier
slowly), but I was wondering if there was a more efficient way to do this kind of thing. Thanks in advance, Christopher Maier ---(end of broadcast)--- TIP 1: if posting/reading through Usenet, please send an appropriate subscribe-nomail command t