Re: [SQL] help with pagila

2006-09-01 Thread Tom Lane
Andrew Sullivan <[EMAIL PROTECTED]> writes: > On Fri, Sep 01, 2006 at 02:26:39PM -0300, Walter Cruz wrote: >> So I can assume that the MySQL implementation is strange? (It accepts that >> kind of query) > In my experience, it is almost never safe to assume that the MySQL > approach to SQL bears an

Re: [SQL] help with pagila

2006-09-01 Thread Scott Marlowe
On Fri, 2006-09-01 at 12:26, Walter Cruz wrote: > So I can assume that the MySQL implementation is strange? (It accepts > that kind of query) Yes, according to the SQL spec, you should generally get an error when you run a query like this: select field1, field2 from table group by field1 since y

Re: [SQL] help with pagila

2006-09-01 Thread Tomas Vondra
> But, when I add another column on select, like, film_description, I get > the following error: > > "ERROR: column "film.description" must appear in the GROUP BY clause or > be used in an aggregate function" > > If I put that column on GROUP BY everything works ok. But I want > understant why d

Re: [SQL] help with pagila

2006-09-01 Thread Andrew Sullivan
On Fri, Sep 01, 2006 at 02:26:39PM -0300, Walter Cruz wrote: > So I can assume that the MySQL implementation is strange? (It accepts that > kind of query) In my experience, it is almost never safe to assume that the MySQL approach to SQL bears anything but a passing resemblance to SQL proper. Thi

Re: [SQL] help with pagila

2006-09-01 Thread Walter Cruz
So I can assume that the MySQL implementation is strange? (It accepts that kind of query)[]'s- WalterOn 9/1/06, Andrew Sullivan < [EMAIL PROTECTED]> wrote:On Fri, Sep 01, 2006 at 10:31:48AM -0300, Walter Cruz wrote: > "ERROR:  column "film.description" must appear in the GROUP BY clause or be> used

Re: [SQL] help with pagila

2006-09-01 Thread Andrew Sullivan
On Fri, Sep 01, 2006 at 10:31:48AM -0300, Walter Cruz wrote: > "ERROR: column "film.description" must appear in the GROUP BY clause or be > used in an aggregate function" > > If I put that column on GROUP BY everything works ok. But I want understant > why do I need to do that. Can someone teach

[SQL] help with pagila

2006-09-01 Thread Walter Cruz
Hi all. I'm with a little doubt.I'm testing the pagila (the postgres port of mysql sakila sample).Well, I was trying to translate the query:select film.film_id AS FID, film.title AS title, film.description AS description, category.name AS category, film.rental_rate AS price,

Re: [SQL] Help with optional parameters

2006-08-17 Thread Rob Tester
This seems to be the best solution. At first I was a bit skeptical about the perfomance using execute versus using pre-planned queries. However, I found that this model actually executes faster than the paramterized queries that I was trying (even using the if-then-endif model).   Thanks for this

Re: [SQL] Help with optional parameters

2006-08-17 Thread MaXX
Rob Tester wrote: I have the need to have optional values for a query in a stored procedure that I am building. (using postgres 8.1.4). This particular query executes against a huge table (several million rows) and has six optional parameters that can be sent to the function. If one of the para

Re: [SQL] Help with optional parameters

2006-08-16 Thread Michael Fuhr
On Wed, Aug 16, 2006 at 08:39:49PM -0700, Rob Tester wrote: > What is the best way to write a query and get the planner to use indexes > when you have optional parameters and columns that can contain NULL values? Have you considered building a query string and using EXECUTE? That's not as "neat" a

[SQL] Help with optional parameters

2006-08-16 Thread Rob Tester
I have the need to have optional values for a query in a stored procedure that I am building. (using postgres 8.1.4). This particular query executes against a huge table (several million rows) and has six optional parameters that can be sent to the function. If one of the parameters is null then th

Re: [SQL] Help with privilages please

2006-07-26 Thread Andrew Hammond
7.4.1 is quite old and has a number of serious known bugs. I'd suggest you either upgrade to 8.1.4 (current) or, if you can't do that, at least upgrade to 7.4.13 (latest 7.4) immediately. Hilary Forbes wrote: > Tom > > Thank you - I think that the underlying problem is that I was trying out > >

Re: [SQL] Help with privilages please

2006-07-21 Thread Hilary Forbes
Tom Thank you - I think that the underlying problem is that I was trying out REVOKE ALL FROM TABLE suppliers FOR public; then connect as hilary and I can still see the table rows. I appear to have to revoke each type eg REVOKE SELECT FROM TABLE suppliers FOR public; etc and then the code works. Is

Re: [SQL] Help with privilages please

