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 th

Re: [SQL] Query with LIMIT clause

2012-09-09 Thread David Johnston
Always reply to list. It is also preferred to bottom-post. Indexes are never simple answers and there isn't enough info to really give good advice here. You should try different versions and estimate performance (read and write). My guess is that a compound index (2 columns) would work well t

Re: [SQL] Query with LIMIT clause

2012-09-09 Thread JORGE MALDONADO
Firstly, who should I reply to, you or the list? Your solution is working pretty fine, I appreciate your advice. Now, I am sure that an index is a good idea in order to make the query fast. What would be a good criteria to define an index? Will an index for final date and another for initial date i

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 d

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

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

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] 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] 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)ti

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

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.

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.

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

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

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

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

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

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

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

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, > > > > >

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

Re: [SQL] Query design assistance - getting daily totals

2007-12-13 Thread Steve Midgley
Hi, Rodrigo is exactly right in my opinion. To provide a little more info on this calendar or day dimension idea.. You can create, for example, a time table dimension which stores every day of every year as a unique record (for as far into the future as you need). You can then associate vari

Re: [SQL] Query Assistance

2007-12-12 Thread Richard Huxton
Gary Chambers wrote: D'Arcy... Have you considered this? I considered integrating the begin and end times into the table. I'm capturing the data via ACPI events, so it's "transactional" by nature. I want to be able to keep track of false transitions (hence the is_outage field). I'm looking

Re: [SQL] Query design assistance - getting daily totals

2007-12-12 Thread Rodrigo De León
On Dec 12, 2007 1:39 AM, Paul Lambert <[EMAIL PROTECTED]> wrote: > It's a financial application which needs to work using a concept of > 'financial periods' which may not necessarily correspond to calendar > months and it's much easier to manage in this way than it is to merge it > all together usi

Re: [SQL] Query Assistance

2007-12-12 Thread Gary Chambers
D'Arcy... > Have you considered this? I considered integrating the begin and end times into the table. I'm capturing the data via ACPI events, so it's "transactional" by nature. I want to be able to keep track of false transitions (hence the is_outage field). I'm looking for a way to simplify t

Re: [SQL] Query Assistance

