[GENERAL] Foreign keys question (performance)

2011-12-04 Thread Phoenix Kiula
Hi. I have a foreign key as such: ALTER TABLE child_table ADD CONSTRAINT fk_child FOREIGN KEY (stringid) REFERENCES parent_table (stringid) MATCH FULL ON DELETE CASCADE ; Questions: 1. Is "MATCH FULL" adding any value here? If the foreign key is just on an "id" column, what purpose does it se

Re: [GENERAL] Foreign keys question (performance)

2011-12-04 Thread Alban Hertroys
On 4 Dec 2011, at 11:19, Phoenix Kiula wrote: > Hi. > > I have a foreign key as such: > > > ALTER TABLE child_table > ADD CONSTRAINT fk_child > FOREIGN KEY (stringid) REFERENCES parent_table (stringid) MATCH FULL > ON DELETE CASCADE ; > > > Questions: > > 1. Is "MATCH FULL" adding any value

[GENERAL] Weird behavior: deleted row still in index?

2011-12-04 Thread Phoenix Kiula
Hi. I have deleted a row from a table. Confirmed by "SELECT". All associated children tables don't have this key value either. Yet, when I insert this row back again, the primary key index on this table gives me a duplicate error. As demonstrated below. PGSQL version is 9.0.5. Is this common? I

Re: [GENERAL] Foreign keys question (performance)

2011-12-04 Thread Phoenix Kiula
On Sun, Dec 4, 2011 at 7:14 PM, Alban Hertroys wrote: > On 4 Dec 2011, at 11:19, Phoenix Kiula wrote: > > INSERTs in the parent table don't need to check for any reference from the > child table, since they're new; there can't be a reference. UPDATEs and > DELETEs do though, whether you le

Re: [GENERAL] Weird behavior: deleted row still in index?

2011-12-04 Thread Alban Hertroys
On 4 Dec 2011, at 12:32, Phoenix Kiula wrote: > mydb=# delete from stores where id = '20xrrs3'; > DELETE 0 > Time: 0.759 ms It says it didn't delete any rows. Since you get a duplicate key violation on inserting a row to that table, there's obviously a row with that id there. Perhaps there's a D

Re: [GENERAL] Weird behavior: deleted row still in index?

2011-12-04 Thread Szymon Guz
On 4 December 2011 12:32, Phoenix Kiula wrote: > Hi. > > I have deleted a row from a table. Confirmed by "SELECT". All > associated children tables don't have this key value either. > > Yet, when I insert this row back again, the primary key index on this > table gives me a duplicate error. > > A

Re: [GENERAL] Weird behavior: deleted row still in index?

2011-12-04 Thread Phoenix Kiula
On Sun, Dec 4, 2011 at 7:55 PM, Szymon Guz wrote: . > and then show us the whole table structure, especially any rules or > triggers. Not many rules or triggers. See below. I ran a REINDEX on the key allegedly being violated, and it finished it in 30 mins or so, but still the same problem:

Re: [GENERAL] Shared memory usage in PostgreSQL 9.1

2011-12-04 Thread Stephen Frost
* Christoph Zwerschke (c...@online.de) wrote: > (Btw, what negative consequences - if any - does it have if I set > kernel.shmmax higher as necessary, like all available memory? Does > this limit serve only as a protection against greedy applications?) Didn't see this get answered... The long-and

Re: [GENERAL] Shared memory usage in PostgreSQL 9.1

2011-12-04 Thread sfrost
This message has been digitally signed by the sender. Re___GENERAL__Shared_memory_usage_in_PostgreSQL_9_1.eml Description: Binary data - Hi-Tech Gears Ltd, Gurgaon, India -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to y

Re: [GENERAL] Shared memory usage in PostgreSQL 9.1

2011-12-04 Thread Tomas Vondra
On 4.12.2011 15:06, Stephen Frost wrote: > * Christoph Zwerschke (c...@online.de) wrote: >> (Btw, what negative consequences - if any - does it have if I set >> kernel.shmmax higher as necessary, like all available memory? Does >> this limit serve only as a protection against greedy applications?)

Re: [GENERAL] Shared memory usage in PostgreSQL 9.1