2006-07-20 Thread Tom Lane
Hilary Forbes <[EMAIL PROTECTED]> writes: > I have an existing table suppliers and I have created a new user > 'hilary' > REVOKE ALL on TABLE suppliers FROM hilary; > now login as hilary > SELECT * from suppliers; > and I get all the records!!! Most likely there's been a grant of (at least) select

Re: [SQL] Help with privilages please

2006-07-20 Thread Richard Broersma Jr
REVOKE ALL on TABLE suppliers FROM hilary; now login as hilary SELECT * from suppliers; and I get all the records!!! If I create a **new** table though and then do the above, the permissionswork I get a polite message telling me "no go". Thissounds to me like a problem with earlier compatibility

Re: [SQL] Help with privilages please

2006-07-20 Thread Stephan Szabo
On Thu, 20 Jul 2006, Hilary Forbes wrote: > Dear All > > We are running pg v 7.4.1 and importantly the database has been > converted from earlier versions of pg (6.5 I seem to recall). > > I have an existing table suppliers and I have created a new user 'hilary' > > REVOKE ALL on TABLE suppliers F

[SQL] Help with privilages please

2006-07-20 Thread Hilary Forbes
Dear All We are running pg v 7.4.1 and importantly the database has been converted from earlier versions of pg (6.5 I seem to recall). I have an existing table suppliers and I have created a new user 'hilary' REVOKE ALL on TABLE suppliers FROM hilary; now login as hilary SELECT * from suppliers; a

Re: [SQL] Help with performance and explain.

2006-07-07 Thread Oisin Glynn
Oisin Glynn wrote: I have an issue with a select returning very slowly approx 198 seconds. I took a backup of this DB and restored it on another system and it is returning in 28 seconds. Windows 2000 PG Version 8.0.3 Data is inserted into the table row by row. Table has index on service e

[SQL] Help with performance and explain.

2006-07-07 Thread Oisin Glynn
I have an issue with a select returning very slowly approx 198 seconds. I took a backup of this DB and restored it on another system and it is returning in 28 seconds. Windows 2000 PG Version 8.0.3 Data is inserted into the table row by row. Table has index on service explain SELECT callr

Re: [SQL] help..postgresql mulyiple return values

2006-05-18 Thread Tony Wasson
On 5/12/06, Michael Joseph Tan <[EMAIL PROTECTED]> wrote: hi, im new in postgresql, generally new in databases. im trying to make a function using PGAdminIII which returns several types, example, my query is: "select count(id) as requests, organization from connection_requests group by organiz

[SQL] help..postgresql mulyiple return values

2006-05-17 Thread Michael Joseph Tan
hi, im new in postgresql, generally new in databases.   im trying to make a function using PGAdminIII which returns several types, example, my query is:   "select count(id) as requests, organization from connection_requests group by organization"   id is of type int8, organization is of ty

Re: [SQL] Help with a seq scan on multi-million row table

2006-05-11 Thread ogjunk-pgjedan
- Original Message From: Andrew Sullivan <[EMAIL PROTECTED]> To: pgsql-sql@postgresql.org Sent: Thursday, May 11, 2006 1:18:08 PM Subject: Re: [SQL] Help with a seq scan on multi-million row table On Thu, May 11, 2006 at 10:09:44AM -0700, [EMAIL PROTECTED] wrote: > Hi Markus & Tom, >

Re: [SQL] Help with a seq scan on multi-million row table

2006-05-11 Thread Andrew Sullivan
On Thu, May 11, 2006 at 10:09:44AM -0700, [EMAIL PROTECTED] wrote: > Hi Markus & Tom, > > Higher statistics for this column hm, I'd love to try changing > it to see how that changes things, but I'm afraid I don't know how > to do that. How can I change the statistics target value for this > c

Re: [SQL] Help with a seq scan on multi-million row table

2006-05-11 Thread ogjunk-pgjedan
933 This number grows daily by... not sure how much, probably 5k a day currently. Thanks, Otis - Original Message From: Markus Schaber <[EMAIL PROTECTED]> To: [EMAIL PROTECTED] Cc: pgsql-sql@postgresql.org Sent: Thursday, May 11, 2006 6:33:55 AM Subject: Re: [SQL] Help with a

Re: [SQL] Help with a seq scan on multi-million row table

2006-05-11 Thread Tom Lane
Markus Schaber <[EMAIL PROTECTED]> writes: > Did you try to set higher statistics targets for this columns? Yeah, I was about to suggest the same after looking at the pg_stats entry. It shows estimated num_distinct as 60825, ie only about 60k distinct values in the column, which sounds kinda low

Re: [SQL] Help with a seq scan on multi-million row table

2006-05-11 Thread Markus Schaber
Hi, Otis, [EMAIL PROTECTED] wrote: > I'm not sure which numbers you are referring to when you said the estimate is > off, but here are some numbers: > The whole table has 6-7 M rows. > That query matches about 2500 rows. > > If there are other things I can play with and help narrow this dow

