Re: [SQL] Converting from MS Access field aliases

2007-07-12 Thread Nis Jørgensen
Tom Lane skrev: > This is not an "extension", it is *directly* contrary to both the letter > and spirit of the SQL standard. I can hardly believe that M$ did that > ... oh, actually, I can entirely believe it. The OP has a serious > problem of vendor lockin now, and that's exactly what M$ wants.

Re: [SQL] Converting from MS Access field aliases

2007-07-12 Thread Tom Lane
Adam Tauno Williams <[EMAIL PROTECTED]> writes: > On Thu, 2007-07-12 at 13:23 -0400, Tom Lane wrote: >> chester c young <[EMAIL PROTECTED]> writes: >>> SELECT field1 / 2 AS foo, >>> field2 * 2 AS bar, >>> foo + bar AS total >>> WHERE foo < 12; >> This is not an "extension", it is *directly* contra

Re: [SQL] Query Plan

2007-07-12 Thread Gregory Stark
"Radhika Sambamurti" <[EMAIL PROTECTED]> writes: > When I run the query with combination of FirmClearingID & status the run > times are approx 3700ms. > But when I add tradedate ie date_trunc('day', tradedate) = '20070703' the > run time becomes a horrendous 19631.958 ms. I'm not really able to m

Re: [SQL] Converting from MS Access field aliases

2007-07-12 Thread Gregory Stark
"Adam Tauno Williams" <[EMAIL PROTECTED]> writes: > "AS" works in Informix, and I believe, in DB2 as well. So it is at > least pretty common; I'm not saying it is correct. Since Informix > predates M$-SQL they at least didn't invent it. AS works in Postgres too. But the defined aliases are onl

[SQL] Query Plan

2007-07-12 Thread Radhika Sambamurti
Hi, I have a complicated view joining 3 tables. Here are the run times: LOG: duration: 3380.672 ms statement: explain analyze SELECT * from vtradeblock where FirmClearingid = 'FIRMA' and status = 1; LOG: duration: 3784.152 ms statement: explain analyze SELECT * from vtradeblock where date_tr

Re: [SQL] Converting from MS Access field aliases

2007-07-12 Thread Adam Tauno Williams
On Thu, 2007-07-12 at 13:23 -0400, Tom Lane wrote: > chester c young <[EMAIL PROTECTED]> writes: > >> SELECT field1 / 2 AS foo, > >> field2 * 2 AS bar, > >> foo + bar AS total > >> WHERE foo < 12; > > First, I think it would be great if this worked - like the alias to an > > update table added in 8

Re: [SQL] Converting from MS Access field aliases

2007-07-12 Thread paallen
Joel, To avoid ms access from managing the query, use a pass-through query. Then access will send the raw sql statment to psql and psql will return just the results to access. It will speed things up a bit too for large datasets. Phillip allen Sent via BlackBerry by AT&T -Original Messag

Re: [SQL] Converting from MS Access field aliases

2007-07-12 Thread Tom Lane
Joel Richard <[EMAIL PROTECTED]> writes: > What's really screwy is what I found when I hooked access into my > PostgreSQL database using pgsqlODBC (I know, it's an abomination) and > I logged the statements that PostgreSQL was processing. In MS Access > this query: >SELECT foo AS bar, b

Re: [SQL] Converting from MS Access field aliases

2007-07-12 Thread Joel Richard
On Jul 12, 2007, at 1:23 PM, Tom Lane wrote: chester c young <[EMAIL PROTECTED]> writes: SELECT field1 / 2 AS foo, field2 * 2 AS bar, foo + bar AS total WHERE foo < 12; First, I think it would be great if this worked - like the alias to an update table added in 8.2 - saves a lot of typing

Re: [SQL] Converting from MS Access field aliases

2007-07-12 Thread Tom Lane
chester c young <[EMAIL PROTECTED]> writes: >> SELECT field1 / 2 AS foo, >> field2 * 2 AS bar, >> foo + bar AS total >> WHERE foo < 12; > First, I think it would be great if this worked - like the alias to an > update table added in 8.2 - saves a lot of typing and makes queries > much more readab

Re: [SQL] Converting from MS Access field aliases

2007-07-12 Thread chester c young
>SELECT field1 / 2 AS foo, > field2 * 2 AS bar, > foo + bar AS total >WHERE foo < 12; > > The first two fields are fine, it's the third that's a problem. The > database reports > >ERROR: column "foo" does not exist > First, I think it would be great if this w

Re: [SQL] Converting from MS Access field aliases

2007-07-12 Thread Nicholas Barr
> Good morning, > > Oh joyous day! We are upgrading a legacy database system from MS > Access to PostgreSQL! Yay! > > Ok, rejoicing over. Here's our issue and PLEASE point me to the right > place if this has been discussed before. > > In MS Access one can reuse field aliases later in the same query

Re: [SQL] Using case or if to return multiple rows

2007-07-12 Thread Tom Lane
"Pavel Stehule" <[EMAIL PROTECTED]> writes: > it's possible with one big disadvantage. This query will do seq scan > both tables and it can be slow on big tables. No, it should be reasonably OK, because if the added condition doesn't involve the tables being scanned it'll be turned into a one-time

[SQL] Converting from MS Access field aliases

2007-07-12 Thread Joel Richard
Good morning, Oh joyous day! We are upgrading a legacy database system from MS Access to PostgreSQL! Yay! Ok, rejoicing over. Here's our issue and PLEASE point me to the right place if this has been discussed before. In MS Access one can reuse field aliases later in the same query. For

Re: [SQL] Using case or if to return multiple rows

2007-07-12 Thread Pavel Stehule
> > > select case when t3.date='' then > select * from table1 > else > select * from table 2 > from table3 t3 where t3.date='x' > > Problem is that I have to do it in Plain SQL. you problem is not quite clear. do you want to output al

Re: [SQL] Using case or if to return multiple rows

2007-07-12 Thread Ragnar
On fim, 2007-07-12 at 12:15 +0530, Ashish Karalkar wrote: > I want to select data from two diffrent table based on third tables > column > somthing like: > > > select case when t3.date='' then > select * from table1 > else > select * from table 2 >

Re: [SQL] Using case or if to return multiple rows

2007-07-12 Thread Pavel Stehule
Hello what is relation between t1 and t3 and t2 and t3? Which row from t3 specifies value? You cannot do it in plain SQL. SQL is well for set operations. You can use plpgsql and SRF function. -- table1 and table2 have to have same structure CREATE OR REPLACE FUNCTION output_tab(date) RETURNS