Re: [SQL] Advice for index design

2013-04-11 Thread Greg Sabino Mullane
st create separate indexes and you will be fine, especially given the very small size of the table. If you find your queries going slow, you could start investigating compound indexes (or in this case, partial indexes). - -- Greg Sabino Mullane g...@turnstep.com End Point Corporation http://www.end

Re: [SQL] How can this INSERT fail?

2012-04-25 Thread Greg Sabino Mullane
of Postgres and the latter does carry a potential performance penalty). - -- Greg Sabino Mullane g...@turnstep.com PGP Key: 0x14964AC8 201204251322 http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8 -BEGIN PGP SIGNATURE- iEYEAREDAAYFAk+YM6IACgkQv

Re: [SQL] compare table names

2012-01-09 Thread Greg Sabino Mullane
d be 'less' than 0102 because it's January, etc. Assuming you change it to MMDD, you could run a simple query like this: SELECT tablename FROM pg_tables WHERE tablename ~ '^tmp_staging' AND substring(tablename from '\d+')::date < now() - '10 days&#x

Re: [SQL] 9.0+ way of determining if a LISTEN channel has a backend listening?

2011-06-01 Thread Greg Sabino Mullane
possibly use advisory locks if you really need to know what another session is listening to. - -- Greg Sabino Mullane g...@turnstep.com End Point Corporation http://www.endpoint.com/ PGP Key: 0x14964AC8 201106011822 http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8 -

[SQL] with queries

2010-09-15 Thread Greg Quinn
Forget my previous post. I am stupid. It doesn't work with 8.3.7, sorry to trouble you. -- Greg Quinn Australian Phenomics Facility greg.qu...@anu.edu.au (02) 61259407 -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription:

[SQL] with queries

2010-09-15 Thread Greg Quinn
M... ^ test=# Tried this with 8.4 and 9.0rc1, same result. Any help (even to tell me that I'm an idiot!) would be much appreciated. In the meantime my query will revert to Plan A, but it would be so much neater using a 'with'. -- Greg Quinn Australian Phenomics Facility

[SQL] sql disaster - subquery error but delete continues

2010-09-10 Thread Greg Caulton
form_record_details table please tell me this is fixed since 8.3 Greg

Re: [SQL] Does IMMUTABLE property propagate?

2010-03-25 Thread Greg Stark
#x27;m confused, I thought it was volatile and strict that prevented inlining. -- greg -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql

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
1 row) postgres=# select i from (select i, dense_rank() over (order by i desc) as r from i) as x where r = 2; i 99 (1 row) -- greg -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql

Re: [SQL] Odd sort behaviour

2009-09-01 Thread Greg Stark
a.it aeo...@hotmail.com a.fisched...@t-online.de aflores3...@gmail.com afr...@advancedneurosurgeons.com agave...@comcast.net agelsin...@amirsys.com agis1...@yahoo.gr -- greg http://mit.edu/~gsstark/resume.pdf -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make c

Re: [SQL] mysql code questions

2009-08-12 Thread Greg Stark
sed solution. It also supports an extension which could be even more efficient than all of them: select DISTINCT ON (id) from tt order by id,create_date desc If you have an index on (Or if you have an index on and use "order by id desc, create_date desc" in the query) then this

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

2009-07-07 Thread Greg Stark
weren't already having a problem with that in <8.2.11 then perhaps you would be ok. -- greg http://mit.edu/~gsstark/resume.pdf -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql

Re: [SQL] Best way to simulate Booleans

2009-07-07 Thread Greg Stark
postgres and making a "boolean" domain in Oracle for char(1) and then write all sql to compare with = 'f' and = 't'. It's annoying you can't use "WHERE foo_flag" and have to write "WHERE foo_flag = 't'" but otherwise that would give

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

2009-07-02 Thread Greg Stark
3 - because L3 is higher than L2 and ratio of L3 : L2 isĀ 2 : 1 Are you just looking for the most frequent seg for each customer? select distinct on (customer) customer,seg from (select customer, seg, count(*) as n from tab group by seg) order by customer, n desc That doesn't give th

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

2009-06-12 Thread Greg Stark
t the postgres shared buffers and worse, it does affect other buffers that probably would still be cached. The best answer is usually to build a test configuration large enough that it has similar cache effects as your production environment. Then test random values and repeat the test many time

Re: [SQL] Performance problem with row count trigger