Re: [SQL] Help with a seq scan on multi-million row table

2006-05-10 Thread ogjunk-pgjedan
s 6-7 M rows. That query matches about 2500 rows. If there are other things I can play with and help narrow this down, please let me know. Thanks, Otis - Original Message From: Tom Lane <[EMAIL PROTECTED]> To: [EMAIL PROTECTED] Cc: pgsql-sql@postgresql.org Sent: Wednesday, May 10,

Re: [SQL] Help with a seq scan on multi-million row table

2006-05-10 Thread Tom Lane
<[EMAIL PROTECTED]> writes: > Aha! set hashjoin=off did the trick. >-> Index Scan using ix_user_url_tag_user_url_id on > user_url_tag userurltag0_ (cost=0.00..157.34 rows=103 width=14) (actual > time=1.223..1.281 rows=5 loops=1666) > Index Cond: (userurlta

Re: [SQL] Help with a seq scan on multi-million row table

2006-05-10 Thread ogjunk-pgjedan
d from something called Hibernate, and I'm not sure if that will let me set enable_hashjoin=off through its API... Thanks, Otis - Original Message From: Tom Lane <[EMAIL PROTECTED]> To: [EMAIL PROTECTED] Cc: pgsql-sql@postgresql.org Sent: Wednesday, May 10, 2006 8:27:01 PM Sub

Re: [SQL] Help with a seq scan on multi-million row table

2006-05-10 Thread Tom Lane
<[EMAIL PROTECTED]> writes: >-> Hash Join (cost=2797.65..140758.50 rows=3790 width=10) > (actual time=248.530..380635.132 rows=8544 loops=1) > Hash Cond: ("outer".user_url_id = "inner".id) > -> Seq Scan on user_url_tag userurltag0_

Re: [SQL] Help with a seq scan on multi-million row table

2006-05-10 Thread ogjunk-pgjedan
OTECTED] Cc: pgsql-sql@postgresql.org Sent: Wednesday, May 10, 2006 3:23:29 PM Subject: Re: [SQL] Help with a seq scan on multi-million row table On Wed, May 10, 2006 at 13:13:59 -0500, [EMAIL PROTECTED] wrote: > Hello, > > I have a little 2-table JOIN, GROUP BY, ORDER BY query th

Re: [SQL] Help with a seq scan on multi-million row table

2006-05-10 Thread Bruno Wolff III
On Wed, May 10, 2006 at 13:13:59 -0500, [EMAIL PROTECTED] wrote: > Hello, > > I have a little 2-table JOIN, GROUP BY, ORDER BY query that does a sequential > scan on a multi-million row table. I _thought_ I had all the appropriate > indices, but apparently I do not. I was wondering if anyo

[SQL] Help with a seq scan on multi-million row table

2006-05-10 Thread ogjunk-pgjedan
Hello, I have a little 2-table JOIN, GROUP BY, ORDER BY query that does a sequential scan on a multi-million row table. I _thought_ I had all the appropriate indices, but apparently I do not. I was wondering if anyone can spot a way I can speed up this query. The query currently takes... *g

Re: [SQL] SQL help (Informix outer to EnterpriseDB outer)

2006-04-17 Thread kevin
I could probably work this out for you but I have no time today. However, as a 'plan b' maybe try this... 1- create a temp table based on all tables & conditions in the query except for the outer table (i.e. user, ascpDef, address, invention, and user) 2- do an outer join on the above temp table

[SQL] SQL help (Informix outer to EnterpriseDB outer)

2006-04-17 Thread gurkan
Hi all, I have been working on converting our Informix DB to PostgreSQL. There are some differences with SQL syntax. I have done many outer conversion so far, but all has either one outer or simple one. But this one I do not know how to do it. I have searched but could not find similar to what I n

Re: [SQL] SQL help (Informix outer to EnterpriseDB outer)

2006-04-12 Thread kevin . kempter
On Wednesday 12 April 2006 12:49, [EMAIL PROTECTED] wrote: > Hi all, > I have been working on converting our Informix DB to PostgreSQL. There are > some differences with SQL syntax. > > I have done many outer conversion so far, but all has either one outer or > simple > one. But this one I do not k

[SQL] SQL help (Informix outer to EnterpriseDB outer)

2006-04-12 Thread gurkan
Hi all, I have been working on converting our Informix DB to PostgreSQL. There are some differences with SQL syntax. I have done many outer conversion so far, but all has either one outer or simple one. But this one I do not know how to do it. I have searched but could not find similar to what I n

Re: [SQL] help with function

2006-03-16 Thread Daniel Caune
> Hello, > > I have 2 tables where each table has a column named "comments" and the > tables are related as a one to many. I want to concatenate all the > comments of the many side to the one side so I wrote the following > plpgsql function to do so. > > > CREATE OR REPLACE FUNCTION fixcomment