2011-12-04 Thread Christoph Zwerschke
Am 04.12.2011 15:17, schrieb sfr...@snowman.net: Didn't see this get answered... The long-and-short of that there aren't any negative consequences of having it higher, as I understand it anyway, except the risk of greedy apps. In some cases, shared memory can't be swapped out, which makes it a

Re: [GENERAL] Shared memory usage in PostgreSQL 9.1

2011-12-04 Thread Tom Lane
Christoph Zwerschke writes: > Am 03.12.2011 20:31, schrieb Christoph Zwerschke: >> Then, the corrected sum is 449627320 Bytes, which is only about 2MB less >> than was requested. This remaining discrepancy can probably be explained >> by additional overhead for a PostgreSQL 9.1 64bit server vs. a

[GENERAL] WITH and WITH RECURSIVE in single query

2011-12-04 Thread Maxim Boguk
Hi. Is here any way to combine WITH and WITH RECURSIVE into single query? Something like: WITH t AS (some complicated select to speed up recursive part), RECURSIVE r AS ( ... UNION ALL ... ) ? -- Maxim Boguk Senior Postgresql DBA.

Re: [GENERAL] WITH and WITH RECURSIVE in single query

2011-12-04 Thread Tom Lane
Maxim Boguk writes: > Is here any way to combine WITH and WITH RECURSIVE into single query? You have to put RECURSIVE immediately after WITH, but that doesn't force you to actually make any particular query in the WITH-list recursive. It just makes it possible for a query to be self-referential,

[GENERAL] Questions about setting an array element value outside of the update

2011-12-04 Thread Maxim Boguk
Lets say i have subquery which produce array[], position and new_value Is here less clumsy way to set array[position] to the new_value (not update but just change an element inside an array) than: SELECT _array[1:pos-1] ||newval ||_array[_pos+1:array_length(_array, 1)] FR

Re: [GENERAL] WITH and WITH RECURSIVE in single query

2011-12-04 Thread David Johnston
On Dec 4, 2011, at 22:28, Maxim Boguk wrote: > Hi. > > Is here any way to combine WITH and WITH RECURSIVE into single query? > > Something like: > > WITH t AS (some complicated select to speed up recursive part), > RECURSIVE r AS > ( > ... > UNION ALL > ... > ) > > ? > > -- > Maxim Boguk >

Re: [GENERAL] WITH and WITH RECURSIVE in single query

2011-12-04 Thread Maxim Boguk
On Mon, Dec 5, 2011 at 2:45 PM, David Johnston wrote: > On Dec 4, 2011, at 22:28, Maxim Boguk wrote: > > > Hi. > > > > Is here any way to combine WITH and WITH RECURSIVE into single query? > > > > Something like: > > > > WITH t AS (some complicated select to speed up recursive part), > > RECURSI

Re: [GENERAL] Questions about setting an array element value outside of the update

2011-12-04 Thread David Johnston
On Dec 4, 2011, at 22:43, Maxim Boguk wrote: > Lets say i have subquery which produce array[], position and new_value > > Is here less clumsy way to set array[position] to the new_value (not update > but just change an element inside an array) than: > > SELECT >_array[1:pos-1] >

[GENERAL] pl/pgsql and arrays[]

2011-12-04 Thread Maxim Boguk
Some quetions about pl/pgsql and arrays[]. Is such constructions as: RETURN NEXT array[1]; OR SELECT val INTO array[1] FROM ...; Should not work? At least documentation about RETURN NEXT says: "RETURN NEXT expression;" I think array[1] is a valid expression. -- Maxim Boguk Senior Postgres

[GENERAL] What's the best way in Postgres9 to store a bunch of arbitrary boolean values for a row?

2011-12-04 Thread Mike Christensen
I have a database full of recipes, one recipe per row. I need to store a bunch of arbitrary "flags" for each recipe to mark various properties such as Gluton-Free, No meat, No Red Meat, No Pork, No Animals, Quick, Easy, Low Fat, Low Sugar, Low Calorie, Low Sodium and Low Carb. Users need to be ab

Re: [GENERAL] Questions about setting an array element value outside of the update

