[SQL] after delete trigger behavior

2005-06-22 Thread Russell Simpkins
Hello, I have created a trigger function to update the sort_order column of a mapping table. I have table a that has a many to many relation ship with table b that is mapped as a_b where a_id, and b_id are the pk columns and there is a sort_order column. Since a_b is a mapping table there are

Re: [SQL] after delete trigger behavior

2005-06-22 Thread Russell Simpkins
I suspect that if you read the spec carefully it would want a "triggered data change violation" error raised here. My advice is not to use a BEFORE trigger for this. What would you recommend then. I am using Hibernate in my java application and if the sort_order column (in this example colum

Re: [SQL] after delete trigger behavior

2005-06-22 Thread Russell Simpkins
.flash_id || ''''; sort := sort +1; END IF; END LOOP; END LOOP; RETURN OLD; END; ' language 'plpgsql'; that I will rejigger to the test table and try out. Thanks for the input. From: Tom Lane <[EMAIL PROTECTED]

Re: [SQL] after delete trigger behavior

2005-06-23 Thread Russell Simpkins
After delete worked and the a foreach execute update seems to work best. Below is a satisfactory test set. -- create test table CREATE TABLE test1 ( a int, b int, c int); -- create resort function CREATE OR REPLACE FUNCTION resort_test1() RETURNS TRIGGER AS ' DECLARE eachrow RECORD; innerrow

Re: [SQL] Grouping Too Closely

2005-06-23 Thread Russell Simpkins
I'm not sure if this is the best thing to do in all occasions, but I have found a great speed increase using unions over group by. select fkey, uid, seq2 from mytable where seq2 > 2 and seq1 = ( select min(seq1) from mytable); union select fkey, uid, seq2 from mytable where seq2 > 2 and seq1 =

Re: [SQL] ORDER records based on parameters in IN clause

2005-06-29 Thread Russell Simpkins
>> when I say >> select * from table where id IN (2003,1342,799, 1450) >> I would like the records to be ordered as 2003, 1342, 799, 1450. >Just say: >select * from table where id IN (2003,1342,799, 1450) ORDER BY id; >If that doesn't work, you will have to be more specific and send us the exact qu

Re: [SQL] ORDER records based on parameters in IN clause

2005-06-29 Thread Russell Simpkins
fair enough. but a simple order by id would never work. From: Michael Fuhr <[EMAIL PROTECTED]> To: Russell Simpkins <[EMAIL PROTECTED]> CC: pgsql-sql@postgresql.org Subject: Re: [SQL] ORDER records based on parameters in IN clause Date: Wed, 29 Jun 2005 05:57:23 -0600 On Wed, Jun

Re: [SQL] Number of rows in a cursor ?

2005-08-24 Thread Russell Simpkins
[EMAIL PROTECTED] wrote: You cannot count the number of rows in a cursor, unfortunately. I recently ran in to this problem. How sad, then I have to repeat the query, first for counting and last for data fetch :-( /BL If you need a count, why not just execute one of the methods to get a c

Re: [SQL] SQLException - SET AUTOCOMMIT TO OFF is no longer supported

2005-08-24 Thread Russell Simpkins
  16:09:37,093 WARN  [TransactionImpl] XAException: tx=TransactionImpl:XidImpl [FormatId=257, GlobalId=dinesh//1, BranchQual=] errorCode=XA_UNKNOWN(0) org.jboss.resource.connectionmanager.JBossLocalXAException: Error trying to start local tx: ; - nested throwable: (org.jb

Re: [SQL] SQLException - SET AUTOCOMMIT TO OFF is no longer supported

2005-08-24 Thread Russell Simpkins
  I have created datasource but getting this error on JBOSS startup.   Using: PostgreSQL 8.0 JBOSS: JBOSS-3.2.6   16:09:37,093 WARN  [TransactionImpl] XAException: tx=TransactionImpl:XidImpl [FormatId=257, GlobalId=dinesh//1, BranchQual=] errorCode=XA_UNKNOWN(0)

Re: [SQL] Tidying values on variable instantiation

2005-08-26 Thread Russell Simpkins
Desired Outcome(s): * I would like to have the convenience of declaring a column that obeys a constraint (similar to using a domain), but allows a "tidy-up" as the value is created BEFORE asserting the constraint. This *might* be termed a "domain trigger". (Perhaps even a WORM is possible!).

Re: [SQL] Help with multistage query

2005-09-07 Thread Russell Simpkins
  I have a perl script that issues a series of SQL statements to perform some queries.  The script works, but I believe there must be a more elegant way to do this.   The simplified queries look like this:   SELECT id FROM t1 WHERE condition1;   ;returns about 2k record

Re: [SQL] Primary and Foreign Key?

2005-09-22 Thread Russell Simpkins
This is valid ddl to accomplish what you wish. create table peoplegroups { peopleid int not null, groupid int not null, primary key (peopleid, groupid), foreign key (peopleid) references people, foreign key (groupid) references group } Check the docs for other options etc. From: "Announce" <[

Re: [SQL] Scripting GRANT on functions

2005-10-06 Thread Russell Simpkins
You could continue with this function, with an additional cursor to get the parameters for the function. If this is a one off thing, that you just need to do once, you could use pg_dump to get the create function statements and then simply alter them with an re in your favorite editor.   Yo

Re: [SQL] Design problemi : using the same primary keys for inherited objects.

2005-10-14 Thread Russell Simpkins
- Original Message - i've got a strange design question to ask you.It's something I couldn't answer to while feeling confusely it was anabsolutely BAD thing to do.For our application, we have developed our own framework which sits ontop of PostgreSQL. It uses object progr

Re: [SQL] Design problem : using the same primary keys for inherited objects.

2005-10-14 Thread Russell Simpkins
Thanks Russ, but well... It doesn't help me a lot. Our needs seem to allow that we use an id as primary key and foreign key at the same time. What i fear more is that it be against a good database design practice, because leading to potential problems. I give a clearer example : CREATE TABLE act