Re: [SQL] help with function

2006-03-16 Thread Алексей Заяц
Hello > EXECUTE 'UPDATE sale SET comments = ' || Use PERFORM instead Alexey ---(end of broadcast)--- TIP 9: In versions below 8.0, the planner will ignore your desire to choose an index scan if your joining column's datatypes do not

[SQL] help with function

2006-03-16 Thread lacou
Hello, I have 2 tables where each table has a column named "comments" and the tables are related as a one to many. I want to concatenate all the comments of the many side to the one side so I wrote the following plpgsql function to do so. CREATE OR REPLACE FUNCTION fixcomments() RETURNS

Re: [SQL] Help with "missing FROM clause" needed

2006-03-06 Thread Greg Stark
"A. Kretschmer" <[EMAIL PROTECTED]> writes: > *untested* > DELETE FROM partner_zu using partner > WHERE partner_zu.pa_id = partner.id > ... > The point is the 'using ...' You can also just set the add_missing_from to true for that one session if you prefer. I don't think there's any plans to remo

Re: [SQL] Help with "missing FROM clause" needed

2006-03-06 Thread A. Kretschmer
am 06.03.2006, um 15:27:54 +0100 mailte Thomas Beutin folgendes: > >>DELETE FROM partner_zu > >>WHERE partner_zu.pa_id = partner.id > >>AND partner_zu.m_id = '25' > >>AND partner.open = 'm' > >>AND partner.a_id = partner_zu.a_id > >>AND partner_zu.a_id = '104335887112347'; > >DELETE FROM partner_z

Re: [SQL] Help with "missing FROM clause" needed

2006-03-06 Thread Thomas Beutin
Richard Huxton wrote: Thomas Beutin wrote: Hi, to be compatible with the postgres standard syntax in 8.1.x i need some help for rewriting my "delete" statements ("select" is not a problem). I use the following statement: DELETE FROM partner_zu WHERE partner_zu.pa_id = partner.id AND partne

Re: [SQL] Help with "missing FROM clause" needed

2006-03-06 Thread Richard Huxton
Thomas Beutin wrote: Hi, to be compatible with the postgres standard syntax in 8.1.x i need some help for rewriting my "delete" statements ("select" is not a problem). I use the following statement: DELETE FROM partner_zu WHERE partner_zu.pa_id = partner.id AND partner_zu.m_id = '25' AND par

Re: [SQL] Help with "missing FROM clause" needed

2006-03-06 Thread A. Kretschmer
am 06.03.2006, um 14:25:52 +0100 mailte Thomas Beutin folgendes: > Hi, > > to be compatible with the postgres standard syntax in 8.1.x i need some > help for rewriting my "delete" statements ("select" is not a problem). I > use the following statement: > > DELETE FROM partner_zu > WHERE partne

[SQL] Help with "missing FROM clause" needed

2006-03-06 Thread Thomas Beutin
Hi, to be compatible with the postgres standard syntax in 8.1.x i need some help for rewriting my "delete" statements ("select" is not a problem). I use the following statement: DELETE FROM partner_zu WHERE partner_zu.pa_id = partner.id AND partner_zu.m_id = '25' AND partner.open = 'm' AND pa

Re: [SQL] Help with distinctly non-intuitive rule behaviour

2006-03-05 Thread Tom Lane
"Simon Kinsella" <[EMAIL PROTECTED]> writes: > CREATE RULE rule_soft_delete_user AS ON DELETE TO users > WHERE user_departed > now() > DO INSTEAD > UPDATE users SET user_departed = now() > WHERE user_id = OLD.user_id; This is run before the delete. However, since it's a conditional

[SQL] Help with distinctly non-intuitive rule behaviour

2006-03-05 Thread Simon Kinsella
Hello, Can this possibly be right? >From my troubleshooting of a DELETE rule it appears that the rule's WHERE condition sees the *results* of the rule-actions. Apart from being pretty odd, this is a proving to be a big problem in my situation. Here is a cut-down example: Given a table 'users',

Re: [SQL] Help with trigger that updates a row prior to a potentially aborted deletion?

2006-03-03 Thread Andrew Sullivan
On Fri, Mar 03, 2006 at 12:19:22AM -, Simon Kinsella wrote: > Hi Andrew, > > I think I may have cracked this problem by combining a RULE ON DELETE which > calls a function instead of the standard DELETE op. No triggers. It was a Ah. Yes, likely. Yeah, you can't do that. A -- Andrew Sull

Re: [SQL] Help with trigger that updates a row prior to a potentially aborted deletion?

2006-03-02 Thread Simon Kinsella
Sent: Thursday, March 02, 2006 12:20 PM To: pgsql-sql@postgresql.org Subject: Re: [SQL] Help with trigger that updates a row prior to a potentially aborted deletion? On Wed, Mar 01, 2006 at 08:41:20PM -, Simon Kinsella wrote: > Ok thanks, will check this out. Is that the same as savepoint

