Re: [SQL] pg, mysql comparison with "group by" clause

2005-10-12 Thread Anthony Molinaro
Greg, Ok, I think I see where you're going (I don't agree, but I think I get you now). So, using your example of: "dept_name is guaranteed to be the same for all records with the same dept_id." Here: select d.deptno,d.dname from emp e, dept d where e.deptno=d.deptno DEPTNO DNAME --

Re: [SQL] UPDATE Trigger on multiple tables

2005-10-12 Thread Tom Lane
Ferindo Middleton Jr <[EMAIL PROTECTED]> writes: > Is it possible to have a single trigger on multiple tables > simultaneously? Example: > CREATE TRIGGER emp_cust_stamp BEFORE INSERT OR UPDATE ON employees, customers > FOR EACH ROW EXECUTE PROCEDURE last_updated_stamp(); No. You can use the

[SQL] UPDATE Trigger on multiple tables

2005-10-12 Thread Ferindo Middleton Jr
Is it possible to have a single trigger on multiple tables simultaneously? Example: CREATE TRIGGER emp_cust_stamp BEFORE INSERT OR UPDATE ON employees, customers FOR EACH ROW EXECUTE PROCEDURE last_updated_stamp(); I tried something like the above but get an error message at the comma. I tri

Re: [SQL] pg, mysql comparison with "group by" clause

2005-10-12 Thread Greg Stark
"Anthony Molinaro" <[EMAIL PROTECTED]> writes: > Greg, > You'll have to pardon me... > > I saw this comment: > > "I don't see why you think people stumble on this by accident. > I think it's actually an extremely common need." > > Which, if referring to the ability to have items in the sele

Re: [SQL] pg, mysql comparison with "group by" clause

2005-10-12 Thread Anthony Molinaro
Greg, You'll have to pardon me... I saw this comment: "I don't see why you think people stumble on this by accident. I think it's actually an extremely common need." Which, if referring to the ability to have items in the select that do not need to be included in the group, (excluding consta

Re: [SQL] pg, mysql comparison with "group by" clause

2005-10-12 Thread Greg Stark
"Anthony Molinaro" <[EMAIL PROTECTED]> writes: > By changing the values in the select/group by you are changing > Group! How can you arbitrarily add or exclude a column? > You can't do it. Go back and reread the previous posts again. You missed the whole point. -- greg --

Re: [SQL] pg, mysql comparison with "group by" clause

2005-10-12 Thread Anthony Molinaro
Tom, Don't do it man... It's not the same. The standard has it wrong (that or I misunderstood your explanation). But this statement: > you shouldn't have to explicitly list the other columns from that > table --- they are guaranteed to have unique values per group anyway ...is way off. By c

Re: [SQL] Update timestamp on update

2005-10-12 Thread Michael Glaesemann
On Oct 13, 2005, at 11:52 , Tom Lane wrote: Jeff Williams <[EMAIL PROTECTED]> writes: Thanks. Triggers was my first thought, but chapter 35 on Triggers didn't really indicate a way I could do this easily and scared me with a lot of c code. Yeah. This is a documentation issue that's bo

Re: [SQL] pg, mysql comparison with "group by" clause

2005-10-12 Thread Anthony Molinaro
> I don't see why you think people stumble on this by accident. I think it's > actually an extremely common need. I can't imagine how that's a common need at all. It makes no sense. When you add an additional column in the select, it must be included in the group by as it changes the meaning of

Re: [SQL] Update timestamp on update

2005-10-12 Thread Stewart Ben (RBAU/EQS4) *
> The problem is that we treat the PL languages as add-ons and therefore > the documentation of the "core" system shouldn't rely on them ... but > that leaves us presenting C-code triggers as the only examples in > chapter 35. There is a paragraph in there suggesting you go look at > the PL langu

Re: [SQL] Update timestamp on update

2005-10-12 Thread Tom Lane
Jeff Williams <[EMAIL PROTECTED]> writes: > Thanks. Triggers was my first thought, but chapter 35 on Triggers didn't > really indicate a way I could do this easily and scared me with a lot of > c code. Yeah. This is a documentation issue that's bothered me for awhile. The problem is that we treat

