[SQL] Delete with join -- deleting related table entries?

2006-02-08 Thread Bryce Nesbitt
When I delete a record from a certain table, I need to delete a (possibly) attached note as well. How can I do this with postgres? The tables are like this: reservation reservation_id stuff... isuse issue_id reservation_id stuff.. note issue_id text comments... A s

Re: [SQL] Delete with join -- deleting related table entries?

2006-02-08 Thread BigSmoke
I'm not sure if this is true for you as I can't see your complete table definitions, but I'd usually do this by using issue_id INTEGER REFERENCES issue ON DELETE CASCADE in my column definition. See [1] for more information. [1]http://www.postgresql.org/docs/current/interactive/ddl-constraint

Re: [SQL] (NONE)

2006-02-08 Thread BigSmoke
Your question is not clear at all. ---(end of broadcast)--- TIP 1: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to [EMAIL PROTECTED] so that your message can get through to the mailing list cle

Re: [SQL] Delete with join -- deleting related table entries?

2006-02-08 Thread Owen Jacobson
Bryce Nesbitt wrote: > When I delete a record from a certain table, I need to delete a > (possibly) attached note as well. How can I do this with > postgres? The > tables are like this: > > reservation > reservation_id > stuff... > > isuse > issue_id > reservation_id r

Re: [SQL] Delete with join -- deleting related table entries?

2006-02-08 Thread Bryce Nesbitt
BigSmoke wrote: > ...I'd usually do this by using > issue_id INTEGER REFERENCES issue ON DELETE CASCADE > Good, and valuable, thanks! But at the moment I can't change the schema. So is there a way to do a cascaded or joined delete in a sql schema that did not anticipate it? Again, this is d

Re: [SQL] Delete with join -- deleting related table entries?

2006-02-08 Thread Owen Jacobson
Owen Jacobson wrote: > BEGIN; > DELETE FROM note WHERE issue_id IN (SELECT issue_id FROM isuse > WHERE reservation_id = reservation_to_delete); > DELETE FROM isuse WHERE reservation_id = reservation_to_delete; > DELETE FROM reservations WHERE reservation_id = > reservation_to_delete; >

Re: [SQL] regarding debugging?

2006-02-08 Thread BigSmoke
Checking how your PgSQL statements are executed, can be done using EXPLAIN [1]. EXPLAIN ANALYZE will also execute (but not dry-run!) your statement. I work with a seperate development and production database. Once the changes to the schema in the development DB are done, I commit them to the prod

Re: [SQL] Delete with join -- deleting related table entries?

2006-02-08 Thread Bryce Nesbitt
Owen Jacobson wrote: > BEGIN; > DELETE FROM note WHERE issue_id IN (SELECT issue_id FROM isuse > WHERE reservation_id = reservation_to_delete); > DELETE FROM isuse WHERE reservation_id = reservation_to_delete; > DELETE FROM reservations WHERE reservation_id = reservation_to_delete; > COMM

Re: [SQL] Delete with join -- deleting related table entries?

