Re: [SQL] wired behaviour

2008-11-28 Thread Ragnar Hafstað
On fös, 2008-11-28 at 15:22 +0100, Lutz Steinborn wrote: > Hello Paul, > > thanks for the quick answer. > > > NULL values? > Jepp, thats it. > I've supposed this but can't believe it. So NULL is something out of this > dimension :-) Yes, that is one way of putting it. A more useful way to look

Re: [SQL] insert only if conditions are met?

2005-08-31 Thread Ragnar Hafstað
On Wed, 2005-08-31 at 12:49 -0400, Henry Ortega wrote: > Ok. Here's TABLE A > > empdate hours type > JSMITH 08-15-2005 5 WORK > JSMITH 08-15-2005 3 WORK > JSMITH 08-25-2005 6 WORK > > I want to insert the ff

Re: [SQL] insert only if conditions are met?

2005-08-31 Thread Ragnar Hafstað
On Wed, 2005-08-31 at 11:49 -0400, Henry Ortega wrote: > What I am trying to do is > * Insert a record for EMPLOYEE A to TABLE A > IF > the sum of the hours worked by EMPLOYEE A on TABLE A > is not equal to N > > Is this possible? Sure, given a suitable schema It is not clear to me, if the hour

Re: [SQL] how to use column name with Case-sensitive with out usig

2005-08-06 Thread Ragnar Hafstað
On Sat, 2005-08-06 at 05:00 +, wisan watcharinporn wrote: > how can i use > > create table myName( >myColumnName varchar(32) > ); > > select myColumnName from myColumnName ; Assuming you meant 'from myName' here, this should work. On the other hand, this will NOT work: create table "

Re: [SQL] ids from grouped rows

