Re: [SQL] Cast on character columns in views

2007-09-04 Thread Luiz K. Matsumura
Luiz K. Matsumura wrote: Richard Broersma Jr wrote: --- "Luiz K. Matsumura" <[EMAIL PROTECTED]> wrote: CREATE VIEW view1( id, col1, type1, type2) AS SELECT table1.id, table1.col1, CAST( table2.type1 AS CHARACTER( 3 )), NULL FROM table1 JOIN table2 ON table2.fk_tabl

[SQL] Partial index on boolean - Sometimes fails to index scan

2007-09-04 Thread Bryce Nesbitt
This is a reformulation of an earlier question.  I've got a confusing case of a partial index not working.  The column in question is a not-null boolean, which is false only for the most recent entries into the table. # explain analyze select count(vehicleeve0_.VEHICLE_EVENT_ID) as x0_0_ from

Re: [SQL] Difference between "foo is false" and "foo=false"? Partial index on boolean.

2007-09-04 Thread Richard Huxton
Bryce Nesbitt wrote: Tom Lane wrote: Bryce Nesbitt <[EMAIL PROTECTED]> writes: They give different results for NULL --- specifically, NULL for the former and FALSE for the latter. Don't blame me, it's in the spec... Thanks, and Got It. This particular column is: reconciled | boolea

[SQL] EXECUTE 'EXECUTE ...' or how to use dynamic prepared statements ?