2006-02-08 Thread Markus Schaber
Hi, Bryce, Bryce Nesbitt wrote: > BEGIN; > DELETE FROM note WHERE issue_id IN (SELECT issue_id FROM isuse > WHERE reservation_id IN > (select reservation_id from reservations where date > magic); > DELETE FROM isuse WHERE reservation_id IN > (select reservation_id from reserva

Re: [SQL] Delete with join -- deleting related table entries?

2006-02-08 Thread Owen Jacobson
Bryce Nesbitt wrote: > Owen Jacobson wrote: > > > BEGIN; > > DELETE FROM note WHERE issue_id IN (SELECT issue_id FROM isuse > > WHERE reservation_id = reservation_to_delete); > > DELETE FROM isuse WHERE reservation_id = reservation_to_delete; > > DELETE FROM reservations WHERE reservati

Re: [SQL] Delete with join -- deleting related table entries?

2006-02-08 Thread Bryce Nesbitt
Markus Schaber wrote: > Hi, Bryce, > > Bryce Nesbitt wrote: > > >> BEGIN; >> DELETE FROM note WHERE issue_id IN (SELECT issue_id FROM isuse >> WHERE reservation_id IN >> (select reservation_id from reservations where date > magic) >> ); >> DELETE FROM isuse WHERE reservation_i

Re: [SQL] Delete with join -- deleting related table entries?

2006-02-08 Thread Owen Jacobson
Bryce Nesbitt wrote: > Markus Schaber wrote: > > > Bryce Nesbitt wrote: > > > > > >> BEGIN; > >> DELETE FROM note WHERE issue_id IN (SELECT issue_id FROM isuse > >> WHERE reservation_id IN > >> (select reservation_id from reservations where date > magic) > >> ); > >> DELETE F

[SQL] Non Matching Records in Two Tables

2006-02-08 Thread Ken Hill
I need some help with a bit of SQL. I have two tables. I want to find records in one table that don't match records in another table based on a common column in the two tables. Both tables have a column named 'key100'. I was trying something like: SELECT count(*) FROM table1, table2 WHERE (tab

Re: [SQL] Non Matching Records in Two Tables

2006-02-08 Thread Frank Bax
At 04:10 PM 2/8/06, Ken Hill wrote: I need some help with a bit of SQL. I have two tables. I want to find records in one table that don't match records in another table based on a common column in the two tables. Both tables have a column named 'key100'. I was trying something like: SELECT co

Re: [SQL] Non Matching Records in Two Tables

2006-02-08 Thread Markus Schaber
Hi, Ken, Ken Hill schrieb: > I need some help with a bit of SQL. I have two tables. I want to find > records in one table that don't match records in another table based on > a common column in the two tables. Both tables have a column named > 'key100'. I was trying something like: > > SELECT cou

Re: [SQL] Non Matching Records in Two Tables

2006-02-08 Thread Owen Jacobson
Ken Hill wrote: > I need some help with a bit of SQL. I have two tables. I want > to find records in one table that don't match records in another > table based on a common column in the two tables. Both tables > have a column named 'key100'. I was trying something like: > > SELECT count(*) > FRO

Re: [SQL] Non Matching Records in Two Tables

2006-02-08 Thread Ken Hill
On Wed, 2006-02-08 at 16:27 -0500, Frank Bax wrote: At 04:10 PM 2/8/06, Ken Hill wrote: >I need some help with a bit of SQL. I have two tables. I want to find >records in one table that don't match records in another table based on a >common column in the two tables. Both tables have a colu

[SQL] Syntax for "IF" clause in SELECT

2006-02-08 Thread pgsql
Greetings, the following is an MySQL statement that I would like to translate to PostgreSQL: Could someone point me to a documentation of a coresponding Systax for an "IF" clause in the a SELECT, or is the some other way to do this select  if(spektrum is null,' ','J'),  if(s19 is null,' ','

Re: [SQL] Syntax for "IF" clause in SELECT

2006-02-08 Thread Bricklen Anderson
[EMAIL PROTECTED] wrote: Greetings, the following is an MySQL statement that I would like to translate to PostgreSQL: Could someone point me to a documentation of a coresponding Systax for an "IF" clause in the a SELECT, or is the some other way to do this select if(spektrum is null,' '

[SQL] Column Index vs Record Insert Trade-off?

2006-02-08 Thread Ken Hill
Is there a performance trade-off between column indexes and record inserts? I know that in MS Access there is such a trade-off. This being indexes make SQL queries perform faster at the cost of record insert speed. Put another way, the more column indexes in a table, the slower a record insert

[SQL] unique constraint instead of primary key? what disadvantage(ODBC usage)?

2006-02-08 Thread george young
[PostgreSQL 8.1.0 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 4.0.1] I'm designing a completely new schema for my database. A major criterion is that it facilitate ad-hoc queries via MS-access, excel and OpenOffice, presumably with ODBC. My question regards the use of UNIQUE constraints inste

Re: [SQL] Syntax for "IF" clause in SELECT

2006-02-08 Thread Ken Hill
This has been something I've been trying do so that I can do some column comparisons as part of "data-cleaning" work. I'll let you know if this helps me accomplish my task! On Wed, 2006-02-08 at 15:20 -0800, Bricklen Anderson wrote: [EMAIL PROTECTED] wrote: > Greetings, > > the following is

Re: [SQL] unique constraint instead of primary key? what

2006-02-08 Thread Ken Hill
On Wed, 2006-02-08 at 21:04 -0500, george young wrote: [PostgreSQL 8.1.0 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 4.0.1] I'm designing a completely new schema for my database. A major criterion is that it facilitate ad-hoc queries via MS-access, excel and OpenOffice, presumably with O

Re: [SQL] unique constraint instead of primary key? what

2006-02-08 Thread george young
On Wed, 08 Feb 2006 18:34:22 -0800 Ken Hill <[EMAIL PROTECTED]> threw this fish to the penguins: > On Wed, 2006-02-08 at 21:04 -0500, george young wrote: > > > [PostgreSQL 8.1.0 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 4.0.1] > > I'm designing a completely new schema for my database. A ma