2005-07-20 Thread Ragnar Hafstað
On Wed, 2005-07-20 at 08:46 -0400, Lindsay wrote: > SELECT name, MAX(age), id_for_row_with_max_age > FROM Person > GROUP BY name how about: select distinct on (name) name, age, id from person order by name, age desc; gnari ---(end of broadcast

Re: [SQL] left joins

2005-07-06 Thread Ragnar Hafstað
On Wed, 2005-07-06 at 11:33 +0100, Nick Stone wrote: > I've had exactly yhe same problem - try changing the query to. > > select count(*) > from h left join p using (r,pos) and p.r_order=1 > where h.tn > 20 > and h.tn < 30 really ? is this legal SQL ? is this a 8.0 feature ? I get syntax error

Re: [SQL] Changed to: how to solve the get next 100 records problem

2005-05-18 Thread Ragnar Hafstað
On Wed, 2005-05-18 at 12:42 -0300, Alain wrote: > I found something that is both fast and simple (program side): > ... > subsequent selects are > (select ... from tab WHERE skey=skey_last AND pkey>pkey_last > ORDER BY skey,pkey LIMIT 100) > UNION > (select ... from tab WHERE s

Re: [SQL] Does Postgresql have a similar pseudo-column "ROWNUM" as

2005-05-17 Thread Ragnar Hafstað
On Wed, 2005-05-18 at 00:13 +0200, PFC wrote: > > your subsequent selects are > > select ... from tab WHERE skey>skey_last > >OR (skey=skey_last AND pkey>pkey_last) > > ORDER BY skey,pkey > > LIMIT 100 OFFSET 100; > > why offset

Re: [SQL] Does Postgresql have a similar pseudo-column "ROWNUM" as

2005-05-17 Thread Ragnar Hafstað
On Tue, 2005-05-17 at 15:43 -0300, Alain wrote: > [how to solve the get next 100 records problem] I am assuming this is for a web like interface, in other words that cursors are not applicable > > [me] > > if you are ordering by a unique key, you can use the key value > > in a WHERE clause. > >

Re: [SQL] Does Postgresql have a similar pseudo-column "ROWNUM" as

2005-05-17 Thread Ragnar Hafstað
On Tue, 2005-05-17 at 14:48 -0300, Alain wrote: > > Andrew Sullivan escreveu: > > On Thu, May 12, 2005 at 01:07:00PM -0600, [EMAIL PROTECTED] wrote: > > > >>Does Postgresql have a similar pseudo-column "ROWNUM" as Oracle? If > >>so, we can write the following query: > > > > > > No. What is the

Re: [SQL] ORDER BY handling mixed integer and varchar values

2005-05-16 Thread Ragnar Hafstað
On Mon, 2005-05-16 at 11:47 -0700, David B wrote: (sorting text columns numerically) > And of course I get stuff ordered as I want it. > BUT… with many product categories being numeric based they come out in > wrong order '10 comes before 2" etc. > > So I tried > Select product_desc, product_

Re: [SQL] Replacing a table with constraints

2005-05-13 Thread Ragnar Hafstað
On Fri, 2005-05-13 at 14:38 -0400, Mark Fenbers wrote: > I have a table called Counties which partially contains a lot bad > data. By" bad data", I mean some records are missing; some exist and > shouldn't; and some records have fields with erroneous information. > However, the majority of the dat

Re: [SQL] Trimming the cost of ORDER BY in a simple query

2005-05-03 Thread Ragnar Hafstað
On Mon, 2005-05-02 at 21:35 -0700, [EMAIL PROTECTED] wrote: > Query (shows the last 7 dates): > > => SELECT DISTINCT date_part('year', uu.add_date), date_part('month', > uu.add_date), date_part('day', uu.add_date) FROM user_url uu WHERE > uu.user_id=1 ORDER BY date_part('year', uu.add_da

Re: [SQL] can someone jelp me on this?

2005-05-01 Thread Ragnar Hafstað
On Tue, 2005-04-26 at 20:18 +, Lord Knight of the Black Rose wrote: > hey guys I have a question that I couldnt maneged to solve for the last 4 > days. Im kinda new to these stuff so dont have fun with me if it was so > easy. Ok now heres the question. > > [snip class assignment] we'd all l

Re: [SQL] subselect query time and loops problem

2005-04-10 Thread Ragnar Hafstað
On Sun, 2005-04-10 at 07:54 -0700, pankaj naug wrote: > [quoting Tom] > >Evidently one has been analyzed much more recently than the other, > because the estimated row counts are wildly different. > > Both the explain/analyse queries has been run at the same time. in that case, is the data the

Re: [SQL] getting count for a specific querry

2005-04-08 Thread Ragnar Hafstað
On Fri, 2005-04-08 at 12:32 -0400, Tom Lane wrote: > Ragnar =?ISO-8859-1?Q?Hafsta=F0?= <[EMAIL PROTECTED]> writes: > > you might reduce the performance loss if your dataset is ordered by > > a UNIQUE index. > > > select * from mytable where somecondition > > ORDER by uniquec

Re: [SQL] getting count for a specific querry

2005-04-08 Thread Ragnar Hafstað
On Fri, 2005-04-08 at 09:29 -0400, Joel Fradkin wrote: > Our app currently pulls a bunch of data to several query pages. > > My idea is to use the limit and offset to return just the first 50 > records, if they hit next I can set the offset. > > My understanding was this gets slower as you move

Re: [SQL] getting count for a specific querry

2005-04-08 Thread Ragnar Hafstað
On Fri, 2005-04-08 at 11:07 -0400, Andrew Sullivan wrote: > On Fri, Apr 08, 2005 at 09:29:13AM -0400, Joel Fradkin wrote: > > > > Is there a fast way to get the count? > > Not really, no. You have to perform a count() to get it, which is > possibly expensive. One way to do it, though, is to do

Re: [SQL] 9.17.5. Row-wise Comparison

2005-04-07 Thread Ragnar Hafstað
On Thu, 2005-04-07 at 06:44 -0700, TJ O'Donnell wrote: > it might break in future. > > >if (b > 1) then true > >else if (b = 1 and c > 2) then true > >else if (b = 1 and c = 2 and d > 3) then true > >else false > Your spec sql snippet is like an OR, isn't it, instead > of an AN

Re: [SQL] select & group by

2005-04-04 Thread Ragnar Hafstað
On Mon, 2005-04-04 at 12:16 +0200, Michael L. Hostbaek wrote: > I've got a problem selecting some specific data from my table. Imagine > the following rows: > > part | mfg | qty | price | eta > --- > TEST1 ABC 10 100(No ETA, as item

Re: [SQL] A SQL Question About distinct, limit, group by, having,

2005-03-31 Thread Ragnar Hafstað
On Thu, 2005-03-31 at 13:14 +0800, Lin Kun Hsin wrote: > below is the sql schema. i hope it will help. > > i want the top 3 score students in every class this has been discussed before. a quick google gives me: http://archives.postgresql.org/pgsql-sql/2004-04/msg00067.php gnari

Re: [SQL] Query performance problem

2005-03-17 Thread Ragnar Hafstað
On Fri, 2005-03-18 at 10:49 +0530, Kenneth Gonsalves wrote: > On Thursday 17 Mar 2005 7:35 pm, Richard Huxton wrote: > > > Not necessarily. NOT NULL here helps to ensure you can add values > > together without the risk of a null result. There are plenty of > > "amount" columns that should be not-n

Re: [SQL] Scheme not dropping

2005-03-15 Thread Ragnar Hafstað
On Tue, 2005-03-15 at 18:44 +, Graham Vickrage wrote: > I am dropping a database with an additional scheme other than public on > version 7.3.2. > > When I come to recreate the database with the same scheme it gives me > the error: > > ERROR: namespace "xxx" already exists does the scheme e

Re: [SQL] How to cast VARCHAR to BYTEA and vice-versa?

2005-03-14 Thread Ragnar Hafstað
On Tue, 2005-03-08 at 07:31 -0800, Moran.Michael wrote: > Hello all, > > I have a table with a VARCHAR column that I need to convert to a BYTEA. > > How do I cast VARCHAR to BYTEA? have you looked at the encode() and decode() functions ? http://www.postgresql.org/docs/7.4/interactive/functions

Re: [SQL] Serial and Index

2005-02-27 Thread Ragnar Hafstað
On Sun, 2005-02-27 at 12:54 +, Sam Adams wrote: > I read at http://jamesthornton.com/postgres/FAQ/faq-english.html#4.15.1 > that when a serial is created then an index is created on the column. > However I can't seem to find this anywhere in the PoistgreSQL manual. Is > this true? Thanks. no,

Re: [SQL] schemas and paths with the alter statement

2005-02-22 Thread Ragnar Hafstað
On Tue, 2005-02-22 at 11:06 -0800, Theodore Petrosky wrote: > I have to first admit that I am very green at this. I > thought that one could refer to a table in a fully > qualified path... public.testtable > ... > ALTER TABLE public.test ADD CONSTRAINT public.test_PK > PRIMARY KEY (test); > ... > a

Re: [SQL] pg primary key bug?

2005-02-22 Thread Ragnar Hafstað
On Tue, 2005-02-22 at 10:33 +0100, pginfo wrote: > > > We are using jdbc (jdbc driver from pg) + jboss (java based > application server) + connection pool (biult in jboss). > ... > Will vacuum full generate this problem if we have locked table in this > time? (It is possible to have locked ta

Re: [SQL] Making NULL entries appear first when ORDER BY

2005-02-15 Thread Ragnar Hafstað
On Wed, 2005-02-16 at 00:55 +, Andreas Joseph Krogh wrote: > SELECT start_date, start_time, end_time, title > FROM onp_crm_activity_log > WHERE start_date IS NOT NULL > ORDER BY start_date ASC, start_time ASC; > > start_date | start_time | end_time | title > ---

Re: [PERFORM] [SQL] OFFSET impact on Performance???

2005-01-25 Thread Ragnar Hafstað
On Thu, 2005-01-20 at 11:59 -0500, Greg Stark wrote: > The best way to do pages for is not to use offset or cursors but to use an > index. This only works if you can enumerate all the sort orders the > application might be using and can have an index on each of them. > > To do this the query woul