2009-04-06 Thread Greg Sabino Mullane
ng the temporary hash we build up - I think the version I emailed neglected to do that. Wouldn't want those numbers to stick around in the session. - -- Greg Sabino Mullane g...@turnstep.com End Point Corporation PGP Key: 0x14964AC8 200904061028 http://big

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

2009-04-05 Thread Greg Sabino Mullane
ECT ..." | perl -pe 's/^\n// if $.<2' This strips a newline from the first line only of the output, and only if the line consists of nothing else. Highly recommended for cron. - -- Greg Sabino Mullane g...@turnstep.com End Point Corporation PGP Key: 0x14964AC8 20090

Re: [SQL] Performance problem with row count trigger

2009-04-02 Thread Greg Sabino Mullane
ENABLE TRIGGER update_assoc_count_insert"); ## x3 etc. spi_exec_query("ALTER TABLE assoc DISABLE TRIGGER update_assoc_count_perl"); -- Put FK magic here return 'Bulk load complete'; $_$; - -- Usage: SELECT start_bulkload_assoc_count(); - -- Lots of inserts a

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 try

Re: [SQL] GROUP BY on a column which might exist in one of two tables

2008-06-25 Thread Greg Sabino Mullane
COUNT(hit_id) AS total_hits FROM ( SELECT partner_id, hit_id, NULL AS view_id FROM hits UNION ALL SELECT partner_id, NULL, view_id FROM views ) AS foo GROUP BY 1; - -- Greg Sabino Mullane [EMAIL PROTECTED] End Point Corporation PGP Key: 0x14964AC8 200806251019 http://biglum

Re: [SQL] Select into

2008-03-20 Thread Greg Sabino Mullane
= 456; INSERT INTO foo SELECT * FROM tempfoo; COMMIT; - -- Greg Sabino Mullane [EMAIL PROTECTED] End Point Corporation PGP Key: 0x14964AC8 200803200737 http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8 -BEGIN PGP SIG

Re: [SQL] Funny date-sorting task

2007-05-13 Thread Greg Sabino Mullane
: SELECT * FROM yourtable ORDER BY CASE WHEN X::date = now()::date THEN 1 WHEN X::date < now()::date THEN 2 WHEN X IS NULL THEN 3 ELSE4 END, CASE WHEN X::date-now()::date < 0 THEN now()-X ELSE X-now() END; - -- G

Re: [SQL] Maintence DB

2007-03-13 Thread Greg Toombs
(From the pgadmin documentation) "The maintenance DB field is used to specify the initial database that pgAdmin connects to, and that will be expected to have the pgAgent schema and adminpack objects installed (both optional). On PostgreSQL 8.1 and above, the maintenance DB is normally called '

Re: [SQL] A form of inheritance with PostgreSQL

2007-03-12 Thread Greg Toombs
warning. Anyway, thanks for the heads-up. Alvaro Herrera wrote: Greg Toombs wrote: What disaster do you foresee? Is that version unstable? Yes. There are known, unfixed bugs, and architectural problems that cannot be fixed.

Re: [SQL] A form of inheritance with PostgreSQL

2007-03-12 Thread Greg Toombs
What disaster do you foresee? Is that version unstable? Tom Lane wrote: Greg Toombs <[EMAIL PROTECTED]> writes: After reading a few more methods of doing things, I went with the simplest one, as 1. time is of the essence, and 2. I'm stuck with PostgreSQL 7.1 on the se

Re: [SQL] A form of inheritance with PostgreSQL

2007-03-12 Thread Greg Toombs
y key of the parent class to a serial. Children have an integer column with constraints as the primary key and foreign key to the parent primary key column. Thanks again, - Greg Steve Midgley wrote: Hi Greg, While not in a C++ framework, you might find that it's not too hard to implement

[SQL] A form of inheritance with PostgreSQL

2007-03-08 Thread Greg Toombs
h a trigger?) Any advice will be appreciated! As I'm relatively new to Postgre, I might need some help with the actual implementation as well. Thank you. - Greg

Re: [SQL] Seeking quick way to clone a row, but give it a new pk.

2007-02-08 Thread Greg Sabino Mullane
-BEGIN PGP SIGNED MESSAGE- Hash: RIPEMD160 > I need to create some nearly identical copies of rows in > a complicated table. > > Is there a handy syntax that would let me copy a existing row, > but get a new primary key for the copy? http://people.planetpostgresql.org

