Re: [SQL] subselect prob in view

2004-06-22 Thread Gary Stainburn
On Monday 21 Jun 2004 4:11 pm, Gary Stainburn wrote: > On Monday 21 Jun 2004 3:19 pm, Tom Lane wrote: > > Gary Stainburn <[EMAIL PROTECTED]> writes: > > > from requests r, users u, request_types t, > > > request_states s, dealerships d, departments de, customers c > > > lef

Re: [SQL] subselect prob in view

2004-06-22 Thread Stephan Szabo
On Tue, 22 Jun 2004, Gary Stainburn wrote: > On Monday 21 Jun 2004 4:11 pm, Gary Stainburn wrote: > > On Monday 21 Jun 2004 3:19 pm, Tom Lane wrote: > > > Gary Stainburn <[EMAIL PROTECTED]> writes: > > > > from requests r, users u, request_types t, > > > > request_states s, dealersh

Re: [SQL] subselect prob in view

2004-06-22 Thread Tom Lane
Gary Stainburn <[EMAIL PROTECTED]> writes: > The two selects work seperately, but I'm still getting the > syntax for the combined quiery wrong. What you've got here reduces to select co.co_r_id, co.count as com_count, cor.count as com_unseen from (select ...) co, (select ...) cor on co.co_

Re: [SQL] plpgsql - Insert from a record variable?

2004-06-22 Thread Phil Endecott
Phil> execute ''column_values := Phil> column_values || quote_literal(r.'' || cr.column_name || '')''; basic> FOR rec IN EXECUTE basic> ''select column_values || quote_literal(r.'' || basic> cr.column_name || '') alias column_values''; LOOP basic> column_values := rec.column_values; basi

[SQL] matching rows differing only by fkey,pkey

2004-06-22 Thread Matthew Nuzum
I'm duplicating some fields in the table but the duplicates will have a new primary key and a new foreign key. For example, Table "b" looks like this: bid (pkey default value is a sequence) aid (fkey) field1 field2 field3 INSERT INTO b (aid, field1, field2, field3) SELECT 23, field1, fiel

Re: [SQL] matching rows differing only by fkey,pkey

2004-06-22 Thread Richard Huxton
Matthew Nuzum wrote: When the relationships are one to one or one to many this process is easy, however sometimes there's a many to many relationship. It seems that a helpful tool would be a query that can return just the pkey of the original record copied from and the pkey of the newly created rec

Re: [SQL] matching rows differing only by fkey,pkey

2004-06-22 Thread Bruno Wolff III
On Tue, Jun 22, 2004 at 12:34:35 -0400, Matthew Nuzum <[EMAIL PROTECTED]> wrote: > Any ideas? If someone has an alternate method of achieving the same result > I'd be excited to hear about it. A more precise formulation of what exactly you are doing might be helpful. >From your description it so

Re: [SQL] matching rows differing only by fkey,pkey

2004-06-22 Thread Matthew Nuzum
Thanks for your suggestion to use curval(), that will be useful. I'd entirely forgotten about that function. That likely will help when combined with Richard's suggestion and an idea I already had. I'm sorry that the problem wasn't clearer. The best way I can describe it is like this: The end

Re: [SQL] matching rows differing only by fkey,pkey

2004-06-22 Thread Richard Huxton
Bruno Wolff III wrote: On Tue, Jun 22, 2004 at 13:40:03 -0400, Matthew Nuzum <[EMAIL PROTECTED]> wrote: The end result is to duplicate the data for a particular record in table "a" so that all of it's related data in tables "b" and "c" is duplicated. Where "b" is the middle table in a many to m