Re: [SQL] Comparing two tables of different database

2009-05-02 Thread M.P.Dankoor
In case dblink was not installed, you could try the following: 1. dump only the data from the table from database 1 pg_dump -U username -a -d -t tablename dbname > tablename.sql 2. create a (temp) table in database 2 SELECT * INTO tablename_bak from tablename WHERE 1 = 2 3. restore the dumped d

Re: [SQL] How concat 3 strings if 2 are not empty?

2009-02-20 Thread M.P.Dankoor
Andreas, Kretschmer was quite close, try following: case when trim(coalesce(s1,'')) = '' and trim(coalesce(s3,'')) = '' then '' when trim(coalesce(s1,'')) != '' and trim(coalesce(s2,'')) != '' and trim(coalesce(s3,'')) != '' then s1 || s2 || s3 else trim(coalesce(s1,'')) || trim(coalesce

Re: [SQL] I need some magical advice

2009-01-29 Thread M.P.Dankoor
Andreas you could either use the system columns oid or ctid. The ctid will always be available, but the oid will only be available if you created the table with "with oids" syntax( > version 8.0). UPDATE status_table SET status_id = -1 WHERE ctid = (SELECT MIN(RMV.ctid) FROM status_

Re: [SQL] PRIMARY KEY

2007-03-07 Thread M.P.Dankoor
values in this column - ie, if a user cancels after you seect nextval, but before you insert - the value of the sequence has already increased, and will be increased again before returning a value when you next select nextval Cheers, ~p On Wed, 2007-03-07 at 12:57 +0100, M.P.Dankoor wrote: H

Re: [SQL] PRIMARY KEY

2007-03-07 Thread M.P.Dankoor
Hello, Is it possible to redesign your table as follows: create table Mod48_00_2007 ( IDtext, N_GEN serial not null, FORMSTORE text, COD_NOTATIO text, PA_COGNOMEtext, constraint pk_Mod48_00_2007 primary key (N_GEN) ); Your insert simply becomes: INSERT INTO MOD

Re: [SQL] sub-limiting a query

2007-02-17 Thread M.P.Dankoor
Louis-David Mitterrand wrote: Hello, I've got a table of shows with different types (movie, theater, ballet,etc.) and I am looking for a select that can return the 10 last entered shows AND at most 2 of each type. Is that possible in one query? The table looks basically like: created_on

Re: [SQL] sub-limiting a query

2007-02-17 Thread M.P.Dankoor
Louis-David Mitterrand wrote: Hello, I've got a table of shows with different types (movie, theater, ballet,etc.) and I am looking for a select that can return the 10 last entered shows AND at most 2 of each type. Is that possible in one query? The table looks basically like: created_on

Re: [SQL] Conditional SQL Query

2007-01-11 Thread M.P.Dankoor
I think that the simplest solution is to use an union e.g: select PRD.product_code ,PRD.product_name ,NULL::intAS production_no ,PTT.stock_code_to_make_product ,PTT.amount from product PRD ,product_tree_template PTT where 1 = 1 AND PRD.product_code = PTT.