Re: [SQL] " in transaction" can't be killed with pg_cancel_backend(). Is it a bug?

2011-01-04 Thread Bryce Nesbitt
Michael Glaesemann wrote: On Jan 4, 2011, at 17:29, Bryce Nesbitt wrote: Should I expect pg_cancel_backend() to work in a case like this? If not does this sound like a reportable bug? pg_cancel_backend() cancels the running query for that backend. In the case of, there is no

[SQL] " in transaction" can't be killed with pg_cancel_backend(). Is it a bug?

2011-01-04 Thread Bryce Nesbitt
Dear helpful postgres people; I've got a database deadlock. The initiating process was " in transaction" with PID 2219. Use of pg_cancel_backend() returns true, but does not actually kill the process. When this happens I kill the PID at the Unix level, which feels sort of stupid, like drivi

[SQL] "slow lock" log in addition to log_min_duration_statement ?

2010-11-10 Thread Bryce Nesbitt
I have a cluster with log_min_duration_statement set to log slow queries. Presently what I'm tracking down is almost certainly a lock problem. Is there any analog of log_min_duration_statement for locks? If there is a lock on a certain critical tables for more than a few hundredths of a secon

[SQL] Sequential scan evaluating function for each row, seemingly needlessly

2010-09-07 Thread Bryce Nesbitt
On psql 8.3.9, I ran a limited query limited to 5 results. There was a moderately expensive function call which I expected to be called 5 times, but was apparently called for each row of the sequential scan. Why? preproduction=> explain analyze select url(context_key) from extractq order b

[SQL] Returning to default (e.g. blank) table permissions after a revoke?

2010-06-10 Thread Bryce Nesbitt
If I create a new table the "Access privileges" are blank, which gives implicit access to the table owner. But if I touch the grants, then revoke, the privileges are set to {} which is not the same thing: production=> create table zzz_junk1 (); production=> \z zzz_junk1 Schema | Name| Ty

[SQL] Remote monitoring of Postgres w/minimal grants

2010-03-09 Thread Bryce Nesbitt
I'm setting up remote monitoring of postgres, but running into an uncomfortable situation with permissions. Basically it seems hard to set up a secure "read only" role, yet also allow proper monitoring. A brief writeup of that is here: http://help.logicmonitor.com/installation-getting-started/n

Re: [SQL] Using || operator to fold multiple columns into one

2009-12-29 Thread Bryce Nesbitt
Craig Ringer wrote: On 24/12/2009 5:04 AM, Rosser Schwarz wrote: On Wed, Dec 23, 2009 at 1:44 AM, Craig Ringer wrote: Your invocation of COALESCE is incorrect -- it is n-ary, but it returns its first non-NULL argument. Yes. That was the point. I think we're assuming the OP wants different th

[SQL] Using || operator to fold multiple columns into one

2009-12-23 Thread Bryce Nesbitt
Dear experts, This point is confusing me with the || operator. I've got a table with "one column per data type", like so: # \d context_keyvals; Table "public.context_keyvals" Column|Type | Modifiers -+-+---

Re: [SQL] pg_restore followed by immediate VACUUM ANALYZE

