[SQL] SQL query with Overlapping date time ranges

2013-04-18 Thread chinnaobi
v42013-04-10 16:25:27+08 2013-04-10 16:24:07+08Zone1 13 Srv4 2013-04-10 17:17:39+08 2013-04-10 17:14:40+08Zone1 13 Srv4 2013-04-11 21:39:05+08 2013-04-11 21:28:22+08 -- View this message in context: http://postgresql.1045698.n5.nabble.com/SQL-query-with-Overlapp

Re: [SQL] query doesn't always follow 'correct' path..

2013-02-18 Thread Bert
Hello, there were 3 hours in between the 2 queries. so I guess new data was loaded already. new data is being loaded with that etl_run_id. wkr, Bert On Mon, Feb 18, 2013 at 4:20 PM, Виктор Егоров wrote: > 2013/2/18 Bert > >> When I don't touch the indexscan setting I get the following output

Re: [SQL] query doesn't always follow 'correct' path..

2013-02-18 Thread Julien Cigar
On 02/18/2013 16:20, Julien Cigar wrote: On 02/18/2013 15:39, Bert wrote: Hello, Thanks the nice people on irc my problem is fixed. I changed the following settings in the postgres.conf file: default_statistics_target = 5000 -> and I analyzed the tables after the change of course -> now I only

Re: [SQL] query doesn't always follow 'correct' path..

2013-02-18 Thread Julien Cigar
On 02/18/2013 15:39, Bert wrote: Hello, Thanks the nice people on irc my problem is fixed. I changed the following settings in the postgres.conf file: default_statistics_target = 5000 -> and I analyzed the tables after the change of course -> now I only got 2 plans anymore, in stead of 3 defa

Re: [SQL] query doesn't always follow 'correct' path..

2013-02-18 Thread Виктор Егоров
2013/2/18 Bert > When I don't touch the indexscan setting I get the following output: > Total query runtime: 611484 ms. > 20359 rows retrieved. > and the following plan: http://explain.depesz.com/s/sDy > > However, when I put set enable_indexscan=off; in fron of the same query I > get the followi

Re: [SQL] query doesn't always follow 'correct' path..

2013-02-18 Thread Bert
Hello, Thanks the nice people on irc my problem is fixed. I changed the following settings in the postgres.conf file: default_statistics_target = 5000 -> and I analyzed the tables after the change of course -> now I only got 2 plans anymore, in stead of 3 cpu_tuple_cost = 0.1 -> by setting this va

Re: [SQL] query doesn't always follow 'correct' path..

2013-02-18 Thread Bert
Hello, yes, the tables are vacuumed every day with the following command: vacuum analyze schema.table. The last statistics were collected yesterday evening. I collected statistics about the statistics, and I found the following: table_name; starttime; runtime "st_itemseat";"2013-02-17 23:48:42";"0

Re: [SQL] query doesn't always follow 'correct' path..

2013-02-18 Thread Frank Lanitz
Am 18.02.2013 10:43, schrieb Bert: > Does anyone has an idea what triggers this bad plan, and how I can fix it? Looks a bit like wrong statistics. Are the statistiks for your tables correct? Cheers, Frank -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your sub

Re: [SQL] Query execution based on a condition

2012-12-29 Thread Adrian Klaver
On 12/29/2012 11:05 AM, JORGE MALDONADO wrote: I have a query similar to the one shown below but, depending on the value of a field, only the first SELECT statement shoud execute and the other 3 should be ignored. Is there a way to achieve this situation? Probably so, but is hard to be specific

Re: [SQL] Query execution based on a condition

2012-12-29 Thread msi77
Change the conditions of other 3 queries, so those shall give empty row sets depending on your value. 29.12.2012, 23:06, "JORGE MALDONADO" : > I have a query similar to the one shown below but, depending on the value of > a field, only the first SELECT statement shoud execute and the other 3 sho

Re: [SQL] Query execution based on a condition

2012-12-29 Thread David Johnston
From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org] On Behalf Of JORGE MALDONADO Sent: Saturday, December 29, 2012 2:06 PM To: pgsql-sql@postgresql.org Subject: [SQL] Query execution based on a condition I have a query similar to the one shown below but, depending on

[SQL] Query execution based on a condition

2012-12-29 Thread JORGE MALDONADO
I have a query similar to the one shown below but, depending on the value of a field, only the first SELECT statement shoud execute and the other 3 should be ignored. Is there a way to achieve this situation? SELECT fields FROM tblTable WHERE condition UNION SELECT fields FROM tblTable WHERE condi

Re: [SQL] Query with LIMIT clause