[SQL] Odd PL/PgSQL Error -- relation "X" does not exist when using index expression

2007-02-07 Thread Greg Wittel
g: => select init_testdata_a(1); works => select init_testdata_b(2); " PL/pgSQL function "init_testdata_b" line 13 at execute statement ERROR: relation "testdata_2" does not exist CONTEXT: SQL statement " ... Any thoughts? -Greg -

Re: [SQL] Repetitive code

2006-06-16 Thread Greg Stark
s to do a fair amount of work to eliminate duplicates. If you know the rows are going to be distinct or if you don't care about duplicates you can save a lot of time by using UNION ALL instead. -- greg ---(end of broadcast)--- TIP 9: In versions be

Re: [SQL] SELECT DISTINCT too slow

2006-06-01 Thread Greg Stark
of them. Also, incidentally, I don't see how a table of possible keys could help you here. Nothing forces they table MRTPContactValue to use all possible keys... -- greg ---(end of broadcast)--- TIP 4: Have you searched our list archives? http://archives.postgresql.org

Re: [SQL] Table design question

2006-06-01 Thread Greg Stark
corrupted by uppercasing, declared case insensitive, declared private information that couldn't be leaked, and declared offensive words that had to be updated. Each of which is a pain to deal with when it's your primary key. -- greg ---(end of broadcast)--- TIP 2: Don't 'kill -9' the postmaster

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

2006-03-06 Thread Greg Stark
refer. I don't think there's any plans to remove the option, it's just not the default any more. -- greg ---(end of broadcast)--- TIP 4: Have you searched our list archives? http://archives.postgresql.org

Re: [SQL] functions in WHERE clause

2006-03-05 Thread Greg Stark
t explicitly every time anyways. One day you'll need more flexibility or you'll have someone else reading the code and you'll be glad you're not hiding what's going on and hard coding column names inside some macro function anyways. -- greg ---(

Re: [SQL] Tough Problem -- Record Checkouts

2006-02-17 Thread Greg Stark
f the checkout? In any case the where clause isn't all that complex. I think you've confused yourself by drawing the inverse table of what you need. You need the range of CO to expire for a given N, not the range of N in which you should expire a given CO. WHERE co BETWEEN 0 AND

Re: [SQL] view of weekly data

