Re: [SQL] Updating a specific number of rows in pl/pgsql

2009-08-11 Thread D'Arcy J.M. Cain
On Mon, 10 Aug 2009 17:52:36 -0700
"Peter Headland"  wrote:
> I can get the rows I want to update like this:
> 
>   SELECT *
>FROM queue
>WHERE id = p_queue_id
>ORDER BY rank
>LIMIT p_number_of_items;
> 
> Of course, there may not be p_number_of_items available in the queue.
> 
> I want to update all the rows in the cursor in the same way:
> 
>   UPDATE queue SET assigned = TRUE;

Assuming that there is a unique identifier on queue, let's call it
queue_id, you should be able to do something like this:

  UPDATE queue SET assigned = TRUE
  WHERE queue_id IN (SELECT queue_id
FROM queue
WHERE id = p_queue_id
ORDER BY rank
LIMIT p_number_of_items);

-- 
D'Arcy J.M. Cain  |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.

-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql


Re: [SQL] Updating a specific number of rows in pl/pgsql

2009-08-11 Thread Pavel Stehule
2009/8/11 D'Arcy J.M. Cain :
> On Mon, 10 Aug 2009 17:52:36 -0700
> "Peter Headland"  wrote:
>> I can get the rows I want to update like this:
>>
>>   SELECT *
>>    FROM queue
>>    WHERE id = p_queue_id
>>    ORDER BY rank
>>    LIMIT p_number_of_items;
>>
>> Of course, there may not be p_number_of_items available in the queue.
>>
>> I want to update all the rows in the cursor in the same way:
>>
>>   UPDATE queue SET assigned = TRUE;
>
> Assuming that there is a unique identifier on queue, let's call it
> queue_id, you should be able to do something like this:
>
>  UPDATE queue SET assigned = TRUE
>  WHERE queue_id IN (SELECT queue_id
>    FROM queue
>    WHERE id = p_queue_id
>    ORDER BY rank
>    LIMIT p_number_of_items);
>

there are one fast trick
http://www.postgres.cz/index.php/PostgreSQL_SQL_Tricks#Fast_first_n_rows_removing

p.s. replace DELETE by UPDATE
regards
Pavel Stehule

> --
> D'Arcy J.M. Cain          |  Democracy is three wolves
> http://www.druid.net/darcy/                |  and a sheep voting on
> +1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>

-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql


[SQL] Re: Determining logically unique entities across many partially complete rows where at least one column matches

2009-08-11 Thread Jasen Betts
On 2009-08-11, Jamie Tufnell  wrote:
> Hi,
>
> I am faced with a modeling problem and thought I'd see if anyone has run
> into something similar and can offer some advice.
>
> Basically my problem domain is cataloguing "snippets of information" about
> "entities" which are loosely identified.
>
> Entities can be identified up to 3 different methods (email, phone or
> openid.)
>
> Entities can have zero or many emails, phone numbers and openids.  The
> only restriction is they must have at least one value in one of those three
> columns.
>
>
> Some sample data:
>
> snippet #1
> email: null
> phone: +1234567890
> openid: j...@myopenid.net
> information: This is snippet #1
>
> snippet #2
> email: f...@bar.com
> phone: null
> openid: johnny.name
> information: This is snippet #2
>
> At this point snippet #1 and #2 could refer to different entities.
>
> snippet #3
> email: b...@baz.com
> phone: +1234567890
> openid: johnny.name
> information: This is snippet #3
>
> But now all three snippets definitely refer to the same entity, as far as
> we're concerned:
>
> Entity: 1
> OpenIDs: johnny.name, j...@myopenid.net
> Phones: +1234567890
> Emails: f...@bar.com, b...@baz.com
>
> So as far as modeling this goes, I'm stuck between:
>
> 1. Normalizing as usual with some serious triggers to maintain the
>relationships.
> 2. Just having a snippets table with these fields inline and make these
>inferences at query time.
> 3. Something in between.
> 4. Using a document store like CouchDB.