Re: [SQL] Help with trigger that updates a row prior to a potentially aborted deletion?

2006-03-02 Thread Andrew Sullivan
On Wed, Mar 01, 2006 at 08:41:20PM -, Simon Kinsella wrote: > Ok thanks, will check this out. Is that the same as savepoints, or something > different? (am using 8.1.2) Yes, same thing. > At the moment I'm investigating using a rule (rewrite the DELETE as an > UPDATE to set the flag, then use

Re: [SQL] Help with trigger that updates a row prior to a potentially aborted deletion?

2006-03-01 Thread Simon Kinsella
re if it's going to work but if so I'll post back. Thanks! Simon -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Andrew Sullivan Sent: Wednesday, March 01, 2006 6:24 PM To: pgsql-sql@postgresql.org Subject: Re: [SQL] Help with trigger that updates

Re: [SQL] Help with trigger that updates a row prior to a potentially aborted deletion?

2006-03-01 Thread Andrew Sullivan
On Wed, Mar 01, 2006 at 01:30:23PM -, Simon Kinsella wrote: > I'm trying to achieve this with a BEFORE DELETE trigger, which would set the > 'marked_for_deletion' field to TRUE before attempting the delete proper. > Then if the DELETE fails the row would still be tagged and I'd be happy. > Prob

Re: [SQL] Help with trigger that updates a row prior to a potentially aborted deletion?

2006-03-01 Thread Simon Kinsella
Simon Kinsella Cc: pgsql-sql@postgresql.org Subject: Re: [SQL] Help with trigger that updates a row prior to a potentially aborted deletion? On Wed, 1 Mar 2006, Simon Kinsella wrote: > Hi all, > > I have a situation where a DELETE operation may (correctly) fail due > to a RESTRICT FK

Re: [SQL] Help with trigger that updates a row prior to a potentially

2006-03-01 Thread Stephan Szabo
On Wed, 1 Mar 2006, Simon Kinsella wrote: > Hi all, > > I have a situation where a DELETE operation may (correctly) fail due to a > RESTRICT FK constraint. If so, I need to set a flag in the row indicating > that it has been marked for deletion so that I can disregarded in subsequent > queries. >

Re: [SQL] Help with trigger that updates a row prior to a potentially aborted deletion?

2006-03-01 Thread Simon Kinsella
Hello Achilleus Thanks for your feedback. On changing the return to NULL: According to the docs, if I return NULL in the BEFORE trigger itself, all subsequent triggers and the row-level op itself (the actual delete) will be skipped completely, which is no good. I will confirm this to make sure tho

[SQL] Help with trigger that updates a row prior to a potentially aborted deletion?

2006-03-01 Thread Simon Kinsella
Hi all, I have a situation where a DELETE operation may (correctly) fail due to a RESTRICT FK constraint. If so, I need to set a flag in the row indicating that it has been marked for deletion so that I can disregarded in subsequent queries. I'm trying to achieve this with a BEFORE DELETE trigger

Re: [SQL] Help writing a piece of SQL