2006-02-17 Thread Greg Stark
here date_trunc('week',time)=date_trunc('week',dailydata.time) order by time asc limit 1 ) as weeklyopen, (select close from dailydata as d where date_trunc('week',time)=date_trunc('week',d

Re: [SQL] two count columns?

2006-02-17 Thread Greg Stark
at ANALYZE results for the query and try raising work_mem for this query using SET until you see the plan using a hash aggregate. If it can use a hash aggregate for your query (more likely for the first query than the second) without swapping it'll be faster than sorting. -- greg

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

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

2005-12-28 Thread Greg Stark
same as "= ANY" so "1 IN (1,2,NULL)" is the same as "1=1 OR 1=2 OR 1=NULL" which is true even though the last of the three is null. -- greg ---(end of broadcast)--- TIP 6: explain analyze is your friend

Re: [SQL] Storing HTML in table

2005-11-27 Thread Greg Stark
me fixed list of predetermined columns. One the other side is the decidely non-relational model where you just store a large hunk of xml text. What you're looking for is one of the many systems that attempt to bridge these two extremes and provide the best of both worlds. -- gre

Re: [SQL] cli in sql?

2005-11-11 Thread Greg Sabino Mullane
$filename" does not exist\n}); return localtime($^T - (60*60*24* -M _)); $$; SELECT filemodtime('/var/log/messages'); SELECT filemodtime('/dark/matter'); -- Greg Sabino Mullane [EMAIL PROTECTED] PGP Key: 0x14964AC8 20051457 http://biglumber.com/x/web?pk=252

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

2005-10-14 Thread Greg Stark
be a wonderful feature for Postgres. -- greg ---(end of broadcast)--- TIP 9: In versions below 8.0, the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match

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

2005-10-13 Thread Greg Stark
ld be transformed into the equivalent join (or some more general join structure that can cover both sets of semantics) and then planned through the same code path. In an ideal world the user should be guaranteed that equivalent queries would always result in the same plan regardless of how they

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."

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 mis

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

2005-10-12 Thread Greg Stark
ubselects have their own problems here. Mainly Postgres's optimizer, as good as it is, doesn't treat them with the same code paths as joins and can't find all the same plans for them. But in any case you cannot always write a subselect that's equivalent to an arbitrary join. --

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

2005-10-12 Thread Greg Stark
interval '1 month' ELSE false END CASE AND ... There's no advantage to doing this kind of thing though. Good database design principles dictate having one column for each piece of data. Just leave the columns for which the data is inappropriate NULL. NULLs ta

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

2005-10-12 Thread Greg Stark
feature. MySQL treats "select a,b from t group by a" equivalently to Postgres's "select distinct on (a) a,b from t" I suppose "equivalent" isn't quite true. It's more general since it allows aggregate functions as well. The equivalently general Postgres syntax i

Re: [SQL] SEVEN cross joins?!?!?

2005-10-11 Thread Greg Patnude
Aha ! A gamer... playing with armor and hit points and things -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Frank Bax Sent: Tuesday, October 11, 2005 1:06 PM To: pgsql-sql@postgresql.org Subject: Re: [SQL] SEVEN cross joins?!?!? At 08:29 AM 10/1

Re: [SQL] MOVE in SQL vs PLPGSQL

2005-10-06 Thread Greg Stark
t switches involved in communicating those records, but there's no way it would let the server avoid reading all those records from disk. At least as far as I can see. -- greg ---(end of broadcast)--- TIP 6: explain analyze is your friend

Re: [SQL] Need help with `unique parents` constraint

2005-09-12 Thread Greg Sabino Mullane
add another column. But generally, this should be the exception and not the rule. - -- Greg Sabino Mullane [EMAIL PROTECTED] PGP Key: 0x14964AC8 200509122031 http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8 -BEGIN PGP SIGNATURE- iD8DBQFDJh99vJuQZxSWSsgRAiRFAJwKiGVsJhcbxI

Re: [SQL] Need help with 'unique parents' constraint

2005-09-11 Thread Greg Sabino Mullane
SET parent_fk = 4 WHERE child_fk = 3 AND parent_fk = 2; SELECT 'Add non-mother/father' AS "Test should pass"; INSERT INTO relations VALUES (3,5); SELECT 'Change non-mother/father to mother' AS "Test should fail"; UPDATE relations SET parent_fk = 2 WHER

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

2005-09-07 Thread Greg Stark
the data to be easily and freely accessible as > > specific objects, but I do not wish to provide an easy way of > > dumping all of the data as a unit. Of course you could have just done the same thing using an hmac (or a simple hash like crypt) and not had to store an extraneous meaningless piece of information in your database. -- greg ---(end of broadcast)--- TIP 6: explain analyze is your friend

Re: [SQL] How do I copy part of table from db1 to db2 (and rename the columns)?

2005-08-31 Thread Greg Sabino Mullane
easiest to pg_dump the whole database and then drop/rename columns in the new database. - -- Greg Sabino Mullane [EMAIL PROTECTED] PGP Key: 0x14964AC8 200508310915 https://www.biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8 -BEGIN PGP SIGNATURE- iEYEARECAAYFAkMVrhIACgkQvJuQ

Re: [SQL] Tidying values on variable instantiation

2005-08-26 Thread Greg Patnude
IMHO: It's not necessarily the job of the RDBMS to be responsible for formatting and cleaning of your data... This is a job better suited for the application layer and the data model... The RDBMS should only be responsible for enforcing constraints on the data... not validating or purifying the d

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

2005-08-22 Thread Greg Stark
would live outside of transactions and be able to create transactions, commit, and roll them back. But I don't think any of that work is committed yet. I'm not even sure it's been written yet. -- greg ---(end of broadcast)--- TIP 6: explain analyze is your friend

Re: [SQL] ARRAYs and INDEXes ...

2005-08-16 Thread Greg Stark
any (monthly_balance); This would require a GiST index. Look at the intarray contrib module. I don't think there's any equivalent for other data types. You might have to store these values as fixed precision numbers and divide or multiple by 100 to convert. -- greg --

Re: [SQL] ORDER records based on parameters in IN clause

2005-06-30 Thread Greg Sabino Mullane
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 > fair enough. but a simple order by id would never work. That was me, sorry, I must have been asleep when I wrote it. :) - -- Greg Sabino Mullane [EMAIL PROTECTED] PGP Key: 0x14964AC8 200506300636 http://biglumber.com/x/web

Re: [SQL] ORDER records based on parameters in IN clause

2005-06-28 Thread Greg Sabino Mullane
work, you will have to be more specific and send us the exact query. - -- Greg Sabino Mullane [EMAIL PROTECTED] PGP Key: 0x14964AC8 200506282010 http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8 -BEGIN PGP SIGNATURE- iD8DBQFCwedPvJuQZxSWSsgRAsC0AKD2UrMtQJ6RRxbeZ8J2n6

Re: [SQL] people who buy A, also buy C, D, E

2005-06-28 Thread Greg Sabino Mullane
the high number of combinations and large potential for change. > table ordered_products: order_id, product_id, quantity I'm not sure where you are getting "quantity" from: as near as I can tell, this will always be a quantity of 1: one person ordering one item.

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

2005-06-27 Thread Greg Stark
#x27;s not a syntax error. -- greg ---(end of broadcast)--- TIP 4: Don't 'kill -9' the postmaster

Re: [SQL] Grouping Too Closely

2005-06-24 Thread Greg Sabino Mullane
E seq2 > 2 GROUP BY fkey, seq2 ORDER BY 1,2,3; - -- Greg Sabino Mullane [EMAIL PROTECTED] PGP Key: 0x14964AC8 200506250237 http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8 -BEGIN PGP SIGNATURE- iD8DBQFCvPwJvJuQZxSWSsgRAtcHAKDzl67Va8ABP4qyNpvFtWDpjmT/iwCg3D5J k

Re: [SQL] Grouping Too Closely

2005-06-24 Thread Greg Sabino Mullane
, but would this do what you want?: SELECT fkey, uid, seq2, min(seq1) FROM my_table WHERE seq2 > 2 GROUP BY fkey, uid, seq2 ORDER BY 1,2,3; - -- Greg Sabino Mullane [EMAIL PROTECTED] PGP Key: 0x14964AC8 200506250019 http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8 --

Re: [SQL] people who buy A, also buy C, D, E

2005-06-24 Thread Greg Sabino Mullane
good practice for the 8.1.0 jump, right? :) Overall, I was able to get the query to go about a third faster than when I started. Hope this helps. - -- Greg Sabino Mullane [EMAIL PROTECTED] PGP Key: 0x14964AC8 200506242328 http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9