Re: [SQL] Update timestamp on update

2005-10-12 Thread Jeff Williams
Tom Lane wrote: >Jeff Williams <[EMAIL PROTECTED]> writes: > > >>last_status_change timestamp DEFAULT now() >> >> > > > >>What I would like is that whenever the status is changed the >>last_status_change timestamp is updated to the current time. >> >> > >For this you use an ON UPDA

Re: [SQL] SEVEN cross joins?!?!?

2005-10-12 Thread Stewart Ben (RBAU/EQS4) *
> Splitting locations into subsets (like 2,2,3) doesn't work > because it is possible that low values in one location can be offset by > high values in another location, and still result in an excellent combo. > > The good news is these suggestions got me thinking outside > the box. I think I

Re: [SQL] pg, mysql comparison with "group by" clause

2005-10-12 Thread Tom Lane
Greg Stark <[EMAIL PROTECTED]> writes: > I think most MySQL users don't stumble on it, they learn it as the way > to handle the common use case when you join a master table against a > detail table and then want to aggregate all the detail records. In > standard SQL you have to write GROUP BY ... a

Re: [SQL] SEVEN cross joins?!?!?

2005-10-12 Thread Frank Bax
At 09:00 AM 10/12/05, Daryl Richter wrote: Richard Huxton wrote: Frank Bax wrote: Are you saying that you WANT to generate a cross-join, score the millions of results and then pick the best 10? It's doing what you want, but you'd like it to be faster. Or are you saying that you'd like to a

Re: [SQL] Update timestamp on update

2005-10-12 Thread Tom Lane
Jeff Williams <[EMAIL PROTECTED]> writes: > last_status_change timestamp DEFAULT now() > What I would like is that whenever the status is changed the > last_status_change timestamp is updated to the current time. For this you use an ON UPDATE trigger; rules are not a good way to solve it. Se

[SQL] Update timestamp on update

2005-10-12 Thread Jeff Williams
I have a table like: CREATE TABLE products ( id int, status int, last_status_change timestamp DEFAULT now() ); What I would like is that whenever the status is changed the last_status_change timestamp is updated to the current time. I have had a look at the rules and what I want would

Re: [SQL] pg, mysql comparison with "group by" clause

2005-10-12 Thread Greg Stark
Scott Marlowe <[EMAIL PROTECTED]> writes: > Hehe. When I turn on my windshield wipers and my airbag deploys, is it > a documented "feature" if the dealership told me about this behaviour > ahead of time? Well it's more like my car where the dashboard dims when I turn on my headlights which ann

Re: [SQL] Text->Date conversion in a WHERE clause

2005-10-12 Thread Tom Lane
[EMAIL PROTECTED] writes: > SELECT * > FROM > ( > SELECT u.user_id, ud.data > FROM users u, userdata ud > WHERE u.user_id = ud.user_id > AND u.type = 1 > ) subusers > WHERE subusers.data::text::date < now(); > So my question is how does this query ever even SEE the row con

Re: [SQL] pg, mysql comparison with "group by" clause

2005-10-12 Thread Anthony Molinaro
> Not always, but I'd rather get the right answer with difficulty than the wrong one with ease. :) agreed. I made it a point to mention this so called "feature" in my book. This is a bug they never fixed and they decided to call it a feature. It is, imo, *ridiculous*. Regards, Anthony

Re: [SQL] Text->Date conversion in a WHERE clause

2005-10-12 Thread Tom Lane
Collin Peters <[EMAIL PROTECTED]> writes: > WHERE cust3 <> '' > AND cust3::text::timestamp > CURRENT_DATE - interval '1 month' > This results in the error 'ERROR: date/time field value out of range: > "052-44-5863"'. Now that is obviously not a valid date but there > is actually more to the

Re: [SQL] pg, mysql comparison with "group by" clause