I think three tables openid,email, phone  
(phone's a bad one for a unique id IME, especially POTS lines) 

create table (entid integer, phone text unique)

 etc,etc...

then at insert time you use a rule that runs a function 
with exception handling when the unique rules detect a match with some
existing data and then in the exception code you do updates to replace
the higher entid with the lower one 


> The kinds of queries I need to do right now (which will no doubt change):
>
> * Return all snippets.
> * Return all distinct entities.
> * Find all id for a distinct entity given a single piece of id.
> * Find all snippets for a distinct entity.
>
> To do it in one table, I am thinking something like this:
>
> create table snippets (
>   id serial not null primary key,
>   email text,
>   phone_number text,
>   openid text,
>   information text not null,
>   check (email is not null or
>  phone_number is not null or openid is not null)
> );
>
> with queries like:
>
> * Find all snippets for one distinct entity, searching by openid:
>
> select * from snippets
> where phone_number =
>   (select phone_number from snippets where openid = 'j...@myopenid.net')
> or email =
>   (select email from snippets where openid = 'j...@myopenid.net')
> or openid in
>   (select openid from snippets
>where phone_number =
> (select phone_number from snippets where openid = 'j...@myopenid.net')
>or email =
>(select email from snippets where openid = 'j...@myopenid.net'));

but that won't get them all.

> Or if I was to model as usual I am thinking something like this:
>
> create table entities (
>   id serial not null primary key
> );
>
> create table entity_has_email (
>   entity_id integer not null
> references entities (id) on delete cascade on update cascade,
>   email text not null unique
> );
>
> create table entity_has_phone_number (
>   entity_id integer not null
> references entities (id) on delete cascade on update cascade,
>   phone_number text not null unique
> );
>
> create table entity_has_openid (
>   entity_id integer not null
> references entities (id) on delete cascade on update cascade,
>   openid text not null unique
> );
>
> create table snippets (
>   id serial not null primary key,
>   entity_id integer not null
> references entities (id) on delete cascade on update cascade,
>   information text not null
> );
>
> (followed by a mass of on insert/update/delete triggers)

>
> select s.* from snippets s
>   join entity_has_email e on s.entity_id = e.id
>   join entity_has_phone_number p on s.entity_id = p.id
>   join entity_has_openid o on s.entity_id = o.id
> where o.openid = 'j...@myopenid.net';

looks like the wrong query for snippets to me.

 select s.* from snippets s
   join entity_has_openid o on s.entity_id = o.id
 where o.openid = 'j...@myopenid.net';

> Another option, sort of half way between the two could be:
>
> create table snippets (
>   id serial not null primary key,
>   entity_id integer not null
> references entities (id) on delete cascade on update cascade,
>   information text not null
> );
>
> create table entities (
>   id serial not null primary key,
>   email text,
>   phone_number text,
>   openid text,
>   check (email is not null or
>  phone_number is not null or openid is not null)
> );

that's not going to work with your example data.
(subject has two different email addresses)

I guess you could use arrays for email, openid, and phone.


-- 
Sent 

Re: [SQL] Determining logically unique entities across many partially complete rows where at least one column matches

2009-08-11 Thread Rob Sargent
Seems to me that if you can safely identify which snippets correspond to 
a given entity you want a single id for the entity.  An entity-snippet 
relationship seems a must. I would not lean too heavily on a single 
table solution unless you're considering arrays for openid,email and 
phone.  (And given the one-to-many-real-people on phone I would be leery 
of this "identifier".)


Jamie Tufnell wrote:

Hi,

I am faced with a modeling problem and thought I'd see if anyone has run
into something similar and can offer some advice.

Basically my problem domain is cataloguing "snippets of information" about
"entities" which are loosely identified.

Entities can be identified up to 3 different methods (email, phone or
openid.)

Entities can have zero or many emails, phone numbers and openids.  The
only restriction is they must have at least one value in one of those three
columns.


Some sample data:

snippet #1
email: null
phone: +1234567890
openid: j...@myopenid.net
information: This is snippet #1

snippet #2
email: f...@bar.com
phone: null
openid: johnny.name
information: This is snippet #2

At this point snippet #1 and #2 could refer to different entities.

snippet #3
email: b...@baz.com
phone: +1234567890
openid: johnny.name
information: This is snippet #3

But now all three snippets definitely refer to the same entity, as far as
we're concerned:

Entity: 1
OpenIDs: johnny.name, j...@myopenid.net
Phones: +1234567890
Emails: f...@bar.com, b...@baz.com

So as far as modeling this goes, I'm stuck between:

1. Normalizing as usual with some serious triggers to maintain the
   relationships.
2. Just having a snippets table with these fields inline and make these
   inferences at query time.
3. Something in between.
4. Using a document store like CouchDB.

The kinds of queries I need to do right now (which will no doubt change):

* Return all snippets.
* Return all distinct entities.
* Find all id for a distinct entity given a single piece of id.
* Find all snippets for a distinct entity.

To do it in one table, I am thinking something like this:

create table snippets (
  id serial not null primary key,
  email text,
  phone_number text,
  openid text,
  information text not null,
  check (email is not null or
 phone_number is not null or openid is not null)
);

with queries like:

* Find all snippets for one distinct entity, searching by openid:

select * from snippets
where phone_number =
  (select phone_number from snippets where openid = 'j...@myopenid.net')
or email =
  (select email from snippets where openid = 'j...@myopenid.net')
or openid in
  (select openid from snippets
   where phone_number =
(select phone_number from snippets where openid = 'j...@myopenid.net')
   or email =
(select email from snippets where openid = 'j...@myopenid.net'));


Or if I was to model as usual I am thinking something like this:

create table entities (
  id serial not null primary key
);

create table entity_has_email (
  entity_id integer not null
references entities (id) on delete cascade on update cascade,
  email text not null unique
);

create table entity_has_phone_number (
  entity_id integer not null
references entities (id) on delete cascade on update cascade,
  phone_number text not null unique
);

create table entity_has_openid (
  entity_id integer not null
references entities (id) on delete cascade on update cascade,
  openid text not null unique
);

create table snippets (
  id serial not null primary key,
  entity_id integer not null
references entities (id) on delete cascade on update cascade,
  information text not null
);

(followed by a mass of on insert/update/delete triggers)

with queries like:

* Find all snippets for a distinct entity, by one identifying field:

select s.* from snippets s
  join entity_has_email e on s.entity_id = e.id
  join entity_has_phone_number p on s.entity_id = p.id
  join entity_has_openid o on s.entity_id = o.id
where o.openid = 'j...@myopenid.net';

Another option, sort of half way between the two could be:

create table snippets (
  id serial not null primary key,
  entity_id integer not null
references entities (id) on delete cascade on update cascade,
  information text not null
);

create table entities (
  id serial not null primary key,
  email text,
  phone_number text,
  openid text,
  check (email is not null or
 phone_number is not null or openid is not null)
);

* Find all snippets for a distinct entity, by openid = 'j...@myopenid.net'

select * from snippets
where entity_id in (
  select id from entities
  where phone_number =
(select phone_number from entities where openid = 'j...@myopenid.net')
  or email =
(select email from entities where openid = 'j...@myopenid.net')
  or openid in
(select openid from entities
 where phone_number =
   (select phone_number from entities where openid = 'j...@myopenid.net'
 or email =
   (select email from entities where openid = 'j...@myopenid.net') ));

Re: [SQL] Updating a specific number of rows in pl/pgsql

2009-08-11 Thread Peter Headland
>Assuming that there is a unique identifier on queue

Alas, there is not. The PK is made up of 4 columns.

-- 
Peter Headland
Architect
Actuate Corporation

-Original Message-
From: D'Arcy J.M. Cain [mailto:da...@druid.net] 
Sent: Tuesday, August 11, 2009 03:25
To: Peter Headland
Cc: pgsql-sql@postgresql.org
Subject: Re: [SQL] Updating a specific number of rows in pl/pgsql

On Mon, 10 Aug 2009 17:52:36 -0700
"Peter Headland"  wrote:
> I can get the rows I want to update like this:
> 
>   SELECT *
>FROM queue
>WHERE id = p_queue_id
>ORDER BY rank
>LIMIT p_number_of_items;
> 
> Of course, there may not be p_number_of_items available in the queue.
> 
> I want to update all the rows in the cursor in the same way:
> 
>   UPDATE queue SET assigned = TRUE;

Assuming that there is a unique identifier on queue, let's call it
queue_id, you should be able to do something like this:

  UPDATE queue SET assigned = TRUE
  WHERE queue_id IN (SELECT queue_id
FROM queue
WHERE id = p_queue_id
ORDER BY rank
LIMIT p_number_of_items);

-- 
D'Arcy J.M. Cain  |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.

-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql


Re: [SQL] Updating a specific number of rows in pl/pgsql

2009-08-11 Thread Peter Headland
> there are one fast trick
> http://www.postgres.cz/index.php/PostgreSQL_SQL_Tricks#Fast_first_n_rows_removing

Thanks - that's a very useful page!

Unfortunately, there is no single column that provides a unique id, and I am 
reluctant to add one (for example, using a sequence and a new index) for 
performance reasons.

Given that additional constraint, is my original plan using a loop to iterate 
over a cursor reasonable? I don't anticipate p_number_of_items being more than 
20.

-- 
Peter Headland
Architect
Actuate Corporation


-Original Message-
From: Pavel Stehule [mailto:pavel.steh...@gmail.com] 
Sent: Tuesday, August 11, 2009 03:55
To: D'Arcy J.M. Cain
Cc: Peter Headland; pgsql-sql@postgresql.org
Subject: Re: [SQL] Updating a specific number of rows in pl/pgsql

2009/8/11 D'Arcy J.M. Cain :
> On Mon, 10 Aug 2009 17:52:36 -0700
> "Peter Headland"  wrote:
>> I can get the rows I want to update like this:
>>
>>   SELECT *
>>    FROM queue
>>    WHERE id = p_queue_id
>>    ORDER BY rank
>>    LIMIT p_number_of_items;
>>
>> Of course, there may not be p_number_of_items available in the queue.
>>
>> I want to update all the rows in the cursor in the same way:
>>
>>   UPDATE queue SET assigned = TRUE;
>
> Assuming that there is a unique identifier on queue, let's call it
> queue_id, you should be able to do something like this:
>
>  UPDATE queue SET assigned = TRUE
>  WHERE queue_id IN (SELECT queue_id
>    FROM queue
>    WHERE id = p_queue_id
>    ORDER BY rank
>    LIMIT p_number_of_items);
>

there are one fast trick
http://www.postgres.cz/index.php/PostgreSQL_SQL_Tricks#Fast_first_n_rows_removing

p.s. replace DELETE by UPDATE
regards
Pavel Stehule

> --
> D'Arcy J.M. Cain          |  Democracy is three wolves
> http://www.druid.net/darcy/                |  and a sheep voting on
> +1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>

-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql


Re: [SQL] Updating a specific number of rows in pl/pgsql

2009-08-11 Thread Pavel Stehule
2009/8/11 Peter Headland :
>> there are one fast trick
>> http://www.postgres.cz/index.php/PostgreSQL_SQL_Tricks#Fast_first_n_rows_removing
>
> Thanks - that's a very useful page!
>
> Unfortunately, there is no single column that provides a unique id, and I am 
> reluctant to add one (for example, using a sequence and a new index) for 
> performance reasons.

ctid is unique system column in every table.

postgres=# create table x(a int);
CREATE TABLE
Time: 655,062 ms
postgres=# insert into x values(10);
INSERT 0 1
Time: 49,237 ms
postgres=# insert into x values(10);
INSERT 0 1
Time: 1,740 ms
postgres=# select ctid, a from x;
 ctid  | a
---+
 (0,1) | 10
 (0,2) | 10
(2 rows)


>
> Given that additional constraint, is my original plan using a loop to iterate 
> over a cursor reasonable? I don't anticipate p_number_of_items being more 
> than 20.

why not? for small number of iteration is loop over cursor good solution.

Pavel Stehule

>
> --
> Peter Headland
> Architect
> Actuate Corporation
>
>
> -Original Message-
> From: Pavel Stehule [mailto:pavel.steh...@gmail.com]
> Sent: Tuesday, August 11, 2009 03:55
> To: D'Arcy J.M. Cain
> Cc: Peter Headland; pgsql-sql@postgresql.org
> Subject: Re: [SQL] Updating a specific number of rows in pl/pgsql
>
> 2009/8/11 D'Arcy J.M. Cain :
>> On Mon, 10 Aug 2009 17:52:36 -0700
>> "Peter Headland"  wrote:
>>> I can get the rows I want to update like this:
>>>
>>>   SELECT *
>>>    FROM queue
>>>    WHERE id = p_queue_id
>>>    ORDER BY rank
>>>    LIMIT p_number_of_items;
>>>
>>> Of course, there may not be p_number_of_items available in the queue.
>>>
>>> I want to update all the rows in the cursor in the same way:
>>>
>>>   UPDATE queue SET assigned = TRUE;
>>
>> Assuming that there is a unique identifier on queue, let's call it
>> queue_id, you should be able to do something like this:
>>
>>  UPDATE queue SET assigned = TRUE
>>  WHERE queue_id IN (SELECT queue_id
>>    FROM queue
>>    WHERE id = p_queue_id
>>    ORDER BY rank
>>    LIMIT p_number_of_items);
>>
>
> there are one fast trick
> http://www.postgres.cz/index.php/PostgreSQL_SQL_Tricks#Fast_first_n_rows_removing
>
> p.s. replace DELETE by UPDATE
> regards
> Pavel Stehule
>
>> --
>> D'Arcy J.M. Cain          |  Democracy is three wolves
>> http://www.druid.net/darcy/                |  and a sheep voting on
>> +1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.
>>
>> --
>> Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
>> To make changes to your subscription:
>> http://www.postgresql.org/mailpref/pgsql-sql
>>
>

-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql


Re: [SQL] Updating a specific number of rows in pl/pgsql

2009-08-11 Thread Peter Headland
> Unfortunately, there is no single column that provides a unique id.

Correction - I did not understand what ctid was, but now I do, so I will try 
your tip.

-- 
Peter Headland
Architect
Actuate Corporation


-Original Message-
From: Peter Headland 
Sent: Tuesday, August 11, 2009 10:05
To: 'Pavel Stehule'; D'Arcy J.M. Cain
Cc: pgsql-sql@postgresql.org
Subject: RE: [SQL] Updating a specific number of rows in pl/pgsql

> there are one fast trick
> http://www.postgres.cz/index.php/PostgreSQL_SQL_Tricks#Fast_first_n_rows_removing

Thanks - that's a very useful page!

Unfortunately, there is no single column that provides a unique id, and I am 
reluctant to add one (for example, using a sequence and a new index) for 
performance reasons.

Given that additional constraint, is my original plan using a loop to iterate 
over a cursor reasonable? I don't anticipate p_number_of_items being more than 
20.

-- 
Peter Headland
Architect
Actuate Corporation


-Original Message-
From: Pavel Stehule [mailto:pavel.steh...@gmail.com] 
Sent: Tuesday, August 11, 2009 03:55
To: D'Arcy J.M. Cain
Cc: Peter Headland; pgsql-sql@postgresql.org
Subject: Re: [SQL] Updating a specific number of rows in pl/pgsql

2009/8/11 D'Arcy J.M. Cain :
> On Mon, 10 Aug 2009 17:52:36 -0700
> "Peter Headland"  wrote:
>> I can get the rows I want to update like this:
>>
>>   SELECT *
>>    FROM queue
>>    WHERE id = p_queue_id
>>    ORDER BY rank
>>    LIMIT p_number_of_items;
>>
>> Of course, there may not be p_number_of_items available in the queue.
>>
>> I want to update all the rows in the cursor in the same way:
>>
>>   UPDATE queue SET assigned = TRUE;
>
> Assuming that there is a unique identifier on queue, let's call it
> queue_id, you should be able to do something like this:
>
>  UPDATE queue SET assigned = TRUE
>  WHERE queue_id IN (SELECT queue_id
>    FROM queue
>    WHERE id = p_queue_id
>    ORDER BY rank
>    LIMIT p_number_of_items);
>

there are one fast trick
http://www.postgres.cz/index.php/PostgreSQL_SQL_Tricks#Fast_first_n_rows_removing

p.s. replace DELETE by UPDATE
regards
Pavel Stehule

> --
> D'Arcy J.M. Cain          |  Democracy is three wolves
> http://www.druid.net/darcy/                |  and a sheep voting on
> +1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>

-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql


[SQL] mail alert

2009-08-11 Thread Jan Verheyden
Hi All,

I was looking in what way it's possible to alert via mail when some conditions 
are true in a database.

Thanks in advance!

Jan


[SQL] Month/year between two dates

2009-08-11 Thread Bor

Hi to all,

I have a very simple question. Let's say that I have three records (id, date
from, date to):

1 2009-01-01 2009-08-31
2 2009-08-01 2009-08-10
3 2009-08-11 2009-08-31

Now I want to get records, "related" to a single month/year data (two
integers). For 2009/08 (int1 = 2009, int2 = 8) I should get all three
records, for 2009/05 only record 1, but for 2009/11 none of the records.

Is there any simple way to do this? A query would do :).

