array_agg() with join question
2013-05-14 14:08:56 GMT
www.iglass.net
transaction isolationa level - SERIALIZABLE
2013-05-13 09:22:16 GMT
mk
Order of execution
2013-05-06 00:04:18 GMT
Correct implementation of 1:n relationship with n>0?
2013-04-30 14:39:05 GMT
It hit me today that a 1:n relationship can't be implemented just by a single foreign key constraint if n>0. I must have been sleeping very deeply not to notice this. E.g. if there is a table "list" and another table "list_item" and the relationship can be described as "every list has at least one list_item" (and every list_item can only be part of one list, but this is trivial). A "correct" solution would require (at least?): 1. A foreign key pointing from each list_item to its list 2. Another foreign key pointing from each list to one of its list_item. But this must be a list_item that itself points to the same list, so just a simple foreign key constraint doesn't do it. 3. When a list has more than one list_item, and you want to delete the list_item that its list points to, you have to "re-point" the foreign key constraint on the list first. Do I need to use stored proceures then for all insert, update, delete actions? (4. Anything else that I've not seen?) Is there a "straight" (and tested) solution for this in PostgreSQL, that someone has already implemented and that can be re-used? No, I definitely don't want to get into programming PL/PgSQL myself. especially if the solution has to warrant data integrity under all circumstances. Such as concurrent update, insert, delete etc. TIA, Sincerely, Wolfgang -- -- Sent via pgsql-sql mailing list (pgsql-sql <at> postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql
execute
2013-04-25 16:17:06 GMT
Hi every one,
I'm trying to do the follow:
declare
aCad text[][]
begin
...
execute 'aCad:=aCad array[['||var1||','||var2||']]'
...
end; language plpgsqlbut I get the follow error:
sintax erro near to "aCad"
aCad := aCad || array[rCad.cmp,rSql.codfor]
^
I guess I should not use "execute" besides of insert, update, delete ... but how could I do in this case ?
Thanks every one.
Not Able to Delink the old tables
2013-04-23 08:01:51 GMT
Hi,
When i tried to delink the old tables i'm getting the following error
NOTICE: SELECT COUNT(*) AS count from pg_tables where schemaname='fr' and tablename='check_deny_2013_04_17' CONTEXT: PL/pgSQL function "delink_partitions_tables" line 16 at IF NOTICE: Lock SqlLOCK TABLE fr.check_deny_2013_04_17 NOWAIT ; NOTICE: -20000
delink_partitions_tables
(1 row)
But in the pg_stat_activity there is no locked process & there is no process running related to this process...
Thanks in Advance :)
SHABEER.
check for overlapping time intervals
2013-04-22 10:19:17 GMT
Hi,
I am on postgresql 9.1 and use at table like
CREATE TABLE timetable(
tid INTEGER PRIMARY KEY,
gid INTEGER REFERENCES groups(gid),
day DATE,
s TIME NOT NULL, --- start
e TIME NOT NULL, --- end
CHECK (e > s));
Now, i need a constraint to prevent overlapping timeintervals in this
table. For this, i use a trigger:
CREATE OR REPLACE FUNCTION validate_timetable() RETURNS trigger AS $$
BEGIN
IF TG_OP = 'INSERT' THEN
IF EXISTS(
SELECT * FROM timetable
WHERE gid = NEW.gid AND day = NEW.day
AND s < NEW.e AND e > NEW.s)
THEN
RAISE EXCEPTION 'overlapping intervals';
END IF;
ELSIF TG_OP = 'UPDATE' THEN
IF EXISTS(
SELECT * FROM timetable
WHERE gid = NEW.gid AND day = NEW.day
AND tid <> OLD. tid
AND s < NEW.e AND e > NEW.s)
THEN
RAISE EXCEPTION 'overlapping intervals';
END IF;
END IF;
RETURN NEW;
END; $$ LANGUAGE plpgsql;
CREATE TRIGGER validate_timetable
BEFORE INSERT OR UPDATE ON timetable
FOR EACH ROW EXECUTE PROCEDURE
validate_timetable();
Is there a simpler way to check for overlapping timeintervals? I ask
this question, because i have more similar tables with similar layout
and would have to write similar functions again and again.
Thank you for any hints
Wolfgang
--
--
Sent via pgsql-sql mailing list (pgsql-sql <at> postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
Table indexes in a SELECT with JOIN´s
2013-04-20 16:32:00 GMT
SQL query with Overlapping date time ranges
2013-04-19 03:41:06 GMT
I have a temporary table with columns
zone_name, nodeid, nodelabel, nodegainedservice, nodelostservice
Zone1, 3, Windows-SRV1, "2012-11-27 13:10:30+08", "2012-11-27 13:00:40+08"
Zone1, 5, Windows-SRV2, "2012-12-20 13:10:30+08", "2012-12-18 13:00:40+08"
....
....
Many zones and many nodes and same nodes with gained service and lost service many times.
`nodegainedservice` meaning node has come alive and `nodelostservice` meaning node has gone down.
How could I make a query to fetch each zone availability in a period?
e.g., Zone1 have Windows-SRV1, Windows-SRV2. Find how many times and how long both servers are down at the same time or Zone1 is down.
Please use the below sample data
zonename, nodeid, nodelabel, noderegainedservice, nodelostservice
Zone1 27 Srv1 2013-02-21 10:04:56+08 2013-02-21 09:48:48+08
Zone1 27 Srv1 2013-02-21 10:14:01+08 2013-02-21 10:09:27+08
Zone1 27 Srv1 2013-02-21 10:26:29+08 2013-02-21 10:24:20+08
Zone1 27 Srv1 2013-02-21 11:27:24+08 2013-02-21 11:25:15+08
Zone1 27 Srv1 2013-02-28 16:24:59+08 2013-02-28 15:52:59+08
Zone1 27 Srv1 2013-02-28 16:56:19+08 2013-02-28 16:40:18+08
Zone1 27 Srv1 2013-02-28 17:09:28+08 2013-02-28 16:58:38+08
Zone1 27 Srv1 2013-02-28 17:39:50+08 2013-02-28 17:29:47+08
Zone1 27 Srv1 2013-03-01 09:39:36+08 2013-02-28 19:12:26+08
Zone1 27 Srv1 2013-03-01 13:35:07+08 2013-03-01 12:10:03+08
Zone1 27 Srv1 2013-03-04 11:04:14+08 2013-03-04 10:48:07+08
Zone1 27 Srv1 2013-03-06 16:36:56+08 2013-03-06 16:33:10+08
Zone1 27 Srv1 2013-03-13 13:54:11+08 2013-03-06 16:43:51+08
Zone1 27 Srv1 2013-03-14 11:43:28+08 2013-03-13 19:09:31+08
Zone1 27 Srv1 2013-03-18 18:38:16+08 2013-03-15 18:55:31+08
Zone1 27 Srv1 2013-03-22 11:18:57+08 2013-03-22 09:53:38+08
Zone1 27 Srv1 2013-03-28 16:48:27+08 2013-03-26 10:23:47+08
Zone1 27 Srv1 2013-04-04 10:33:24+08 2013-04-04 10:32:51+08
Zone1 27 Srv1 2013-04-04 11:48:54+08 2013-04-04 11:48:23+08
Zone1 27 Srv1 2013-04-08 19:01:34+08 2013-04-08 19:01:03+08
Zone1 27 Srv1 2013-04-08 19:37:05+08 2013-04-08 19:31:38+08
Zone1 27 Srv1 2013-04-08 21:48:07+08 2013-04-08 21:47:35+08
Zone1 27 Srv1 2013-04-08 21:54:02+08 2013-04-08 21:52:29+08
Zone1 27 Srv1 2013-04-10 09:33:53+08 2013-04-10 09:32:34+08
Zone1 27 Srv1 2013-04-10 12:01:01+08 2013-04-10 12:00:30+08
Zone1 27 Srv1 2013-04-10 14:57:25+08 2013-04-10 14:56:53+08
Zone1 27 Srv1 2013-04-10 16:25:50+08 2013-04-10 16:24:31+08
Zone1 27 Srv1 2013-04-10 16:57:02+08 2013-04-10 16:56:19+08
Zone1 27 Srv1 2013-04-10 17:17:37+08 2013-04-10 17:15:18+08
Zone1 27 Srv1 2013-04-11 21:35:43+08 2013-04-11 21:31:50+08
Zone1 39 Srv2 2013-04-05 13:15:53+08 2013-04-05 12:26:04+08
Zone1 39 Srv2 2013-04-05 13:23:10+08 2013-04-05 13:21:14+08
Zone1 39 Srv2 2013-04-05 13:35:23+08 2013-04-05 13:33:32+08
Zone1 39 Srv2 2013-04-05 15:17:25+08 2013-04-05 14:25:51+08
Zone1 39 Srv2 2013-04-07 16:49:56+08 2013-04-05 17:43:01+08
Zone1 39 Srv2 2013-04-09 22:32:19+08 2013-04-07 20:00:44+08
Zone1 39 Srv2 2013-04-09 22:38:02+08 2013-04-09 22:37:40+08
Zone1 39 Srv2 2013-04-10 11:16:21+08 2013-04-10 11:13:32+08
Zone1 39 Srv2 2013-04-10 16:15:37+08 2013-04-10 15:44:05+08
Zone1 39 Srv2 2013-04-10 16:23:07+08 2013-04-10 16:20:59+08
Zone1 39 Srv2 2013-04-10 16:48:46+08 2013-04-10 16:33:29+08
Zone1 39 Srv2 2013-04-10 17:19:11+08 2013-04-10 17:04:10+08
Zone1 39 Srv2 2013-04-11 21:39:21+08 2013-04-11 21:28:51+08
Zone1 39 Srv2 2013-04-11 22:05:02+08 2013-04-11 21:49:44+08
Zone1 39 Srv2 2013-04-15 14:02:11+08 2013-04-12 16:41:48+08
Zone1 39 Srv2 2013-04-17 00:00:00+08 2013-04-15 20:50:40+08
Zone1 29 Srv3 2013-03-12 17:20:02+08 2013-03-12 17:16:49+08
Zone1 29 Srv3 2013-03-12 18:08:30+08 2013-03-12 17:55:43+08
Zone1 13 Srv4 2013-01-09 17:23:59+08 2013-01-09 17:19:13+08
Zone1 13 Srv4 2013-01-10 16:54:27+08 2013-01-10 16:53:48+08
Zone1 13 Srv4 2013-01-10 16:59:55+08 2013-01-10 16:56:56+08
Zone1 13 Srv4 2013-01-10 17:07:10+08 2013-01-10 17:04:11+08
Zone1 13 Srv4 2013-01-10 17:13:54+08 2013-01-10 17:10:42+08
Zone1 13 Srv4 2013-01-16 10:31:45+08 2013-01-15 14:47:25+08
Zone1 13 Srv4 2013-01-24 17:52:35+08 2013-01-24 17:20:31+08
Zone1 13 Srv4 2013-01-28 17:24:25+08 2013-01-28 16:53:10+08
Zone1 13 Srv4 2013-02-18 12:16:45+08 2013-02-18 12:10:05+08
Zone1 13 Srv4 2013-02-18 15:00:26+08 2013-02-18 14:12:04+08
Zone1 13 Srv4 2013-02-18 17:11:10+08 2013-02-18 17:00:58+08
Zone1 13 Srv4 2013-02-21 10:14:24+08 2013-02-21 10:13:45+08
Zone1 13 Srv4 2013-02-25 14:29:39+08 2013-02-25 13:44:50+08
Zone1 13 Srv4 2013-02-26 10:40:08+08 2013-02-26 10:19:33+08
Zone1 13 Srv4 2013-03-04 11:37:34+08 2013-03-04 11:00:56+08
Zone1 13 Srv4 2013-04-10 16:25:27+08 2013-04-10 16:24:07+08
Zone1 13 Srv4 2013-04-10 17:17:39+08 2013-04-10 17:14:40+08
Zone1 13 Srv4 2013-04-11 21:39:05+08 2013-04-11 21:28:22+08
Sent from the PostgreSQL - sql mailing list archive at Nabble.com.
Primary DB stuck becuase of unavailable standby (synchronized streaming) - please help
2013-04-18 15:41:22 GMT
Hi,
I am using Postgres DB with stand by database, configured with streaming in synchronized mode (each commit on primary DB waits for commit on secondary DB).
Sometimes we suffer from network issues and as consequences, secondary machine is not available.
In these situations, our application is stuck and do not respond anymore, since no confirmation comes from the secondary Postgres (obviously… it is down or unavailable….).
Is there any parameter that I can use, to enable recovering from hanging on until someone of us re-establish connection to secondary DB?
Maybe some configuration parameter that sets the time interval for being stuck because of unavailable secondary Postgres?
Please help,
Thanks,
Yuval Sofer
BMC Software
CTM&D Business Unit
DBA Team
972-52-4286-282
RSS Feed