Re: [SQL] join on three tables is slow

2007-12-11 Thread Gerry Reno
Pavel Stehule wrote: On 11/12/2007, Gerry Reno <[EMAIL PROTECTED]> wrote: Ok, I've been playing around with this SQL some more and I found that if I remove this: e.active = '1' from the query that the query now completes in 5 seconds. Nothing else has anywhere near the impact of this boolean

Re: [SQL] join on three tables is slow

2007-12-11 Thread Pavel Stehule
Hello there is diference in agg position. Send, please, query and explain analyze output. And test id = any (... ) looks like hard denormalisation and can do problems. This condition can be slow and for large arrays is better use multivalues. SELECT * FROM tab WHERE x IN (VALUES(10),(20));

[SQL] case sensitivity for tables, columns, and constraint names

2007-12-11 Thread Ertel, Steve
I see that I can create a table with a mixed case name as long as the name is wrapped in quotes. Is there a setting to allow upper case and mixed case names for database tables, fields, etc, without having to wrap each in quotes? Thanks, SteveE

Re: [SQL] case sensitivity for tables, columns, and constraint names

2007-12-11 Thread A. Kretschmer
am Tue, dem 11.12.2007, um 11:05:25 -0600 mailte Ertel, Steve folgendes: >  > I see that I can create a table with a mixed case name as long as the name is > wrapped in quotes. Is there a setting to allow upper case and mixed case > names > for database tables, fields, etc, without having to

Re: [SQL] case sensitivity for tables, columns, and constraint names

2007-12-11 Thread Andrew Sullivan
On Tue, Dec 11, 2007 at 11:05:25AM -0600, Ertel, Steve wrote: > is wrapped in quotes. Is there a setting to allow upper case and mixed > case names for database tables, fields, etc, without having to wrap each > in quotes? No, sorry. The always-one-case rule for unquoted identifiers is ANSI con

Re: [SQL] case sensitivity for tables, columns, and constraint names

2007-12-11 Thread Richard Huxton
Ertel, Steve wrote: I see that I can create a table with a mixed case name as long as the name is wrapped in quotes. Is there a setting to allow upper case and mixed case names for database tables, fields, etc, without having to wrap each in quotes? No, SQL defines identifiers as case-insensit

Re: [SQL] join on three tables is slow

2007-12-11 Thread Gerry Reno
Pavel Stehule wrote: Hello there is diference in agg position. Send, please, query and explain analyze output. And test id = any (... ) looks like hard denormalisation and can do problems. This condition can be slow and for large arrays is better use multivalues. SELECT * FROM tab WHERE x

[SQL] Foreign Key for multi PK or design question

2007-12-11 Thread PostgreSQL Admin
I have a table in which people will have a number of questions to answer. I want those pk to be placed in my user table. So if a user answers three question I want those 3 pk's in the user table (fk). What should I be doing? Thanks in advance, J ---(end of broadcast)

Re: [SQL] Foreign Key for multi PK or design question

2007-12-11 Thread Erik Jones
On Dec 11, 2007, at 12:20 PM, PostgreSQL Admin wrote: I have a table in which people will have a number of questions to answer. I want those pk to be placed in my user table. So if a user answers three question I want those 3 pk's in the user table (fk). What should I be doing? You're goi

Re: [SQL] Foreign Key for multi PK or design question

2007-12-11 Thread A. Kretschmer
am Tue, dem 11.12.2007, um 13:20:52 -0500 mailte PostgreSQL Admin folgendes: > I have a table in which people will have a number of questions to > answer. I want those pk to be placed in my user table. So if a user > answers three question I want those 3 pk's in the user table (fk). > What s

Re: [SQL] Foreign Key for multi PK or design question

