[SQL] generate a range within a view

2013-10-10 Thread Gary Stainburn
, de_id int4 not null, de_date date not null, day_limit int4 not null CHECK (day_limit = 0), primary key (s_id,de_id, de_date), foreign key (s_id, de_id) references site_user_departments (s_id, de_id) ); -- Gary Stainburn Group I.T. Manager Ringways Garages http

Re: [SQL] generate a range within a view

2013-10-10 Thread Gary Stainburn
| 8 H|80 | 2013-10-11 | 5 | 3 H|80 | 2013-10-12 | 6 | 2 (7 rows) goole=# -- Gary Stainburn Group I.T. Manager Ringways Garages http://www.ringways.co.uk -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your

[SQL] unique key problem on update

2013-09-20 Thread Gary Stainburn
round this. Also, the final version will be put onto a WordPress web site which means I will have to port it to MYSQL which I don't know, so any solution that will work with both systems would be a great help. Ta Gary stainburn=# \d skills_pages Table

Re: [SQL] unique key problem on update

2013-09-20 Thread Gary Stainburn
) deferrable ); Cheers. I'll look at that. It's actually the second unique index that's the problem but I'm guessing I can set that index up as deferrable too. Hopefully it'll work for mysql too. -- Gary Stainburn Group I.T. Manager Ringways Garages http://www.ringways.co.uk -- Sent via pgsql-sql

Re: [SQL] value from max row in group by

2013-07-26 Thread Gary Stainburn
, stts_offset+stts_duration from table order by stts_id, stts_offset desc Marc Mamin -- Gary Stainburn Group I.T. Manager Ringways Garages http://www.ringways.co.uk -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org

[SQL] value from max row in group by

2013-07-25 Thread Gary Stainburn
Hi folks, I need help please. I have a table of trip section details which includes a trip ID, start time as an offset, and a duration for that section. I need to extract the full trip duration by adding the highest offset to it's duration. I can't simply use sum() on the duation as that

Re: [SQL] value from max row in group by

2013-07-25 Thread Gary Stainburn
As usual, once I've asked the question, I find the answer myself. However, it *feels* like there should be a more efficient way. Can anyone comment or suggest a better method? timetable= select stts_id, stts_offset+stts_duration as total_duration timetable- from standard_trip_sections

[SQL] pull in most recent record in a view

2012-10-28 Thread Gary Stainburn
= q.st_id join skills k on k.sk_id = q.sk_id order by st_id, sk_id I am still at the concept stage for this project so I can change the schema if required -- Gary Stainburn Group I.T. Manager Ringways Garages http://www.ringways.co.uk -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org

Re: [SQL] pull in most recent record in a view

2012-10-28 Thread Gary Stainburn
join skills k on k.sk_id = q.sk_id; -- Gary Stainburn Group I.T. Manager Ringways Garages http://www.ringways.co.uk -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql

[SQL] weird join producing too many rows

2012-09-12 Thread Gary Stainburn
| ESALES4 | 4197 | WSERV1 | 2731 | LSALESE | (33 rows) users=# -- Gary Stainburn Group I.T. Manager Ringways Garages http://www.ringways.co.uk -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org

Re: [SQL] weird join producing too many rows

2012-09-12 Thread Gary Stainburn
in multiple rows for each p_id somehow. -- Gary Stainburn Group I.T. Manager Ringways Garages http://www.ringways.co.uk -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql

Re: [SQL] generated dates from record dates - suggestions

2012-08-23 Thread Gary Stainburn
-- Gary Stainburn Group I.T. Manager Ringways Garages http://www.ringways.co.uk -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql

Re: [SQL] generated dates from record dates - suggestions

2012-08-21 Thread Gary Stainburn
was wondering, and was looking for suggestions / best practices on how to do this. I had first thought of embedding case/when statements in the view but it could easily become unweildy -- Gary Stainburn Group I.T. Manager Ringways Garages http://www.ringways.co.uk -- Sent via pgsql-sql mailing list

Re: [SQL] generated dates from record dates - suggestions

2012-08-21 Thread Gary Stainburn
, date_2 and date_3. The resulting view needs to contain date_1, date_2, date_3, date_a and date_b where date_a and date_b are calculated based on the first three (plus a text field). -- Gary Stainburn Group I.T. Manager Ringways Garages http://www.ringways.co.uk -- Sent via pgsql-sql mailing

[SQL] generated dates from record dates - suggestions

2012-08-20 Thread Gary Stainburn
rhen date_b=date1 else date_b=date2 etc. What's the best way to do this? I know it's a quite open question but I'm interested to hear different responses -- Gary Stainburn Group I.T. Manager Ringways Garages http://www.ringways.co.uk -- Sent via pgsql-sql mailing list (pgsql-sql

[SQL] left outer join only select newest record

2012-05-23 Thread Gary Stainburn
= u.ud_registration; -- Gary Stainburn Group I.T. Manager Ringways Garages http://www.ringways.co.uk -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql

Re: [SQL] left outer join only select newest record

2012-05-23 Thread Gary Stainburn
- Original Message - From: Gary Stainburn gary.stainb...@ringways.co.uk To: pgsql-sql@postgresql.org Sent: Wednesday, May 23, 2012 10:27 AM Subject: [SQL] left outer join only select newest record Hi folks, I know I've seen posts like this before but Google isn't helping today

Re: [SQL] left outer join only select newest record

2012-05-23 Thread Gary Stainburn
On Wednesday 23 May 2012 10:46:02 Pavel Stehule wrote: select distinct on (s.s_registration) * ... order by u.ud_id desc I tried doing this but it complained about the order by. goole=# select distinct on (s.s_stock_no) s_stock_no, s_regno, s_vin, s_created, ud_id, ud_handover_date from

Re: [SQL] Wrong output from union

2012-04-02 Thread Gary Stainburn
://www.postgresql.org/docs/9.0/interactive/sql-select.html -- Gary Stainburn Group I.T. Manager Ringways Garages http://www.ringways.co.uk -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql

[SQL] Wrong output from union

2012-03-30 Thread Gary Stainburn
' and rm_timestamp = ('2012-03-26'::date + '7 days'::interval); key --- 25:2012-03-27 25:2012-03-28 25:2012-03-29 25:2012-03-30 (4 rows) users=# -- Gary Stainburn Group I.T. Manager Ringways Garages http://www.ringways.co.uk -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org

Re: [SQL] Another constant in foreign key problem.

2012-02-23 Thread Gary Stainburn
this but can't find a suitable solution. Can anyone help please. -- Gary Stainburn Group I.T. Manager Ringways Garages http://www.ringways.co.uk -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org

[SQL] Another constant in foreign key problem.

2012-02-22 Thread Gary Stainburn
this but can't find a suitable solution. Can anyone help please. -- Gary Stainburn Group I.T. Manager Ringways Garages http://www.ringways.co.uk -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql

Re: [SQL] Another constant in foreign key problem.

2012-02-22 Thread Gary Stainburn
and not facility_levels. Everything in the child table would also exist in facility_levels. As this is so specific to PostgreSQL and is not hugely common as a technique, read this as a *possible* solution not a recommended one. Hope this helps -- Gary Stainburn Group I.T. Manager Ringways Garages

Re: [SQL] date range to set of dates expansion

2012-01-20 Thread Gary Stainburn
on a FC9 system using RPM's? Also, the last time I did a server upgrade (FC4 to the FC9 system) upgrading apache, PHP and postgresql broke so many things in my applications it was painful. Can anyone suggest ways I can soak test my systems before upgrading the live system? -- Gary Stainburn

Re: [SQL] date range to set of dates expansion

2012-01-19 Thread Gary Stainburn
live systems? -- Gary Stainburn Group I.T. Manager Ringways Garages http://www.ringways.co.uk -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql

Re: [SQL] date range to set of dates expansion

2012-01-19 Thread Gary Stainburn
On Thursday 19 January 2012 15:11:46 Gary Stainburn wrote: I'll be upgrading my live server as soon as possible, but in the meantime can anyone suggest a way I can do the same thing using Postgresql 8.1 until I can evaluate 8.4 on my live systems? Sorry, I meant 8.3 as my current version

Re: [SQL] date range to set of dates expansion

2012-01-19 Thread Gary Stainburn
called in context that cannot accept a set CONTEXT: PL/pgSQL function date_range line 4 at RETURN NEXT Is there a way to use the integer only generate_series in 8.3 to generate dates by typecasting to/from integers? -- Gary Stainburn Group I.T. Manager Ringways Garages http

Re: [SQL] SOLVED - date range to set of dates expansion

2012-01-19 Thread Gary Stainburn
Sorry for using the list as a scratch-pad for my brain. select aid, asid, generate_series(asdate-'1970-01-01'::date, afdate-'1970-01-01'::date)+'1970-01-01'::date as adate, acomments from availability; Has done the trick. -- Gary Stainburn Group I.T. Manager Ringways Garages http

[SQL] date range to set of dates expansion

2012-01-18 Thread Gary Stainburn
wdate = tdate LOOP return next wdate; wdate:=wdate+1; end LOOP; return; END; $$ LANGUAGE plpgsql; -- Gary Stainburn Group I.T. Manager Ringways Garages http://www.ringways.co.uk -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription

Re: SOLVED - [SQL] foreign keys and lots of tables

2011-05-19 Thread Gary Stainburn
anyway. Gary On Thursday 19 May 2011 01:09:07 David W Noon wrote: On Wed, 18 May 2011 20:10:19 +0100, Gary Stainburn wrote about [SQL] foreign keys and lots of tables: I have the following tables (individual seat allocation removed to make it simpler) Omitting details makes the problem

[SQL] foreign keys and lots of tables

2011-05-18 Thread Gary Stainburn
the bookings table and I don't know how. To complicate things, when the initial booking is made, bot c_id and c_seat are NULL. Will this make any difference? Gary -- Gary Stainburn Group I.T. Manager Ringways Garages http://www.ringways.co.uk -- Sent via pgsql-sql mailing list (pgsql-sql

[SQL] foreign key question

2011-01-05 Thread Gary Stainburn
(u_id) fl_level int4 not null references facility_levels(16, fl_level) Firstly, is this possible, and secondly how would I do it? -- Gary Stainburn I.T. Manager Ringways Garages http://www.ringways.co.uk -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your

Re: [SQL] foreign key question

2011-01-05 Thread Gary Stainburn
On Wednesday 05 January 2011 09:53:43 Gary Stainburn wrote: Now I want to set up a new access level table specific to the itinerary, along the lines of u_id int4 not null references users(u_id) fl_level int4 not null references facility_levels(16, fl_level) Firstly, is this possible

[SQL] create function problem

2010-12-30 Thread Gary Stainburn
THEN RETURN eta; END IF; RETURN req_date; END; $$ LANGUAGE 'plpgsql'; [r...@stan t-cards]# -- Gary Stainburn I.T. Manager Ringways Garages http://www.ringways.co.uk -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org

Re: [SQL] create function problem

2010-12-30 Thread Gary Stainburn
On Thursday 30 December 2010 17:47:09 Adrian Klaver wrote: To follow up I think the OP was looking for ELSEIF not ELSE IF. Changing the ELSE IF to ELSEIF should fix it. Thanks guys. That'll teach me to read tutorials more carefully. -- Gary Stainburn I.T. Manager Ringways Garages http

[SQL] Slow response in select

2010-09-21 Thread Gary Stainburn
that has been live for some time but I've never managed to get to the bottom of why it's much slower than the other views. Gary -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed

Re: [SQL] Slow response in select

2010-09-21 Thread Gary Stainburn
On Tuesday 21 September 2010 15:11:09 Craig Ringer wrote: On 09/21/2010 08:25 PM, Gary Stainburn wrote: Hi folks,I have a view that seems to be very slow compared to similar views on the same server. I've had a look at running explain but I don't really understand it. I've posted

Re: [SQL] Slow response in select

2010-09-21 Thread Gary Stainburn
On Tuesday 21 September 2010 15:20:15 Gary Stainburn wrote: I've posted th explain analyze at http://www1.ringways.co.uk/explain_analyse.txt I've marked a line with a sort in that appears to be the bit that's taking the time. Am I right? I've had a look at this, and I can't even see why

Re: [SQL] simple (?) join

2009-09-28 Thread Gary Stainburn
entry per order. -- Gary Stainburn Gary's Haircut 700 Please visit http://www.justgiving.com/Gary-Stainburn/ to help me raise money for Cancer Research - in return I'll have my head shaved -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription

Re: [SQL] simple (?) join

2009-09-28 Thread Gary Stainburn
ON ol.o_id=o.o_id AND ol.ol_timestamp=max_olt.maxts ; Cheers Jim, That worked. Gary -- Gary Stainburn Gary's Haircut 700 Please visit http://www.justgiving.com/Gary-Stainburn/ to help me raise money for Cancer Research - in return I'll have my head shaved

[SQL] simple join is beating me

2009-07-13 Thread Gary Stainburn
| 5 |4 2009-07-08 | 12 |2 2009-07-07 | 5 |4 2009-07-06 | 2 |7 2009-07-03 | 2 |6 2009-07-02 | 7 |5 2009-07-01 | 19 |3 2009-06-30 | 20 |3 -- Gary Stainburn This email does not contain private

Re: [SQL] simple join is beating me

2009-07-13 Thread Gary Stainburn
first query here */) ordersQuery NATURAL RIGHT JOIN (/* ur second query goes here */) deliveryQuery ORDER BY deliveryQuery.o_date DESC Tararabite, Oliveiros @Allgarve 2009/7/13 Gary Stainburn gary.stainb...@ringways.co.uk hi folks i have the following: select o_ord_date as o_date

[SQL] update from join

2009-05-14 Thread Gary Stainburn
with only one record. I seem to think I need an update. from. statement -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation of Investigatory Powers Act

[SQL] Quick select, slow update - help with performance problems

2008-07-01 Thread Gary Stainburn
1 1/2 minutes. I've noticed that other updates also seem to take a long time. Could I have any suggestions on how I could start looking into why this is. Could it be the config of postgresql, issues with my schema, or something else? Gary -- Gary Stainburn This email does not contain

Re: [SQL] Quick select, slow update - help with performance problems

2008-07-01 Thread Gary Stainburn
On Tuesday 01 July 2008 12:17, Richard Huxton wrote: Gary Stainburn wrote: update used_diary set ud_valet_completed=now(), ud_valet_completed_by=25 where ud_valet_completed is null and ud_valet_required CURRENT_DATE-'7 days'::interval is still running after approx

Re: [SQL] SOLVED - months, intervals and integers

2008-06-04 Thread Gary Stainburn
June 2008 09:44, Gary Stainburn wrote: Hi folks I've got the following table and view and I don't know exactly how to get what I want. The table contains integers for the number of months. I want the view to convert those month integers to intervals that it can add/subtract from a date

[SQL] months, intervals and integers

2008-06-04 Thread Gary Stainburn
start_date to be CURRENT_DATE-'6 months'::interval Any ideas? -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation of Investigatory Powers Act, 2000 -- Sent via

[SQL] performance issue - view and derived field

2008-02-08 Thread Gary Stainburn
(ud_stock) used_diary_ud_pex_valet_completed btree (ud_pex_valet_completed) used_diary_ud_valet_completed btree (ud_valet_completed) used_diary_valet_required btree (ud_valet_required) used_diary_vin_index btree (ud_vin) -- Gary Stainburn This email does not contain private

Re: [SQL] regex_replace problem -additional

2008-01-25 Thread Gary Stainburn
matches the given name and argument types. You may need to add explicit type casts. goole=# -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation of Investigatory

[SQL] regex_replace problem

2008-01-25 Thread Gary Stainburn
-1.fc5 postgresql-contrib-8.1.9-1.fc5 postgresql-server-8.1.9-1.fc5 postgresql-docs-8.1.9-1.fc5 postgresql-python-8.1.9-1.fc5 postgresql-8.1.9-1.fc5 postgresql-test-8.1.9-1.fc5 postgresql-tcl-8.1.9-1.fc5 [EMAIL PROTECTED] ~]# -- Gary Stainburn This email does not contain private

[SQL] odd error updating - varchar

2007-12-14 Thread Gary Stainburn
', 'r_id') RI_ConstraintTrigger_110509 AFTER INSERT OR UPDATE ON requests FROM plates NOT DEFERRABLE INITIALLY IMMEDIATE FOR EAC H ROW EXECUTE PROCEDURE RI_FKey_check_ins('unnamed', 'requests', 'plates', 'UNSPECIFIED', 'r_plates', 'pl_id') goole=# -- Gary Stainburn This email does not contain

Re: [SQL] calculation of pay based on dates

2007-07-13 Thread Gary Stainburn
need it very soon Regards Penchal Surely this would easiest be done using a view rather than a trigger or function. Simply have the salary calculated every time the view is selected. -- Gary Stainburn This email does not contain private or confidential material as it may be snooped

[SQL] select from table and add rows.

2007-07-06 Thread Gary Stainburn
; } This sets up an array with some pseudo values and then populates it with *proper* values from a table. How's the best way to do this all within SQL. -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown

Re: [SQL] select from table and add rows.

2007-07-06 Thread Gary Stainburn
On Friday 06 July 2007 16:02, Andrew Sullivan wrote: On Fri, Jul 06, 2007 at 02:25:08PM +0100, Gary Stainburn wrote: This sets up an array with some pseudo values and then populates it with *proper* values from a table. How's the best way to do this all within SQL. I'm obviously

[SQL] workday function

2007-05-15 Thread Gary Stainburn
a workday function which seems to do what I want. Any help would be appreciated. -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation of Investigatory Powers Act

Re: [SQL] workday function

2007-05-15 Thread Gary Stainburn
* days. -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation of Investigatory Powers Act, 2000 create or replace function easter_sunday(year integer) returns

[SQL] select ..... not in .....

2007-05-14 Thread Gary Stainburn
, v_vin, v_status from vista_details where v_vin not in ( goole(# select substring(w_vin from '(.{11}$)') from walon); v_d_code | v_o_number | v_vin | v_status --++---+-- (0 rows) -- Gary Stainburn This email does not contain private or confidential material

Re: [SQL] select slows from 3 seconds to 30 seconds

2007-05-08 Thread Gary Stainburn
On Saturday 05 May 2007 01:57, Tom Lane wrote: Gary Stainburn [EMAIL PROTECTED] writes: I have the query below which when run takes approx 3 seconds. However when I add the condition 'and w_ws_id = 10' onto the end changes to 30+ seconds. Can anyone see why? I've included the explain

[SQL] select slows from 3 seconds to 30 seconds

2007-05-04 Thread Gary Stainburn
}$)') = w_vin left outer join vista v on v.v_vin = w_vin where w_hide = 0. -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation of Investigatory Powers Act, 2000

[SQL] Another date range join problem

2007-04-05 Thread Gary Stainburn
1 2007-04-13 4 3 1 2007-04-14 5 5 1 2007-04-15 5 6 1 giving 1 1 2007-04-01 2007-04-01 1 2 1 2007-04-10 2007-04-15 4 -- Gary Stainburn This email does not contain private or confidential

[SQL] SOLVED - Another date range join problem

2007-04-05 Thread Gary Stainburn
-21 | 2007-04-22 | 2 | 0 | 2 1 | 28 | 2007-03-01 | 2007-03-01 | 1 | 0 | 1 2 | 28 | 2007-03-02 | 2007-03-07 | 6 | 0 | 6 (6 rows) -- Gary Stainburn This email does not contain private or confidential material as it may be snooped

Solved - [SQL] best way: diary functions.

2007-04-04 Thread Gary Stainburn
,a.afdate) left join roster_staff r on r.rsdate = date_range; Can anyone see any problems or improvements to this? -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes

[SQL] best way: diary functions.

2007-04-03 Thread Gary Stainburn
AS $PROC$ DECLARE wdate date; BEGIN return next fdate; wdate:=fdate+1; while wdate = tdate LOOP return next wdate; wdate:=wdate+1; end LOOP; return; END; $PROC$ LANGUAGE plpgsql; -- Gary Stainburn This email does not contain private or confidential material as it may

Re: [SQL] join/group/count query.

2006-12-21 Thread Gary Stainburn
that. Because the else is NULL, count does work. Although I would imagine sum will also work, count more reflects the logic, i.e. the number of times that condition is true -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government

Re: [SQL] join/group/count query.

2006-12-20 Thread Gary Stainburn
| 6 |0 10| 10|rr Motor| 7 |0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 2 | 5 |0 34| 34|ff fff | 3 |0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 2 |0 102| 102| xxx| 1 |0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |0 -- Gary Stainburn This email does not contain private

[SQL] Update from join

2006-07-07 Thread Gary Stainburn
| ND9057 1795 | YC06SGX | ND | ND9057 2634 | YB06KHT | NL | NL6450 2620 | YF06ZKD | ND | ND9236 (21 rows) -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties

Re: [SQL] Update from join

2006-07-07 Thread Gary Stainburn
On Friday 07 July 2006 11:29, Gary Stainburn wrote: I know this is probably a FAQ but Google etc hasn't helped. I have two tables, both with stock number and registration number in. The second table always has the correct stock number, the first doesn't. I want to copy the data across where

Re: [SQL] SELECT substring with regex

2006-07-07 Thread Gary Stainburn
---+ 150mm | LD AD Asp XR Macro (1 row) The brackets surround the required match -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation

Re: [SQL] select best price

2005-10-26 Thread Gary Stainburn
On Wednesday 26 October 2005 4:21 pm, Gary Stainburn wrote: Hi folks I've got a table holding item code(cs_id), supplier a/c (co_id) , and price (cs_price). How can I select the rows containing the lowest price for each item code? I've tried various forms of min() etc and know it must

[SQL] diary constraints

2005-08-23 Thread Gary Stainburn
, one for the start date/time and one for the return date/time. How do I go about creating constraints on inserts and updates to ensure that a) the finish is after the start b) two allocations for a single vehicle don't overlap. -- Gary Stainburn This email does not contain private

Re: [SQL] Speed up slow select - was gone blind

2005-04-05 Thread Gary Stainburn
. Gary On Friday 01 Apr 2005 1:46 pm, you wrote: Can you send the EXPLAIN ANALYZE of each? We can't really tell where the slowdown is without that. On Apr 1, 2005 12:32 PM, Gary Stainburn [EMAIL PROTECTED] wrote: Hi folks. I've got my select working now, but I haven't received the speed

[SQL] gone blind - can't see syntax error

2005-04-01 Thread Gary Stainburn
= d.d_id, left outer join departments de on r.r_de_id = de.de_id, left outer join customers c on r.r_c_id = c.c_id, left outer join comment_tallies co on r.r_id = co.r_id ORDER BY r.r_id; psql:new-view.sql:19: ERROR: parser: parse error at or near left -- Gary Stainburn This email does not contain

Re: [SQL] gone blind - can't see syntax error

2005-04-01 Thread Gary Stainburn
On Friday 01 April 2005 1:01 pm, you wrote: On Friday 01 Apr 2005 5:06 pm, Gary Stainburn wrote: Hi folks. I've been looking at this for 10 minutes and can't see what's wrong. Anyone care to enlighten me. comma after 'r'? I'd only just added that comma, to try to fix

[SQL] Speed up slow select - was gone blind

