Re: [SQL] staggered query?

2004-04-21 Thread Denis P Gohel
Hi Try this.. SELECT Col1 , Col2 FROM yourtable WHERE to_number(to_char(col1, 'SS'),'99') / 10 ) in (10,20,30,40,50,00); HTH Denis - Original Message - From: Vincent Ladlad [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, April 21, 2004 8:23 AM Subject: [SQL]

[SQL] Order by YYYY MM DD in reverse chrono order trouble

2004-04-21 Thread ogjunk-pgjedan
Hello, I am trying to select distinct dates and order them in the reverse chronological order. Although the column type is TIMESTAMP, in this case I want only , MM, and DD back. I am using the following query, but it's not returning dates back in the reverse chronological order: SELECT

Re: [SQL] transaction

2004-04-21 Thread Andrew Sullivan
On Tue, Apr 20, 2004 at 09:14:48PM +0200, H.J. Sanders wrote: - BEGIN WORK - INSERT ROW - IF FAILED THEN UPDATE ROW - COMMIT WORK You can do it the other way. Begin, update; if 0 rows are updated then insert. A -- Andrew Sullivan | [EMAIL PROTECTED]

Re: [SQL] Order by YYYY MM DD in reverse chrono order trouble

2004-04-21 Thread Stijn Vanroye
Hello, I am trying to select distinct dates and order them in the reverse chronological order. Although the column type is TIMESTAMP, in this case I want only , MM, and DD back. I am using the following query, but it's not returning dates back in the reverse chronological order:

Re: [SQL] Order by YYYY MM DD in reverse chrono order trouble

2004-04-21 Thread ogjunk-pgjedan
Thank you and Denis ([EMAIL PROTECTED]) - that was it. I needed explicit DESC for each ORDER BY criterium. Otis --- Stijn Vanroye [EMAIL PROTECTED] wrote: Hello, I am trying to select distinct dates and order them in the reverse chronological order. Although the column type is

Re: [SQL] Syntax for cmd to EXEC...how many quotes?

2004-04-21 Thread George Weaver
David, I tend to use \ to escape things like ' - I find it makes it somewhat easier to debug. What about: sql_string :=\' INSERT INTO temp_table ( view_name, row_count ) SELECT \' || r_rec.viewname || \', count(*) FROM \'

[SQL] datediff script

2004-04-21 Thread Erik Aronesty
This is a not-quite complete implementation of the SY/MS sql datediff. The months_between function can be extrapolated from it as well. I looked for it on forums, etc. and all I found were people complaining about the lack of an example. Please post fixes/changes or a link to a better one... if

[SQL] Trigger calling a function HELP ME!

2004-04-21 Thread abief_ag_-postgresql
Hi all, first of all, let me explain what I'm trying to do. I have a table with a fairly complicated trigger. In this trigger I have a specific set of codelines that can be executed in more than 50 places that works on the new.* fields in order to fix/clean them. In order to improve

Re: [SQL] Order by YYYY MM DD in reverse chrono order trouble

2004-04-21 Thread Edmund Bacon
Is there some reason you can't do this: SELECT DISTINCT date_part('year', uu.add_date), date_part('month', uu.add_date), date_part('day', uu.add_date) FROM uus INNER JOIN ui ON uus.user_id=ui.id INNER JOIN uu ON ui.id=uu.user_id WHERE uus.x_id=1 ORDER BY uu.add_date DESC; This might

[SQL] Trigger calling a function HELP ME! (2)

2004-04-21 Thread abief_ag_-postgresql
Sorry. I realize I slipped an error in my code: the code is: --- CREATE TABLE public.imp_test ( id int8, value text ) WITHOUT OIDS; CREATE OR REPLACE FUNCTION public.imp_test_to_out_test(imp_test) RETURNS imp_test AS 'begin return $1; end;' LANGUAGE 'plpgsql'

[SQL] Join issue on a maximum value

2004-04-21 Thread Heflin
OK, it's been a while since I've had to do anything remotely complex in SQL, so this may just be a pure brain block on my part. I have 2 tables, auction and image, defined like this: Table public.auction Column | Type |

[SQL] Server Side C programming Environment Set up

2004-04-21 Thread Kemin Zhou
I read a lot of document and did some search and looked at the source code of postgres but did not find a simple solution to my question. How to set up the programming environment for C. IN chapter 33 Extending SQL 33.7.5 Writing Code when run pg_config --includedir-server I got

[SQL] rule's behavior with join interesting

2004-04-21 Thread Kemin Zhou
Here I have a very simple case table1 table1_removed anotherTable create or replace RULE rec_remove as ON DELETE TO table1 do insert into table1_remove select old.*, a.acc from old g join anotherTable a on g.acc=a.other_acc; === the parser complained ERROR: relation *OLD* does not exist

Re: [SQL] Join issue on a maximum value

2004-04-21 Thread Heflin
Bruno Wolff III wrote: On Wed, Apr 21, 2004 at 14:29:34 -0400, Heflin [EMAIL PROTECTED] wrote: So a basic JOIN gets this: SELECT auction.auction_id, image.image_id, image.image_descr FROM auction JOIN image ON auction.auction_id = image.auction_id WHERE auction.auction_owner = 'Mabel'; Now

Re: [SQL] Join issue on a maximum value

2004-04-21 Thread Edmund Bacon
Two choices that work: Either add another JOIN in which retrieves the MAX(image_id) for each auction: SELECT auction.auction_id, image.image_id, image.image_descr FROM auction JOIN image USING(auction_id) JOIN ( SELECT auction_id, MAX(image_id) AS image_id FROM image

Re: [SQL] Join issue on a maximum value

2004-04-21 Thread Bruno Wolff III
On Wed, Apr 21, 2004 at 16:28:10 -0400, Heflin [EMAIL PROTECTED] wrote: The postgres specific way of doing this is: SELECT DISTINCT ON (auction.auction_id) auction.auction_id, image.image_id, image.image_descr FROM auction JOIN image ON auction.auction_id = image.auction_id WHERE

Re: [SQL] Server Side C programming Environment Set up

2004-04-21 Thread Peter Eisentraut
Kemin Zhou wrote: IN chapter 33 Extending SQL 33.7.5 Writing Code when run pg_config --includedir-server I got /usr/local/pgsql/include/server but my machine does have this directory make install-all-headers It's explained in the installation instructions. ---(end