2012-09-09 Thread David Johnston
09, 2012 1:26 PM > To: pgsql-sql@postgresql.org > Subject: [SQL] Query with LIMIT clause > > I have the following records that I get from a query, the fields are date > type in day/month/year format: > > - > Initial Final > Date

Re: [SQL] Query with LIMIT clause

2012-09-09 Thread JORGE MALDONADO
ber 09, 2012 1:26 PM > To: pgsql-sql@postgresql.org > Subject: [SQL] Query with LIMIT clause > > I have the following records that I get from a query, the fields are date > type in day/month/year format: > > - > Initial

Re: [SQL] Query with LIMIT clause

2012-09-09 Thread David Johnston
From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org] On Behalf Of JORGE MALDONADO Sent: Sunday, September 09, 2012 1:26 PM To: pgsql-sql@postgresql.org Subject: [SQL] Query with LIMIT clause I have the following records that I get from a query, the fields are date type in

[SQL] Query with LIMIT clause

2012-09-09 Thread JORGE MALDONADO
I have the following records that I get from a query, the fields are date type in day/month/year format: - Initial Final DateDate - 27/08/2012 04/09/2012 29/08/2012 09/09/2012 28/08/2012 09/09/2012

[SQL] query structure for selecting row by tags

2012-08-01 Thread Samuel Gendler
I need to tag entities in my db with arbitrary strings. That part is simple enough. The difficulty is that I need to select entities based on whether they match an expression built via boolean combinations of tags: (tag1 || tag2 || tag3) && tag4 I can roll my own tagging mechanism, in which case

Re: [SQL] query two tables using same lookup table

2012-07-22 Thread David Johnston
On Jul 22, 2012, at 23:04, ssylla wrote: > Dear list, > > assuming I have two tables as follows > > t1: > id_project|id_auth > 1|1 > 2|2 > > t2: > id_project|id_auth > 1|2 > 2|1 > > > and a lookup-table: > > t3 > id_auth|name_auth > 1|name1 > 2|name2 > > Now I want to query

[SQL] query two tables using same lookup table

2012-07-22 Thread ssylla
Dear list, assuming I have two tables as follows t1: id_project|id_auth 1|1 2|2 t2: id_project|id_auth 1|2 2|1 and a lookup-table: t3 id_auth|name_auth 1|name1 2|name2 Now I want to query t1 an t2 using the 'name_auth' column of lookup-table t3, so that I get the following out

Re: [SQL] Query question

2012-01-28 Thread Lew
On 01/26/2012 04:00 AM, John Tuliao wrote: I seem to have a problem with a specific query: The inside query seems to work on it's own: select prefix from john_prefix where strpos(jpt_test.number,john_prefix.prefix) = '1' order by char_length(john_prefix.prefix) desc limit 1 but when I execute

[SQL] Query question

2012-01-27 Thread John Tuliao
I seem to have a problem with a specific query: The inside query seems to work on it's own: select prefix from john_prefix where strpos(jpt_test.number,john_prefix.prefix) = '1' order by char_length(john_prefix.prefix) desc limit 1 but when I exec

Re: [SQL] sql query problem