Thanks alot.
-- 
View this message in context: 
http://www.nabble.com/Month-year-between-two-dates-tp24917400p24917400.html
Sent from the PostgreSQL - sql mailing list archive at Nabble.com.


-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql


Re: [SQL] Month/year between two dates

2009-08-11 Thread Steve Crawford

Bor wrote:

Hi to all,

I have a very simple question. Let's say that I have three records (id, date
from, date to):

1 2009-01-01 2009-08-31
2 2009-08-01 2009-08-10
3 2009-08-11 2009-08-31

Now I want to get records, "related" to a single month/year data (two
integers). For 2009/08 (int1 = 2009, int2 = 8) I should get all three
records, for 2009/05 only record 1, but for 2009/11 none of the records.

Is there any simple way to do this? A query would do :).

Thanks alot.
  
Lots of ways. The following springs to mind but I'm sure there are 
simpler ways (I'm assuming the date_from and date_to are data-type date 
and you are stuck with using int for year and month).


Use date_trunc to convert any date in a month to the first of the month 
and the following should work (untested):

...
date_trunc('month', date_from) <= (int1::text || '-' || int2::text || 
'-1')::date and
date_trunc('month', date_to) >= (int1::text || '-' || int2::text || 
'-1')::date

...

Cheers,
Steve

