Re: [HACKERS] [SQL] How would I get rid of trailing blank line?

2009-04-02 Thread Tena Sakai
Hi Andrew, > Right. There's a simple pipeline way to get rid of it: > psql -t -f query.sql | sed -e '$d' > query.out Hi Scott, > Tired of those blank lines in your text files? Grep them away: > psql -tf query.sql mydatabase | grep -v "^$" > query.out Thank you Both. Regards, Tena Sakai tsa

Re: [SQL] How would I get rid of trailing blank line?

2009-04-02 Thread Scott Marlowe
On Thu, Apr 2, 2009 at 3:33 PM, Tena Sakai wrote: > Hi Everybody, > > I am using postgres 8.3.4 on linux. > I often use a line like: >   psql -tf query.sql mydatabase > query.out > > -t option gets rid of the heading and count > report at the bottom.  There is a blank line > at the bottom, however

Re: [SQL] How would I get rid of trailing blank line?

2009-04-02 Thread Tena Sakai
Hi Tom, I am a bit surprised to hear that that '\n' is there unconditionally. But I am sure there are more pressing things for you to work on. It's something I can live with. Regards, Tena Sakai tsa...@gallo.ucsf.edu -Original Message- From: Tom Lane [mailto:t...@sss.pgh.pa.us] Sent:

Re: [SQL] FUNCTION problem

2009-04-02 Thread Adrian Klaver
On Thursday 02 April 2009 4:22:06 pm Peter Willis wrote: > Adrian Klaver wrote: > > Did you happen to catch this: > > Note that functions using RETURN NEXT or RETURN QUERY must be called as a > > table source in a FROM clause > > > > Try: > > select * from test_function(1) > > I did miss that, but

Re: [SQL] FUNCTION problem

2009-04-02 Thread Peter Willis
Adrian Klaver wrote: Did you happen to catch this: Note that functions using RETURN NEXT or RETURN QUERY must be called as a table source in a FROM clause Try: select * from test_function(1) I did miss that, but using that method to query the function didn't work either. Postgres doesn't s

Re: [SQL] How would I get rid of trailing blank line?

2009-04-02 Thread Tom Lane
"Tena Sakai" writes: > I often use a line like: > psql -tf query.sql mydatabase > query.out > -t option gets rid of the heading and count > report at the bottom. There is a blank line > at the bottom, however. Is there any way to > have psql not give me that blank line? Doesn't look like it

Re: [SQL] FUNCTION problem

2009-04-02 Thread Adrian Klaver
- "Peter Willis" wrote: > Adrian Klaver wrote: > > On Wednesday 01 April 2009 4:31:20 pm Peter Willis wrote: > >> Hello, > >> > >> I am having a problem with a FUNCTION. > >> The function creates just fine with no errors. > >> > >> However, when I call the function postgres produces an err

[SQL] How would I get rid of trailing blank line?

2009-04-02 Thread Tena Sakai
Hi Everybody, I am using postgres 8.3.4 on linux. I often use a line like: psql -tf query.sql mydatabase > query.out -t option gets rid of the heading and count report at the bottom. There is a blank line at the bottom, however. Is there any way to have psql not give me that blank line? Than

Re: [SQL] Performance problem with row count trigger

2009-04-02 Thread Greg Sabino Mullane
-BEGIN PGP SIGNED MESSAGE- Hash: RIPEMD160 > I was looking to speed up a count(*) query A few things spring to mind: 1) Use a separate table, rather than storing things inside of dataset itself. This will reduce the activity on the dataset table. 2) Do you really need bigint for the c

Re: [SQL] Performance problem with row count trigger

2009-04-02 Thread Wei Weng
On 04/02/2009 03:32 PM, Tom Lane wrote: Tony Cebzanov writes: What I want to do is update the assoc_count field in the dataset table to reflect the count of related records in the assoc field. To do so, I added the following trigger: CREATE OR REPLACE FUNCTIO

Re: [SQL] Performance problem with row count trigger

