[SQL] Intersection of two date interval

2007-01-26 Thread Suha Onay
Hi, How can i find the number of days in the intersection of 2 date interval? For example: 1st interval: (10.01.2007, 20.01.2007) 2nd interval: (13.01.2007, 21.01.2007) The intersection dates are: 13,14,15,16,17,18,19, 20 The result is: 8 How can i find the result, 8 in an sql query without usi

Re: [SQL] Intersection of two date interval

2007-01-26 Thread A. Kretschmer
am Fri, dem 26.01.2007, um 11:39:03 +0200 mailte Suha Onay folgendes: > Hi, > > How can i find the number of days in the intersection of 2 date interval? > For example: > 1st interval: (10.01.2007, 20.01.2007) > 2nd interval: (13.01.2007, 21.01.2007) > The intersection dates are: 13,14,15,16,17,

Re: [SQL] Intersection of two date interval

2007-01-26 Thread Achilleas Mantzios
Στις Παρασκευή 26 Ιανουάριος 2007 11:50, ο/η A. Kretschmer έγραψε: > am Fri, dem 26.01.2007, um 11:39:03 +0200 mailte Suha Onay folgendes: > > Hi, > > > > How can i find the number of days in the intersection of 2 date interval? > > For example: > > 1st interval: (10.01.2007, 20.01.2007) > > 2nd

[SQL] implementing (something like) UNIQUE constraint using PL/pgSQL

2007-01-26 Thread Tomas Vondra
Hello, in our application we need to implement a constraint that enforces 'at most N rows with this value', that is we have a table with 'flag' column and for each value there should be at most 10 rows (for example, the exact number does not matter). I'm trying to implement a PL/pgSQL trigge

Re: [SQL] Using Temporary Tables in postgres functions

2007-01-26 Thread Mario Splivalo
On Thu, 2007-01-25 at 08:03 -0800, Stephan Szabo wrote: > On Thu, 25 Jan 2007, Mario Splivalo wrote: > > > When I try to use TEMPORARY TABLE within postgres functions (using 'sql' > > as a function language), I can't because postgres can't find that > > temporary table. Consider this example: > >

Re: [SQL] Using Temporary Tables in postgres functions

2007-01-26 Thread Mario Splivalo
On Thu, 2007-01-25 at 11:00 -0500, Andrew Sullivan wrote: > On Thu, Jan 25, 2007 at 03:39:14PM +0100, Mario Splivalo wrote: > > When I try to use TEMPORARY TABLE within postgres functions (using 'sql' > > as a function language), I can't because postgres can't find that > > temporary table. Conside

Re: [SQL] Using Temporary Tables in postgres functions

2007-01-26 Thread Mario Splivalo
On Thu, 2007-01-25 at 11:09 -0500, Tom Lane wrote: > Mario Splivalo <[EMAIL PROTECTED]> writes: > > Am I doing something wrong here, or there is no way of using temporary > > tables within 'sql' written functions? > > I believe the problem is that for a SQL function we parse the whole > function b

[SQL] Evaluate a variable

2007-01-26 Thread Luís Sousa
Hi, Is there anyway to evaluate a variable in plpgsql, like eval on PHP? Suppose the example: my_var:=''some value!''; a:=''my_var''; b:= a; I already tried b:=EXECUTE a; without luck! Best regards, Luís Sousa ---(end of broadcast)--- TIP 3: Ha

Re: [SQL] LEFT Join Question

2007-01-26 Thread Andrew Sullivan
On Thu, Jan 25, 2007 at 06:51:34PM -0500, Rob V wrote: > > I know I have to use a left join - but I can seem to figure out the syntax > when dealing w/ different columns of the same table. I haven't tested this to remind myself for sure that it will work, but I think you ought to be able to RIGHT

Re: [SQL] Evaluate a variable

2007-01-26 Thread Alvaro Herrera
Luís Sousa wrote: > Hi, > > Is there anyway to evaluate a variable in plpgsql, like eval on PHP? > Suppose the example: > > my_var:=''some value!''; > a:=''my_var''; > b:= a; > > I already tried b:=EXECUTE a; without luck! Maybe stashing a SELECT in front? -- Alvaro Herrera

Re: [SQL] LEFT Join Question

2007-01-26 Thread Rob V
Thanks codeWarrior - you got me 99% there - I just needed to add the NULL "trick" on the join w/ the contact_phone and contact_address tables and that got me the results I was after! This is what I the final qry looks like : SELECT A.account_id, A.account_username, V.vendor_contract_signed_date,

Re: [SQL] Using Temporary Tables in postgres functions

2007-01-26 Thread Tom Lane
Mario Splivalo <[EMAIL PROTECTED]> writes: > On Thu, 2007-01-25 at 11:09 -0500, Tom Lane wrote: >> I believe the problem is that for a SQL function we parse the whole >> function body before executing any of it. So you'd need to split this >> into two separate functions. > Having two function com

[SQL] Function returning SETOF using plpythonu

2007-01-26 Thread Luís Sousa
Hi, Is it possible to return rows from a function written in plpythonu using SETOF? Example: CREATE FUNCTION "test_python_setof"() RETURNS SETOF text AS ' records=plpy.execute("SELECT name FROM interface"); return records ' LANGUAGE 'plpythonu'; With this code is returning the object fr

Re: [SQL] Intersection of two date interval

2007-01-26 Thread Bruno Wolff III
On Fri, Jan 26, 2007 at 12:02:24 +0200, Achilleas Mantzios <[EMAIL PROTECTED]> wrote: > Suha, > the function is the number of days in the > maximum of the two start dates , untill , minimum of the two end dates > interval. > But in postgresql (7.4.15 at least) there is no MIN(date,date),MAX(dat

Re: [SQL] Function returning SETOF using plpythonu

2007-01-26 Thread Marcin Stępnicki
Dnia Fri, 26 Jan 2007 17:24:52 +, Luís Sousa napisał(a): > Hi, > > Is it possible to return rows from a function written in plpythonu using > SETOF? > > Example: > CREATE FUNCTION "test_python_setof"() > RETURNS SETOF text AS ' > records=plpy.execute("SELECT name FROM interface"); >

Re: [SQL] [NOVICE] Windows 2K Installation difficulties...

2007-01-26 Thread Oisin Glynn
Neil Bibbins wrote: I'm logging in directly on the machine. The installation gets most of the way through, chokes, and rolls the whole thing back. I've tried altering permissions, but the PostgreSQL installer creates new accounts regardless with just user permissions. It's a mystery. Hmmm..

Re: [SQL] implementing (something like) UNIQUE constraint using PL/pgSQL

2007-01-26 Thread Bruno Wolff III
On Fri, Jan 26, 2007 at 10:41:26 +0100, Tomas Vondra <[EMAIL PROTECTED]> wrote: > > in our application we need to implement a constraint that enforces 'at > most N rows with this value', that is we have a table with 'flag' column > and for each value there should be at most 10 rows (for exampl