--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql


Re: [SQL] mail alert

2009-08-11 Thread Denis BUCHER
Hello,

Jan Verheyden a écrit :
> I was looking in what way it’s possible to alert via mail when some
> conditions are true in a database.

a) If the alert is not "very urgent" i.e. you can alter some minutes
later I would do it like this :

1. Create a function that returns what you need, most importantly if the
conditions are met

2. Create a script that does something like "SELECT * FROM function()..."

b) If the email should be sent immediately, you could create a perl
function in the database, launched by a TRIGGER and launching an
"external" script...

Therefore, first you have to know the requirements...

Denis

-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql


Re: [SQL] mail alert

2009-08-11 Thread Rob Sargent

Denis BUCHER wrote:

Hello,

Jan Verheyden a écrit :
  

I was looking in what way it’s possible to alert via mail when some
conditions are true in a database.



a) If the alert is not "very urgent" i.e. you can alter some minutes
later I would do it like this :

1. Create a function that returns what you need, most importantly if the
conditions are met

2. Create a script that does something like "SELECT * FROM function()..."

b) If the email should be sent immediately, you could create a perl
function in the database, launched by a TRIGGER and launching an
"external" script...

Therefore, first you have to know the requirements...

Denis

  

see "check_postgres" for nagios-style monitoring
see \o /tmp/alert_data_file
and \! mailx -s "alert" m...@work.com /tmp/alert_data_file


