Re: [GENERAL] Strange problem with create table as select * from table;

2011-11-05 Thread Adrian Klaver
On Friday, November 04, 2011 3:43:48 pm hubert depesz lubaczewski wrote: > On Fri, Nov 04, 2011 at 05:49:44PM -0400, Tom Lane wrote: > > You said that pg_dump does not show the corruption. That could be > > because the data is coming out through the COPY code path instead of > > the SELECT code pa

Re: [GENERAL] Strange problem with create table as select * from table;

2011-11-05 Thread hubert depesz lubaczewski
On Fri, Nov 04, 2011 at 05:49:44PM -0400, Tom Lane wrote: > You said that pg_dump does not show the corruption. That could be > because the data is coming out through the COPY code path instead of > the SELECT code path. Could you try a pg_dump with --inserts (which > will fetch the data with SEL

Re: [GENERAL] Strange problem with create table as select * from table;

2011-11-05 Thread hubert depesz lubaczewski
On Fri, Nov 04, 2011 at 05:06:35PM -0700, Adrian Klaver wrote: > Another question. > Between 07/20/11 and this recent attempt did you do a CREATE TABLE AS on this > table and not have corrupted rows? don't remember. Best regards, depesz -- The best thing about modern society is how easy it is

[GENERAL] Function Question - Inserting into a table with foreign constraints

2011-11-05 Thread Brandon Phelps
Hello all, Could someone give me an example as to how I would accomplish something like this with a function?: 3 tables: tableA: id (serial), name (varchar), description (varchar), subcat_id (integer) tableB: id (serial), subcat_name (varchar), cat_id (integer) tableC: id (serial), cat_name

Re: [GENERAL] Function Question - Inserting into a table with foreign constraints

2011-11-05 Thread Raymond O'Donnell
On 05/11/2011 04:34, Brandon Phelps wrote: > Hello all, > > Could someone give me an example as to how I would accomplish something > like this with a function?: > > 3 tables: > > tableA: id (serial), name (varchar), description (varchar), subcat_id > (integer) > tableB: id (serial), subcat_name

Re: [GENERAL] Function Question - Inserting into a table with foreign constraints

2011-11-05 Thread Brandon Phelps
On 11/5/2011 10:35 AM, Raymond O'Donnell wrote: On 05/11/2011 04:34, Brandon Phelps wrote: Hello all, Could someone give me an example as to how I would accomplish something like this with a function?: 3 tables: tableA: id (serial), name (varchar), description (varchar), subcat_id (integer) t

Re: [GENERAL] Excessive planner time for some queries with high statistics

2011-11-05 Thread Stuart Bishop
On Sat, Nov 5, 2011 at 1:26 AM, Tom Lane wrote: > Stuart Bishop writes: >> We also found this problem did not occur on one of our staging >> systems, which had a default statistics target of 100. Lowering the >> statistics on the relavant columns from 1000 to 100 and reanalyzing >> made the overh

Re: [GENERAL] Function Question - Inserting into a table with foreign constraints

2011-11-05 Thread David Johnston
On Nov 5, 2011, at 10:46, Brandon Phelps wrote: > On 11/5/2011 10:35 AM, Raymond O'Donnell wrote: >> On 05/11/2011 04:34, Brandon Phelps wrote > > With the method you outlined will I notice any huge performance impacts? The > application would be parsing incoming data from another 3rd party ap

[GENERAL] How to find owning schema in function

2011-11-05 Thread Andrus
8.1+ database contains separate schemas for every company named company1, company2, companyi. order tables in those schemas contain trigger like for company1: CREATE OR REPLACE FUNCTION dok_seq_trig() RETURNS "trigger" AS $$BEGIN IF NEW.tasudok IS NULL AND NEW.doktyyp!='O' THEN NEW.tasudo

Re: [GENERAL] Function Question - Inserting into a table with foreign constraints

2011-11-05 Thread Raymond O'Donnell
On 05/11/2011 14:46, Brandon Phelps wrote: > > With the method you outlined will I notice any huge performance > impacts? The application would be parsing incoming data from another > 3rd party application and could, at times, be executing the function in > very fast succession, although never tw

Re: [GENERAL] Strange problem with create table as select * from table;

2011-11-05 Thread Adrian Klaver
On Friday, November 04, 2011 6:04:02 pm Tom Lane wrote: > I wrote: > > A different line of thought is that there's something about these > > specific source rows, and only these rows, that makes them vulnerable to > > corruption during INSERT/SELECT. Do they by any chance contain any > > values th

Re: [GENERAL] Strange problem with create table as select * from table;

2011-11-05 Thread Tom Lane
I wrote: > A different line of thought is that there's something about these > specific source rows, and only these rows, that makes them vulnerable to > corruption during INSERT/SELECT. Do they by any chance contain any > values that are unusual elsewhere in your table? One thing I'm > wondering

Re: [GENERAL] Strange problem with create table as select * from table;

2011-11-05 Thread Martijn van Oosterhout
On Fri, Nov 04, 2011 at 09:04:02PM -0400, Tom Lane wrote: > Hah ... I have a theory. > > I will bet that you recently added some column(s) to the source table > using ALTER TABLE ADD COLUMN and no default value, so that the added > columns were nulls and no table rewrite happened. And that these

Re: [GENERAL] Foreign Keys and Deadlocks

2011-11-05 Thread Csaba Nagy
Hi David, On Thu, 2011-11-03 at 15:30 -0700, David Kerr wrote: > I suspect that it has to be a transaction, and that further up in the TX is > an update to one of > the reference tables in each TX. This is your cause - updating the referenced table in the same transaction. That will want an excl

Re: [GENERAL] postgresql-9.1.1 PQescapeByteaConn() generating incorrectly quoted output.

2011-11-05 Thread Graham Murray
On Wed, 2011-11-02 at 18:21 +, Tom Lane wrote: > Graham Murray writes: > > Since upgrading test systems to postgresql 9.1, I am seeing some > inserts > > to bytea fields giving errors such as "ERROR: invalid byte sequence > for > > encoding "UTF8": 0xf9" Where the insert is from a C program u

[GENERAL] Linker error VS2008 c++

2011-11-05 Thread Cin123
Hi, I'm traing to read a row from a table using visual studio 2008 and libpq. I'm having problem with getting a int from a querry result, below im pasting my code struct subjects_group { unsigned long id; std::string name; }; list QS_PQsql::getGroups() { list lista;

[GENERAL] What is *wrong* with this query???

2011-11-05 Thread Steve Murphy
I give! I'm flummoxed! Here is what I have, 3 tables: schedule companybuilding status0 3 x active 4 x active 5 x active 3 x active 3

[GENERAL] Custom Contraint Violation Errors

2011-11-05 Thread Michael Musenbrock
Hi, I'm looking for a way to create a custom, for our application parsable, error message on constraint violation. The perfect thing would be, having table names, schemas and primary keys in that error message. My first thought was to create a function which gets triggered by the constraint viola

[GENERAL] Distinct on a non-sort column

2011-11-05 Thread Cstdenis
I am trying to write a query that selects recent submissions (sorted by submission_date) but only selects the most recent one for each user_id. example query: /select distinct on (user_id) * from stories order by date_submitted desc limit 10;/ However postgres will not allow me to filter out

Re: [GENERAL] What is *wrong* with this query???

2011-11-05 Thread David Johnston
See embedded note after “as bld” Dave From: pgsql-general-ow...@postgresql.org [mailto:pgsql-general-ow...@postgresql.org] On Behalf Of Steve Murphy Sent: Saturday, November 05, 2011 12:51 AM To: pgsql-general@postgresql.org Subject: [GENERAL] What is *wrong* with this query??? I gi

Re: [GENERAL] What is *wrong* with this query???

2011-11-05 Thread Adrian Klaver
On Friday, November 04, 2011 9:51:14 pm Steve Murphy wrote: > I give! I'm flummoxed! > > Here is what I have, 3 tables: > > schedule > companybuilding status0 > 3 x active > 4 x active > 5

Re: [GENERAL] What is *wrong* with this query???

2011-11-05 Thread Scott Marlowe
On Fri, Nov 4, 2011 at 10:51 PM, Steve Murphy wrote: > select schedule.id as sched_id, bld.id as bid >     from > schedule >     left join company on schedule.company = company.id >     left join (select * from building where building.company = > company.id order by id limit 1)  as

Re: [GENERAL] What is *wrong* with this query???

2011-11-05 Thread Tair Sabirgaliev
On Sat, Nov 5, 2011 at 10:51 AM, Steve Murphy wrote: > > > I give! I'm flummoxed! > > > > Here is what I have, 3 tables: > > > > schedule > > company    building   status0 > > 3 x   active > > 4 x   active > > 5   

Re: [GENERAL] What is *wrong* with this query???

2011-11-05 Thread Rodrigo Gonzalez
El 05/11/11 01:51, Steve Murphy escribió: I give! I'm flummoxed! Here is what I have, 3 tables: schedule companybuilding status0 3 x active 4 x active 5 x active 3

Re: [GENERAL] Distinct on a non-sort column

2011-11-05 Thread Tair Sabirgaliev
On Sun, Nov 6, 2011 at 12:39 AM, Cstdenis wrote: > I am trying to write a query that selects recent submissions (sorted by > submission_date) but only selects the most recent one for each user_id. > > example query: select distinct on (user_id) * from stories order by > date_submitted desc limit 1

Re: [GENERAL] What is *wrong* with this query???

2011-11-05 Thread Raymond O'Donnell
On 05/11/2011 04:51, Steve Murphy wrote: > select schedule.id as sched_id, bld.id as bid > from > schedule > left join company on schedule.company = company.id > left join (select * from building where building.company = > company.id order by id limit 1) as bld > wh

[GENERAL] explain analyse and nested loop joins

2011-11-05 Thread Oliver Kohll - Mailing Lists
Hi, I have a query I'm trying to optimise. It takes just under a second to run, not too bad for my users but I'm worried that as the size of the data increases, it will get worse. Of course the plan may change when that happens but I'd also like to learn a bit more about optimisation anyway. T

[GENERAL] Fwd: explain analyse and nested loop joins

2011-11-05 Thread Oliver Kohll - Mailing Lists
Oops, forgot to include the query, it's SELECT b2deliveryorders.idb2deliveryorders, a2clientpremises.ida2clientpremises, a2clientpremises.premisesname, a2clientpremises.town, b2deliveryorders.expectedby, b2deliveryorders.dateordered, b2deliveryorders.invoicenumber, b2deliveryorders.deliverymet

Re: [GENERAL] Distinct on a non-sort column

2011-11-05 Thread Tom Lane
Cstdenis writes: > I am trying to write a query that selects recent submissions (sorted by > submission_date) but only selects the most recent one for each user_id. > example query: /select distinct on (user_id) * from stories order by > date_submitted desc limit 10;/ > However postgres will n

Re: [GENERAL] Distinct on a non-sort column

2011-11-05 Thread John R Pierce
On 11/05/11 11:39 AM, Cstdenis wrote: example query: /select distinct on (user_id) * from stories order by date_submitted desc limit 10;/ select user_id,max(date_submitted) from stories group by date_submitted; ? -- john r pierceN 37, W 122 santa cruz ca

Re: [GENERAL] What is *wrong* with this query???

2011-11-05 Thread Antonio Goméz Soto
Steve, Op 05-11-11 05:51, Steve Murphy schreef: I give! I'm flummoxed! Here is what I have, 3 tables: schedule company building status0 3 x active 4 x active 5 x active 3 x active 3 x active 3 x active In the end, I want to replace the building id's above. They start out with the non-

Re: [GENERAL] Distinct on a non-sort column

2011-11-05 Thread Cstdenis
On 11/5/2011 12:49 PM, Tom Lane wrote: Cstdenis writes: I am trying to write a query that selects recent submissions (sorted by submission_date) but only selects the most recent one for each user_id. example query: /select distinct on (user_id) * from stories order by date_submitted desc limit

Re: [GENERAL] Distinct on a non-sort column

2011-11-05 Thread Tom Lane
Cstdenis writes: > If I understand that you are proposing as > select * from > (select distinct on (user_id) * from stories as s order > by user_id) as foo > order by date_submitted desc limit 10; No, you always need to sort by *more* columns than are listed in DISTI

[GENERAL] Some services of pgfoundry down?

2011-11-05 Thread Tatsuo Ishii
It seems web and ssh service on pgfoundry are not available at this moment. Anyone knows why? -- Tatsuo Ishii SRA OSS, Inc. Japan English: http://www.sraoss.co.jp/index_en.php Japanese: http://www.sraoss.co.jp -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes t