[SQL] week ending

2006-07-05 Thread Keith Worthington
Hi All, I just finished writing a query that groups data based on the week number. SELECT EXTRACT(week FROM col_a) AS week_number, sum(col_b) AS col_b_total FROM foo WHERE foobar GROUP BY EXTRACT(week FROM col_a) ORDER BY EXTRACT(week FROM col_a); I would like to generate the starti

Re: [SQL] "CASE" is not a variable

2006-07-05 Thread Keith Worthington
On Wed, 28 Jun 2006 10:48:31 -0700, Bricklen Anderson wrote > Keith Worthington wrote: > >>> "Keith Worthington" <[EMAIL PROTECTED]> writes: > >>> The following is a section of code inside an SQL function. > >> On Wed, 28 Jun 2006 12:16:29 -040

Re: [SQL] "CASE" is not a variable

2006-06-28 Thread Keith Worthington
> > "Keith Worthington" <[EMAIL PROTECTED]> writes: > > The following is a section of code inside an SQL function. > > On Wed, 28 Jun 2006 12:16:29 -0400, Tom Lane wrote > SQL, or plpgsql? It looks to me like misuse of the plpgsql

[SQL] "CASE" is not a variable

2006-06-28 Thread Keith Worthington
Hi All, The following is a section of code inside an SQL function. When I attempt to run it I get the error message '"CASE" is not a variable'. If I split this into two queries (one for each variable) it works fine. Obviously I have a work around but I would like to understand what I am doing

Re: [SQL] Change definition of a view

2006-02-09 Thread Keith Worthington
On Thu, 9 Feb 2006 18:11:24 +0100, Andreas Roth wrote > Hello, > > one question: Is it possible to add or remove a column from a view > without drop the view and recreate it? > > If one or more rules depend on a view, it's very hard to extend a > view. I use the following procedure to extend a

Re: [SQL] Defaulting a column to 'now'

2005-12-14 Thread Keith Worthington
On Wed, 14 Dec 2005 13:10:50 -0500, Ken Winter wrote > How can a column's default be set to 'now', meaning 'now' as of when each > row is inserted? > > For example, here's a snip of DDL: > > create table personal_data (. > > effective_date_and_time TIMESTAMP WITH TIME ZONE not null default > 'n

Re: [SQL] dow question

2005-12-07 Thread Keith Worthington
Michael Glaesemann wrote: On Dec 8, 2005, at 11:03 , Keith Worthington wrote: Is there a better way to do this? The CASE seems inefficient and wordy but perhaps not. I was hoping for day_name(tbl_detail.ship_by_date) || tbl_detail.ship_by_date::text AS sort_by_string but AFAIK

[SQL] dow question

2005-12-07 Thread Keith Worthington
Hi All, I am working on a query which in part is CASE WHEN extract(dow from tbl_detail.ship_by_date) = 0 THEN 'Sunday ' || tbl_detail.ship_by_date::text WHEN extract(dow from tbl_detail.ship_by_date) = 1 THEN 'Monday ' || tbl_detail.ship_by_date::text WHEN extract(dow from t

Re: **SPAM** [SQL] Faster count(*)?

2005-08-11 Thread Keith Worthington
Tom Lane wrote: [EMAIL PROTECTED] writes: I believe running count(*) means fulltable scan, and there's no way to do it without it. But what about some "intermediate" table, with the necessary counts? There's a fairly complete discussion in the PG list archives of a reasonably-efficient schem

[Fwd: RE: Re: [SQL] Rule]

2005-06-08 Thread Keith Worthington
Personally I feel that if this individual can't be bothered to white list the postgresql.org domain they should be banned from the list. Kind Regards, Keith Original Message Subject:RE: Re: [SQL] Rule Date: Wed, 8 Jun 2005 19:02:39 -0300 (BRT) From: AntiSpam UOL <[

Re: [SQL] Rule

2005-06-08 Thread Keith Worthington
David wrote: What I want to do is setup some kind of rule so that whenever a s_data field is updated, that the time_stamp gets update to the current time/date. Normally you want to do that with a before trigger rather than a rule. Ok, I have no knowledge of Tiggers except what I just read i

Re: [SQL] Does Postgresql have a similar pseudo-column "ROWNUM" as

2005-05-20 Thread Keith Worthington
On Tue, 17 May 2005 12:01:03 -0500, Scott Marlowe wrote > On Thu, 2005-05-12 at 14:07, [EMAIL PROTECTED] wrote: > > Hi: > > > > Oracle has a pseudo-column "ROWNUM" to return the sequence > > number in which a row was returned when selected from a table. > > The first row ROWNUM is 1, the second is

Re: [SQL] default value for select?

2005-05-09 Thread Keith Worthington
On Mon, 09 May 2005 12:57:41 -0400, Mark Fenbers wrote > I want to update a column in myTable. The value this column is set > todepends on a nested select statement which sometimes returns 0 > rowsinstead of 1. This is a problem since the column I'm trying to > updateis set to refuse nulls. Here

Re: [SQL] Numeric and CSV under 8.0.1 ?

2005-04-08 Thread Keith Worthington
On Fri, 8 Apr 2005 12:51:47 -0400, Stef wrote > Hello Everyone, > Currently, here at work, I am doing the whole > 'advocacy' part of postgreSQL. It's not really hard to > do, as the other database's are MySQL and Sybase ;) > > There is obviously a whole spat of data munging > going on

Re: [SQL] SQL query help?

2005-03-07 Thread Keith Worthington
John McGough wrote: SELECT Count(*) FROM Work WHERE (UserID='user1' AND MAX(Finished)=0) Work:- +---+---++-+--+ | ID | JobID | UserID | Finished | Comment | +---+---++-+--+ | 1 | 1| user1 | 0 | ...| | 2

Re: [SQL] truncating table permissions

2005-03-04 Thread Keith Worthington
Lynwood Stewart wrote: I was expecting "truncate table " to truncate a table if I had delete permissions. This does not appear to be the case. Would someone confirm this for me, or let me know what I am doing wrong. This is the case. You are not doing anything wrong. There was a discussion

Re: [SQL] aggregate / group by question

2005-02-23 Thread Keith Worthington
T E Schmitz wrote: Hello, I must apologize for not coming up with a more descriptive subject line. I am struggling with the following query and I am not even sure whether what I want to achieve is possible at all: The problem in real-world terms: The DB stores TRANSAKTIONS - which are either sal

UPDATE TRIGGER on view WAS: Re: [SQL] Relation in tables

2005-02-16 Thread Keith Worthington
On Wed, 16 Feb 2005 19:56:25 +0100, PFC wrote > [snip] Use UPDATE triggers on the > views, which in fact write to the products table [snip] You can DO that!?! Are you saying that a client can DELETE or INSERT or UPDATE a view and through a trigger you can make this happen? Way cool. Can you p

Re: [SQL] More efficient OR

2005-02-16 Thread Keith Worthington
> > Hi All, > > > > In several of my SQL statements I have to use a WHERE clause > > that contains mutiple ORs. i.e. > > > > WHERE column1 = 'A' OR > > column1 = 'B' OR > > column1 = 'C' > > > > Is there a more efficient SQL statement that accomplishes the > > same limiting functionali

[SQL] More efficient OR

2005-02-16 Thread Keith Worthington
Hi All, In several of my SQL statements I have to use a WHERE clause that contains mutiple ORs. i.e. WHERE column1 = 'A' OR column1 = 'B' OR column1 = 'C' Is there a more efficient SQL statement that accomplishes the same limiting functionality? Kind Regards, Keith ---

Re: [SQL] hardware mod based on feedback from the list

2005-01-27 Thread Keith Worthington
On Thu, 27 Jan 2005 17:11:55 +, Richard Huxton wrote > > Joel Fradkin wrote: > > > > I was told the Xeon processors will do fine up to 64gig. I > > realize the 64bit chips may be faster, but it is also new > > and I feel safer with existing technologies and hardware > > vendors. > > > > My un

Re: [SQL] Conversion ideas (Views/procedures)

2005-01-19 Thread Keith Worthington
> I am new to Postgres and am converting our MSSQL database to Postgres. > > I just did my first function. > My question is does it make sense to create functions for some of > the common functionality available to the MSSQL world (left, isnull, > etc) so I do not need visit every view, and stor

Re: [SQL] Returning a bool on DELETE in a proc.

2005-01-18 Thread Keith Worthington
> Hi, > > I'm currently writing a function which encapsulates a delete and should > return a bool as indicator for success. > > I tried: > > DELETE FROM "TariffDetails" WHERE "TariffId"=$1 and "BNumberPrefix"=$2; > SELECT TRUE; > > but this makes me not happy. > How can I distingruish

[SQL] sum query

2004-12-03 Thread Keith Worthington
Hi All, I am trying to join three tables and sum the quantities. The first table contains all of the possible items. The second table contains orders and the third table contains the items on each order. For all items found in tbl_item I need the total quantity on open orders. If an item is no

[SQL] update/insert data

2004-11-27 Thread Keith Worthington
Hi All, I have two tables in different schemas. The first table in the data_transfer schema is loaded with a COPY command. I need to transfer the data to the second schema inserting new records and updating existing records. What is the best way to achieve this functionality? Kind Regards, Kei