Re: [SQL] Does IMMUTABLE property propagate?

2010-03-25 Thread Greg Stark
On Thu, Mar 25, 2010 at 2:35 PM, Tom Lane wrote: > When you're intending to have a SQL function be inlined, it's probably > best not to mark it as either IMMUTABLE or STRICT --- that doesn't buy > anything and it can complicate matters as to whether inlining is legal. I'm confused, I thought it w

Re: [SQL] Does IMMUTABLE property propagate?

2010-03-06 Thread Greg Stark
The immutable property had nothing to do with caching results. Postgres never caches the results of functions. The immutable property is used top determine if it's safe to use indexes or other plans that avoid evaluating an expression repeatedly. On 6 Mar 2010 02:45, "Petru Ghita" wrote: -BE

Re: [SQL] an aggregate to return max() - 1 value?

2010-03-04 Thread Greg Stark
SELECT col FROM tab ORDER BY col DESC OFFSET 1 LIMIT 1 In 8.4 OLAP window functions provide more standard and flexibility method but in this case it wouldn't perform as well: postgres=# select i from (select i, rank() over (order by i desc) as r from i) as x where r = 2; i 99 (1 row) post

Re: [SQL] Odd sort behaviour

2009-09-01 Thread Greg Stark
On Tue, Sep 1, 2009 at 11:31 PM, Rob Sargent wrote: > How many ways might one accidentally do that I wonder. Well most operating system distributions ask you when you install them what region you're in and use a collation for that region. In 8.4 you can check what collation a database is set to u

Re: [SQL] mysql code questions

2009-08-12 Thread Greg Stark
On Wed, Aug 12, 2009 at 7:52 PM, Thomas Kellerer wrote: > Ray Stell wrote on 12.08.2009 20:19: > I would probably do it this way: > > SELECT tt. * > FROM testtable tt > WHERE create_date = (SELECT MAX(create_date) >                     FROM testtable tt2 >                     WHERE tt.id = tt2.id);

Re: [SQL] FW: Query length limitation in postgres server > 8.2.9

2009-07-07 Thread Greg Stark
On Tue, Jul 7, 2009 at 11:33 PM, wrote: > After some investigation it seems that the new server is refusing to use the > index's but if I > limit the number of arguments in the latter part of the statement to 100 then > it works as > expected in the expected amount of time using the indexs. Ugh

Re: [SQL] Best way to simulate Booleans

2009-07-07 Thread Greg Stark
On Tue, Jul 7, 2009 at 10:17 AM, Simon Riggs wrote: > > > Integer works best since it converts easily to boolean > > mybool smallint check (mybool in (0, 1)) > > You can use "char" also, but the syntax is less clear. Hm, I was going to suggest using boolean in postgres and making a "boolean" domai

Re: [SQL] Create custom aggregate function and custom sfunc

2009-07-02 Thread Greg Stark
On Thu, Jul 2, 2009 at 3:48 PM, Jasmin Dizdarevic wrote: > customer ; seg > 111 ; L1 > 111 ; L2 > 111 ; L1 > 222 ; L3 > 222 ; L3 > 222 ; L2 > > the result should look like this: > > 111: L1 - because L1 is higher than L2 and ratio of L1 : L2 is 2 : 1 > 222: L3 - because L3 is higher than L2 and rat

Re: [SQL] Taking the cache out of the equation?

2009-06-12 Thread Greg Stark
On Sat, Jun 13, 2009 at 12:12 AM, Erik Jones wrote: > > On Jun 9, 2009, at 10:51 AM, Rob Sargent wrote: > >> Caching helps a *lot* and I'm thankful for that but I would like to take >> it out of the picture as I massage my queries for better performance. >>  Naturally the first invocation of the qu

Re: [SQL] array_to_string(anyarray, text) that was working in 8.1 is not working in 8.3

2008-12-13 Thread Greg Stark
Huh, I didn't realize that ever worked in the past. I thought the way to do what the op describes was to cast it to text[] or whatever datatype you from out-of-band knowledge to expect. -- Greg On 13 Dec 2008, at 19:38, Tom Lane wrote: Corey Horton writes: I'm trying to use array_to_st

Re: [SQL] Repetitive code

2006-06-16 Thread Greg Stark
"Aaron Bono" <[EMAIL PROTECTED]> writes: > I haven't stared at your query as long as you have so I may have missed > something Likewise I'm perhaps speaking too quickly, but at the risk of making a fool of myself: you should perhaps realize that UNION has to do a fair amount of work to eliminate

Re: [SQL] SELECT DISTINCT too slow

2006-06-01 Thread Greg Stark
Alvaro Herrera <[EMAIL PROTECTED]> writes: > Miroslav ?ulc wrote: > > Well, "key" is not primary key from another table. It is just a column > > in pair "key" => "value". > > The structure of the table is this: > > > > Id (primary key) > > MRTPContactId (id of contact from table MRTPContact) > >