2006-02-03 Thread Niklas Johansson
On 3 feb 2006, at 14.06, Nigel Bishop wrote: Thank you very much, that did the business This should generate the same plan as the previous query, but be a little bit more clean and easy to read: SELECT sendto FROM users t1 WHERE domain='rusty.com' AND username = COALESCE((SELECT username

Re: [SQL] Help writing a piece of SQL

2006-02-03 Thread Nigel Bishop
Niklas, Thank you very much, that did the business Cheers Nigel Bishop -Original Message- From: Niklas Johansson [mailto:[EMAIL PROTECTED] Sent: 03 February 2006 13:00 To: Nigel Bishop Cc: pgsql-sql@postgresql.org Subject: Re: [SQL] Help writing a piece of SQL On 3 feb 2006, at

Re: [SQL] Help writing a piece of SQL

2006-02-03 Thread Niklas Johansson
On 3 feb 2006, at 11.43, Nigel Bishop wrote: The query will have the username and domain passed in as variables. If the username and domain exist then return the sendto The bit I’m struggling with is if the username doesn’t exist then return the sendto where the domain exists e.g. username=

Re: [SQL] Help writing a piece of SQL

2006-02-03 Thread Nigel Bishop
Bishop ioko T: +44 (0)1904 435 458 M: +44 (0)7881 624 386 F: +44 (0)1904 435 450 E: [EMAIL PROTECTED] W: www.ioko.com -Original Message- From: Richard Huxton [mailto:[EMAIL PROTECTED] Sent: 03 February 2006 11:02 To: Nigel Bishop Cc: pgsql-sql@postgresql.org Subject: Re: [SQL] Help

Re: [SQL] Help writing a piece of SQL

2006-02-03 Thread Richard Huxton
Nigel Bishop wrote: username |domain |sendto +-+---+- - Postmaster | intthit08.uk.rabbit.com | root root | intthit08.uk.rabbit.com | [EMAIL PROTECTED] stoat.grif

[SQL] Help writing a piece of SQL

2006-02-03 Thread Nigel Bishop
Hi, I would appreciate some help writing a piece of SQL   PG803   My table/data looks like this:   username |    domain     |    sendto    +-+---+--  Postmaster   | intthit0

Re: [SQL] [HELP] Defining a function as a procedure

2006-01-26 Thread Tom Lane
"Daniel Caune" <[EMAIL PROTECTED]> writes: > Is there a way to define a function as a procedure, I mean a function > that returns nothing. In recent versions you can say RETURNS VOID, which is a bit of a hack but it gets the point across... regards, tom lane -

[SQL] [HELP] Defining a function as a procedure

2006-01-26 Thread Daniel Caune
Hi,   Is there a way to define a function as a procedure, I mean a function that returns nothing.   CREATE OR REPLACE FUNCTION foo() AS $$ BEGIN   END; $$ LANGUAGE 'plpgsql';   Actually, PostgreSQL complains as a “function result type must be specified”.  I can patch my function

Re: [SQL] Help with simple query

2005-12-28 Thread George Pavlov
or, from the "stupid tricks" category: SELECT n.user_id, max(lpad(extract(epoch from n.modified_date),12,'0') || ' ' || note) FROM notes n GROUP by n.user_id i am not *really* suggesting this! ---(end of broadcast)--- TIP 5: don't forget

Re: [SQL] Help with simple query

2005-12-28 Thread PFC
If you want the latest by user, you can cheat a bit and use the fact that the id's are incrementing, thus ordering by the id is about the same as ordering by the date field. I know it can be inexact in some corner cases, but it's a good approximation, and very useful in practice : SELECT user

Re: [SQL] Help with simple query

2005-12-28 Thread Frank Bax
At 06:58 PM 12/28/05, Collin Peters wrote: The following query will return me all the latest dates, but I can't return the note_id or subject with it. SELECT n.user_id, max(n.modified_date) FROM notes n GROUP by n.user_id ORDER BY n.user_id Is this simpler than I am making it? No, it's not "s

Re: [SQL] Help with simple query

2005-12-28 Thread Tom Lane
Collin Peters <[EMAIL PROTECTED]> writes: > Is there a nice simple query I can run that will return me a list of > all the *latest* notes for all users (users can have many notes in the > table)? You can use SELECT DISTINCT ON for that, if you don't mind using a Postgres-only feature. See the "we

[SQL] Help with simple query

2005-12-28 Thread Collin Peters
I have a simple table called notes which contains notes for users. The table has 4 columns: note_id (auto-incrementing primary key), user_id (foreign key to a users table), note (varchar), and modified_date (timestamp). Is there a nice simple query I can run that will return me a list of all the

Re: [SQL] Help on a complex query (avg data for day of the week)

2005-12-21 Thread Matthew Smith
Michael, Thanks heaps for that! Cheers, Matt Smith On Thu, 22 Dec 2005 01:37 pm, Michael Fuhr wrote: > On Thu, Dec 22, 2005 at 11:59:24AM +1100, Matthew Smith wrote: > > Sadly I am using 7.3, it seems that generate_series() is 8.0 and later. > > Yes, but it's easily written in PL/pgSQL for earl

Re: [SQL] Help on a complex query (avg data for day of the week)

2005-12-21 Thread Michael Fuhr
On Thu, Dec 22, 2005 at 11:59:24AM +1100, Matthew Smith wrote: > Sadly I am using 7.3, it seems that generate_series() is 8.0 and later. Yes, but it's easily written in PL/pgSQL for earlier versions. Example: CREATE FUNCTION generate_series(integer, integer) RETURNS SETOF integer AS ' DECLARE

Re: [SQL] Help on a complex query (avg data for day of the week)

2005-12-21 Thread Matthew Smith
Richard (and list), Thanks for the help! More below: On Wed, 21 Dec 2005 09:04 pm, Richard Huxton wrote: > Matthew Smith wrote: > > I want to form a query that returns the average total usage for each day > > of the week, eg: > > [snip] > > > To get this info, I am using the following query: > >

Re: [SQL] Help on a complex query (avg data for day of the week)

2005-12-21 Thread Richard Huxton
Matthew Smith wrote: I want to form a query that returns the average total usage for each day of the week, eg: [snip] To get this info, I am using the following query: select dow as day, sum(sum_data)/count(dow) as avg_usage from (select extract('dow' from date_trunc('day', time)) as dow, sum

Re: [SQL] Help me do a LOOP

2005-12-21 Thread Richard Huxton
Calin Meze wrote: I need to test each record of a cursor for some requirements, something like this [snip] -- the problem is that I do not know how to make the while loop execute until the last record "WHILE (still in the cursor)"... So I need something like Can anyone help me with this? It

[SQL] Help on a complex query (avg data for day of the week)

2005-12-20 Thread Matthew Smith
Hello, I have a table containing a timestamp and data usage fields (among others). This table stores amounts of data usage and the times then the data was used, eg: time | data +-- 2005-03-26 09:32:43+11 | 162 I want to form a query that retu

[SQL] Help me do a LOOP

2005-12-20 Thread Calin Meze
 I need to test each record of a cursor for some requirements, something like thisDECLARE xpvnr varchar(50);  xdata date;  xcod int;  xagentd varchar(3);  xid bigint;  xserie varchar(4);  xnr varchar(7);  xsocasig varchar(3); DECLARE myCursor CURSOR FOR

Re: [SQL] Need SQL Help Finding Current Status of members

2005-12-18 Thread Michael Fuhr
On Sat, Dec 17, 2005 at 07:34:22PM -0500, Michael Avila wrote: > The table is not empty. I did some playing around with the SQL Statement but > got no where. So I added a record status column that will be non-NULL when > the status becomes history because a new status is added. Yeah, I cheated to >

Re: [SQL] Need SQL Help Finding Current Status of members

2005-12-17 Thread Michael Avila
for the help. Mike > -Original Message- > From: Michael Fuhr [mailto:[EMAIL PROTECTED] > Sent: Saturday, December 17, 2005 7:26 PM > To: Michael Avila > Cc: SQL PostgreSQL MailList > Subject: Re: [SQL] Need SQL Help Finding Current Status of members > > > On

Re: [SQL] Need SQL Help Finding Current Status of members

2005-12-17 Thread Michael Fuhr
On Fri, Dec 16, 2005 at 07:44:46PM -0500, Michael Avila wrote: > Just tried it and it returned nothing. > > > > Select * from memberstatus A where not exists > > >(select * from emberstatus B where B.member_id=A.member_id and > > > B.status_date >A.status_date) > > Why the WHERE NOT EXISTS?

Re: [SQL] Help on function creating

2005-12-17 Thread Bruno Wolff III
On Fri, Dec 16, 2005 at 14:03:14 -0200, Alexandre Gonçalves Jacarandá <[EMAIL PROTECTED]> wrote: > Guys, I can do what I need but I have other problem: How can I named > columns with another data ? For example: You might be better off doing this in your application rather than entirely with sql.

Re: [SQL] Need SQL Help Finding Current Status of members

2005-12-16 Thread Michael Avila
ROTECTED] > > [mailto:[EMAIL PROTECTED] Behalf Of Patrick JACQUOT > > Sent: Friday, December 16, 2005 5:12 AM > > Cc: SQL PostgreSQL MailList > > Subject: Re: [SQL] Need SQL Help Finding Current Status of members > > > > > > Richard Huxton wrot

Re: [SQL] Help on function creating

2005-12-16 Thread Alexandre Gonçalves Jacarandá
Guys, I can do what I need but I have other problem: How can I named columns with another data ? For example: select * from crosstab('select pessoa_nome(ref_pessoa), ref_disciplina, nota_final from matricula where ref_periodo = ''25CASI'' order by 1,2', 'select ref_disciplina from disciplinas_ofer

Re: [SQL] Need SQL Help Finding Current Status of members

2005-12-16 Thread Alvaro Herrera
Michael Avila wrote: > Interesting. I think I understand that. I have never worked with a SELECT > within a SELECT (I think that is called a subquery). I am guessing that it > works its way through the member status records until the latest date > "floats" to the top (nothing is > than it). > > Wil

Re: [SQL] Need SQL Help Finding Current Status of members

2005-12-16 Thread Michael Avila
m performance-wise if there are thousands of records? Thanks for the help. Mike > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] Behalf Of Patrick JACQUOT > Sent: Friday, December 16, 2005 5:12 AM > Cc: SQL PostgreSQL MailList > Subject:

Re: [SQL] Need SQL Help Finding Current Status of members

2005-12-16 Thread Patrick JACQUOT
Richard Huxton wrote: Michael Avila wrote: I have a table which keeps track of the status of members. In the table is member_id int(8) status_code char(1) status_date date KEY member_id (member_id,status_code,status_date) Each member can have multiple records because a record is added each

Re: [SQL] Need SQL Help Finding Current Status of members

2005-12-16 Thread Richard Huxton
Michael Avila wrote: I have a table which keeps track of the status of members. In the table is member_id int(8) status_code char(1) status_date date KEY member_id (member_id,status_code,status_date) Each member can have multiple records because a record is added each time the status chan

Re: [SQL] Need SQL Help Finding Current Status of members

2005-12-15 Thread Michael Fuhr
On Thu, Dec 15, 2005 at 08:31:09PM -0500, Michael Avila wrote: > What I want to do is find the latest status for each member. Actually I want > to find all those with an status of "A". But it must be the current (latest) > status. How do I find the most current date for each member in a pile of > m

[SQL] Need SQL Help Finding Current Status of members

2005-12-15 Thread Michael Avila
I have a table which keeps track of the status of members. In the table is member_id int(8) status_code char(1) status_date date KEY member_id (member_id,status_code,status_date) Each member can have multiple records because a record is added each time the status changes but the old record i

Re: [SQL] Help on function creating

2005-12-08 Thread Alexandre Gonçalves Jacarandá
Thanks Andrew, Osvaldo ( Obrigado) and Aaron !! Sory Andrew the right version number is 7.4.3 and I'll study the crosstab because it's seems to fit for sutuation. See you... Andrew Sullivan escreveu: > I think you can do this with the contrib/crosstab stuff. But AFAIK, > there's no such thing as

Re: [SQL] Help on function creating

2005-12-07 Thread Aaron Koning
Have you considered using a view to create the report? AaronOn 12/7/05, Alexandre Gonçalves Jacarandá <[EMAIL PROTECTED]> wrote: Hello everyone, I'm using postgresql form an year and I have somedifficult to write a function to make an report. I'm running PostgreSQL7.5.3 on i686-pc-linux-gnu (Mandr

[SQL] Help on function creating

2005-12-07 Thread Alexandre Gonçalves Jacarandá
Hello everyone, I'm using postgresql form an year and I have some difficult to write a function to make an report. I'm running PostgreSQL 7.5.3 on i686-pc-linux-gnu (Mandriva 10.1). My table structure is: Tabela "public.matricula" Column | Type |Modifiers

Re: [SQL] Help needed

2005-11-30 Thread Richard Huxton
NosyMan wrote: Hi everyone, I have some kind of strange problem. I want to build general parametrized trigger for my database. The parameter sent to the trigger contains a column name that trigger should be check. The 'vt' variable contains the column name. In the above statement I want th

[SQL] Help needed

2005-11-30 Thread NosyMan
Hi everyone, I have some kind of strange problem. I want to build general parametrized trigger for my database. The parameter sent to the trigger contains a column name that trigger should be check. CREATE OR REPLACE FUNCTION F_T_IU__check() RETURNS trigger AS $$ DECLARE

Re: [SQL] Help with simple SQL query?

2005-10-05 Thread Joost Kraaijeveld
On Wed, 2005-10-05 at 14:21 +0200, Frank van Vugt wrote: > Hi Joost, > > Try joining and comparing the order table with/to an aggregated orderline > table, something like this: > > select order_id, order_price, sum_price, order_price - sum_price as diff > from order, (select parent_order_id, su

Re: [SQL] Help with simple SQL query?

2005-10-05 Thread Frank van Vugt
Hi Joost, Try joining and comparing the order table with/to an aggregated orderline table, something like this: select order_id, order_price, sum_price, order_price - sum_price as diff from order, (select parent_order_id, sum(orderline_price) as sum_price from orderline group by parent_

Re: [SQL] Help with simple SQL query?

2005-10-05 Thread Gregory S. Williamson
order_price NOT IN (select sum(orderline_price) from orderline group by parent_order_id) HTH, Greg Williamson DBA GlobeXplorer LLC -Original Message- From: [EMAIL PROTECTED] on behalf of Joost Kraaijeveld Sent: Wed 10/5/2005 4:35 AM To: Pgsql-sql@postgresql.org Cc: Subject:[SQL

[SQL] Help with simple SQL query?

2005-10-05 Thread Joost Kraaijeveld
Hi, I have 2 tables with the following columns: order: order_id, order_price orderline: parent_order_id, orderline_price I want all orders order where _price <> sum(orderline_price). What is wrong with the following query: select order_id from order, orderline where order_id = parent_order_id

Re: [SQL] Help with multistage query

2005-10-04 Thread Jim C. Nasby
On Wed, Sep 07, 2005 at 05:37:47PM -0400, Matt Emmerton wrote: > > - Original Message - > From: Russell Simpkins > To: pgsql-sql@postgresql.org > Sent: Wednesday, September 07, 2005 4:05 PM > Subject: Re: [SQL] Help with multistage query > > I

Re: [SQL] Help with a view

2005-09-22 Thread Dmitri Bichko
hursday, September 22, 2005 2:12 PM > To: pgsql-sql@postgresql.org > Subject: Re: [SQL] Help with a view > > > On Thursday 22 September 2005 20:03, Dmitri Bichko wrote: > > > SELECT * FROM principals WHERE event = 15821 AND person != 2? > > Sure, that's a concis

<    1   2   3   4   5   >