2005-10-12 Thread Scott Marlowe
On Wed, 2005-10-12 at 16:54, Greg Stark wrote: > Stephan Szabo <[EMAIL PROTECTED]> writes: > > > On Tue, 11 Oct 2005, Rick Schumeyer wrote: > > > > > I'm not sure what I was thinking, but I tried the following query in pg: > > > > > > SELECT * FROM t GROUP BY state; > > > > > > pg returns an erro

Re: [SQL] Text->Date conversion in a WHERE clause

2005-10-12 Thread Greg Stark
Collin Peters <[EMAIL PROTECTED]> writes: > I have a table that has some columns which store 'custom' fields so the > content varies according to the user that the row belongs to. For one > of the groups of users the field is a date (the type of the field is > 'text' though). I'm trying to perfo

Re: [SQL] regular expression

2005-10-12 Thread Yasir Malik
This isn't a PostgreSQL issue, but rather one of understanding how regular expressions work in general. See the previously mentioned "Pattern Matching" section of the PostgreSQL documentation for the PostgreSQL-specific details, and use a search engine to find a regular expression tutorial; they'

Re: [SQL] pg, mysql comparison with "group by" clause

2005-10-12 Thread Greg Stark
Stephan Szabo <[EMAIL PROTECTED]> writes: > On Tue, 11 Oct 2005, Rick Schumeyer wrote: > > > I'm not sure what I was thinking, but I tried the following query in pg: > > > > SELECT * FROM t GROUP BY state; > > > > pg returns an error. > > > > Mysql, OTOH, returns the first row for each state. (T

Re: [SQL] Text->Date conversion in a WHERE clause

2005-10-12 Thread cadiolis
As an example: CREATE TABLE userdata ( userdata_id serial NOT NULL, user_id smallint, data text ); CREATE TABLE users ( user_id serial NOT NULL, name text, "type" smallint ); INSERT INTO userdata (userdata_id, user_id, data) VALUES (1, 1, '2005-01-01'); INSERT INTO userda

Re: [SQL] regular expression

2005-10-12 Thread Michael Fuhr
[Please copy the mailing list on replies.] On Wed, Oct 12, 2005 at 04:28:47PM -0400, [EMAIL PROTECTED] wrote: > Thanks for the reply. It helped a lot. I was goint to ask similar question > regarding regular expression, but this time I need not the numeric part. What > I > mean is; > say that this

[SQL] Text->Date conversion in a WHERE clause

2005-10-12 Thread Collin Peters
I have a table that has some columns which store 'custom' fields so the content varies according to the user that the row belongs to. For one of the groups of users the field is a date (the type of the field is 'text' though). I'm trying to perform a query where it only returns values in a certai

[SQL] Strange join...maybe some improvements???

2005-10-12 Thread Andy
I have 3 tables: CREATE TABLE orders(  id int4 SERIAL,  id_ag int4,  id_modell int4 ->> this is linked to the modell.id )   CREATE TABLE modell(  id int4 SERIAL,  id_hersteller int4)   CREATE TABLE contactpartner(  id int4 SERIAL,  id_ag int4, ->> this is linked to order.id_ag or modell.i

Re: [SQL] SEVEN cross joins?!?!?

2005-10-12 Thread Daryl Richter
Richard Huxton wrote: Frank Bax wrote: Are you saying that you WANT to generate a cross-join, score the millions of results and then pick the best 10? It's doing what you want, but you'd like it to be faster. Or are you saying that you'd like to avoid the explosion in rows altogether? In

Re: [SQL] SEVEN cross joins?!?!?

2005-10-12 Thread Richard Huxton
Frank Bax wrote: Are you saying that you WANT to generate a cross-join, score the millions of results and then pick the best 10? It's doing what you want, but you'd like it to be faster. Or are you saying that you'd like to avoid the explosion in rows altogether? In either case - I don't su

Re: [SQL] Returning NULL results?

2005-10-12 Thread Mario Splivalo
On Tue, 2005-10-11 at 15:39 +0100, Richard Huxton wrote: > Mario Splivalo wrote: > > > > Of course, if it returns no rows, I'm presented with an error, saying: > > > > ERROR: record "rec" has no field "_qv" > > > > This is logical. My question would be is there a way around this > > withouth fi