2005-04-01 Thread Gary Stainburn
on r.r_plates = pl.pl_id ORDER BY r.r_id; -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation of Investigatory Powers Act, 2000 ---(end

Re: [SQL] best way to swap two records (computer details)

2005-03-23 Thread Gary Stainburn
=# -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation of Investigatory Powers Act, 2000 ---(end of broadcast

Re: [SQL] best way to swap two records (computer details)

2005-03-23 Thread Gary Stainburn
p_name = \'SPARE\', p_location = \'spare\', p_site = \'L\' where p_id = 2; This isn't quite what I want. I want to SWAP the p_name and p_location between the two records, not set them to static values. Any help would be appreciated. -- Gary Stainburn This email does not contain private

Re: [SQL] best way to swap two records (computer details)

2005-03-23 Thread Gary Stainburn
); ERROR: parser: parse error at or near p_owner hardware=# Sorted it. The 'IF' should be 'WHEN' -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation

[SQL] best way to swap two records (computer details)

2005-03-18 Thread Gary Stainburn
appreciated) -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation of Investigatory Powers Act, 2000 ---(end of broadcast

[SQL] order by question

2005-03-09 Thread Gary Stainburn
are not bumped to the top of the list, but instead appear in their correct position in the order by value part. Is it possible and if so how do I do it? -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown

Re: [SQL] order by question

2005-03-09 Thread Gary Stainburn
On Wednesday 09 March 2005 1:06 pm, you wrote: Gary Stainburn wrote: Hi folks. I seem to remember somewhere being shown how to bump specific rows to the top of a list; something along the lines of: select c_id as key, c_des as value from customers order by c_id = 7, c_id = 160

[SQL] simple update from select ??

2005-03-07 Thread Gary Stainburn
of owned -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation of Investigatory Powers Act, 2000 ---(end of broadcast

Re: [SQL] simple update from select ??

2005-03-07 Thread Gary Stainburn
piece_pieces.pp_part=pieces.p_id; Under Sean's suggestion I did this inside a transaction block so I could check that it did what I wanted. -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown

[SQL] tree structure photo gallery date quiery

2004-11-16 Thread Gary Stainburn
-01-01 09:12:12 and Root should return 4, 2004-11-10 12:12:00 -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation of Investigatory Powers Act, 2000

Re: [SQL] tree structure photo gallery date quiery

2004-11-16 Thread Gary Stainburn
On Tuesday 16 November 2004 1:08 pm, sad wrote: On Tuesday 16 November 2004 14:29, Gary Stainburn wrote: Hi folks. I'm looking at the possibility of implementing a photo gallery for my web site with a tree structure How would I go about creating a view to show a) the number

[SQL] curious delay on view/where

2004-10-28 Thread Gary Stainburn
branch != 'Doncaster' and select * from stock_available where branch != 'Leeds' which only return the equivelent of the top two (we only have Leeds and Doncaster) are les than 1 second. Anyone got any ideas of the cause, or thoughts on how I can trace the problem? -- Gary Stainburn This email

Re: [SQL] extra info - curious delay on view/where

2004-10-28 Thread Gary Stainburn
On Thursday 28 October 2004 11:16 am, Gary Stainburn wrote: Hi folks. I have the following view: CREATE VIEW stock_available as SELECT * FROM stock_details WHERE available = true AND visible = true AND location not in (SELECT descr FROM ignored); Stock_details is itself a view

Re: [SQL] curious delay on view/where

2004-10-28 Thread Gary Stainburn
On Thursday 28 October 2004 3:25 pm, Tom Lane wrote: Gary Stainburn [EMAIL PROTECTED] writes: Anyone got any ideas of the cause, or thoughts on how I can trace the problem? EXPLAIN ANALYZE results for the fast and slow cases would be interesting. Also, have you ANALYZEd the underlying

[SQL] table update using result from join

2004-10-11 Thread Gary Stainburn
requests set r_fuel=what, r_c_id = 7 where r_c_id in (... -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation of Investigatory Powers Act, 2000

Re: [SQL] subselect prob in view

2004-06-22 Thread Gary Stainburn
On Monday 21 Jun 2004 4:11 pm, Gary Stainburn wrote: On Monday 21 Jun 2004 3:19 pm, Tom Lane wrote: Gary Stainburn [EMAIL PROTECTED] writes: from requests r, users u, request_types t, request_states s, dealerships d, departments de, customers c left outer join

[SQL] subselect prob in view

2004-06-21 Thread Gary Stainburn
: JOIN/ON clause refers to requests, which is not part of JOIN [EMAIL PROTECTED] gary]$ which at least makes sense. -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes

Re: [SQL] subselect prob in view

2004-06-21 Thread Gary Stainburn
On Monday 21 Jun 2004 3:19 pm, Tom Lane wrote: Gary Stainburn [EMAIL PROTECTED] writes: from requests r, users u, request_types t, request_states s, dealerships d, departments de, customers c left outer join (select co_r_id, count(co_r_id) from comments group

[SQL] view problem - too many rows out

2004-05-12 Thread Gary Stainburn
=# -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation of Investigatory Powers Act, 2000 ---(end of broadcast

solved Re: [SQL] view problem - too many rows out

2004-05-12 Thread Gary Stainburn
On Wednesday 12 May 2004 11:02 am, Gary Stainburn wrote: Hi folks. [snip] create view order_summary as select c.cs_id, cs.count as qty, c.cs_make, c.cs_code, c.cs_type, cst.cst_desc, c.cs_colour, o.or_id, o.or_supp, o.or_date, o.or_received, o.or_no, orst.orst_desc

[SQL] three-way join

2004-04-19 Thread Gary Stainburn
as select cost_cs_id, cost_cl_id, cost_css_id, count(*) as qty from cons_stock group by cost_cs_id, cost_cl_id, cost_css_id; I then have trouble joining this to the consumables and locations table to get the results I need. -- Gary Stainburn This email does not contain private or confidential

Re: [SQL] three-way join

2004-04-19 Thread Gary Stainburn
, cost_css_id; Regards, Stijn Vanroye ---(end of broadcast)--- TIP 6: Have you searched our list archives? http://archives.postgresql.org -- Gary Stainburn This email does not contain private or confidential material as it may

Re: [SQL] three-way join - solved

2004-04-19 Thread Gary Stainburn
On Monday 19 April 2004 4:01 pm, Gary Stainburn wrote: On Monday 19 April 2004 3:06 pm, Stijn Vanroye wrote: Gary wrote: Hi folks, here's a straight forward join that I simply can't get my head round. I've got consumables: cs_id, cs_make, cs_comments cons_locations

Re: [SQL] working with unix timestamp

2004-03-17 Thread Gary Stainburn
On Tuesday 16 March 2004 5:56 pm, Frank Finner wrote: On Tue, 16 Mar 2004 16:54:18 + Gary Stainburn [EMAIL PROTECTED] sat down, thought long and then wrote: Hi folks. I've got a last_updated field on my stock records of type timestamp. This last_updated field I get using the perl

[SQL] working with unix timestamp

2004-03-16 Thread Gary Stainburn
Hi folks. I've got a last_updated field on my stock records of type timestamp. This last_updated field I get using the perl code: my $timestamp=(stat $localcsv/VehicleStock.$data_suffix)[10]; How can I insert the integer timestamp in $timestamp into my table? -- Gary Stainburn This email

[SQL] where not unique

2004-03-12 Thread Gary Stainburn
to regcount in case it was a reserved word problem). -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation of Investigatory Powers Act, 2000

[SQL] alias problem on join

2004-02-06 Thread Gary Stainburn
group by account) as s bank-# on s.account = a.key; I get ERROR: No such attribute or function 'key' Any ideas why? Also, I'm sure I can do this more efficiently as a single select/join, but can't seem to work out why (Friday morning syndrome). Anyone give me a clue? -- Gary Stainburn

  1   2   >