Re: [SQL] Table design question

2006-06-01 Thread Greg Stark
"David Clarke" <[EMAIL PROTECTED]> writes: > is it really that big an issue these days to have a 100 character primary > key? Are there postgres-specific implications for either approach? It's exactly the same size issue as ever. A 20% increase in space usage is a 20% performance hit in certain

Re: [SQL] Help with "missing FROM clause" needed

2006-03-06 Thread Greg Stark
"A. Kretschmer" <[EMAIL PROTECTED]> writes: > *untested* > DELETE FROM partner_zu using partner > WHERE partner_zu.pa_id = partner.id > ... > The point is the 'using ...' You can also just set the add_missing_from to true for that one session if you prefer. I don't think there's any plans to remo

Re: [SQL] functions in WHERE clause

2006-03-05 Thread Greg Stark
Tom Lane <[EMAIL PROTECTED]> writes: > A SQL-language function like this should get inlined into the query, > so that you don't lose any performance compared to writing out the > full expression each time. I think what's going on here is that he doesn't really want a function in the programming s

Re: [SQL] Tough Problem -- Record Checkouts

2006-02-17 Thread Greg Stark
"Alfred" <[EMAIL PROTECTED]> writes: > CO| N > --+--- > 0 | 15-59 > 1 | 0, 16-59 > 2 | 0-1, 17-59 > 15| 0-14, 30-59 > 16| 0-15, 31-59 > 30| 0-29, 45-59 > 31| 0-30, 46-59 > 45| 0-44 > 46| 1-45 >

Re: [SQL] view of weekly data

2006-02-17 Thread Greg Stark
"Ding Xiangguang" <[EMAIL PROTECTED]> writes: > Hi, friend, > > Suppose there is table of daily transaction data with 5 fields, > > time(date), open(float8), high(float8), low(float8), close(float8) > > Is it possible to create a view of weekly data, i.e. open is the first > day'open, high is t

Re: [SQL] two count columns?

2006-02-17 Thread Greg Stark
Jan Danielsson <[EMAIL PROTECTED]> writes: > select from_ip, count(from_ip) as entries, count(select * from log where > ...) as tot_entries, max(ts)::timestamp(0) as last_access from log where > to_port=22 and direction='in' group by from_ip select from_ip, count(from_ip) as entries,

Re: [SQL] How to implement Microsoft Access boolean (YESNO)

2006-01-23 Thread Greg Stark
Tom Lane <[EMAIL PROTECTED]> writes: > Greg Stark <[EMAIL PROTECTED]> writes: > > "Jesper K. Pedersen" <[EMAIL PROTECTED]> writes: > >> Having checked the I/O format it seems that MS Access exports the > >> values of a YESNO field as 0 and 1

Re: [SQL] How to implement Microsoft Access boolean (YESNO)

2006-01-23 Thread Greg Stark
"Jesper K. Pedersen" <[EMAIL PROTECTED]> writes: > Having checked the I/O format it seems that MS Access exports the > values of a YESNO field as 0 and 1 If only Postgres's boolean type were as helpful. -- greg ---(end of broadcast)--- TIP 3: H

Re: [SQL] "large" IN/NOT IN subqueries result in query returning wrong data

2005-12-28 Thread Greg Stark
elein <[EMAIL PROTECTED]> writes: > > Note that the above are not inverses because you changed the lefthand > > input. You do get consistent results when you just add or omit NOT: > Yes, you are right. I skipped the permutations to get down to the point. Remember that NULL means "unknown". So "1

Re: [SQL] Storing HTML in table

2005-11-27 Thread Greg Stark
Rob <[EMAIL PROTECTED]> writes: > I would like complete control over this information -- so if sometime in the > future it's decided to totally redesign the layout. Also, at some point a > tool will be created so novice computer users can enter nicely formatted > markup -- meaning you won't have

Re: [SQL] pg, mysql comparison with "group by" clause

2005-10-14 Thread Greg Stark
"Anthony Molinaro" <[EMAIL PROTECTED]> writes: > More awkward? What *you're* suggesting is more awkward. You realize that > right? How can syntax that is understood and accepted for years be more > awkward? Well gosh, I would say that that's something only a newbie could say about SQL of all thi

Re: [SQL] pg, mysql comparison with "group by" clause

2005-10-13 Thread Greg Stark
Scott Marlowe <[EMAIL PROTECTED]> writes: > Sorry, but it's worse than that. It is quite possible that two people > could run this query at the same time and get different data from the > same set and the same point in time. That shouldn't happen accidentally > in SQL, you should know it's comi

Re: [SQL] pg, mysql comparison with "group by" clause