2007-12-12 Thread D'Arcy J.M. Cain
On Wed, 12 Dec 2007 11:58:20 -0500 "Gary Chambers" <[EMAIL PROTECTED]> wrote: > All... > > I have a simple table in PostgreSQL 8.2.5: > > CREATE TABLE power_transitions ( > -- Transition ID (PK) > tid integer NOT NULL, > -- State ID (0 = Unknown, 1 = Online (AC power), 2 = Offline (Ba

Re: [SQL] Query design assistance - getting daily totals

2007-12-12 Thread Scott Marlowe
On Dec 12, 2007 12:39 AM, Paul Lambert <[EMAIL PROTECTED]> wrote: > A. Kretschmer wrote: > > am Wed, dem 12.12.2007, um 10:34:35 +0900 mailte Paul Lambert folgendes: > >> year_id integer > >> month_id integer > >> working_day integer > > > > Why this broken data types? We have date and timestamp[t

Re: [SQL] Query design assistance - getting daily totals

2007-12-11 Thread A. Kretschmer
am Wed, dem 12.12.2007, um 15:39:48 +0900 mailte Paul Lambert folgendes: > A. Kretschmer wrote: > >am Wed, dem 12.12.2007, um 10:34:35 +0900 mailte Paul Lambert folgendes: > >>year_id integer > >>month_id integer > >>working_day integer > > > >Why this broken data types? We have date and timestam

Re: [SQL] Query design assistance - getting daily totals

2007-12-11 Thread Paul Lambert
A. Kretschmer wrote: am Wed, dem 12.12.2007, um 10:34:35 +0900 mailte Paul Lambert folgendes: year_id integer month_id integer working_day integer Why this broken data types? We have date and timestamp[tz]. It's a financial application which needs to work using a concept of 'financial pe

Re: [SQL] Query design assistance - getting daily totals

2007-12-11 Thread A. Kretschmer
am Wed, dem 12.12.2007, um 10:34:35 +0900 mailte Paul Lambert folgendes: > I have a table of account balances as at the end of a working day and > want to from that, calculate daily total figures. > > Eg, let's say I have a table structure of: > year_id integer > month_id integer > working_day i

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] Query Problem from FoxPro???

2007-07-03 Thread dBHS Jakarta
Dear All, It turns out that, column "is_pilih" was written with "Is_Pilih". PostgreSQL column name is case sensitive! After I change the column name to "is_pilih" everything's showed up! Another NEW Question arose: "Why the is_pilih data type become Character when it displayed in VFP?" Anybod

Re: [SQL] Query Problem from FoxPro???

2007-06-30 Thread Jaime Casanova
On 7/1/07, dBHS Jakarta <[EMAIL PROTECTED]> wrote: I try to query from FoxPro via ADODB, Recordset using this SelectCmd: "SELECT * FROM mst_lang" Everything is showed. When I try to query using: "SELECT lang_id, lang_nm, is_pil FROM mst_lang" No Results showed... Does anybody know what's the p

Re: [SQL] query to select a linked list

2007-05-10 Thread Louis-David Mitterrand
On Thu, May 10, 2007 at 09:49:32AM +1000, Robert Edwards wrote: > > Hi Louis-David, > > I also have written a forum application using PostgreSQL. > > My schema has a "threadid" for each posting, which is actually also the > "messageid" of the first posting in the thread, but that is irrelevant.

Re: [SQL] query to select a linked list

2007-05-09 Thread Robert Edwards
Hi Louis-David, I also have written a forum application using PostgreSQL. My schema has a "threadid" for each posting, which is actually also the "messageid" of the first posting in the thread, but that is irrelevant. I can then just select all messages belonging to that thread. The actual hie

Re: [SQL] query to select a linked list

2007-05-09 Thread Gregory Stark
"Scott Marlowe" <[EMAIL PROTECTED]> writes: > Are you sure the tablefunc functions, which include both connectby and > crosstab functions, aren't up to date with 8.2? They certainly are up > to 8.1, where I'm running them right now on my workstation. They built > for 8.2 and installed, but I hav

Re: [SQL] query to select a linked list

2007-05-09 Thread Scott Marlowe
On Wed, 2007-05-09 at 08:29, Aaron Bono wrote: > On 5/9/07, Louis-David Mitterrand <[EMAIL PROTECTED]> > wrote: > Hi, > > To build a threaded forum application I came up the following > schema: > > forum > -- > id_forum | integer

Re: [SQL] query to select a linked list

2007-05-09 Thread Scott Marlowe
On Wed, 2007-05-09 at 08:24, Gregory Stark wrote: > "Louis-David Mitterrand" <[EMAIL PROTECTED]> writes: > > > Each message a unique id_forum and an id_parent pointing to the replied > > post (empty if first post). > > > > How can I build an elegant query to select all messages in a thread? > >

Re: [SQL] query to select a linked list

2007-05-09 Thread Louis-David Mitterrand
On Wed, May 09, 2007 at 04:30:21PM +0200, Louis-David Mitterrand wrote: > On Wed, May 09, 2007 at 02:55:20PM +0200, Louis-David Mitterrand wrote: > > Hi, > > > > To build a threaded forum application I came up the following schema: > > > > forum > > -- > > id_forum | integer| not null defaul

Re: [SQL] query to select a linked list

2007-05-09 Thread Louis-David Mitterrand
On Wed, May 09, 2007 at 02:55:20PM +0200, Louis-David Mitterrand wrote: > Hi, > > To build a threaded forum application I came up the following schema: > > forum > -- > id_forum | integer| not null default nextval('forum_id_forum_seq'::regclass) > id_parent| integer| > subject | text | n

Re: [SQL] query to select a linked list

2007-05-09 Thread Achilleas Mantzios
Στις Τετάρτη 09 Μάιος 2007 15:55, ο/η Louis-David Mitterrand έγραψε: > Hi, > > To build a threaded forum application I came up the following schema: > > forum > -- > id_forum | integer| not null default > nextval('forum_id_forum_seq'::regclass) id_parent| integer| > subject | text | not nul

Re: [SQL] query to select a linked list

2007-05-09 Thread Aaron Bono
On 5/9/07, Louis-David Mitterrand <[EMAIL PROTECTED]> wrote: Hi, To build a threaded forum application I came up the following schema: forum -- id_forum | integer| not null default nextval('forum_id_forum_seq'::regclass) id_parent| integer| subject | text | not null message | text |

Re: [SQL] query to select a linked list

2007-05-09 Thread Louis-David Mitterrand
On Wed, May 09, 2007 at 02:24:22PM +0100, Gregory Stark wrote: > "Louis-David Mitterrand" <[EMAIL PROTECTED]> writes: > > > Each message a unique id_forum and an id_parent pointing to the replied > > post (empty if first post). > > > > How can I build an elegant query to select all messages in a

Re: [SQL] query to select a linked list

2007-05-09 Thread Gregory Stark
"Louis-David Mitterrand" <[EMAIL PROTECTED]> writes: > Each message a unique id_forum and an id_parent pointing to the replied > post (empty if first post). > > How can I build an elegant query to select all messages in a thread? You would need recursive queries which Postgres doesn't support. T

Re: [SQL] Query RE using COPY

2007-05-08 Thread Jonah H. Harris
On 5/8/07, Paul Lambert <[EMAIL PROTECTED]> wrote: Right now the software that does the extracts is developed by our applications developers, but I'll be taking that onto my side in the near future, just looking for a workaround until then. Sorry, but there isn't one. An unqualified COPY expec

Re: [SQL] Query RE using COPY

2007-05-07 Thread Paul Lambert
Phillip Smith wrote: Can you modify the 'extract' and make the extra column "\n" which is the null escape? That would be the only other option. Right now the software that does the extracts is developed by our applications developers, but I'll be taking that onto my side in the near future

Re: [SQL] Query RE using COPY

2007-05-07 Thread Phillip Smith
stgresql.org Subject: Re: [SQL] Query RE using COPY Jonah H. Harris wrote: > COPY mytbl (col1, col2, col3, col4, col6) FROM 'myfile.txt' WITH > DELIMITER AS '^' QUOTE '\f' CSV HEADER; > > I would rather not do it this way as I use the same load script

Re: [SQL] Query RE using COPY

2007-05-07 Thread Paul Lambert
Jonah H. Harris wrote: COPY mytbl (col1, col2, col3, col4, col6) FROM 'myfile.txt' WITH DELIMITER AS '^' QUOTE '\f' CSV HEADER; I would rather not do it this way as I use the same load script at all customer sites where the extracts and requirements may vary. I.e. one customer may not use t

Re: [SQL] Query RE using COPY

2007-05-07 Thread Jonah H. Harris
COPY mytbl (col1, col2, col3, col4, col6) FROM 'myfile.txt' WITH DELIMITER AS '^' QUOTE '\f' CSV HEADER; On 5/7/07, Paul Lambert <[EMAIL PROTECTED]> wrote: I use the COPY command to load data from a file into tables in my database. The following is an example done in psql: COPY deals_t

Re: [SQL] Query Join Performance

2007-04-25 Thread Alvaro Herrera
Aaron Bono wrote: > Looks like a vacuum analyze did the trick. Performance is beautiful now. I > should have tried that earlier. > > I thought I had the auto vacuum turned on (PostgreSQL 8.1) but I guess it > doesn't do analyze? > > Anyway, I will schedule a vacuum analyze nightly - it is low

Re: [SQL] Query Join Performance

2007-04-25 Thread Aaron Bono
On 4/25/07, Tom Lane <[EMAIL PROTECTED]> wrote: "Aaron Bono" <[EMAIL PROTECTED]> writes: > The biggest problem I notice is when I add a join from a child table > (zip_city) to a parent table (zip). I have filtered the child table down to > about 650 records but when I add the join to the parent

Re: [SQL] Query Join Performance

2007-04-25 Thread Tom Lane
"Aaron Bono" <[EMAIL PROTECTED]> writes: > The biggest problem I notice is when I add a join from a child table > (zip_city) to a parent table (zip). I have filtered the child table down to > about 650 records but when I add the join to the parent which has over > 800,000 records, performance tank

Re: [SQL] Query Join Performance

2007-04-25 Thread Aaron Bono
On 4/25/07, Richard Huxton <[EMAIL PROTECTED]> wrote: Aaron Bono wrote: > Performance tanks with this query - it takes over 120 seconds (that is > where > I set the timeout). > BTW, on our Linux box the full query we run (which adds 3 more tables on > the > whole operation along with more filte

Re: [SQL] Query Join Performance

2007-04-25 Thread Richard Huxton
Aaron Bono wrote: Performance tanks with this query - it takes over 120 seconds (that is where I set the timeout). BTW, on our Linux box the full query we run (which adds 3 more tables on the whole operation along with more filtering on the zip table) finishes in under 10 seconds. Problem i

Re: [SQL] Query to return schema/table/columname/columntype

2007-01-19 Thread codeWarrior
You mean like this: CREATE OR REPLACE VIEW sys_tabledef AS SELECT columns.table_catalog, columns.table_schema, columns.table_name, columns.column_name, columns.ordinal_position, columns.column_default, columns.is_nullable, columns.data_type, columns.character_maximum_length, columns.character

Re: [SQL] Query to return schema/table/columname/columntype

2007-01-19 Thread chester c young
> I am trying to modify the dabo (a python wxpython > ide for database forms creation) code to allow the > selection of tables in any schema. I need a query > that will return records with schema, table, > columname and columne type. create view pg_cols as select s.nspname as schema_nm,

Re: [SQL] Query to return schema/table/columname/columntype

2007-01-19 Thread Bruno Wolff III
On Fri, Jan 19, 2007 at 12:41:19 +, [EMAIL PROTECTED] wrote: > For background I am selecting table & schema by > the query: > SELECT schemaname || '.' || tablename AS tablename > FROM pg_tables ORDER BY tablename; Are you guaranteed that all of the names are lower case? If not you may want t

Re: [SQL] Query to return schema/table/columname/columntype

2007-01-19 Thread paallen
Hi all, I think I have fixed my own problem. At: http://developer.postgresql.org/~momjian/upgrade_tips_7.3 I found the answer which was: SELECT a.attrelid as oid, a.attname, t.typname FROM pg_attribute a inner join pg_type t on a.atttypid = t.oid WHERE a.attrelid = 'co.hole_tes

Re: [SQL] Query a select that returns....

2006-12-19 Thread Achilleas Mantzios
Στις Τρίτη 19 Δεκέμβριος 2006 16:01, ο/η Carlos Santos έγραψε: > Hi! > I need to query a select that returns all the fields of an specific primary > key, but I don't have the single column's name that is constrained as > primary key. How can I do that? > Something like: > SELECT * FROM myTable WHE

Re: [SQL] Query is fast and function is slow

2006-12-07 Thread Tom Lane
Richard Ray <[EMAIL PROTECTED]> writes: > Changing both parameters to char(9) and name fixed the problem > It appears to be using the index > If time allows could you explain this a bit EXPLAIN will show you what's going on: regression=# create table foo (f1 char(9) unique); NOTICE: CREATE TABLE

Re: [SQL] Query is fast and function is slow

2006-12-07 Thread Richard Ray
On Thu, 7 Dec 2006, Tom Lane wrote: Richard Ray <[EMAIL PROTECTED]> writes: On Thu, 7 Dec 2006, Thomas Pundt wrote: Just a guess: is the column "doc_num" really of type text? Maybe using "text" in the function lets the planner choose a sequential scan? Actually "doc_num" is char(9) I change

Re: [SQL] Query is fast and function is slow

2006-12-07 Thread Tom Lane
Richard Ray <[EMAIL PROTECTED]> writes: > On Thu, 7 Dec 2006, Thomas Pundt wrote: >> Just a guess: is the column "doc_num" really of type text? Maybe using "text" >> in the function lets the planner choose a sequential scan? > Actually "doc_num" is char(9) > I changed text to char(9) and got same

  1   2   3   4   >