Re: [SQL] SELECT with sum on groups ORDERING by the subtotals

2005-06-16 Thread Greg Sabino Mullane
+-- 99120 | 338 92110 | 120 92190 | 41 If you do need the other rows, you will have to specify a way of ordering the rows within a code group. - -- Greg Sabino Mullane [EMAIL PROTECTED] PGP Key: 0x14964AC8 200506161458 http://biglumber.com/x/web?pk=2529DF6AB8F79407E944

Re: [SQL] getting details about integrity constraint violation

2005-06-14 Thread Greg Sabino Mullane
st: just come up with a standard naming scheme, such as: "tablename|colname|is_not_unique" which should be human and machine parseable (perl example): if ($error =~ m#^(.+)\|(.+)\|is_not_unique$#o) { die qq{Whoops : looks like column "$2" of table "$1" needs

Re: [SQL] getting details about integrity constraint violation

2005-06-13 Thread Greg Sabino Mullane
name the table constraints yourself with a descriptive name, so you always know exactly what is going on: greg=# create table unitest(a int, b text); CREATE TABLE greg=# alter table unitest add constraint "unitest_column_a_is_not_unique" unique(a); NOTICE: ALTER TABLE / ADD UNIQUE wi

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

2005-05-12 Thread Greg Stark
d by the GROUP BY column and avoids the extra sort which could cause you problems. So this is not guaranteed by the SQL spec to work (but then the SQL spec doesn't have custom aggregates at all) but Postgres goes out of its way to make sure this doesn't break unnecessarily. [This is

Re: [SQL] UPDATE WITH ORDER BY

2005-04-27 Thread Greg Sabino Mullane
x27;)::int AS newid, * FROM fruit ORDER BY lower(description); ALTER TABLE newfruit DROP COLUMN id; ALTER TABLE newfruit RENAME COLUMN newid TO id; DROP TABLE fruit; ALTER TABLE newfruit RENAME TO fruit; DROP SEQUENCE fruit_seq; COMMIT; SELECT * FROM fruit ORDER BY id ASC; - -- Greg Sabino Mulla

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

2005-04-14 Thread Greg Stark
a for READ COMMITTED mode, but I think I'm on the same general path as you. -- greg ---(end of broadcast)--- TIP 5: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faq

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

2005-04-14 Thread Greg Stark
participate in any transactional issues like keeping old versions of records around. -- greg ---(end of broadcast)--- TIP 8: explain analyze is your friend

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

2005-04-12 Thread Greg Stark
e of quoting issues if "dont" is coming from user supplied inputs. -- greg ---(end of broadcast)--- TIP 5: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faq

Re: [SQL] Date/Time Conversion

2005-04-03 Thread Greg Stark
tual time of the event, and a second column with the local time zone in which you can choose to use to display the time? -- greg ---(end of broadcast)--- TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]

Re: [SQL] New record position

2005-03-31 Thread Greg Patnude
There's a difference between "natural" order (the location in the database or on disk) and "record" order (the order specified by the primary key)... -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Chris Browne Sent: Wednesday, March 30, 2005 3:04 PM To

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

2005-03-30 Thread Greg Stark
change: update pg_constraint set condeferrable = 't' where contype = 'f' update pg_trigger set tgdeferrable=true where tgisconstraint = true I think an ALTER CONSTRAINT to change these settings as well as the ON {UPDATE,DELETE} behaviour would be neat. -- greg -

Re: [SQL] How do I do this?

2005-03-23 Thread Greg Sabino Mullane
27;),'/') FROM mytable; - -- Greg Sabino Mullane [EMAIL PROTECTED] PGP Key: 0x14964AC8 200503232033 http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8 -BEGIN PGP SIGNATURE- iD8DBQFCQhkMvJuQZxSWSsgRAjTaAJ9zmgSOBH/Nre/XMw+JajBni8YyDwCg1DyV Cd5rIhi026KFoFZEFjMOY