2009-04-02 Thread Tom Lane
Tony Cebzanov writes: > What I want to do is update the assoc_count field in the dataset table > to reflect the count of related records in the assoc field. To do so, I > added the following trigger: > CREATE OR REPLACE FUNCTION update_assoc_count_insert() > RETURNS TRIGGER AS > ' > BEGIN >

Re: [SQL] Performance problem with row count trigger

2009-04-02 Thread Tony Cebzanov
Hi Craig, thanks for your help. Craig Ringer wrote: > MVCC bloat from the constant updates to the assoc_count table, maybe? That's what a coworker suggested might be happening. The fact that a no-op trigger performs fine but the UPDATE trigger doesn't would seem to confirm that it's something in

Re: [SQL] Performance problem with row count trigger

2009-04-02 Thread Craig Ringer
Tony Cebzanov wrote: > The throughput of the first batch of 1,000 is diminished, but still > tolerable, but after 10,000 inserts, it's gotten much worse. This > pattern continues, to the point where performance is unacceptable after > 20k or 30k inserts. > > To rule out the performance of the tr

Re: [SQL] FUNCTION problem

2009-04-02 Thread Peter Willis
Adrian Klaver wrote: On Wednesday 01 April 2009 4:31:20 pm Peter Willis wrote: Hello, I am having a problem with a FUNCTION. The function creates just fine with no errors. However, when I call the function postgres produces an error. Perhaps someone can enlighten me. --I can reproduce the e

Re: [SQL] ibatis with overlaps query

2009-04-02 Thread Tom Lane
Emi Lu writes: > With ibatis, do overlap checking: > (1) select (DATE #begin_date#, DATE #end_date#) overlaps > (DATE '2008-01-01', DATE '2009-01-01') > . #begin_date# is varchar > . #end_date# is varchar > Cause: java.sql.SQLException: ERROR: syntax error at or near "$4" > However, when I up

Re: [SQL] SQL to Check whether "AN HOUR PERIOD" is between start and end timestamps

2009-04-02 Thread Tom Lane
Alvaro Herrera writes: > Another way to phrase the WHERE clause is with the OVERLAPS operator, > something like this: > WHERE (start_ts, end_ts) OVERLAPS ('2008-12-07 07:59:59', '2008-12-07 > 08:59:59') > What I'm not so sure about is how optimizable this construct is. Not at all :-( --- or a

[SQL] Performance problem with row count trigger

2009-04-02 Thread Tony Cebzanov
I was looking to speed up a count(*) query, as per the recommendations on the postgres wiki: http://wiki.postgresql.org/wiki/Slow_Counting I decided to use the trigger approach to get an accurate count that doesn't depend on VACUUM being run recently. I've got it working, but the addition of the

[SQL] ibatis with overlaps query

2009-04-02 Thread Emi Lu
Good morning, With ibatis, do overlap checking: (1) select (DATE #begin_date#, DATE #end_date#) overlaps (DATE '2008-01-01', DATE '2009-01-01') . #begin_date# is varchar . #end_date# is varchar Always get: Cause: java.sql.SQLException: ERROR: syntax error at or near "$4" Howeve

Re: [SQL] SQL to Check whether "AN HOUR PERIOD" is between start and end timestamps

2009-04-02 Thread Alvaro Herrera
James Kitambara wrote: > Dear Srikanth, > You can solve your problem by doing this > > THE SQL IS AS FOLLOWS >   ASSUME TIME INTERVAL 2008-12-07 07:59:59 TO 2008-12-07 08:58:59 AND THE > TABLE NAME time_interval > >  COUNT (*) FROM   >     (select customer_id, log_session_id, start_ts, end_ts ,

Re: [SQL] SQL to Check whether "AN HOUR PERIOD" is between start and end timestamps

2009-04-02 Thread James Kitambara
Dear Srikanth, You can solve your problem by doing this THE SQL IS AS FOLLOWS   ASSUME TIME INTERVAL 2008-12-07 07:59:59 TO 2008-12-07 08:58:59 AND THE TABLE NAME time_interval  COUNT (*) FROM       (select customer_id, log_session_id, start_ts, end_ts , end_ts-start_ts as "Interval" from time_