2011-12-04 Thread Tom Lane
David Johnston writes: >> Is here less clumsy way to set array[position] to the new_value (not update >> but just change an element inside an array) than: >> >> SELECT >> _array[1:pos-1] >> ||newval >> ||_array[_pos+1:array_length(_array, 1)] > I do not know if there is a cleaner way but regar

Re: [GENERAL] WITH and WITH RECURSIVE in single query

2011-12-04 Thread David Johnston
On Dec 4, 2011, at 22:58, Maxim Boguk wrote: > > > On Mon, Dec 5, 2011 at 2:45 PM, David Johnston wrote: > On Dec 4, 2011, at 22:28, Maxim Boguk wrote: > > > Hi. > > > > Is here any way to combine WITH and WITH RECURSIVE into single query? > > > > Something like: > > > > WITH t AS (some comp

Re: [GENERAL] WITH and WITH RECURSIVE in single query

2011-12-04 Thread Maxim Boguk
On Mon, Dec 5, 2011 at 3:15 PM, David Johnston wrote: > On Dec 4, 2011, at 22:58, Maxim Boguk wrote: > > > > On Mon, Dec 5, 2011 at 2:45 PM, David Johnston < > pol...@yahoo.com> wrote: > >> On Dec 4, 2011, at 22:28, Maxim Boguk < >> maxim.bo...@gmail.com> wrote: >> >> > Hi. >> > >> > Is here a

Re: [GENERAL] pl/pgsql and arrays[]

2011-12-04 Thread Pavel Stehule
Hello it work on my pc postgres=# \sf fx CREATE OR REPLACE FUNCTION public.fx() RETURNS SETOF integer LANGUAGE plpgsql AS $function$ declare g int[] = '{20}'; begin return next g[1]; return; end; $function$ postgres=# select fx(); fx 20 (1 row) regards Pavel Stehule 2011/12/5 Maxi

Re: [GENERAL] pl/pgsql and arrays[]

2011-12-04 Thread Maxim Boguk
On Mon, Dec 5, 2011 at 3:53 PM, Pavel Stehule wrote: > Hello > > it work on my pc > > postgres=# \sf fx > CREATE OR REPLACE FUNCTION public.fx() > RETURNS SETOF integer > LANGUAGE plpgsql > AS $function$ declare g int[] = '{20}'; > begin > return next g[1]; > return; > end; > $function$ > post

Re: [GENERAL] pl/pgsql and arrays[]

2011-12-04 Thread Pavel Stehule
2011/12/5 Maxim Boguk : > > > On Mon, Dec 5, 2011 at 3:53 PM, Pavel Stehule > wrote: >> >> Hello >> >> it work on my pc >> >> postgres=# \sf fx >> CREATE OR REPLACE FUNCTION public.fx() >>  RETURNS SETOF integer >>  LANGUAGE plpgsql >> AS $function$ declare g int[] = '{20}'; >> begin >>  return ne

Re: [GENERAL] What's the best way in Postgres9 to store a bunch of arbitrary boolean values for a row?

2011-12-04 Thread Craig Ringer
On 12/05/2011 12:10 PM, Mike Christensen wrote: I have a database full of recipes, one recipe per row. I need to store a bunch of arbitrary "flags" for each recipe to mark various properties such as Gluton-Free, No meat, No Red Meat, No Pork, No Animals, Quick, Easy, Low Fat, Low Sugar, Low Calo

Re: [GENERAL] psql query gets stuck indefinitely

2011-12-04 Thread tamanna madaan
Hi Tomas I tried it on the system having postgres-8.4.0 . And the behavior is same . Cluster means a group of machines having postgres installed on all of them . Same database is created on all the machines one of which working as master DB on which operation (like insert/delete/update) will

Re: [GENERAL] What's the best way in Postgres9 to store a bunch of arbitrary boolean values for a row?

2011-12-04 Thread Mike Christensen
>> I have a database full of recipes, one recipe per row.  I need to >> store a bunch of arbitrary "flags" for each recipe to mark various >> properties such as Gluton-Free, No meat, No Red Meat, No Pork, No >> Animals, Quick, Easy, Low Fat, Low Sugar, Low Calorie, Low Sodium and >> Low Carb.  User