2009-11-30 Thread Bryce Nesbitt
Tom Lane wrote: Does pg_restore not update the query planner statistics? Correct. Autovacuum might fix them eventually, but usually it's worth forcing the issue once you've completed your data loading. (This might involve multiple steps, which is why pg_restore doesn't try t

[SQL] pg_restore followed by immediate VACUUM ANALYZE

2009-11-30 Thread Bryce Nesbitt
I looking at a script that does a pg_restore followed by an immediate VACUUM ANALYZE (postgres 8.3). I'm told that without the VACUUM ANALYZE the database will run slow. Does this ring true? Does pg_restore not update the query planner statistics? -- Sent via pgsql-sql mailing list (pgsql-sq

[SQL] Mangled high bit characters with pg_server_prepare=0 in DBD::Pg

2009-11-04 Thread Bryce Nesbitt
I've just tracked down a serious bug with PG_BYTEA columns, which is probably perl specific. But I thought people might want to know: Package: libdbd-pg-perl Version: upgrading to 2.8.7 compared to 1.49. Our 1.49 was patched for the memory leak in BYTEA. With 2.8.7, if pg_server_prepare is s

[SQL] Why don't I get a LATIN1 encoding here with SET ENCODING?

2009-11-03 Thread Bryce Nesbitt
I'm tracking another bug, but wanted to verify stuff on the command line.  I can't figure out why this did not work: # psql dblack3-deleteme Welcome to psql 8.3.8 (server 8.3.4), the PostgreSQL interactive terminal. dblack3-deleteme=> create table bryce1 (key int,val1 text,val2 bytea); dblack3

Re: [SQL] Why don't I get a LATIN1 encoding here with SET ENCODING?

2009-11-03 Thread Bryce Nesbitt
Craig Ringer wrote: Yes - but you are *not* presenting a Latin-1 character. You're presenting four Latin-1 characters: '\', '3', '7', '5' Well, then I have a different question. If I can view a bytea column as so: > select object from context_objects where context_key=100041; obje

Re: [SQL] Why don't I get a LATIN1 encoding here with SET ENCODING?

2009-11-03 Thread Bryce Nesbitt
Craig Ringer wrote: In truth, that's how I'd expect it to happen. If I ask for the byte 0xfd in a string, I don't want the server to decide that I must've meant something else because I have a different client encoding. If I wanted encoding conversion, I wouldn't have written it in an escape fo

[SQL] pg_restore "WARNING: errors ignored on restore"

2009-10-28 Thread Bryce Nesbitt
So when restoring a particular DB with pg_restore, I get "WARNING: errors ignore on restore". Is there a way to dump a list of those errors? # /usr/local/bin/pg_restore8.3 -d SUP-3067 -h 192.168.1.93 -p 5433 -U postgres -L toc_with_parts_commented_out.txt -v production_db.dump.20091016 ...

Re: [SQL] AccessExclusiveLock on CREATE TABLE REFERENCES deadlocks (formatted better)

2009-09-22 Thread Bryce Nesbitt
Tom Lane wrote: Bryce Nesbitt writes: 1) Why the AccessExclusiveLock on create table? It has to install a trigger on the referenced table. There has been some discussion that maybe CREATE TRIGGER could take just ExclusiveLock and not AccessExclusiveLock, but it hasn&#

[SQL] AccessExclusiveLock on CREATE TABLE REFERENCES deadlocks

2009-09-22 Thread Bryce Nesbitt
Dear Postgres Gurus; I've just diagnosed a PostgreSQL 8.3.4 server which, about once a month, would deadlock shortly after 11pm. It had been doing this for years, and the prior response was simply to reboot everything. The culprit boils down to: # create table cache_table_20090921 ( site_key

[SQL] AccessExclusiveLock on CREATE TABLE REFERENCES deadlocks (formatted better)

2009-09-22 Thread Bryce Nesbitt
Dear Postgres Gurus; I've just diagnosed a PostgreSQL 8.3.4 server which, about once a month, would deadlock shortly after 11pm. It had been doing this for years, and the prior response was simply to reboot everything. The culprit boils down to: # create table cache_table_20090921 ( site_key

Re: [SQL] Avoiding "will create implicit index" NOTICE

2009-06-11 Thread Bryce Nesbitt
RY KEY, btree (userid, site_key) "test_5_pkey" UNIQUE, btree (userid, site_key) Foreign-key constraints: "test_5_site_key_fkey" FOREIGN KEY (site_key) REFERENCES contexts(context_key) ON DELETE CASCADE "test_5_userid_fkey" FOREIGN KEY (userid) REFERENCE

Re: [SQL] Avoiding "will create implicit index" NOTICE

2009-06-10 Thread Bryce Nesbitt
Thanks, that's good. Rob Sargent wrote: > create table junk_six (foo int) > create unique index junk_six_id on junk_six(foo) -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql

[SQL] Avoiding "will create implicit index" NOTICE

2009-06-01 Thread Bryce Nesbitt
I'm looking for a good way to avoid triggering the "will create implicit index" NOTICE that Postgres (all versions) puts out. This ends up spamming cron scripts for no good reason: => create table junk_six (foo int, primary key (foo)); NOTICE: CREATE TABLE / PRIMARY KEY will create implicit i

[SQL] Postgres process resident size does not drop after killing statement

2009-04-14 Thread Bryce Nesbitt
Every so often our production Postgres 8.3 system will get statement that runs for a few hours, or a few days, or more, and needs to be killed dead. We kill it with pg_cancel_backend(), and cpu usage of the process immediately drops, and the process starts serving other statements. But the curio

Re: [SQL] Postgres entering zombie state once a week in production evnvironment