2005-10-12 Thread Greg Stark
"Anthony Molinaro" <[EMAIL PROTECTED]> writes: > Greg, > You'll have to pardon me... > > I saw this comment: > > "I don't see why you think people stumble on this by accident. > I think it's actually an extremely common need." > > Which, if referring to the ability to have items in the sele

Re: [SQL] pg, mysql comparison with "group by" clause

2005-10-12 Thread Greg Stark
"Anthony Molinaro" <[EMAIL PROTECTED]> writes: > By changing the values in the select/group by you are changing > Group! How can you arbitrarily add or exclude a column? > You can't do it. Go back and reread the previous posts again. You missed the whole point. -- greg --

Re: [SQL] pg, mysql comparison with "group by" clause

2005-10-12 Thread Greg Stark
Scott Marlowe <[EMAIL PROTECTED]> writes: > Hehe. When I turn on my windshield wipers and my airbag deploys, is it > a documented "feature" if the dealership told me about this behaviour > ahead of time? Well it's more like my car where the dashboard dims when I turn on my headlights which ann

Re: [SQL] Text->Date conversion in a WHERE clause

2005-10-12 Thread Greg Stark
Collin Peters <[EMAIL PROTECTED]> writes: > I have a table that has some columns which store 'custom' fields so the > content varies according to the user that the row belongs to. For one > of the groups of users the field is a date (the type of the field is > 'text' though). I'm trying to perfo

Re: [SQL] pg, mysql comparison with "group by" clause

2005-10-12 Thread Greg Stark
Stephan Szabo <[EMAIL PROTECTED]> writes: > On Tue, 11 Oct 2005, Rick Schumeyer wrote: > > > I'm not sure what I was thinking, but I tried the following query in pg: > > > > SELECT * FROM t GROUP BY state; > > > > pg returns an error. > > > > Mysql, OTOH, returns the first row for each state. (T

Re: [SQL] MOVE in SQL vs PLPGSQL

2005-10-06 Thread Greg Stark
Tom Lane <[EMAIL PROTECTED]> writes: > Richard Huxton writes: > > Ah, now I see what you're saying. You're quite right in your suspicions, > > "MOVE..." isn't supported for plpgsql cursors. You could probably do > > something with EXECUTE and returning a refcursor from a previous > > function,

Re: [SQL] uuid type (moved from HACKERS)

2005-09-07 Thread Greg Stark
Josh Berkus writes: > Mark, Nathan, > > I'm moving this over to the PGSQL-SQL list, away from -hackers, as it's no > longer a -hackers type discussion. Hope you don't mind! > > > On Wed, Sep 07, 2005 at 11:31:16AM -0700, Josh Berkus wrote: > > > I'm also a little baffled to come up with any

Re: [SQL] PL/SQL Function: self-contained transaction?

2005-08-22 Thread Greg Stark
"Marc G. Fournier" <[EMAIL PROTECTED]> writes: > In PostgreSQL, as everyone knows, a QUERY == a transaction, unless wrap'd in a > BEGIN/END explicitly ... how does that work with a function? is there an > implicit BEGIN/END around the whole transaction, or each QUERY within the > function itself

Re: [SQL] ARRAYs and INDEXes ...

2005-08-16 Thread Greg Stark
"Marc G. Fournier" <[EMAIL PROTECTED]> writes: > SELECT * FROM customers WHERE monthly_balance[6] = 0.00; This, like the other poster said, can be accomplished with a set of simple expression indexes. > As an example ... or > > SELECT * FROM customers WHERE 0.00 = any (monthly_balance); This w

Re: [SQL] SELECT * FROM foo OFFSET -1 LIMIT 1

2005-06-27 Thread Greg Stark
Markus Bertheau <[EMAIL PROTECTED]> writes: > Offset for negative numbers means 0, as it seems. I think there is a > sensible meaning for negative offset numbers and wondered, what > arguments led to negative offsets being processed as 0 offset. Frankly I'm surprised it's not a syntax error. --

Re: [SQL] interesting SQL puzzle - concatenating column with itself.

2005-05-12 Thread Greg Stark
Nick Fankhauser <[EMAIL PROTECTED]> writes: > Alvaro Herrera wrote: > > > The order is not really guaranteed, though if this is a one-shot thing, > > you may get away with turning off hashed aggregates. > > > > When I read this, I assumed there was a runtime parameter I could set that was > sim

Re: [SQL] row-attribute in EXPLAIN-output doesn't match count(*)

2005-04-14 Thread Greg Stark
Tom Lane <[EMAIL PROTECTED]> writes: > We have to start the transaction no later than event #2 since there has > to be something to hold the lock. But it'd be easy enough to decouple > this from BEGIN, and it'd be good enough to solve the "COMMIT;BEGIN" > problem. Oh I think I finally figured ou

Re: [SQL] row-attribute in EXPLAIN-output doesn't match count(*)