2012-01-17 Thread David Johnston
On Jan 17, 2012, at 8:35, Andreas Kretschmer wrote: > Alok Thakur wrote: > >> Dear, >> >> I am trying to provide you as much details as possible. >> >> answer` ( >> `id` int(10) NOT NULL AUTO_INCREMENT, >> `question_id` int(10) NOT NULL, >> `user_id` int(10) NOT NULL, >> `answer` int(10)

Re: [SQL] sql query problem

2012-01-17 Thread Andreas Kretschmer
Alok Thakur wrote: > Dear, > > I am trying to provide you as much details as possible. > > answer` ( > `id` int(10) NOT NULL AUTO_INCREMENT, > `question_id` int(10) NOT NULL, > `user_id` int(10) NOT NULL, > `answer` int(10) NOT NULL, -> > `status` tinyint(1) NOT NULL, --> Status wil

Re: [SQL] sql query problem

2012-01-17 Thread Alok Thakur
FROM > UserTable INNER JOIN result ON UserTable.id = result.user_id > > Sent from my Windows Phone > From: Alok Thakur > Sent: 15/01/2012 22:08 > To: pgsql-...@postgresql.org > Subject: [SQL] sql query problem > Dear All, > > I have two tables one contains details of user an

Re: [SQL] Query Problem... Left OuterJoin / Tagging Issue

2012-01-17 Thread John Tuliao
Thank you so much for your prompt reply David. I will consider your advice and put it to mind and action. I hope you all don't get tired of helping! For now, I will note down what I need to and do the necessary adjustments. Thank you for your time! On Friday, 13 January, 2012 10:26 PM, David

Re: [SQL] sql query problem

2012-01-15 Thread Misa Simic
result.user_id Sent from my Windows Phone From: Alok Thakur Sent: 15/01/2012 22:08 To: pgsql-sql@postgresql.org Subject: [SQL] sql query problem Dear All, I have two tables one contains details of user and other contains result. The details are: 1. UserTable - id, name, phone 2. result - id,

Re: [SQL] sql query problem

2012-01-15 Thread Oliveiros
What does a 0 state mean? Failed? And a 1 state? Passed? Best, Oliveiros 2012/1/14 Alok Thakur > Dear All, > > I have two tables one contains details of user and other contains > result. The details are: > 1. UserTable - id, name, phone > 2. result - id, question_id, user_id, status (0 or 1) >

[SQL] sql query problem

2012-01-15 Thread Alok Thakur
Dear All, I have two tables one contains details of user and other contains result. The details are: 1. UserTable - id, name, phone 2. result - id, question_id, user_id, status (0 or 1) I want the list like this: User Id Name Attended Failed Passed but i could not find the way to do this

Re: [SQL] Query Problem... Left OuterJoin / Tagging Issue

2012-01-13 Thread David Johnston
On Jan 12, 2012, at 23:31, John Tuliao wrote: > Hi, > > I've been working on this for quite awhile now and don't seem to get the > proper query. > > I have basically 4 tables. > > 1. Table john_test contains the numbers of the calls. > 2. Table john_country contains the country with prefix.

[SQL] Query Problem... Left OuterJoin / Tagging Issue

2012-01-12 Thread John Tuliao
Hi, I've been working on this for quite awhile now and don't seem to get the proper query. I have basically 4 tables. 1. Table john_test contains the numbers of the calls. 2. Table john_country contains the country with prefix. 3. Table john_clients contains the clients and their sub_id's

[SQL] Re: Re: [SQL] Query Timeout Question

2011-12-08 Thread feng.zhou
pgsql-sql 主题: Re: [SQL] Query Timeout Question On 12/09/2011 09:44 AM, feng.zhou wrote: Hi I set query timeout in code by using SQLSetStmtAttr ODBC API . SQLSetStmtAttr( StatementHandle, SQL_ATTR_QUERY_TIMEOUT, (SQLPOINTER)timeout, 0 ) ; SQLExecute(StatementHandle); But I find this setting h

Re: [SQL] Query Timeout Question

2011-12-08 Thread Craig Ringer
On 12/09/2011 09:44 AM, feng.zhou wrote: Hi I set query timeout in code by using SQLSetStmtAttr ODBC API . SQLSetStmtAttr( StatementHandle, SQL_ATTR_QUERY_TIMEOUT, (SQLPOINTER)timeout, 0 ) ; SQLExecute(StatementHandle); But I find this setting has no effect.Before adding timeout setting, SQLEx

Re: [SQL] Query Timeout Question

2011-12-08 Thread feng.zhou
sorry, timeout is 15 seconds 2011-12-09 feng.zhou 发件人: feng.zhou 发送时间: 2011-12-09 09:25:49 收件人: pgsql-sql 抄送: 主题: [SQL] Query Timeout Question Hi I set query timeout in code by using SQLSetStmtAttr ODBC API . SQLSetStmtAttr( StatementHandle, SQL_ATTR_QUERY_TIMEOUT, (SQLPOINTER

[SQL] Query Timeout Question

2011-12-08 Thread feng.zhou
Hi I set query timeout in code by using SQLSetStmtAttr ODBC API . SQLSetStmtAttr( StatementHandle, SQL_ATTR_QUERY_TIMEOUT, (SQLPOINTER)timeout, 0 ) ; SQLExecute(StatementHandle); But I find this setting has no effect.Before adding timeout setting, SQLExecute costs 47 seconds.After adding timeou

[SQL] Query to select nested comments sorted by nesting and date

2011-06-20 Thread Cstdenis
00ms for ltree based vs 1.5 seconds for WITH RECURSIVE). I could do the sorting in the php code, but it seems more efficient if I can just do it all in a single SQL query.

Re: [SQL] Query Performance

2009-12-08 Thread Postgre Novice
tgre Novice Cc: pgsql-sql@postgresql.org Sent: Mon, December 7, 2009 7:23:19 PM Subject: Re: [SQL] Query Performance Yes, the problem is the nested loop scan - it's scanning users 609070 times, which is awful. Could you provide explain plan that executed fast? Was it executed with the same

Re: [SQL] Query Performance

2009-12-07 Thread tv
Yes, the problem is the nested loop scan - it's scanning users 609070 times, which is awful. Could you provide explain plan that executed fast? Was it executed with the same parameter values or did the parameters change (maybe it's slow for some parameters values only)? Have you tried to rewrite

[SQL] Query Performance

2009-12-07 Thread Postgre Novice
Hello List, I have a query which use to run very fast now has turn into show stopper . PostgreSQL:8.2 explain analyze select user_name,A.user_id, dnd_window_start, dnd_window_stop, B.subs as subs, B.city_id as city_id, B.source_type as source_type from

Re: [SQL] [PERFORM] SQL Query Performance - what gives?

2009-08-19 Thread Pierre Frédéric Caillau d
The bitmask allows the setting of multiple permissions but the table definition doesn't have to change (well, so long as the bits fit into a word!) Finally, this is a message forum - the actual code itself is template-driven and the bitmask permission structure is ALL OVER the templates; gettin

Re: [SQL] [PERFORM] SQL Query Performance - what gives?

2009-08-18 Thread Karl Denninger
Tom Lane wrote: > Karl Denninger writes: > >> The problem appearsa to lie in the "nested loop", and I don't understand >> why that's happening. >> > It looks to me like there are several issues here. > > One is the drastic underestimate of the number of rows satisfying the > permission con

Re: [SQL] [PERFORM] SQL Query Performance - what gives?

2009-08-18 Thread Tom Lane
Karl Denninger writes: > The problem appearsa to lie in the "nested loop", and I don't understand > why that's happening. It looks to me like there are several issues here. One is the drastic underestimate of the number of rows satisfying the permission condition. That leads the planner to think

Re: [SQL] [PERFORM] SQL Query Performance - what gives?

2009-08-18 Thread Karl Denninger
Kevin Grittner wrote: > Karl Denninger wrote: > >>-> Index Scan using forum_name on forum >> (cost=0.00..250.63 rows=1 width=271) (actual time=0.013..0.408 >> rows=63 loops=1) >> Filter: (((contrib IS NULL) OR (contrib = ' >> '::text) OR (contrib ~~ '%b%':

Re: [SQL] [PERFORM] SQL Query Performance - what gives?

2009-08-18 Thread Kevin Grittner
Karl Denninger wrote: >-> Index Scan using forum_name on forum > (cost=0.00..250.63 rows=1 width=271) (actual time=0.013..0.408 > rows=63 loops=1) > Filter: (((contrib IS NULL) OR (contrib = ' > '::text) OR (contrib ~~ '%b%'::text)) AND ((permission & 127) =

Re: [SQL] [PERFORM] SQL Query Performance - what gives?

2009-08-18 Thread Kevin Grittner
Karl Denninger wrote: > Let's take the following EXPLAIN results: We could tell a lot more from EXPLAIN ANALYZE results. The table definitions (with index information) would help, too. -Kevin -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscripti

Re: [SQL] [PERFORM] SQL Query Performance - what gives?

2009-08-18 Thread Karl Denninger
First query: ticker=# explain analyze select * from post, forum where forum.name = post.forum and invisible <> 1 and to_tsvector('english', message) @@ to_tsquery('violence') order by modified desc limit 100; QUERY PLAN

[SQL] SQL Query Performance - what gives?

2009-08-18 Thread Karl Denninger
Let's take the following EXPLAIN results: ticker=# explain select * from post, forum where forum.name = post.forum and invisible <> 1 and to_tsvector('english', message) @@ to_tsquery('violence') order by modified desc limit 100;

Re: [SQL] Query planning question

2009-05-11 Thread John Lister
"John Lister" writes: Am I right in assuming the planner thinks a sequential scan is quicker than 10k index hits, would tweaking the costs fix this or would i be better updating the stats for the product_id and manufacturer_id fields? AFAICT the planner did exactly the right things here. You

Re: [SQL] Query planning question

2009-05-11 Thread Tom Lane
"John Lister" writes: > Am I right in assuming the planner thinks a sequential scan is quicker than > 10k index hits, would tweaking the costs fix this or would i be better > updating the stats for the product_id and manufacturer_id fields? AFAICT the planner did exactly the right things here.

[SQL] Query planning question

2009-05-11 Thread John Lister
Doing the following query select distinct m.id, m.name from manufacturer_manufacturer m join product_product p on (p.manufacturer_id=m.id) join retailer_offer o on (o.product_id=p.id) where o.retailer_id=XXX and o.active results in one of 2 query plans depending upon the v

Re: [SQL] Query with Parameters and Wildcards

2009-04-27 Thread Jure Kobal
customerfirstname, > >> customerid, customerlastname, customermiddleinitial, customerphone, > >> customerreferredby, customerstateabbr, customerstreet1, customerstreet2, > >> customersuffix, customertitle, customerworkphone, customerworkphoneext, > >> customerzip FROM lanemanage

Re: [SQL] Query with Parameters and Wildcards

2009-04-27 Thread landsharkdaddy
>> >> Please tell me is it work for you. >> >> Regards >> Hidayat >> >> - Original Message - >> From: "landsharkdaddy" >> To: >> Sent: Monday, April 27, 2009 9:19 PM >> Subject: Re: [SQL] Query with Parameters and

Re: [SQL] Query with Parameters and Wildcards

2009-04-27 Thread Jure Kobal
ers WHERE (customerlastname ILIKE $1 || > '%') > $$ > LANGUAGE SQL; > > Please tell me is it work for you. > > Regards > Hidayat > > - Original Message - > From: "landsharkdaddy" > To: > Sent: Monday, April 27, 2009 9:19 PM > S

Re: [SQL] Query with Parameters and Wildcards

2009-04-27 Thread dayat
(customerlastname ILIKE $1 || '%') $$ LANGUAGE SQL; Please tell me is it work for you. Regards Hidayat - Original Message - From: "landsharkdaddy" To: Sent: Monday, April 27, 2009 9:19 PM Subject: Re: [SQL] Query with Parameters and Wildcards > > When I try the foll

Re: [SQL] Query with Parameters and Wildcards

2009-04-27 Thread landsharkdaddy
When I try the following like you suggested I get an error that says "operator does not exist: || unknown SELECT customercellphone, customercity, customerdatecreated, customerdatelastmodified, customeremail, customerfax, customerfirstname, customerid, customerlastname, customermiddleinitial, cu

Re: [SQL] Query with Parameters and Wildcards

2009-04-27 Thread Mario Splivalo
landsharkdaddy wrote: I have not tried that but I will in the morning. The @ in SQL is used to indicate a parameter passed to the query. In PostgreSQL it seems that the : is the same as the @ in SQL Server. I tried something like: SELECT * FROM Customers WHERE FirstName LIKE :custfirst + '%';

Re: [SQL] Query with Parameters and Wildcards

2009-04-26 Thread landsharkdaddy
I have not tried that but I will in the morning. The @ in SQL is used to indicate a parameter passed to the query. In PostgreSQL it seems that the : is the same as the @ in SQL Server. I tried something like: SELECT * FROM Customers WHERE FirstName LIKE :custfirst + '%'; And it told me th

Re: [SQL] Query with Parameters and Wildcards

2009-04-26 Thread Scott Marlowe
On Sun, Apr 26, 2009 at 6:21 PM, landsharkdaddy wrote: > > I have a query that works on SQL Server to return customers that contain the > string entered by the user by accepting parameters and using the LIKE > keyword. I would like to move this to postgreSQL but I'm just not sure how > to get it d

Re: [SQL] Query with Parameters and Wildcards

2009-04-26 Thread Ries van Twisk
On Apr 26, 2009, at 7:21 PM, landsharkdaddy wrote: I have a query that works on SQL Server to return customers that contain the string entered by the user by accepting parameters and using the LIKE keyword. I would like to move this to postgreSQL but I'm just not sure how to get it done.

[SQL] Query with Parameters and Wildcards

2009-04-26 Thread landsharkdaddy
I have a query that works on SQL Server to return customers that contain the string entered by the user by accepting parameters and using the LIKE keyword. I would like to move this to postgreSQL but I'm just not sure how to get it done. This is the query SELECT * FROM Customers WHERE FirstName

Re: [SQL] Query to retrieve all indexed columns

2008-11-19 Thread Tom Lane
"Bart van Houdt" <[EMAIL PROTECTED]> writes: > I am working on a query to retrieve all indexed columns and came up with > the following query: > ... > Tis query works for single column indexes, but with multiple column > indexes I get incorrect results... I'm having a hard time figuring out > how t

[SQL] Query to retrieve all indexed columns

2008-11-19 Thread Bart van Houdt
Hi, I am working on a query to retrieve all indexed columns and came up with the following query: select pgc.relname as indexname ,pgc2.relname as tablename ,pga.attname as columnname ,pga.attnum as columnnumber ,replace(pgi.indkey::text, ' ', ',') as columnindex

Re: [SQL] Query to match location transitions

2008-11-15 Thread Tomasz Myrta
sub3 napisal 14.11.2008 20:12: Hi, I was hoping someone could help me build a better query. I have a table of time/locations. Occasionally, we have multiple timestamps for the same location. I would like to remove those extra timestamps and only show the transition from one location to anothe

[SQL] Query to match location transitions

2008-11-14 Thread sub3
Hi, I was hoping someone could help me build a better query. I have a table of time/locations. Occasionally, we have multiple timestamps for the same location. I would like to remove those extra timestamps and only show the transition from one location to another. So... create table time_loca

Re: [SQL] Query optimizing

2008-11-10 Thread Richard Huxton
Richard Huxton wrote: > Do you have an index on (id,dt_modified) for manage_followup? Can you > provide an EXPLAIN ANALYSE for this? > Hi Richard, > > Firstly, thank-you very much for your swift reply. To answer your > question, > I had not been using an index on dt_modfied. I have added it now

Re: [SQL] Query optimizing

2008-11-10 Thread Sebastian Ritter
Cheers for you help guys. Having filtered and then joined has substantially reduced the run time. Much obliged, Sebastian On Mon, Nov 10, 2008 at 12:32 PM, Richard Huxton <[EMAIL PROTECTED]> wrote: > Sebastian Ritter wrote: > > Could it have something > > to do with the fact that it is a subquer

Re: [SQL] Query optimizing

2008-11-10 Thread Richard Huxton
Sebastian Ritter wrote: > Could it have something > to do with the fact that it is a subquery and thus the planner can not > deduce filtering conditions from the outer query against it? My apologises > if that made no sense. Could make a difference. > In summary, what im trying to understand is t

Re: [SQL] Query optimizing

2008-11-10 Thread Sebastian Ritter
Cheers for this Richard. The more I think about it, I believe the join is being made against ALL issues and followups first and then filtered by my where clause conditions afterwards. This would in incur a scan against all 15,000 issues and 95,000 followups. Set theory tells me that I should not us

Re: [SQL] Query optimizing

2008-11-10 Thread Sebastian Ritter
Hi Helio, Sorry about the parenthesis - Bad copy/pasting skills! To further discuss your suggestion: Wouldn't adding n_issue=i.id as a where clause filter cause the sub-query to become correlated and thus much less efficient ? I may be wrong, or may have miss-understood your suggestion. Thanks fo

Re: [SQL] Query optimizing

2008-11-10 Thread Helio Campos Mello de Andrade
Hi Sebastian, - First of all i think there is an open-parenthesis missing in the query V2. Maybe in the V2 version you cold restrict the results in the INNER query a bit more if you use a restriction clause like "WHERE n_issue = i.id" in that. It will certainly lower the number of rows returned b

Re: [SQL] Query optimizing

2008-11-10 Thread Richard Huxton
Sebastian Ritter wrote: > A lot of the reports our technical officers submit to us include a listing > of all actioned issues for a given day along with the last modified followup > of each said issue. With the number of rows in our database increasing at a > high rate, these queries are starting t

[SQL] Query optimizing

2008-11-10 Thread Sebastian Ritter
Hi all, I was hoping to receive some advise on a slow running query in our business' Issue Tracking System. To shed some light on the below mentioned queries, here is a brief summary of how users interact with the system. The two main components in the system are a Issues and Followups. An Issue i

Re: [SQL] simple SQL query

2008-10-29 Thread Tom Lane
"Kevin Duffy" <[EMAIL PROTECTED]> writes: > Can someone explain why the NULL ISINs in Security is causing > so much grief? I do not get it. NULL generally is taken as "unknown" in SQL comparisons. So if you have any nulls in the output of the sub-select, what the upper select sees is a situatio

Re: [SQL] simple SQL query

2008-10-29 Thread Andreas Joseph Krogh
On Wednesday 29 October 2008 21:56:14 Kevin Duffy wrote: > > Gentlemen: > > Thanks so much for your assistance. > > This returns 512 rows. > select * from tmp_index_member tim > where tim.ISIN NOT IN > (select ISIN from security sec > where ISIN is NOT NULL and >securitytype

Re: [SQL] simple SQL query

2008-10-29 Thread Kevin Duffy
the NULL ISINs in Security is causing so much grief? I do not get it. KD -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Andreas Joseph Krogh Sent: Wednesday, October 29, 2008 3:58 PM To: pgsql-sql@postgresql.org Subject: Re: [SQL] simple SQL query

Re: [SQL] simple SQL query

2008-10-29 Thread Andreas Joseph Krogh
On Wednesday 29 October 2008 18:39:42 Kevin Duffy wrote: > Hello: > > > > I have a couple of queries that are giving me headaches. > > They are actually very simple, but I do not understand why > > I am not getting the expected results. Maybe I need new glasses. > > Please be kind. > >

[SQL] simple SQL query

2008-10-29 Thread Kevin Duffy
Hello: I have a couple of queries that are giving me headaches. They are actually very simple, but I do not understand why I am not getting the expected results. Maybe I need new glasses. Please be kind. The table definitions are below. The table TMP_INDEX_MEMBER contains 21057 row

Re: [SQL] Query how-to

2008-10-03 Thread Marc Mamin
this was silly from me! this should naturally look like this: select case when status ='Closed' then stop_date else start_date end as adate, sum(case when status ='Closed' then 1 else 0 end) as closedCount, sum(case when status ='New' then 1 else 0 end) as openedCount fro

Re: [SQL] Query how-to

2008-10-03 Thread Marc Mamin
Hi, What about something like that ? select adate, sum(openedCount) as openedCount, sum(closedCount) as closedCount from ( select sum(case when status ='Closed' then stop_date else start_date end) as adate, sum(case when status ='Closed' then 1 else 0 end) as closedCount sum(cas

Re: [SQL] Query how-to

2008-10-02 Thread Frank Bax
Montaseri wrote: Given table T1 and columns id, start_date, stop_date and status, propose a query that reports count of items opened and closed . status is an enum including NEW, xxx, , CLOSED. The first status of an item is NEW (could be used in place of start_date) For example Date

Re: [SQL] Query how-to

2008-10-02 Thread Richard Broersma
On Thu, Oct 2, 2008 at 1:49 PM, Montaseri <[EMAIL PROTECTED]> wrote: > I was wondering if you can help me with the following query. > > Given table T1 and columns id, start_date, stop_date and status, propose a > query that reports count of items opened and closed . status is an enum > including NE

[SQL] Query how-to

2008-10-02 Thread Montaseri
Hi, I was wondering if you can help me with the following query. Given table T1 and columns id, start_date, stop_date and status, propose a query that reports count of items opened and closed . status is an enum including NEW, xxx, , CLOSED. The first status of an item is NEW (could be used i

Re: [SQL] Query prepared plan

2008-07-29 Thread Emi Lu
Similar to \dt to show all tables, within one session, may I know the command to list all prepared query plan please? select * from pg_prepared_statements; Thank you! I think this is the command. Too bad that I could not use it under 8.0x. select * from pg_prepared_statements; ERROR: rela

Re: [SQL] Query prepared plan

2008-07-28 Thread Alvaro Herrera
Emi Lu wrote: > Similar to \dt to show all tables, within one session, may I know the > command to list all prepared query plan please? select * from pg_prepared_statements; -- Alvaro Herrerahttp://www.CommandPrompt.com/ The PostgreSQL Company - Command Prompt,

Re: [SQL] Query prepared plan

2008-07-28 Thread Emi Lu
Tom Lane wrote: Emi Lu <[EMAIL PROTECTED]> writes: Somebody know about how to find prepared query plan through command line? PREPARE fooplan(...) EXPLAIN EXECUTE fooplan(...) Thank you Tom. Similar to \dt to show all tables, within one session, may I know the command to lis

Re: [SQL] Query prepared plan

2008-07-25 Thread Tom Lane
Emi Lu <[EMAIL PROTECTED]> writes: > Somebody know about how to find prepared query plan through command line? PREPARE fooplan(...) EXPLAIN EXECUTE fooplan(...) regards, tom lane -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make change

Re: [SQL] Query prepared plan

2008-07-25 Thread Emi Lu
Good morning, May I know the "commands" to . show current session's prepared plans . see the definition of a prepared plan E.g., psql> PREPARE fooplan (int, text, bool, numeric) AS INSERT INTO foo VALUES($1, $2, $3, $4); (1) Similar to "\dt", I want to see "fooplan" (2) Similar to "\d table

[SQL] Query prepared plan

2008-07-23 Thread Emi Lu
Good morning, May I know the "commands" to . show current session's prepared plans . see the definition of a prepared plan E.g., psql> PREPARE fooplan (int, text, bool, numeric) AS INSERT INTO foo VALUES($1, $2, $3, $4); (1) Similar to "\dt", I want to see "fooplan" (2) Similar to "\d tableNa

Re: [SQL] query: last N price for each product?

2008-07-04 Thread Frank Bax
David Garamond wrote: Dear SQL masters, The query for "latest price for each product" goes like this (which I can grasp quite easily): SELECT * FROM price p1 WHERE ctime=(SELECT MAX(ctime) FROM price p2 WHERE p1.product_id=p2.product_id) or: SELECT * FROM price p1 WHERE NOT EXISTS (SELECT

Re: [SQL] query: last N price for each product?

2008-07-04 Thread Claus Guttesen
> The query for "latest price for each product" goes like this (which I > can grasp quite easily): > > SELECT * FROM price p1 > WHERE ctime=(SELECT MAX(ctime) FROM price p2 WHERE > p1.product_id=p2.product_id) > > or: > > SELECT * FROM price p1 > WHERE NOT EXISTS (SELECT * FROM price p2 WHERE

[SQL] query: last N price for each product?

2008-07-04 Thread David Garamond
Dear SQL masters, The query for "latest price for each product" goes like this (which I can grasp quite easily): SELECT * FROM price p1 WHERE ctime=(SELECT MAX(ctime) FROM price p2 WHERE p1.product_id=p2.product_id) or: SELECT * FROM price p1 WHERE NOT EXISTS (SELECT * FROM price p2 WHERE p

Re: [SQL] Query question

2008-05-22 Thread Medi Montaseri
Thanks Stephan, My real DDL include a forign key reference to T2.id and since I am ok with NULL value then the "left outer join" indeed have solved the problem. Thanks again Medi On Thu, May 22, 2008 at 2:50 PM, Stephan Szabo <[EMAIL PROTECTED]> wrote: > On Thu, 22 May 2008, Medi Montaseri wrot

Re: [SQL] Query question

2008-05-22 Thread Stephan Szabo
On Thu, 22 May 2008, Medi Montaseri wrote: > Hi, > I can use some help with the following query please. > > Given a couple of tables I want to do a JOIN like operation. Except that one > of the columns might be null. > > create table T1 ( id serial, name varchar(20) ); > create table T2 ( id seria

[SQL] Query question

2008-05-22 Thread Medi Montaseri
Hi, I can use some help with the following query please. Given a couple of tables I want to do a JOIN like operation. Except that one of the columns might be null. create table T1 ( id serial, name varchar(20) ); create table T2 ( id serial, name varchar(20) ); create table T1_T2 ( id serial, t1_

Re: [SQL] Query tuning

2008-05-16 Thread Simon Riggs
On Fri, 2008-05-16 at 09:21 -0600, Scott Marlowe wrote: > On Thu, May 15, 2008 at 12:00 AM, <[EMAIL PROTECTED]> wrote: > > Hi, > > > > select count(distinct(j.JOBID)) as jobCount > > from JOB_TYPE_FIRST a, JOB_TYPE_SECOND b, JOB_ALLOCATION_WORKLIST j > > where (( a.JOBID = j.JOBID) > > and (a.BO

Re: [SQL] Query tuning

2008-05-16 Thread Scott Marlowe
On Thu, May 15, 2008 at 12:00 AM, <[EMAIL PROTECTED]> wrote: > Hi, > > select count(distinct(j.JOBID)) as jobCount > from JOB_TYPE_FIRST a, JOB_TYPE_SECOND b, JOB_ALLOCATION_WORKLIST j > where (( a.JOBID = j.JOBID) > and (a.BOOK_ID = :bookId)) > or ((b.JOBID = j.JOBID) > and (b.BOOK_ID = :bookId)

Re: [SQL] Query tuning

2008-05-16 Thread Moiz Kothari
Hi kapil, Here you have specified 3 tables, does JOB_TYPE_FIRST and JOB_TYPE_SECOND both contain all the JOBID in the third table? Maybe i can help you if you elaborate your problem a bit more. Regards, Moiz Kothari On Thu, May 15, 2008 at 11:30 AM, <[EMAIL PROTECTED]> wrote: > Hi, > > > > >

[SQL] Query tuning

2008-05-14 Thread kapil.munish
Hi, I have a query which is run across 3 tables JOB_TYPE_FIRST, JOB_TYPE_SECOND and JOB_ALLOCATION_WORKLIST. The column JOBID is referenced in JOB_ALLOCATION_WORKLIST table and primary key in both JOB_TYPE_FIRST, JOB_TYPE_SECOND tables. There is one more column BOOK_ID which is supplied

Re: [SQL] query results in XML format?

2008-03-06 Thread Peter Eisentraut
Emi Lu wrote: > Can someone suggestion some tutorial/hyperlinks/docs about how > postgresql output query results into xml files? http://www.postgresql.org/docs/8.3/static/functions-xml.html#FUNCTIONS-XML-MAPPING -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your

[SQL] query results in XML format?

2008-03-06 Thread Emi Lu
Hello, Can someone suggestion some tutorial/hyperlinks/docs about how postgresql output query results into xml files? Thanks a lot! -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://mail.postgresql.org/mj/mj_wwwusr?domain=postgresql.org

Re: [SQL] sql query question ?

2007-12-31 Thread Trilok Kumar
Dear Shane, Thanks for the reply and your observation about the word i have used. It is idle odometer reading. The actual Scenario is that the vehicle is taken by the driver. When he comes the next day. He is suppose to login again. Here i am trying to find out how much distance has the vehic

  1   2   3   4   5   6   >