2009-04-14 Thread Bryce Nesbitt
Scott Marlowe wrote: What does pg_locks say during this time? Specifically about locks that aren't granted? I don't know, yet. Though these events go for 15-30 minutes before postgres restart, and no deadlocks are detected, so I don't think it is locks. -- Sent via pgsql-sql mailing list (p

Re: [SQL] Postgres entering zombie state once a week in production evnvironment

2009-04-14 Thread Bryce Nesbitt
Thanks for the thoughts on what to check. Unfortunately, the priority of the people responding to the incidents has been to get the system live again. I will add these items to a list that, hopefully, will be run through prior to restarting Postgres. Achilleas Mantzios wrote: Did you check

[SQL] Postgres entering zombie state once a week in production evnvironment

2009-04-14 Thread Bryce Nesbitt
We have a medium scale installation of Postgres 8.3 that is freezing about once a week. I'm looking for any hints on how to diagnose the situation, as nothing is logged. The system is matched pair of Sunfire servers, running Debian Etch with a 2.6.18-6-amd64 kernel, PostgreSQL 8.3.4, and DRBD

Re: [SQL] Way to eliminate pg_dump activity from pg_stat_all ?

2009-01-20 Thread Bryce Nesbitt
Erik Jones wrote: It would be nice to get pg_dump activity out of the stats for another reason --- pg_dump adds to the sequential scan activity, in a way that does not represent the "typical" use of the database. Essentially pg_dump is an atypical user of the database, so it's stats are "dif

Re: [SQL] Way to eliminate pg_dump activity from pg_stat_all ?

2009-01-20 Thread Bryce Nesbitt
er's perspective, pg_dump is just a client executing queries. If the db is never used, why are you continually backing it up? On Dec 16, 2008, at 12:55 PM, Bryce Nesbitt wrote: But I think I'm getting clutter from the nightly backups. Is there a way to keep pg_dump activity out of the s

Re: [SQL] index compatible date_trunc in postgres?

2008-12-19 Thread Bryce Nesbitt
Tom Lane wrote: Why are you worrying? The old method surely didn't get indexed either. Continuous improvement? Since there already IS an index available, I figure I might as well use it, especially since this DB had real performance issues. The table itself is medium sized in our world, at

[SQL] index compatible date_trunc in postgres?

2008-12-18 Thread Bryce Nesbitt
I've got a legacy app that does 8.3 incompatible date searches like so: explain select count(*) from contexts where publication_date like '2006%'; explain select count(*) from contexts where publication_date like '2006-09%'; I've got my choice of refactoring, but all these share the same sequentia

[SQL] Way to eliminate pg_dump activity from pg_stat_all ?

2008-12-16 Thread Bryce Nesbitt
I've got a bunch of tables in a legacy database that I know are never used, and some more I'm not sure about.  So I tried to identify and confirm with: select pg_stat_reset(); -- Wait a long time select * from pg_stat_all_tables where schemaname='public' order by seq_scan,seq_tup_read

Re: [SQL] Best way to "and" from a one-to-many joined table?

2008-12-10 Thread Bryce Nesbitt
Milan Oparnica wrote: > This is how I do it, and it runs fast: > select p.* > from test_people p inner join test_attributes a on p.people_id = > a.people_id > where a."attribute" = @firstAttr or a."attribute" = @secondAttr But that does an "or" search, not "and", returning Satan in addition to Ob

Re: [SQL] Best way to "and" from a one-to-many joined table?