2005-04-14 Thread Greg Stark
Andrew Sullivan <[EMAIL PROTECTED]> writes: > On Thu, Apr 14, 2005 at 07:21:38PM +0200, Andreas Joseph Krogh wrote: > > > > So, what you're suggesting is that a restart of the webapp should make > > vacuum > > able to delete those dead rows? > > Yes, but that'll only solve your problem for now

Re: [SQL] ignore single character in SELECT query?

2005-04-12 Thread Greg Stark
[EMAIL PROTECTED] writes: > So basically I want to ignore a single character (the apostrophe > character), anywhere in the middle of my search word, in selecting > results. How can I do this? WHERE replace(name,,'') like '%dont%' Beware of quoting issues if "dont" is coming from user suppl

Re: [SQL] Date/Time Conversion

2005-04-03 Thread Greg Stark
James G Wilkinson <[EMAIL PROTECTED]> writes: > I hope that this is some silly beginner's mistake. I have spent quite a bit > of > time > reading the PostgreSQL documentation and cannot find my error. I have also > scanned the PostgreSQL archive and the web for help, but I have not found > anyt

Re: [SQL] can you change an FK constraint from NOT DEFERRABLE to DEFERRABLE

2005-03-30 Thread Greg Stark
Bruno Wolff III <[EMAIL PROTECTED]> writes: > It does look like you can only ADD and DROP constraints, not directly > alter or replace them. So making a reference deferable is go to require > a DROP and ADD which will need to recheck the constraint. I asked the same question a few days ago on pgs

Re: [SQL] Consecutive row count query

2005-03-17 Thread Greg Stark
Leon Stringer <[EMAIL PROTECTED]> writes: > Hi, > > I wondered if anyone could answer the following question: > > If I have a table such as the one below: > > col1 col_order > --- > Apple 1 > Apple 2 > Orange 3 > Banana 4 > Apple 5 > > Is there a way I can get the following result

Re: [SQL] order by question

2005-03-09 Thread Greg Stark
Gary Stainburn <[EMAIL PROTECTED]> writes: > > Alternatively: (a<>6),(a<>4),a > > Although this does exactly what I want, at first glance it should do > exactly the opposite. > > I'm guessing that for each line it evaluates > not (a=6) 0 for true else 1 Not really, "not a=6" is an expression t

Re: [SQL] same question little different test MSSQL vrs Postgres

