Re: [SQL] Date and filling issues

2008-03-20 Thread chester c young
> > A sample of the current results data would be like > datesales > 2008-03-07 100.00 > 2007-03-10 150.00 > 2007-03-18 50.00 > > and what I'm trying to do is fill in the missing dates with sales > values of 0. what I do is have a table called days t

[SQL] Dynamic sql and variable record types

2008-03-20 Thread Erik Jones
Hi, I've been working on a generic date partitioning system and I think I've reached something that can't be done, but I thought I'd post a question to the masses in the hope that I'm missing something. The basic idea of what I'm doing is some userland scripts that will accept a table name

Re: [SQL] compare 2 tables in sql

2008-03-20 Thread Tena Sakai
Hi Jonah, Just a postscript. It is important to check both ways. Because (sometimes) vice versa is not necessarily true. Case in point below: blitzen=> select * from foo blitzen-> except blitzen->select * from moo; alleleid | markerid | value | datecreated | datereplaced --+

Re: [SQL] compare 2 tables in sql

2008-03-20 Thread Tena Sakai
Hi Jonah, > Still, you should UNION the result of > both exceptions into a single result set. Great suggestion. Many thanks. Regards, Tena Sakai [EMAIL PROTECTED] -Original Message- From: Jonah H. Harris [mailto:[EMAIL PROTECTED] Sent: Thu 3/20/2008 12:21 PM To: Tena Sakai Cc: pgsql-

Re: [SQL] compare 2 tables in sql

2008-03-20 Thread Jonah H. Harris
On Thu, Mar 20, 2008 at 1:44 PM, Tena Sakai <[EMAIL PROTECTED]> wrote: > Just a postscript. It is important to check > both ways. Because (sometimes) vice versa is > not necessarily true. Case in point below: Yes, I'm well aware of that. Still, you should UNION the result of both exceptions

Re: [SQL] Rollback locks table - why?

2008-03-20 Thread Jan Peters
Yes, Tom, it looks like this: Locked Transaction:458553 I misread that. Sorry for that, I am actually a Geographer and just "using" the tools at hand. So I was not clear enough, it is a lock, but it's just the one of the transaction, right. That still does not explain why the Query Editor loc

Re: [SQL] Rollback locks table - why?

2008-03-20 Thread Jan Peters
Hm, Tom, your're right, it works in the console, but not in the editor window, strange... -- Pt! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your s

Re: [SQL] Rollback locks table - why?

2008-03-20 Thread Jan Peters
Hello Tom, > so the problem must be in something you didn't show us. What exactly > are you doing to decide that you need to roll back? Also, none of these > statements (except the CREATE) would take an exclusive lock on test, so > there must be something else going on that you didn't show us.

Re: [SQL] Rollback locks table - why?

2008-03-20 Thread Tom Lane
"Jan Peters" <[EMAIL PROTECTED]> writes: > If I run the transaction block from above again I get first a unique > key violation (that is ok, because that's what I trying to check for) > but there is NO rollback to sp1, only the "Unique Key" error message > and after that I get the dreaded "current

Re: [SQL] Rollback locks table - why?

2008-03-20 Thread Jan Peters
Hello Craig, > > Maybe you should tell the readers of this list a little more about what > you're trying to do and why? > -- ok, so I'll do that: I am programming a small economic Java simulation/serious game that has to calculate the GDP after 12 rounds. For doing this, I need the capital of

Re: [SQL] Select into

2008-03-20 Thread Erik Jones
On Mar 20, 2008, at 7:10 AM, Joe wrote: Gavin 'Beau' Baumanis wrote: The copy is inside the same table, so I don't understand why it (the required query ) would require any joins. Ie. I want to copy the contents of a row (but for the id column - of course) into a record in the same tabl

Re: [SQL] Rollback locks table - why?

2008-03-20 Thread Craig Ringer
Jan Peters wrote: Yes, you are correct: I just want to issue an insertion of a row at the very beginning of an application start. So, when the table "test" is empty, the row with "runde = 0" should be inserted. If this row is already present, it should be updated. This is quite common - yo

Re: [SQL] Select into

2008-03-20 Thread Gurjeet Singh
On Thu, Mar 20, 2008 at 7:08 PM, Joe <[EMAIL PROTECTED]> wrote: > Gurjeet Singh wrote: > > Except that it doesn't work... Did you try to execute that query; I am > > assuming not. > Of course I did, My bad... I did not run your query either, and based my assumption on my previous attempt that ha

Re: [SQL] Rollback locks table - why?

2008-03-20 Thread Jan Peters
Hello Craig, > Jan Peters wrote: > > If I run the transaction block from above again I get first a unique key > violation (that is ok, because that's what I trying to check for) but > there is NO rollback to sp1, only the "Unique Key" error message and after > that > I get the dreaded "current tr

Re: [SQL] Select into

2008-03-20 Thread Joe
Gurjeet Singh wrote: Except that it doesn't work... Did you try to execute that query; I am assuming not. Of course I did, do you think I create results by editing them into my email? The script: delete from t1; insert into t1 values (1, 123, 'first record'); insert into t1 values (2, 456, 's

Re: [SQL] Rollback locks table - why?

2008-03-20 Thread Craig Ringer
Jan Peters wrote: If I run the transaction block from above again I get first a unique key violation (that is ok, because that's what I trying to check for) but there is NO rollback to sp1, only the "Unique Key" error message and after that I get the dreaded "current transaction is aborted" err

[SQL] Rollback locks table - why?

2008-03-20 Thread Jan Peters
Hello list, I am a bit confused. See the code below: BEGIN; SAVEPOINT sp1; INSERT INTO test(id,runde) VALUES(2, 0); --if there is a unique key violstion: ROLLBACK TO sp1; UPDATE test SET id = 1000 WHERE runde = 0; COMMIT; When I first run this statement, I do not get any error message, but also

[SQL] Rollback locks table - why?

2008-03-20 Thread Jan Peters
Hello list, I am a bit confused. See the code below: BEGIN; SAVEPOINT sp1; INSERT INTO test(id,runde) VALUES(2, 0); --if there is a unique key violstion: ROLLBACK TO sp1; UPDATE test SET id = 1000 WHERE runde = 0; COMMIT; When I first run this statement, I do not get any error message, but also

Re: [SQL] Select into

2008-03-20 Thread Craig Ringer
Gurjeet Singh wrote: Except that it doesn't work... Did you try to execute that query; I am assuming not. It does, or at least a query written to work the same way works fine for me. Not only that, but at least in the presence of a unique index the query planner optimises it to the same quer

Re: [SQL] Select into

2008-03-20 Thread Gurjeet Singh
On Thu, Mar 20, 2008 at 5:40 PM, Joe <[EMAIL PROTECTED]> wrote: > Gavin 'Beau' Baumanis wrote: > > > > The copy is inside the same table, so I don't understand why it (the > > required query ) would require any joins. > > > > Ie. I want to copy the contents of a row (but for the id column - of > >

Re: [SQL] Select into

2008-03-20 Thread Joe
Gavin 'Beau' Baumanis wrote: The copy is inside the same table, so I don't understand why it (the required query ) would require any joins. Ie. I want to copy the contents of a row (but for the id column - of course) into a record in the same table. I think what you want is something like

Re: [SQL] Select into

2008-03-20 Thread Craig Ringer
craig=# update x set val = foundrow.val from ( select val from x where id = 2 ) as foundrow where id = 1 ; UPDATE 1 Thinking about it, it'd actually be better written as: UPDATE x SET val = foundrow.val FROM ( SELECT val FROM x AS x2 WHERE x2.id = 2 ) AS foundrow WHERE id = 1; ... be

Re: [SQL] Select into

2008-03-20 Thread Gavin 'Beau' Baumanis
Hi Everyone, I want to thank everyone for their help / suggestions... I really appreciate it. Though I think I have found a winner. craig=# update x set val = foundrow.val from ( select val from x where id = 2 ) as foundrow where id = 1 ; UPDATE 1 Very elegant, very clean... Very nice! T

Re: [SQL] Select into

2008-03-20 Thread Gurjeet Singh
On Thu, Mar 20, 2008 at 5:35 PM, Craig Ringer <[EMAIL PROTECTED]> wrote: > > craig=# explain update x set val = foundrow.val from ( select val from x > where id = 4123 ) as foundrow where id = 5912 ; > Thats nifty. -- [EMAIL PROTECTED] [EMAIL PROTECTED] gmail | hotmail | indiatimes | yahoo }.

Re: [SQL] Select into

2008-03-20 Thread Craig Ringer
Gavin 'Beau' Baumanis wrote: The copy is inside the same table, so I don't understand why it (the required query ) would require any joins. Maybe you should use FROM clause in the update that references a row-valued subquery? craig=# create table x ( id serial, val integer ); NOTICE: CREATE

Re: [SQL] Select into

2008-03-20 Thread Gurjeet Singh
On Thu, Mar 20, 2008 at 4:39 PM, Gavin 'Beau' Baumanis < [EMAIL PROTECTED]> wrote: > HI Gurjeet, > You're right. > > But what information do you need to know? > > The copy is inside the same table, so I don't understand why it (the > required query ) would require any joins. > > Ie. I want to copy

Re: [SQL] Select into

2008-03-20 Thread Greg Sabino Mullane
-BEGIN PGP SIGNED MESSAGE- Hash: RIPEMD160 > Ie. I want to copy the contents of a row (but for the id > column - of course) into a record in the same table. BEGIN; CREATE TEMP TABLE tempfoo AS SELECT * FROM foo WHERE id = 123; UPDATE tempfoo SET id = 456; DELETE FROM foo WHERE id = 456;

Re: [SQL] Select into

2008-03-20 Thread Gavin 'Beau' Baumanis
HI Gurjeet, You're right. But what information do you need to know? The copy is inside the same table, so I don't understand why it (the required query ) would require any joins. Ie. I want to copy the contents of a row (but for the id column - of course) into a record in the same table.

Re: [SQL] Select into

2008-03-20 Thread Gurjeet Singh
On Thu, Mar 20, 2008 at 4:19 PM, A. Kretschmer < [EMAIL PROTECTED]> wrote: > am Thu, dem 20.03.2008, um 20:57:53 +1100 mailte Gavin 'Beau' Baumanis > folgendes: > > Hi Everyone, > > > > I have asked our DBA at work and h is not too sure either... so I > > thought it best to on the list. > > > > B

Re: [SQL] Select into

2008-03-20 Thread A. Kretschmer
am Thu, dem 20.03.2008, um 20:57:53 +1100 mailte Gavin 'Beau' Baumanis folgendes: > Hi Everyone, > > I have asked our DBA at work and h is not too sure either... so I > thought it best to on the list. > > Basically, what I am after is a way to copy the contents of one record > into another.

[SQL] Select into

2008-03-20 Thread Gavin 'Beau' Baumanis
Hi Everyone, I have asked our DBA at work and h is not too sure either... so I thought it best to on the list. Basically, what I am after is a way to copy the contents of one record into another. Something like select into; but where the destination record already exists, as opposed to cr