2007-12-11 Thread PostgreSQL Admin
This is my layout so far: CREATE TABLE users ( id serial NOT NULL, --question REFERENCES questions(id) ON DELETE CASCADE ## ON REMOVED## ); CREATE TABLE questions ( id serial NOT NULL, questions varchar(450) NOT NULL ); CREATE TABLE answers ( id serial NOT NULL, question_id int REFERENCES questi

Re: [SQL] Foreign Key for multi PK or design question

2007-12-11 Thread Alvaro Herrera
PostgreSQL Admin wrote: > This is my layout so far: > > CREATE TABLE users ( > id serial NOT NULL, > --question REFERENCES questions(id) ON DELETE CASCADE ## ON REMOVED## > ); > > CREATE TABLE questions ( > id serial NOT NULL, > questions varchar(450) NOT NULL > ); > > CREATE TABLE answers ( > i

Re: [SQL] join on three tables is slow

2007-12-11 Thread Pavel Stehule
Hello 1) increase statistics on res_partner_address.type (about 100) alter table ... ALTER [ COLUMN ] column SET STATISTICS integer do analyze, and look again on plans. There are difference -> Seq Scan on res_partner_address a (cost=0.00..88.40 rows=16 width=552) (actual time=0.106..3.

Re: [SQL] Foreign Key for multi PK or design question

2007-12-11 Thread A. Kretschmer
am Tue, dem 11.12.2007, um 14:12:38 -0500 mailte PostgreSQL Admin folgendes: > This is my layout so far: > [ table-layout] > ... > Does this look correct? Yes, why not? Do you have problems? Which? I can't see problems, it's a normalized design IMHO. Andreas -- Andreas Kretschmer Kontakt: Hey

Re: [SQL] Foreign Key for multi PK or design question

2007-12-11 Thread PostgreSQL Admin
No problems with the design - I was not thinking with the DB hat on at first. I have been working on clustering for a while... just adjusting. Thanks everyone. :) ---(end of broadcast)--- TIP 5: don't forget to increase your free space map settings

[SQL] Query design assistance - getting daily totals

2007-12-11 Thread Paul Lambert
I have a table of account balances as at the end of a working day and want to from that, calculate daily total figures. Eg, let's say I have a table structure of: year_id integer month_id integer working_day integer account integer account_balance numeric(19,4) Example data might be something l

Re: [SQL] join on three tables is slow

2007-12-11 Thread Tom Lane
Gerry Reno <[EMAIL PROTECTED]> writes: > Pavel Stehule wrote: >> there is diference in agg position. Send, please, query and explain >> analyze output. [ explain analyze output ] The rowcount estimates seem pretty far off, even for simple cases that I'd expect it to get right, eg > ->

[SQL] Function result using execute

2007-12-11 Thread Paul Lambert
I have a function which uses execute to populate the value of a variable based on a defined select construct. The relevant part of the code looks like thus: EXECUTE curr_query INTO curr_amount; RAISE NOTICE '%',curr_amount; IF NOT FOUND THEN curr_amount=0; END IF; RAISE NOTI

Re: [SQL] Function result using execute

2007-12-11 Thread Tom Lane
Paul Lambert <[EMAIL PROTECTED]> writes: > The relevant part of the code looks like thus: > EXECUTE curr_query INTO curr_amount; > RAISE NOTICE '%',curr_amount; > IF NOT FOUND THEN >curr_amount=0; > END IF; > ... which suggests to me that although the > execute has populat

Re: [SQL] Function result using execute

2007-12-11 Thread Erik Jones
On Dec 11, 2007, at 11:15 PM, Paul Lambert wrote: I have a function which uses execute to populate the value of a variable based on a defined select construct. The relevant part of the code looks like thus: EXECUTE curr_query INTO curr_amount; RAISE NOTICE '%',curr_amount; IF NOT FO

Re: [SQL] Function result using execute

2007-12-11 Thread Paul Lambert
Tom Lane wrote: Do you really need an EXECUTE? If so, maybe you could restructure this using a FOR ... IN EXECUTE, or some such thing. I'll always only ever have a single result since the function gets passes all the fields making up the primary key of the table, so doing a for in seems like

Re: [SQL] Query design assistance - getting daily totals

2007-12-11 Thread A. Kretschmer
am Wed, dem 12.12.2007, um 10:34:35 +0900 mailte Paul Lambert folgendes: > I have a table of account balances as at the end of a working day and > want to from that, calculate daily total figures. > > Eg, let's say I have a table structure of: > year_id integer > month_id integer > working_day i

Re: [SQL] Query design assistance - getting daily totals

2007-12-11 Thread Paul Lambert
A. Kretschmer wrote: am Wed, dem 12.12.2007, um 10:34:35 +0900 mailte Paul Lambert folgendes: year_id integer month_id integer working_day integer Why this broken data types? We have date and timestamp[tz]. It's a financial application which needs to work using a concept of 'financial pe

Re: [SQL] Query design assistance - getting daily totals

2007-12-11 Thread A. Kretschmer
am Wed, dem 12.12.2007, um 15:39:48 +0900 mailte Paul Lambert folgendes: > A. Kretschmer wrote: > >am Wed, dem 12.12.2007, um 10:34:35 +0900 mailte Paul Lambert folgendes: > >>year_id integer > >>month_id integer > >>working_day integer > > > >Why this broken data types? We have date and timestam