Re: [SQL] equivalent of oracle rank() in postgres

2005-03-21 Thread Greg Sabino Mullane
ct equivalent to rank(), but there are certainly other ways to get the results. The above query can be written in PostgreSQL as: SELECT employee_id, last_name, salary FROM employees WHERE salary = (SELECT DISTINCT salary FROM employees ORDER BY salary DESC OFFSET 2 LIMIT 1); - -- Greg Sabino Mul

Re: [SQL] best way to swap two records (computer details)

2005-03-18 Thread Greg Patnude
How about a user defined function ??? CREATE OR REPLACE FUNCTION harwareupdate(integer, integer) RETURNS BOOLEAN AS ' update pieces set p_name = \'LSALES1\', p_location = \'Mike Haley\', p_site = \'L\' where p_id = $1; update pieces set p_name = \'SPARE\', p_location = \'spare\', p_

Re: [SQL] Consecutive row count query

2005-03-17 Thread Greg Stark
l_count>1 to make it worthwhile. The only reason you might have a problem is if it's really "semantically wrong" which would be if there's data attached to Apple or Orange that might be different from one streak of results to the other. -- greg ---(end of broadcast)--- TIP 7: don't forget to increase your free space map settings

Re: [SQL] order by question

2005-03-09 Thread Greg Stark
you put "not a=6" in your select column list you'll see the true and false values appear. -- greg ---(end of broadcast)--- TIP 2: you can get off all lists at once with the unregister command (send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])

Re: [SQL] table constraints

2005-03-01 Thread Greg Patnude
foreign keys and primary keys have to be defined as unique at the table / column level if you want to implement a check constraint -- your contrived example doesn't stand up all that well -- If you want to use constraints -- then your database schema should conform to traditional RDBMS theory a

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

2005-02-15 Thread Greg Sabino Mullane
rt_time IS NULL THEN 0 ELSE 1 END, start_time - -- Greg Sabino Mullane [EMAIL PROTECTED] PGP Key: 0x14964AC8 200502152309 http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8 -BEGIN PGP SIGNATURE- iD8DBQFCEseYvJuQZxSWSsgRAlipAJwKAyqAyLbo9hfpoWkz0SOlTY3feACfa+ng DqNY4DAJ5T

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

2005-01-26 Thread Greg Stark
e. And b) lower random_page_cost. random_page_cost tells postgres how much slower indexes are than table scans and at the default setting it accurately represents most disk hardware. If your database fits within RAM and is often cached then you might have to lower it to mod

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