--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql


Re: [SQL] Month/year between two dates

2009-08-11 Thread ramasubramanian

Dear Bor,
   How you will 1 record for 2009/05 (if you use 2009/05 ) it will fetch 
all the records as it is not having month 05

am i correct?

- Original Message - 
From: "Bor" 

To: 
Sent: Tuesday, August 11, 2009 6:43 PM
Subject: [SQL] Month/year between two dates




Hi to all,

I have a very simple question. Let's say that I have three records (id, 
date

from, date to):

1 2009-01-01 2009-08-31
2 2009-08-01 2009-08-10
3 2009-08-11 2009-08-31

Now I want to get records, "related" to a single month/year data (two
integers). For 2009/08 (int1 = 2009, int2 = 8) I should get all three
records, for 2009/05 only record 1, but for 2009/11 none of the records.

Is there any simple way to do this? A query would do :).

Thanks alot.
--
View this message in context: 
http://www.nabble.com/Month-year-between-two-dates-tp24917400p24917400.html

Sent from the PostgreSQL - sql mailing list archive at Nabble.com.


--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql 



--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql


Re: [SQL] mail alert

2009-08-11 Thread ramasubramanian
Hi,
Can you just tell me whether your database is place on which 
server(linux/or windows or..)?
  - Original Message - 
  From: Jan Verheyden 
  To: 'pgsql-sql@postgresql.org' 
  Sent: Tuesday, August 11, 2009 6:31 PM
  Subject: [SQL] mail alert


  Hi All,

   

  I was looking in what way it's possible to alert via mail when some 
conditions are true in a database.

   

  Thanks in advance!

   

  Jan


Re: [SQL] mail alert

2009-08-11 Thread Shoaib Mir
> - Original Message -
> *From:* Jan Verheyden 
> *To:* 'pgsql-sql@postgresql.org' <%27pgsql-...@postgresql.org%27>
> *Sent:* Tuesday, August 11, 2009 6:31 PM
> *Subject:* [SQL] mail alert
>
>  Hi All,
>
>
>
> I was looking in what way it’s possible to alert via mail when some
> conditions are true in a database.
>
>
>
>
I guess you might be able to do that by using PLPython, PLPerl or PLTcl and
using the standard functions for doing emails in there.

-- 
Shoaib Mir
http://shoaibmir.wordpress.com/