2008-12-05 Thread Bryce Nesbitt
It works (with a DISTINCT clause added because of the duplicated row for Obama).  It has a nice clean looking explain plan.  It has the slowest execution time on this sample table (though that might not mean anything). SELECT DISTINCT person_name FROM test_people p JOIN test_attributes a ON ((

[SQL] Best way to "and" from a one-to-many joined table?

2008-12-05 Thread Bryce Nesbitt
Dear Experts, I'm looking for a good technique to do "and" searches on one-to-many joined tables.  For example, to find people with both 'dark hair' and 'president': # select * from test_people join test_attributes using (people_id); +---+-+---+ | people_id | p

[SQL] Measuring degredation of CLUSTER INDEX operation

2008-11-10 Thread Bryce Nesbitt
I've got a table for which "CLUSTER tablename USING index" makes an order of magnitude difference. Are there ways to determine how "unclustered" this table becomes over time, so I can schedule downtime to recluster? I could use the pg_stat tables, but this seems awkward. -Bry

Re: [SQL] Seq scan on join, not on subselect? analyze this

2008-11-02 Thread Bryce Nesbitt
Tom Lane wrote: Why are the rowcount estimates so far off? Maybe you need to increase the statistics target for this table. regards, tom lane Tom, How does one tell the rowcount is off in a query plan?  I've never found a great reference on interpreting the query analyze output! Upp

[SQL] Seq scan on join, not on subselect? analyze this

2008-11-02 Thread Bryce Nesbitt
Dear Postgres Folks, I'm a bit confused why the query planner is not restricting my join, and not using the index. Two explain analyze statements follow. Why is the second so much better? lyell5=> vacuum analyze; lyell5=> select version(); PostgreSQL 8.3.4 on x86_64-pc-linux-gnu, compiled by GCC

[SQL] Seq scan on join, not on subselect? analyze this

2008-11-02 Thread Bryce Nesbitt
I'm a bit confused why the query planner is not restricting my join, and not using the index. Two explain analyze statements follow. Why is the second so much better? lyell5=> select version(); PostgreSQL 8.3.4 on x86_64-pc-linux-gnu, compiled by GCC cc (GCC) 4.1.2 20061115 (prerelease) (Debian 4

[SQL] SQL Statement Missing From Log

2008-10-27 Thread Bryce Nesbitt
Dear Helpful People, I'm getting a bunch of: 2008-10-25 14:36:59 PDT ERROR: syntax error at or near "SET" at character 9 2008-10-25 14:36:59 PDT ERROR: syntax error at or near "fetch" at character 9 2008-10-25 14:36:59 PDT ERROR: current transaction is aborted, commands ignored until end of tr

Re: [SQL] Truncate on pg_dump / pg_restore

2008-10-25 Thread Bryce Nesbitt
chris smith wrote: On Sat, Oct 25, 2008 at 5:32 PM, Bryce Nesbitt <[EMAIL PROTECTED]> wrote: I've got tables with pretty disposable data... meaning I want to drop the data... but restore empty indexed tables at pg_restore time. Do a schema-only dump. pg_

[SQL] Truncate on pg_dump / pg_restore

2008-10-24 Thread Bryce Nesbitt
Dear Postgres Gurus; Is there a way to truncate a table, at pg_dump time? I'm aware of various ways to exclude a table from a dump (>= 8.2), or to selectively pg_restore. What I'm seeking here is different. I've got tables with pretty disposable data... meaning I want to drop the data... but re

[SQL] Supplying a default on read, if a column does not exist in DB

2008-05-19 Thread Bryce Nesbitt
Is there a clean way in Postgres to specify a default return value, if a column does not exist in a database? In pseudocode: select p_email, CASE WHEN EXISTS("p_email_alt") THEN p_email_alt ELSE 'none' END from eg_application; I can kind of almost get there with: select p_email, CASE WHEN EXI

Re: [SQL] psql word wrapping to terminal width - testers?

2008-03-03 Thread Bryce Nesbitt
Karsten Hilbert wrote: # \pset format aligned-wrapped # \pset border 2 # select * from distributors order by did; +--++-+---+ | did |name|descr| long_col_name | +--++--

[SQL] psql word wrapping to terminal width - testers?

2008-03-02 Thread Bryce Nesbitt
latforms, and others find it useful, I'd like to learn how and where to introduce it as a patch. Any tips are appreciated. This is intended to solve that annoying case where a few rows in a column are too long, blowing past the widest window you can fit onscreen. -Bryce Nesbitt -

[SQL] comment on COLUMN, broken or misunderstanding?

2008-02-17 Thread Bryce Nesbitt
I'm expecting COLUMN comments to work much like table comments, but I'm getting nothing back. Is this a reportable bug, or a misunderstanding? # comment on column sched.days is 'Bitmask 0=Sunday,7=Holiday, 8=School day, 9=Special'; COMMENT # \dd sched.days; Schema | Name | Object | Description -

Re: [SQL] Backward compatibility psql 8.1 to 8.2

2008-02-15 Thread Bryce Nesbitt
I'm running SUSE 10.3. I have to install something behind the back of the package manager to keep two versions of psql around. Its not the end of the world, but it's a hassle... and fiddly in it's own right. A 8.2/8.3 client that could talk to 8.1 would save hassle here. Richard Huxton wrote: >

Re: [SQL] Proposed archival read only trigger on rows - prevent history modification

2008-02-12 Thread Bryce Nesbitt
(because our legacy application, which won't change, is using the underlying tables.  We can't do step #5). Bryce Nesbitt wrote: Yes, the view approach has some advantages. But it still leaves the underlying tables naked to modification. And since the most likely error is...

Re: [SQL] Proposed archival read only trigger on rows - prevent history modification

2008-02-12 Thread Bryce Nesbitt
Yes, the view approach has some advantages. But it still leaves the underlying tables naked to modification. And since the most likely error is... well... me (or another admin) at the SQL prompt, we want underlying tables protected also. chester c young wrote: > instead of triggers I use update-a

[SQL] Backward compatibility psql 8.1 to 8.2

2008-02-12 Thread Bryce Nesbitt
I'm getting the dreaded psql warning: WARNING: You are connected to a server with major version 8.1, but your psql client is major version 8.2. Some backslash commands, such as \d, might not work properly. And indeed, most stuff works, but \d for a specific table fails. Has there been ta

[SQL] Proposed archival read only trigger on rows - prevent history modification

2008-01-28 Thread Bryce Nesbitt
seems somewhat on target. I am using postgres, in a mostly database independent manner. Bryce Nesbitt http://www.citycarshare.org/ ---(end of broadcast)--- TIP 3: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faq

Re: [SQL] extract or date_part on an interval? How many e

2008-01-27 Thread Bryce Nesbitt
Sigh. Ok, I settled on: select '1987-01-29'::timestamp + interval '21 years' > now(); Which is closer to what I wanted anyway (this was all about determining who was under 21 years old).  This at least should be robust over leap years. Tom Lane wrote: There is nothing simple about datetim

[SQL] extract or date_part on an interval? How many e

2008-01-27 Thread Bryce Nesbitt
Hmm. Seemed so simple. But how do I get the number of years an interval represents? extract is clearly the wrong way: stage=# select 'now()-'1987-02-01' as interval,extract(year from now()-'1987-02-01') as age; interval | age --+- 7665 days 18:05:51.

[SQL] Syntax question: use of join/using with fully qualified table name

2008-01-27 Thread Bryce Nesbitt
I've got a join where a certain column name appears twice: select username,last_name from eg_member join eg_membership using (member_id) join eg_account using (account_id) join eg_person using (person_id); ERROR: common column name "person_id" appears more than once in left table My first incli

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

[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-03 Thread Bryce Nesbitt
Tom Lane wrote: Bryce Nesbitt <[EMAIL PROTECTED]> writes: Could someone explain the difference between "foo=false" and "foo is false", for a boolean type column? They give different results for NULL --- specifically, NULL for the former and FA

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

2007-09-03 Thread Bryce Nesbitt
Expecting to save 4 seconds per query, I built a partial index on a table, and was surprised that it did not work.  Could someone explain the difference between "foo=false" and "foo is false", for a boolean type column? stage=# create index eg_ve_reconciled_partial on eg_vehicle_event (reconci

Re: [SQL] Authentification failed

2007-08-14 Thread Bryce Nesbitt
Judith wrote: > Hello everybody!! > > I'm trying in SUSE to connect to a postgres db and this is the error: > > Ident Authentification failed for user <> > > I'm already created the user with createuser root, but the error > persist, I would aprecciate some help, thanks in advanced ...or just

[SQL] Getting pk of the most recent row, in a group by

2007-08-13 Thread Bryce Nesbitt
I've got a table of "coupons" which have an expiration date. For each type of coupon, I'd like to get the primary key of the coupon which will expire first. # create table coupon ( coupon_id serial primary key, type varchar(255), expires date ); insert into coupon values(

[SQL] How to cast, if type has spaces in the name

2007-07-26 Thread Bryce Nesbitt
How do I specify a cast, if the type name has spaces? foo::integer is easy, but foo::'timestamp without time zone' is more murky. In my case I have a table, and a view. For no apparent reason the table has timestamp without time zone, but I need timestamp with time zone. I'm using "select column

Re: [SQL] The nested view from hell - Restricting a subquerry

2007-07-26 Thread Bryce Nesbitt
One down. Total runtime of the simplest query went from 34661.572 ms to .634 ms (45,000 times faster). stage=> explain analyze select * from eg_order_summary_view where invoice_id=1432655; QUERY PLAN

Re: [SQL] The nested view from hell - Restricting a subquerry

2007-07-22 Thread Bryce Nesbitt
Great analysis Gregory & Tom... UNION ALL will make a difference. --- Here invoices consist of orders, orders consist of order lines. Thus, each order_id corresponds to just one invoice_id. One possibility is to add an invoice_i

[SQL] The nested view from hell - Restricting a subquerry

2007-07-21 Thread Bryce Nesbitt
. Is there a way to get the "where invoice_id=x" into the subquery? "select distinct order_id from eg_order where invoice_id=x" would do it. I can't redesign the view, because it all goes into an object relational mapper that thinks it's a real tabl

[SQL] Technique for turning time ranges into a graph

2007-06-20 Thread Bryce Nesbitt
I have a bunch of data which is expressed in terms of start and stop dates, e.g.: Member Start Stop Fred 2007-01-01 2007-05-01 Joe 2005-05-04 2007-04-01

Re: [SQL] Doing a conditional aggregate (e.g. count(*) if x=y) in postgres?

2007-05-14 Thread Bryce Nesbitt
Ah perfect. I was struggling with CASE outside the SUM(), which was not working. ---(end of broadcast)--- TIP 7: You can help support the PostgreSQL project by donating at http://www.postgresql.org/about/donate

[SQL] Doing a conditional aggregate (e.g. count(*) if x=y) in postgres?

2007-05-14 Thread Bryce Nesbitt
All; Is there a way to get a conditional aggregate? I have this two column view: SELECT count(*) AS count, xx_plan.plan_name FROM xx_membership JOIN xx_account USING (account_id) JOIN xx_plan USING (plan_id) WHERE xx_membership.status = 10 GROUP BY xx_plan.plan_name; And would like

[SQL] Large journal as psql table. Good idea? Triggering.

2007-04-23 Thread Bryce Nesbitt
Dear Postgres folks; I'm considering using a postgres table for something that could be done with a flat file. Is this a good idea? I have events on a machine "A", which need to be sent by an SMS/Cell Phone modem that's on a totally different machine "B". Potentially this is a job for a flat fi

Re: [SQL] Very slow DELETE on 4000 rows of 55000 row table

2007-04-04 Thread Bryce Nesbitt
Tom Lane wrote: > Bryce Nesbitt <[EMAIL PROTECTED]> writes: > >> I've got a DELETE FROM that seems to run forever, pegging the CPU at >> 100%. I can't figure out why it's slow. Any clues? >> > > Unindexed foreign key constraints point

[SQL] Very slow DELETE on 4000 rows of 55000 row table

2007-04-02 Thread Bryce Nesbitt
I've got a DELETE FROM that seems to run forever, pegging the CPU at 100%. I can't figure out why it's slow. Any clues? stage=# EXPLAIN DELETE FROM EG_INVOICE WHERE PERIOD_ID = 1017506; Index Scan using ix22f7bc70c7de2059 on eg_invoice (cost=0.00..105.39 rows=3955 width=6) Index Cond: (peri

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

2007-02-07 Thread Bryce Nesbitt
Philip Hallstrom wrote: >> 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? I'd then go in an edit the 1 or 2 >> additional columns that differ. The dupl

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

2007-02-07 Thread Bryce Nesbitt
I have a table that describes some properties. It is logically equivalent to: pk userid favorite_color time_zone count 122100 red Pacific7 145101 blue Eastern 7 For various reasons I need to manually add a few r

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

2007-02-07 Thread Bryce Nesbitt
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? I'd then go in an edit the 1 or 2 additional columns that differ. The duplicate would be in the same table as the o

[SQL] unexpected EOF within message length word

2006-11-14 Thread Bryce Nesbitt
is current, this may be part of the battle. Any clues? Is there a way to get a "test connection" functionality, similar to the MySQL ODBC driver? -Bryce Nesbitt -- Visit http://www.obviously.com/ ---(end of broadcast)

[SQL] Is this a bug? Deleting a column deletes the constraint.

2006-10-11 Thread Bryce Nesbitt
I got bit by this to be sure, but is it a bug? I guess I'd hoped for a warning at the critical step (see "poof" below): create table tester (one int, two int, three int); alter table only tester add constraint no_dupes unique (one, two, three); insert into tester values(1,2,3); insert into tester

[SQL] LOG: logger shutting down

2006-10-02 Thread Bryce Nesbitt
My postmaster won't start. This is on a Fedora Core fc5 box, new and clean. It's postgres 8.1.4. All I get is "LOG: logger shutting down" in the pgstartup.log. I've checked for permission errors. At the relevant moment I get: # sh -x /etc/init.d/postgresql start ... ++ cat /var/lib/pgsql/data/

Re: [SQL] Can function results be used in WHERE?

2006-07-11 Thread Bryce Nesbitt
Tom Lane wrote: > But as far as the underlying misconception goes, you seem to think that > "4" in the WHERE clause might somehow be taken as referring to the > fourth SELECT result column (why you don't think that the "1" would > likewise refer to the first result column isn't clear). This is not

Re: [SQL] Can function results be used in WHERE?

2006-07-10 Thread Bryce Nesbitt
Aaron Bono wrote: > > > On 7/10/06, *Bryce Nesbitt* <[EMAIL PROTECTED] > <mailto:[EMAIL PROTECTED]>> wrote: > > > I think it is ugly also, but no other syntax seems to work: > > stage=# select > pod_code,lat,lon,calculate_distance(lat,lon

Re: [SQL] Can function results be used in WHERE?

2006-07-10 Thread Bryce Nesbitt
Aaron Bono wrote: > First I recommend making your function IMMUTABLE since, given the same > arguments, it gives the same result - this will allow PostgreSQL to > optimize the function call and cache the results. Will do! > Then, don't use "4", use "calculate_distance(lat,lon, > 37.789629,-122.42

[SQL] Can function results be used in WHERE?

2006-07-10 Thread Bryce Nesbitt
I have a function, the results of which seem to apply to ORDER BY and HAVING, but not to WHERE. Is this expected? -- Return distance in some mystery units (TODO: convert to miles or kilometers) CREATE FUNCTION calculate_distance(double precision, double precision, double precision, double preci

Re: [SQL] grant select on database demo to user

2006-05-06 Thread Bryce Nesbitt
A. Kretschmer wrote: > Is there a way to grant to all tables, with a single grant? I know how > > > No, but you can use a little Script, please read: > http://people.planetpostgresql.org/greg/index.php?/archives/38-guid.html#extended > > HTH, Andreas > Thanks, What always happens is I create

[SQL] grant select on database demo to user

2006-05-02 Thread Bryce Nesbitt
I find myself with long lists of tables grant select on xx_tax to user; grant select on xx_trip to user; grant select on xx_foo to user; Is there a way to grant to all tables, with a single grant? I know how to do it in mysql, but not postgres. As close as I get it: #grant select on data

Re: [SQL] How to copy data between joined columns?

2006-04-07 Thread Bryce Nesbitt
Tom Lane wrote: Bryce Nesbitt <[EMAIL PROTECTED]> writes: If it were for the same rows in the same table, I would not have asked. This is for columns from two tables, whos relationship is only meaningful after a join. You have to write out the join condition lo

Re: [SQL] How to copy data between joined columns?

2006-04-07 Thread Bryce Nesbitt
Scott Marlowe wrote: > If it's for the same rows in the same table, you're overworking it. > > update table set field1=field2 where somecondition; > If it were for the same rows in the same table, I would not have asked. This is for columns from two tables, whos relationship is only meaningful a

[SQL] How to copy data between joined columns?

2006-04-07 Thread Bryce Nesbitt
that meet a particular where condition. -Bryce Nesbitt -- Visit http://www.obviously.com/ ---(end of broadcast)--- TIP 3: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faq

Re: [SQL] group by function, make SQL cleaner?

2006-04-03 Thread Bryce Nesbitt
Bryce Nesbitt wrote: > Tom Lane wrote: >> In this particular case you could say >> >> ... GROUP BY 1 ORDER BY 1; >> >> "ORDER BY n" as a reference to the n'th SELECT output column is in the >> SQL92 spec. (IIRC they removed it in SQL

[SQL] psqlODBC driver -- too many tables shown

2006-03-27 Thread Bryce Nesbitt
I'm using the current Windows psqlODBC driver. "Show system" tables is turned off, but not working. When I use an ODBC client I see all tables... including system tables, and views & tables for which no permission exists. Anyone else see this? And where can I submit a bug report (I've looked, b

[SQL] Bitfields always atomic? Other way to store attributes?

2006-03-27 Thread Bryce Nesbitt
"volunteer on the xxx project", or none of the above. I could assign each role a bit. Or, create a string field: "Friend,Money, Emp,VolXXX". Or, create related tables: friend_pk, address_id cardlist_pk, address_id money_pk, add

Re: [SQL] Custom type

2006-03-22 Thread Bryce Nesbitt
Terry Lee Tucker wrote: > rnd=# \h comment > Command: COMMENT > Description: define or change the comment of an object > ..I believe this is what you need. > Cool! That's a great feature. Though it would be even nicer if the comment showed when you "\d" a table:: stage=# comment on table

Re: [SQL] group by function, make SQL cleaner?

2006-03-16 Thread Bryce Nesbitt
Tom Lane wrote: In this particular case you could say ... GROUP BY 1 ORDER BY 1; "ORDER BY n" as a reference to the n'th SELECT output column is in the SQL92 spec. (IIRC they removed it in SQL99, but we still support it, and I think most other DBMSes do too.) "GROUP BY n" is *not* in an

[SQL] group by function, make SQL cleaner?

2006-03-15 Thread Bryce Nesbitt
I've got a working query: stage=# SELECT date_trunc('day',endtime),count(*) FROM eg_event where endtime >= '2006-02-01' and endtime < '2006-03-01' GROUP BY date_trunc('day',endtime) ORDER BY date_trunc('day',endtime); date_trunc | count -+--- 2006-02-01 00:00:0

[SQL] Advice on setting up a grid like view for spreadsheet users

2006-03-10 Thread Bryce Nesbitt
All; I have a need to create a view.  The data table does not exist yet, the question is on how to best set it up in postgres.  The resulting view has to be spreadsheet-like, and will be loaded directly via ODBC into Excel for number crunching.  Maybe something like:        R

Re: [SQL] Sequential scan where Index scan expected (update)

2006-03-03 Thread Bryce Nesbitt
Andrew Sullivan wrote: thing_event_id=1; ^ in quotes. The automatic int4-int8 coercion is probably your problem. Also Yup that's it.  But this project uses (ugh) Hibernate.  I can't change it.  I may have to change from BIGINT primary keys to IN

[SQL] Sequential scan where Index scan expected (update)

2006-03-02 Thread Bryce Nesbitt
I'm getting sequential scans (and poor performance), on scans using my primary keys. This is an older postgres. Can anyone help figure out why? demo=# \d xx_thing Table "public.xx_thing" Column |Type | Modifiers -

[SQL] Sequential scan where Index scan expected.

2006-03-02 Thread Bryce Nesbitt
I'm getting sequential scans (and poor performance), on scans using my primary keys. Can anyone help figure out why? demo=# \d xx_thing Table "public.xx_thing" Column |Type | Modifiers -+

Re: [SQL] Replication - state of the art?

2006-03-01 Thread Bryce Nesbitt
Andrew Sullivan wrote: > On Wed, Mar 01, 2006 at 09:51:46AM -0800, Bryce Nesbitt wrote: > >> switch over and rebuild the DB. "No-lost transaction" is far more >> important than switch time. >> > > You can't guarantee that without two phase c

[SQL] Replication - state of the art?

2006-03-01 Thread Bryce Nesbitt
le, easy to maintain? Bryce Nesbitt ---(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] Non Matching Records in Two Tables

2006-02-14 Thread Bryce Nesbitt
Ken Hill wrote: >> also (hate to be obvious) have you analyzed lately? >> I'd say that's fair game, not obvious. Vacuum/Analyze is ar so aparent to a person moving to Postgres from other DB's. ---(end of broadcast)--- TIP 4: Have you searched

Re: [SQL] Very slow updates when using IN syntax subselect

2006-02-13 Thread Bryce Nesbitt
Tom Lane wrote: > Peter Eisentraut <[EMAIL PROTECTED]> writes: > >> Bryce Nesbitt wrote: >> >>> They occur in finite time. That's good, thanks. But jeeze, can't >>> postgres figure this out for itself? >>> >> I&#x

Re: [SQL] Very slow updates when using IN syntax subselect

2006-02-11 Thread Bryce Nesbitt
Peter Eisentraut wrote: > Bryce Nesbitt wrote: > >>> It seems pretty clear that you've never vacuumed nor analyzed these >>> tables ... else the planner would have some clue about their sizes. >>> Do that and then see what you get. >>> &

Re: [SQL] Very slow updates when using IN syntax subselect

2006-02-11 Thread Bryce Nesbitt
Tom Lane wrote: > Bryce Nesbitt <[EMAIL PROTECTED]> writes: > >> Tom Lane wrote: >> >>> What does EXPLAIN show for this and for the base query? >>> > > >>-> Seq Scan on event (cost=0.00..0.00

Re: [SQL] Very slow updates when using IN syntax subselect

2006-02-10 Thread Bryce Nesbitt
Tom Lane wrote: > Bryce Nesbitt <[EMAIL PROTECTED]> writes: > >> update event set reconciled=true where event_id in >> (select event_id from event join token using (token_number) >> where token_status=50 and reconciled=false LIMIT 1); >> &

  1   2   >