Re: [despammed] [SQL] Duplicated records

2005-05-24 Thread Andreas Kretschmer
am 24.05.2005, um 17:59:31 -0300 mailte [EMAIL PROTECTED] folgendes: > Hi. > How can I delete the duplicated records with "DELETE FROM TABLE WHERE..." > clause?? Please read http://www.gtsm.com/oscon2003/deletetid.html Its a very good article about this problem. Regards, Andreas -- Andreas Kr

Re: [SQL] DROP IF ...

2005-05-24 Thread Thomas F. O'Connell
The following function takes a table name as a parameter and drops the table and returns true if there are zero rows (otherwise, it returns false): CREATE OR REPLACE FUNCTION dropzero( varchar ) RETURNS bool AS ' DECLARE zerotable ALIAS FOR $1; zerocurs refcursor; rowc

Re: [SQL] Duplicated records

2005-05-24 Thread PFC
How can I delete the duplicated records with "DELETE FROM TABLE WHERE..." clause?? The problem is becouse I have imported data from Dbase (dbf) file, and this function have not built the Constraint (unique, primary key, ...), and this function is usually executed. If you have no primary

[SQL] Duplicated records

2005-05-24 Thread lucas
Hi. How can I delete the duplicated records with "DELETE FROM TABLE WHERE..." clause?? The problem is becouse I have imported data from Dbase (dbf) file, and this function have not built the Constraint (unique, primary key, ...), and this function is usually executed. select * from table1; --id m

Re: [SQL] Tip ?

2005-05-24 Thread Scott Marlowe
On Tue, 2005-05-24 at 13:26, Alain wrote: > This tip was at the end of a message (from Szűcs Gábor). > > > TIP 9: the planner will ignore your desire to choose an index scan if your > > joining column's datatypes do not match > > it looks very important, but I cannot understand it. Sound as

Re: [SQL] could not devise a query plan

2005-05-24 Thread Tom Lane
=?ISO-8859-2?Q?Sz=FBcs_G=E1bor?= <[EMAIL PROTECTED]> writes: > ABSTRACT: The following query fails. > SELECT * FROM > (SELECT a,b FROM cdqp WHERE a=1 AND b=2) AS aa > NATURAL FULL JOIN > (SELECT a,b FROM cdqp WHERE a=1 and b=2) AS bb > WHERE a+b = 3; Thanks for

[SQL] Tip ?

2005-05-24 Thread Alain
This tip was at the end of a message (from Szűcs Gábor). TIP 9: the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match it looks very important, but I cannot understand it. Sound as a small and easy mistake that can make things go sour

Re: [SQL] Help: Function for splitting VARCHAR column and migrating its data to 2 new tables

2005-05-24 Thread Tony Wasson
On 5/23/05, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > I am restructuring my DB schema and need help migrating data from 1 > column of an existing table to two new tables. I have some Java code > that can do this for me, but it's very slow, and I am now hoping I can > migrate this data with so

[SQL] DROP IF ...

2005-05-24 Thread CG
PostgreSQL 7.4 ... I'm trying to find a way to drop a table via SQL if it contains 0 rows. Here was my thought: CREATE OR REPLACE FUNCTION dropif(text, bool) RETURNS bool AS 'DECLARE tblname ALIAS FOR $1; condition ALIAS FOR $2; BEGIN IF (condition) THEN EXECUTE(\'DROP TABLE "\' || tb

Re: [SQL] Transaction in plpgslq

2005-05-24 Thread Andrew Hammond
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Rafa Couto wrote: > I understand "FOR UPDATE" clause is locking while is selecting rows > only. It does not secure atomic execution from 'SELECT' to 'UPDATE' in > next statement. Is not it? Locks adhere until the transaction ends. I included links to

Re: [SQL] Transaction in plpgslq

2005-05-24 Thread Richard Huxton
Rafa Couto wrote: I have got a plpgsql function: -- BEGIN; SELECT min(id) INTO _contacto_id FROM contactos WHERE contactos.operadora_id IS NULL AND contactos.actividad_id = _actividad_id; UPDATE contactos SET operadora_id = _operadora_id WHERE id = _contacto_id; -- COMMI

Re: [SQL] could not devise a query plan

2005-05-24 Thread Szűcs Gábor
Dear Gnanavel, (please reply to the lists...) Indeed it works! Still, I think it's a bug. As for this solution being a workaround, it's a bit of pain, since the subselect names (effectively, the included subselects) are not constant. As for my workaround, I used a condition to not include t

Re: [SQL] Transaction in plpgslq

2005-05-24 Thread Jan B.
Rafa Couto wrote: 2005/5/20, Andrew Hammond <[EMAIL PROTECTED]>: The solution to your problem is locking (or concurrency control if you prefer). While we're at it, we might as well optimize your statement a little too using ORDER BY with LIMIT instead of min(). SELECT id INTO _contacto_id FRO

Re: [SQL] could not devise a query plan

2005-05-24 Thread Szűcs Gábor
Dear Gurus, Sorry for upping a 13-month-old thread; please tell if I should've opened another one. Here I come again, with another silly join. Please forgive me, but our queries are built from blocks :) VERSION: 7.4.6, 7.4.8, 8.0.0rc4 (sorry, no newer installed right now) ABSTRACT: The fol

Re: [SQL] Transaction in plpgslq

2005-05-24 Thread Rafa Couto
2005/5/20, Andrew Hammond <[EMAIL PROTECTED]>: > The solution to your problem is locking (or concurrency control if you > prefer). While we're at it, we might as well optimize your statement a > little too using ORDER BY with LIMIT instead of min(). > > SELECT id INTO _contacto_id > FROM contacto

Re: [SQL] datatype conversion on postgresql 7.4.1

2005-05-24 Thread Richard Huxton
Timo Roessner wrote: and if i try something like: alter table fragment alter column x type numeric(15,2) i get an syntax error, so this seems to be no feature in 7.4.1 (didnt find anything like that in the docs too) what can i do to solve this? there must be some way in postgresql 7.4.1