2007-09-04 Thread Marc Mamin
Hello, I have a large upddate to perform on tables which are dynamically generated (dynamic names). In this simplified example, the operation should replace in each family the "mygroup" of each item of rang=0 with the "mygroup" value of the element of rang=1 : (the * indicate the modified valu

Re: [SQL] EXECUTE 'EXECUTE ...' or how to use dynamic prepared statements ?

2007-09-04 Thread Dirk Jagdmann
Hello Marc, at first I tried to solve your update of the tables. The example you gave should be done with an update statement like the following: update test_table set mygroup=(select t.mygroup from test_table as t where t.family = test_table.family

[SQL] Use of delete...returning in function problem

2007-09-04 Thread Bart Degryse
I'm trying to use a delete statement with returning clause in a function: CREATE OR REPLACE FUNCTION "public"."test_delete"() RETURNS void AS $body$ DECLARE rec billing_errors_new; BEGIN FOR rec IN ( delete from billing_errors_new where errortypeid IN (1,2) returning *) LO

[SQL] 8.0.1 to 8.0.13 upgrade added 15% lack of time of query execution

2007-09-04 Thread Aleksandr Vinokurov
Hello all, I beg your pardon if I do not know some thing, but I was disappointed after taken an upgrade from 8.0.1 to 8.0.13, now the query, that I had optimized so far to run for 92 sec on 8.0.1, takes 106 seconds on 8.0.13. The plan seems to stay unmodified, except statistics used for its

Re: [SQL] Use of delete...returning in function problem

2007-09-04 Thread Richard Huxton
Bart Degryse wrote: I'm trying to use a delete statement with returning clause in a function: FOR rec IN ( delete from billing_errors_new where errortypeid IN (1,2) returning *) LOOP I get following error though: ERROR: syntax error at or near "delete" at character 4 QU

Re: [SQL] Cast on character columns in views

2007-09-04 Thread Richard Broersma Jr
--- "Luiz K. Matsumura" <[EMAIL PROTECTED]> wrote: > When I drop the view first , and then create again the view (in a > separated transaction), now the command works! (this is a bug?) Well according to the manual, it is working as it is intended to work: http://www.postgresql.org/docs/8.2/intera

Re: [SQL] Cast on character columns in views

2007-09-04 Thread Richard Broersma Jr
--- "Luiz K. Matsumura" <[EMAIL PROTECTED]> wrote: > Ugh, I'm totally crazy with this views > I'm using pgadmin with postgres, when I clink on "view the data of > selected object" button all works fine. > But when I open a query tool window and do: > > SELECT * FROM view1; > Now, again type1 co

Re: [SQL] Use of delete...returning in function problem

2007-09-04 Thread Bart Degryse
Amazing what a bracket can do :) Thanks for the help. >>> Richard Huxton <[EMAIL PROTECTED]> 2007-09-04 12:45 >>> Bart Degryse wrote: > I'm trying to use a delete statement with returning clause in a function: > FOR rec IN ( > delete from billing_errors_new where errortypeid IN (1,2) re

Re: [SQL] How to influence the planner

2007-09-04 Thread Scott Marlowe
On 8/31/07, Richard Ray <[EMAIL PROTECTED]> wrote: > Changing to enable_seqscan = on does solve this problem, thanks > Is there some method of crafting a query that will assert my wishes to the > planner > When is enable_seqscan = off appropriate enable_xxx = off are troubleshooting tools. They

Re: [SQL] Partial index on boolean - Sometimes fails to index scan

2007-09-04 Thread Bryce Nesbitt
Richard Huxton provided the answer: It's a prepared query-plan, which means it can't plan to use the index because the next EXECUTE might have reconciled=true. Bryce Nesbitt wrote: ...Which is all good.  But the Hibernate version of query still takes several seconds, and still appears in

Re: [SQL] Cast on character columns in views

2007-09-04 Thread Tom Lane
Richard Broersma Jr <[EMAIL PROTECTED]> writes: > --- "Luiz K. Matsumura" <[EMAIL PROTECTED]> wrote: >> But when I open a query tool window and do: >> SELECT * FROM view1; >> Now, again type1 column returns as bpchar. > This might be a good question to ask on the PGAdmin mailing list or even try

[SQL] Trigger to change different row in same table

2007-09-04 Thread PostgreSQL Admin
I want to write a trigger that updates a different row on the same table. It's pretty basic: before the any row in his table updated I want to set a only row that has the value true to false. I keep getting this error: SQL statement "update theirry.articles set master_featured = false where mast

Re: [SQL] Trigger to change different row in same table

2007-09-04 Thread PostgreSQL Admin
chester c young wrote: > how are you preventing recursion? > > That could be the problem, suggestions? ---(end of broadcast)--- TIP 4: Have you searched our list archives? http://archives.postgresql.org

Re: [SQL] Use of delete...returning in function problem

2007-09-04 Thread Tom Lane
Richard Huxton <[EMAIL PROTECTED]> writes: > I think it's just the brackets () - plpgsql's parser isn't terribly > sophisticated. It's not plpgsql's fault --- you'll get the same result if you put parentheses around a DELETE command at the SQL command line. regression=# (delete from fool); ERROR

Re: [SQL] How to influence the planner

2007-09-04 Thread Richard Ray
Thanks guys Lesson learned On Tue, 4 Sep 2007, Scott Marlowe wrote: On 8/31/07, Richard Ray <[EMAIL PROTECTED]> wrote: Changing to enable_seqscan = on does solve this problem, thanks Is there some method of crafting a query that will assert my wishes to the planner When is enable_seqscan = o

[SQL] work hour calculations

2007-09-04 Thread novice
Hello All, SELECT notification_time, finished_time, sum(finished_time - notification_time) as actual FROM log GROUP BY notification_time, finished_time; gives me: notification_time| finished_time | actual ++- 20

Re: [SQL] work hour calculations

2007-09-04 Thread novice
correction: > The result I'm expecting for the above to be > >notification_time| finished_time | actual > ++- 2007-07-06 15:50:00+10 | 2007-07-09 07:10:00+10 | 01:20:00 > 2007-07-07 12:30:00+10 | 2007-07-09 07

Re: [SQL] work hour calculations

2007-09-04 Thread A. Kretschmer
am Wed, dem 05.09.2007, um 13:45:46 +1000 mailte novice folgendes: > Hello All, > > SELECT notification_time, finished_time, sum(finished_time - > notification_time) as actual > FROM log > GROUP BY notification_time, finished_time; > > gives me: > >notification_time| finished_time