2005-01-26 Thread Greg Stark
"Joel Fradkin" <[EMAIL PROTECTED]> writes: > I tried the SET ENABLE_SEQSCAN=FALSE; > And the result took 29 secs instead of 117. > > After playing around with the cache and buffers etc I see I am no longer > doing any swapping (not sure how I got the 100 sec response might have been > shared buff

Re: [SQL] same question little different test MSSQL vrs Postgres

2005-01-26 Thread Greg Stark
"Joel Fradkin" <[EMAIL PROTECTED]> writes: > QUERY PLAN > "Seq Scan on tblcase (cost=0.00..30066.21 rows=37401 width=996) (actual > time=0.344..962.260 rows=22636 loops=1)" > " Filter: ((clientnum)::text = 'SAKS'::text)" > "Total runtime: 1034.434 ms" Well that says it only took 1s. So it seems

Re: [SQL] same question little different test MSSQL vrs Postgres

2005-01-25 Thread Greg Stark
"Joel Fradkin" <[EMAIL PROTECTED]> writes: > I also tried a simple select * from tblcase where clientum = 'SAKS' Try: explain analyze select * from tblcase where clientum = 'SAKS' Send the output. -- greg ---(end of broadcast)--- TIP 4: Don't

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

2005-01-25 Thread Greg Stark
Alex Turner <[EMAIL PROTECTED]> writes: > I am also very interesting in this very question.. Is there any way to > declare a persistant cursor that remains open between pg sessions? > This would be better than a temp table because you would not have to > do the initial select and insert into a f

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

2005-01-20 Thread Greg Stark
"Andrei Bintintan" <[EMAIL PROTECTED]> writes: > > If you're using this to provide "pages" of results, could you use a cursor? > What do you mean by that? Cursor? > > Yes I'm using this to provide "pages", but If I jump to the last pages it goes > very slow. The best way to do pages for is not t

Re: [SQL] Column with recycled sequence value

2005-01-13 Thread Greg Stark
Andrew Sullivan <[EMAIL PROTECTED]> writes: > You can set the sequence up to cycle (so once it gets to the end, it > wraps around to the beginning again). The keyword is CYCLE at CREATE > SEQUENCE time. It defaults to NO CYCLE. > > One potential problem, of course, are collisions on the table,

Re: [SQL] replacing mysql enum

2004-12-11 Thread Greg Stark
Ian Barwick <[EMAIL PROTECTED]> writes: > What I still don't quite understand is why IN in a CHECK context is > handled differently to say: select 1 where 'x' in (null,'a','b','c') ? > This could be a bit of a gotcha for anyone constructing a constraint > similar to the original poster's and not

Re: [SQL] Making dirty reads possible?

2004-12-06 Thread Greg Stark
[EMAIL PROTECTED] writes: > But not possible for real at the moment? > > So, summarising: > - Nested transactions is not (yet) supported > - READ UNCOMMITTED isolation level is not (yet) supported > - the EXECUTE plpgsql construct does not circumvent the transaction Well nested transactions are

Re: [SQL] Comparing Dates

2004-11-18 Thread Greg Stark
"Thomas F.O'Connell" <[EMAIL PROTECTED]> writes: > select 2004-06-08; > ?column? > -- > 1990 > > I'm not exactly sure how the bare string is converted internally, but it's > clearly not a complete date like you're expecting. What string? That's just integer arithmetic. -- greg

Re: [SQL] Simple SQL Question

2004-11-06 Thread Greg Stark
Tomasz Myrta <[EMAIL PROTECTED]> writes: > > select * from table1 LIMIT x > > gives me the first x row of the result. > > After that, I save the last value, and next time, I adjust > > the query as > > select * from table1 where itemkey>:lastvalue LIMIT x > > Why do you complicate it so much? Ev

Re: [SQL] vacuum analyze slows sql query

2004-11-03 Thread Greg Stark
patrick ~ <[EMAIL PROTECTED]> writes: > I noticed that a freshly created db with freshly inserted data (from > a previous pg_dump) would result in quite fast results. However, > after running 'vacuum analyze' the very same query slowed down about > 1250x (Time: 1080688.921 ms vs Time: 864.522 ms

Re: [SQL] Cross tabulations

2004-10-19 Thread Greg Stark
"Muhyiddin A.M Hayat" <[EMAIL PROTECTED]> writes: > Dear all, > > I need to do something similar to a cross tabulation, but without any > aggregation. join your table to itself four times: select * from (select check_time::date as date, employee_id, check_time-check_time::date as in from te

Re: [SQL] Inserting into table only if the row does not already

2004-10-16 Thread Greg Stark
"C. Bensend" <[EMAIL PROTECTED]> writes: > The risk of a cron gone wild is acceptable to me at this moment. Gee, now I have images of late-night advertisements for bofh-porn video tapes of Cron Jobs Gone Wild(tm) dancing through my head... thanks. -- greg ---(end of b

Re: [SQL] Inserting into table only if the row does not already exist.

2004-10-14 Thread Greg Stark
"C. Bensend" <[EMAIL PROTECTED]> writes: > INSERT INTO table ( column1, column2, column3 ) >SELECT column1, column2, column3 >WHERE NOT EXISTS ( > SELECT column1, column2, column3 FROM table WHERE > column1 = $column1 AND > column2 = $column2 AND > column3

Re: [SQL] help on a query

2004-10-08 Thread Greg Stark
Michelle Murrain <[EMAIL PROTECTED]> writes: > The OUTER JOIN version is quite a bit more efficient (by an order of magnitude) > than the option with WHERE NOT EXISTS subquery. This is going to be heavily dependent on the version of postgres. IN/NOT IN execution has improved a lot in 7.4 and lat

Re: [SQL] [GENERAL] need ``row number``

2004-09-24 Thread Greg Stark
Tom Lane <[EMAIL PROTECTED]> writes: > Karsten Hilbert <[EMAIL PROTECTED]> writes: > > I am not convinced I'll need a SRF. I am not trying to > > calculate something that isn't there yet. I am just trying to > > join two views appropriately. I might have to employ some > > variant of Celko's integ

Re: [SQL] JOIN performance

2004-09-21 Thread Greg Stark
Tom Lane <[EMAIL PROTECTED]> writes: > Fixing this properly is a research project, and I haven't thought of any > quick-and-dirty hacks that aren't too ugly to consider :-( Just thinking out loud here. Instead of trying to peek inside the CASE couldn't the optimizer just wrap the non-strict expr

Re: [SQL] COUNT(*) to find records which have a certain number of dependencies ?

2004-09-20 Thread Greg Stark
T E Schmitz <[EMAIL PROTECTED]> writes: > ) as somealias on (model_fk = model_pk) > > (subquery in FROM must have an alias) ARGH! This is one of the most annoying things about postgres! It bites me all the time. Obviously it's totally insignificant since it's easy for my to just throw an "AS x"

Re: [SQL] COUNT(*) to find records which have a certain number of

2004-09-20 Thread Greg Stark
T E Schmitz <[EMAIL PROTECTED]> writes: > SELECT > BRAND_NAME,MODEL_NAME ... > intersect ... Huh, I never think of the set operation solutions. I'm curious how it compares speed-wise. -- greg ---(end of broadcast)--- TIP 5: Have you checked our

Re: [SQL] COUNT(*) to find records which have a certain number of dependencies ?

2004-09-20 Thread Greg Stark
T E Schmitz <[EMAIL PROTECTED]> writes: > I want to select only those BRAND/MODEL combinations, where the MODEL has more > than one TYPE, but only where one of those has TYPE_NAME='xyz'. > I am not interested in MODELs with multiple TYPEs where none of them are called > 'xyz'. There are lots of

Re: [SQL] ORDER BY and NULLs

2004-09-19 Thread Greg Stark
Tom Lane <[EMAIL PROTECTED]> writes: > > The paragraph continues: > > "If the SELECT command included the clause WHERE phone NOT NULL, > > PostgreSQL could use the index to satisfy the ORDER BY clause. > > An index that covers optional (NOT NULL) columns will not be used to > > speed table join

Re: [SQL] ORDER BY and NULLs

2004-09-19 Thread Greg Stark
T E Schmitz <[EMAIL PROTECTED]> writes: > I just dug out the PostgreSQL book again because I thought I might've garbled > it: > > Quote: "PostgreSQL will not index NULL values. Because an index will never > include NULL values, it cannot be used to satisfy the ORDER BY clause of a > query that r

Re: [SQL] 1-byte integers

2004-09-18 Thread Greg Stark
stig erikson <[EMAIL PROTECTED]> writes: > how can i specify an integer to be one byte byte or even 4 bits long? > int1, int(1), tinyint are nowhere to be seen. > smallest i can find is smallint that is 2 bytes. There's a type called "char" (the double quotes are needed). It's used by postgres s

Re: [SQL] implementing an out-of-transaction trigger

2004-09-15 Thread Greg Stark
"Iain" <[EMAIL PROTECTED]> writes: > Though, as far as I can tell, there is no way to have the notify activate a > pl/pgsql function directly. I'll still need to write a client program to > create a session and actually do the listening, that is if I havn't missed > anything else... Right, presu

Re: [SQL] Isnumeric function?

2004-09-10 Thread Greg Stark
Tom Lane <[EMAIL PROTECTED]> writes: > Greg Stark <[EMAIL PROTECTED]> writes: > > That's all well and good. But when I tried to make a version of your > > situation that used a function I found it doesn't work so well with > > functional indexes:

Re: [SQL] Isnumeric function?

2004-09-10 Thread Greg Stark
Greg Stark <[EMAIL PROTECTED]> writes: > Theo Galanakis <[EMAIL PROTECTED]> writes: > > > I created the Index you specified, however it chooses to run a seq scan on > > the column rather than a Index scan. How can you force it to use that > > Index.. > >

Re: [SQL] Isnumeric function?

2004-09-09 Thread Greg Stark
Theo Galanakis <[EMAIL PROTECTED]> writes: > I created the Index you specified, however it chooses to run a seq scan on > the column rather than a Index scan. How can you force it to use that > Index.. > > CREATE INDEX idx_content_numeric ON botched_table(content) WHERE content ~ > '^[0-9]{1,9}$

Re: [SQL] Isnumeric function?

2004-09-08 Thread Greg Stark
Theo Galanakis <[EMAIL PROTECTED]> writes: > error: btree item size 2744 exceeds maximum 2713. > > I assume I had to change some server settings to extend the maximum, however I would guess the block size. But I'm just guessing. > in the end this column holds content, and even applying a

Re: [SQL] Aggregate query for multiple records

2004-08-28 Thread Greg Stark
Scott Gerhardt <[EMAIL PROTECTED]> writes: > Hello, I am new to the list, my apology if this question is beyond the scope or > charter of this list. > > My questions is: > What is the best method to perform an aggregate query to calculate sum() values > for each distinct wid as in the example be

Re: [SQL] from PG_DUMP to CVS

2004-08-26 Thread Greg Stark
"Riccardo G. Facchini" <[EMAIL PROTECTED]> writes: > After searching throught the list, I assume you mean this link: > http://www.rbt.ca/autodoc/index.html > by Rod Taylor. > > Looks promising, but still what I need is a proper CVS output, as I > need to review the changes made to the specific da

Re: [SQL] only last records in subgroups

2004-08-22 Thread Greg Stark
Dino Vliet <[EMAIL PROTECTED]> writes: > x,0 and y,4 but how do I manage this in sql? I was > hoping for a keyword LAST or so, where I can specify > that when I've ordered my results with order by, I > could only get the last of the subgroups (the first > one is easy because I could use limit 1)

Re: [SQL] sleep function

2004-08-22 Thread Greg Stark
John DeSoi <[EMAIL PROTECTED]> writes: > On Aug 10, 2004, at 10:57 AM, Bruce Momjian wrote: > > > I can't think of one, no. I think you will have to use one of the > > server-side languages and call a sleep in there. > > This is no good in the real world since it pounds the CPU, but it worked

Re: [SQL] reply to setting

2004-08-22 Thread Greg Stark
Joe Conway <[EMAIL PROTECTED]> writes: > This is very true. In fact, I get mildly annoyed when people *don't* include > the direct reply to me, because I very actively filter/redirect my mail. > Replies directly to me are pretty much guaranteed to be seen quickly, but the > ones that go to the li

Re: [SQL] How to create an aggregate?

2004-08-01 Thread Greg Stark
Ray Aspeitia <[EMAIL PROTECTED]> writes: > I also would like to pass the delimiter to the aggregate as a parameter and > I am not sure if it can handle that. Currently aggregates that take multiple parameters are just not supported. -- greg ---(end of broadcast)--

Re: FW: [SQL] "=" operator vs. "IS"

2004-06-29 Thread Greg Stark
Stephan Szabo <[EMAIL PROTECTED]> writes: > IS TRUE and IS FALSE have a different effect from =true and =false when > the left hand side is NULL. The former will return false, the latter will > return NULL. No, actually they both return false. (But thanks, I didn't even realize they were specia

Re: FW: [SQL] "=" operator vs. "IS"

2004-06-29 Thread Greg Stark
Rich Hall <[EMAIL PROTECTED]> writes: > "(anything) = NULL" is always Null, this cannot be what the coder intended. I often have such things in my SQL. Consider what happens when you have SQL constructed dynamically. Or more frequently, consider that many drivers still don't use the new binary pl

Re: [SQL] Empty array IS NULL?

2004-06-28 Thread Greg Stark
Markus Bertheau <[EMAIL PROTECTED]> writes: > oocms=# SELECT ARRAY(SELECT 1 WHERE FALSE); > ?column? > -- > This one seems strange to me. Shouldn't it result in an empty array? -- greg ---(end of broadcast)--- TIP 9: the planner wi

Re: [SQL] Selecting "sample" data from large tables.

2004-06-03 Thread Greg Stark
> Joseph Turner <[EMAIL PROTECTED]> writes: > > I have a table with a decent number of rows (let's say for example a > > billion rows). I am trying to construct a graph that displays the > > distribution of that data. However, I don't want to read in the > > complete data set (as reading a billi

Re: [SQL] Multiple outer join on same table

2004-05-13 Thread Greg Stark
Marco Lazzeri <[EMAIL PROTECTED]> writes: > Hi! > I'm searching a better (quicker) way to retrieve data as I used to do > using the following query... > > == > > SELECT main.codice, >other.value AS value_one, >other.value AS value_two > FROM main > LEFT OUTER JOIN other

Re: [SQL] isolation level

2004-05-13 Thread Greg Stark
Bruno Wolff III <[EMAIL PROTECTED]> writes: > On Thu, May 13, 2004 at 18:13:23 +, > Jaime Casanova <[EMAIL PROTECTED]> wrote: > > Hi all, is there a way to set the isolation level to something like the > > sql standard dirty read. > > No. There will be a way to use the standard name in a

Re: [SQL] Concatenate results of a single column query

2004-04-19 Thread Greg Stark
Christoph Haller <[EMAIL PROTECTED]> writes: > Interesting feature, but I cannot find function array_append: > ERROR: AggregateCreate: function array_append(integer[], integer) does not exist It's new in Postgres 7.4 I think you could do this in 7.3 though, it would just be more awkward. Try |

Re: [SQL] Concatenate results of a single column query

2004-04-18 Thread Greg Stark
Marco Lazzeri <[EMAIL PROTECTED]> writes: > SELECT > p.name, ARRAY(SELECT nicknames FROM people WHERE people.id = p.id) > FROM people AS p > Any suggestions? Something like: db=> create aggregate array_aggregate (basetype = integer, sfunc = array_append, stype = integer[], initcond = '{}');

Re: [SQL] trigger/for key help

2004-04-13 Thread Greg Stark
Tom Lane <[EMAIL PROTECTED]> writes: > Greg Stark <[EMAIL PROTECTED]> writes: > > Is there a reason postgres goes out of its way to pick names that > > will be harder to work with than necessary? > > If we use ordinary identifiers for system-generated names the

Re: [SQL] trigger/for key help

2004-04-12 Thread Greg Stark
Tom Lane <[EMAIL PROTECTED]> writes: > Bret Hughes <[EMAIL PROTECTED]> writes: > > FWIW I tried to use alter table but could never get the parser to accept > > $1 as a constraint name. I used single and double quotes as well as a > > lame attempt \$1. > > Hm, "$1" works for me ... Hm, this rem

Re: [SQL] SQL challenge--top 10 for each key value?

2004-04-10 Thread Greg Stark
elein <[EMAIL PROTECTED]> writes: > create or replace function pycounter(integer) > returns integer as > ' >if args[0] == 0: > SD["nextno"] = 1 > return SD["nextno"] >try: > SD["nextno"] += 1 >except: > SD["nextno"] = 1 >return SD["nextno"] > ' language 'pl

Re: [SQL] SQL challenge--top 10 for each key value?

2004-04-09 Thread Greg Stark
Josh Berkus <[EMAIL PROTECTED]> writes: > Rod, > > > Something along the lines of the below would accomplish what you want > > according to spec. ROW_NUMBER() is a spec defined function. (6.10 of > > SQL200N) > > Great leaping little gods! They added something called "row number" to the > spe

Re: [SQL] SQL challenge--top 10 for each key value?

2004-04-08 Thread Greg Stark
Jeff Boes <[EMAIL PROTECTED]> writes: > I headed off in the direction of groups of SELECTs and UNIONs, and quit when I > got to something like four levels of "SELECT ... AS FOO" ... four? wimp, that's nothing! ok, seriously I think there's no way to do this directly with straight SQL. You would

Re: [SQL] Slow sub-selects, max and count(*)

2004-03-27 Thread Greg Stark
Josh Berkus <[EMAIL PROTECTED]> writes: > Max() and Count() cannot use indexes for technical reasons. Browse through > the archives of SQL, PERFORM, and HACKERS for about 12,000 discussions on the > subject. Please don't confuse the issue by throwing Max() and Count() into the same basket.

Re: [SQL] Index not used - now me

2004-02-09 Thread Greg Stark
Christoph Haller <[EMAIL PROTECTED]> writes: > Why appear? If the Index Scan has a Total runtime: 2.46 msec and the Seq Scan > a Total runtime: 46.19 msec, then the Index Scan is much faster. > Or am I completely off the track reading the explain analyze output? To estimate the relative costs

Re: [SQL] limit 1 and functional indexes: SOLVED

2004-01-30 Thread Greg Stark
"Alexandra Birch" <[EMAIL PROTECTED]> writes: > It works perfectly - thanks a million! > Strangely the offset 0 does not seem to make any difference. > Gotta read up more about subqueries :) > > explain analyze > select code,order_date >from ( > select code, order_date >

Re: [SQL] limit 1 and functional indexes

2004-01-29 Thread Greg Stark
Bruno Wolff III <[EMAIL PROTECTED]> writes: > >QUERY PLAN > > > > Sort (cost=11824.16..11831.5

Re: [SQL] How can I get the last element out of GROUP BY sets?

2004-01-22 Thread Greg Stark
Tom Lane <[EMAIL PROTECTED]> writes: > Robert Creager <[EMAIL PROTECTED]> writes: > > ... one piece of data I need is the last value for each GROUP BY > > period. Alas, I cannot figure out how to do this. > > SELECT DISTINCT ON (rather than GROUP BY) could get this done for you. Or if you need

Re: [SQL] Index not recognized

2003-12-06 Thread Greg Stark
"Grace C. Unson" <[EMAIL PROTECTED]> writes: > Why is it that my index for text[] data type is not recognized by the > Planner? > > I did these steps: > > 1. create function textarr(text[]) returns text language sql as 'select > $1[1]' strict immutable > 2. create index org_idx on EmpData (text

Re: [SQL] OFFSET and subselects

2003-11-28 Thread Greg Stark
[EMAIL PROTECTED] (Dmitri Bichko) writes: > I am running in trouble with pagination here, somehow (rather naively) I > assumed that when doing a LIMIT and OFFSET, the subselects on the records > before the OFFSET would not be performed, which quite apparently is not the > case. So, LIMIT 50 OFFSE

Re: [SQL] Scaler forms as function arguments

2003-11-28 Thread Greg Stark
Joe Conway <[EMAIL PROTECTED]> writes: > In 7.4 you could use an array. It would look like this: Though note that 7.4 doesn't know how to optimize this form: db=> explain select * from foo where foo_id in (1,2); QUERY PLAN

Re: [SQL] Expressional Indexes

2003-11-21 Thread Greg Stark
Tom Lane <[EMAIL PROTECTED]> writes: > No, because the above represents a moving cutoff; it will (and should) > be rejected as a non-immutable predicate condition. You could do > something like > > CREATE INDEX my_Nov_03_index on my_table (create_date) > WHERE (cre

Re: [SQL] Expressional Indexes

2003-11-18 Thread Greg Stark
"Randolf Richardson, DevNet SysOp 29" <[EMAIL PROTECTED]> writes: > For example, if I want to index on a date field but only have the index > keep track of the most recent 30 days (and then create a secondary index for > all dates) so as to improve performance on more heavily loaded syste

Re: [SQL] Programatically switching database

2003-11-16 Thread Greg Stark
ow <[EMAIL PROTECTED]> writes: > My concern though ... wouldn't pgSql server collapse when faced with > transaction spawning across 100M+ records? The number of records involved really doesn't faze Postgres at all. However the amount of time spent in the transaction could be an issue if there is

  1   2   >