2005-01-26 Thread Greg Stark
Total runtime: 1034.434 ms" Well that says it only took 1s. So it seems this is highly dependent on whether the data is in cache. Perhaps it was in cache on MSSQL when you profiled it there and not on postgres? You could put an index on clientnum, but if the data is usually in cache like this it m

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 broa

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

2005-01-25 Thread Greg Stark
vantage if the data were stored in a temporary table marked as not having to be WAL logged. Instead it could be automatically cleared on every database start. -- greg ---(end of broadcast)--- TIP 6: Have you searched our list archiv

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

2005-01-25 Thread Spiegelberg, Greg
Isn't this a prime example of when to use a servlet or something similar in function? It will create the cursor, maintain it, and fetch against it for a particular page. Greg -Original Message- From: Richard Huxton [mailto:[EMAIL PROTECTED] Sent: Thursday, January 20, 2005 10:21

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

2005-01-20 Thread Greg Stark
ill always come to the same postgres session and has some garbage collection if the user disappears. And it means the URL is only good for a limited amount of time. If they bookmark it it'll break if they come back the next day.) -- greg ---(end of broadcast)---

Re: [SQL] Column with recycled sequence value

2005-01-13 Thread Greg Stark
terrupted without losing work. Oh, and this won't work if you have any external references to these values from outside your database. Say if the value is something like a customer account number that you've previously sent to customers... -- greg ---(end o

Re: [SQL] replacing mysql enum

2004-12-11 Thread Greg Stark
ting a constraint > similar to the original poster's and not realising it has no effect. well WHERE foo IN (null, ...) returns null if foo isn't explicitly in the list (ie, "it may or may not equal the unknown value in the list"). And I think constraints that retur

Re: [SQL] Making dirty reads possible?

2004-12-06 Thread Greg Stark
onnect to the database and do the batch jobs. They can output progress logs or keep information about their progress in some shared space. They can also control the transaction more freely committing in the middle of the job if it's safe. -- greg ---(end of broad

Re: [SQL] Comparing Dates

2004-11-18 Thread Greg Stark
e expecting. What string? That's just integer arithmetic. -- greg ---(end of broadcast)--- TIP 2: you can get off all lists at once with the unregister command (send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])

Re: [SQL] Simple SQL Question

2004-11-06 Thread Greg Stark
less of what page is being fetched. Yours will perform more and more slowly as the user gets deeper into the results. Note that both queries are wrong however. You need an "ORDER BY itemkey" or else nothing guarantees the second page has any relation at all to the first page. -- greg

Re: [SQL] vacuum analyze slows sql query

2004-11-03 Thread Greg Stark
;explain verbose" use "explain analyze". I don't know if it was in 7.1 but you say you reproduced the problem with 7.4. It would be helpful to see the results of "explain analyze select ..." on the query before and after the vacuum analyze. -- greg

Re: [SQL] 'show databases' in psql way?

2004-11-02 Thread Greg Sabino Mullane
tablespace FROM pg_catalog.pg_database JOIN pg_catalog.pg_tablespace t ON (dattablespace=t.oid) ORDER BY 1; - -- Greg Sabino Mullane [EMAIL PROTECTED] PGP Key: 0x14964AC8 200411022120 -BEGIN PGP SIGNATURE- iD8DBQFBiFTSvJuQZxSWSsgRApflAJ0RiVndbc6u//cXX/S7uM8K91lWbgCfYVbC

Re: [SQL] 'show databases' in psql way?

2004-11-01 Thread Greg Sabino Mullane
tgres: my @dbs = DBI->data_sources('Pg'); - -- Greg Sabino Mullane [EMAIL PROTECTED] PGP Key: 0x14964AC8 200411012240 -BEGIN PGP SIGNATURE- iD8DBQFBhwIHvJuQZxSWSsgRArd1AJ9hKXD+cSaM2L3RUXQdabuRofNFjwCfaHT0 +bRPuYhuED0mnlp1FRtvQQw= =tsqe -END PGP SIGNATURE

Re: [SQL] Cross tabulations

2004-10-19 Thread Greg Stark
g records and will give an error if there are multiple records instead of doing strange things. Neither of these will be particularly pretty on the performance front. -- greg ---(end of broadcast)--- TIP 7: don't forget to increase your free space map settings

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

  1   2   3   >