Re: [SQL] DateDiff() function

2013-07-10 Thread Gavin Flower
On 11/07/13 17:17, Huan Ruan wrote: Hi Guys We are migrating to Postgres. In the current system, we use datediff() function to get the difference between two dates, e.g. datediff (month, cast('2013-01-01' as timestamp), cast('2013-02-02' as timestamp) returns 1. I understand that Postgres h

Re: [SQL] Advice for index design

2013-04-10 Thread Gavin Flower
On 11/04/13 10:30, JORGE MALDONADO wrote: I have a table of artists with fields like the ones below: * Name * Birthday * Sex (male/female) Our application offers a catalog of artists where a user can select a range of birthdays and/or sex. For example, a user can get an artists catalog for th

Re: [SQL] strange corruption?

2012-12-27 Thread Gavin Flower
On 28/12/12 05:44, John Fabiani wrote: On 12/27/2012 08:21 AM, Gavin Flower wrote: On 28/12/12 03:27, John Fabiani wrote: Hi, I have the following statement in a function. UPDATE orderseq SET orderseq_number = (orderseq_number + 1) WHERE (orderseq_name='InvcNumber'); A

Re: [SQL] strange corruption?

2012-12-27 Thread Gavin Flower
On 28/12/12 03:27, John Fabiani wrote: Hi, I have the following statement in a function. UPDATE orderseq SET orderseq_number = (orderseq_number + 1) WHERE (orderseq_name='InvcNumber'); All it does is update a single record by incrementing a value (int). But it never completes. Thi

Re: [SQL] checking the gaps in intervals

2012-10-12 Thread Gavin Flower
On 07/10/12 14:30, Jasen Betts wrote: On 2012-10-05, Anton Gavazuk wrote: Hi dear community, Have probably quite simple task but cannot find the solution, Imagine the table A with 2 columns start and end, data type is date start end 01 dec. 10 dec 11 dec. 13 dec 17 dec.

Re: [SQL] checking the gaps in intervals

2012-10-08 Thread Gavin Flower
On 06/10/12 11:42, Anton Gavazuk wrote: Hi dear community, Have probably quite simple task but cannot find the solution, Imagine the table A with 2 columns start and end, data type is date start end 01 dec. 10 dec 11 dec. 13 dec 17 dec. 19 dec . If I have interval, fo

Re: [SQL] checking the gaps in intervals

2012-10-08 Thread Gavin Flower
On 06/10/12 11:42, Anton Gavazuk wrote: Hi dear community, Have probably quite simple task but cannot find the solution, Imagine the table A with 2 columns start and end, data type is date start end 01 dec. 10 dec 11 dec. 13 dec 17 dec. 19 dec . If I have interval, fo

Re: [SQL] ORDER BY COLUMN_A, (COLUMN_B or COLUMN_C), COLUMN_D

2012-09-12 Thread Gavin Flower
On 13/09/12 09:44, Rodrigo Rosenfeld Rosas wrote: This is my first message in this list :) I need to be able to sort a query by column A, then B or C (which one is smaller, both are of the same type and table but on different left joins) and then by D. How can I do that? Thanks in advance, Rod

Re: [SQL] Unable To Modify Table

2012-01-14 Thread Gavin Flower
On 13/01/12 05:56, David Johnston wrote: [...] Contrary to my earlier advice assigning a sequential ID (thus using a numeric TYPE) is one of the exceptions where you can use a number even though you cannot meaningfully perform arithmetic on the values. The reason you would use a numeric value in

Re: [SQL] sorting months according to fiscal year

2011-08-22 Thread Gavin Flower
On 23/08/11 01:27, Enzen user wrote: Hi I have to rearrange the months according to the fiscal year i.e from April to march and use the same in the order by clause of a query. I have written the following postgresql function for the same, but to_number is returning an error. Can you please tell

Re: [SQL] using explain output within pgsql

2011-07-13 Thread Gavin Flower
On 11/07/11 08:18, Pavel Stehule wrote: 2011/7/10 Uwe Bartels: Hi Pavel, is it posible to get this running even with dynamic sql? I didn't write that. I'm using execute to run this create table probably yes postgres=# do $$ declare x text; begin execute e'explain(format yaml) select *

Re: [SQL] interesting sequence (Correctin)

2011-07-07 Thread Gavin Flower
On 06/07/11 21:47, Gavin Flower wrote: I forgot the format required of the order number, so to get the full yesr, I should have used: to_char(day, 'MMDD') [...] v_order_num := type::text || '-' ||

Re: [SQL] interesting sequence

2011-07-06 Thread Gavin Flower
On 06/07/11 01:52, John Fabiani wrote: Hi, I have a special need to create a sequence like function. "O-20110704 -2" which is "O" for order (there are other types) "20110704" is for July 4, 2011 '2' the second order of the day for July 4, 2011 I of course can get the type and date. What I do

Re: [SQL] selecting records X minutes apart

2011-06-13 Thread Gavin Flower
How about this (that does not require special functions nor triggers: DROP TABLE IF EXISTS val; CREATE TABLE val ( id int, ts timestamp ); INSERT INTO val VALUES (0, '1-Jan-2010 20:00'), (1, '1-Jan-2010 20:03'), (1, '1-Jan-2010 20:04'), (0, '1-Jan-2010 20:05'),