[GENERAL] User-Defined Variables

2008-07-10 Thread Daniel Futerman
Hi,

Is there a quick solution to implementing user-defined variables in
PostgreSQL as they are used in MySQL?

I have the following MySQL script which i want to implement in Postgres
(NOTE : all ` have been changed to " for Postgres use):

SET @OTHER_CONCEPT_ID = (SELECT "concept_id" FROM "concept_name" where name
= 'MRO' LIMIT 1);

Thanks,
Daniel.


Re: [GENERAL] User-Defined Variables

2008-07-10 Thread Pavel Stehule
Hello

PostgreSQL doesn't support this  feature. There are some techniques
that you can use:
http://www.pgsql.cz/index.php/PostgreSQL_SQL_Tricks#Any_other_session_variables
http://www.postgresql.org/docs/8.3/static/plperl-global.html

Regards
Pavel Stehule


2008/7/10 Daniel Futerman <[EMAIL PROTECTED]>:
> Hi,
>
> Is there a quick solution to implementing user-defined variables in
> PostgreSQL as they are used in MySQL?
>
> I have the following MySQL script which i want to implement in Postgres
> (NOTE : all ` have been changed to " for Postgres use):
>
> SET @OTHER_CONCEPT_ID = (SELECT "concept_id" FROM "concept_name" where name
> = 'MRO' LIMIT 1);
>
> Thanks,
> Daniel.
>

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] User-Defined Variables

2008-07-10 Thread Leif B. Kristensen
On Thursday 10. July 2008, Daniel Futerman wrote:
>Hi,
>
>Is there a quick solution to implementing user-defined variables in
>PostgreSQL as they are used in MySQL?
>
>I have the following MySQL script which i want to implement in
> Postgres (NOTE : all ` have been changed to " for Postgres use):
>
>SET @OTHER_CONCEPT_ID = (SELECT "concept_id" FROM "concept_name" where
> name = 'MRO' LIMIT 1);

You should probably think about using a function instead, like eg:

CREATE OR REPLACE
FUNCTION other_concept_id(INTEGER) RETURNS INTEGER AS $$
SELECT concept_id FROM concept_name where name = 'MRO' LIMIT 1;
$$ LANGUAGE sql STABLE;

hth,
-- 
Leif Biberg Kristensen | Registered Linux User #338009
Me And My Database: http://solumslekt.org/blog/
My Jazz Jukebox: http://www.last.fm/user/leifbk/

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[GENERAL] functional index not used, looping simpler query just faster

2008-07-10 Thread Ivan Sergio Borgonovo
I've this:

CREATE TABLE catalog_brands
(
  brandid serial NOT NULL,
  "name" character varying(64) NOT NULL,
  delivery smallint NOT NULL DEFAULT (24 * 15),
  deliverymessage character varying(64),
  brandtypeid integer,
  brandgroupid integer,
  CONSTRAINT catalog_brands_pkey PRIMARY KEY (brandid),
  CONSTRAINT catalog_brands_brandgroupid_fkey FOREIGN KEY
(brandgroupid) REFERENCES catalog_brandgroup (brandgroupid) MATCH
SIMPLE ON UPDATE NO ACTION ON DELETE SET NULL,
  CONSTRAINT catalog_brands_brandtypeid_fkey FOREIGN KEY
(brandtypeid) REFERENCES catalog_brandtype (brandtypeid) MATCH SIMPLE
  ON UPDATE NO ACTION ON DELETE SET NULL
);

CREATE INDEX catalog_brands_name_index
  ON catalog_brands
  USING btree
  (upper(name::text));

CREATE TABLE catalog_items
(
  itemid bigint NOT NULL,
  brand integer NOT NULL,
  name character varying(256) NOT NULL,
/* snip */
  datainserimento timestamp without time zone,
  dapub smallint,
  CONSTRAINT catalog_items_statusid_fkey FOREIGN KEY (statusid)
  REFERENCES catalog_item_status (statusid) MATCH SIMPLE
  ON UPDATE NO ACTION ON DELETE NO ACTION
);

CREATE INDEX catalog_items_brands_index
  ON catalog_items
  USING btree
  (upper(brands::text));

CREATE UNIQUE INDEX catalog_items_itemsid_index
  ON catalog_items
  USING btree
  (itemid);
ALTER TABLE catalog_items CLUSTER ON catalog_items_itemsid_index;

catalog_items contains ~ 650K records
catalog_brands 44 records

Now I try this:

explain select i1.brands, i1.name, i1.dataPub, i1.datainserimento
  from catalog_items i1
  inner join catalog_brands b1 on upper(i1.brands)=upper(b1.name)
  where i1.ItemID in (
  select i2.ItemID from catalog_items i2
inner join catalog_brands b2 on upper(i2.brands)=upper(b2.name)
where i1.brands=i2.brands
and i2.dataPub>(now() - interval '8 month') and
i2.datainserimento>(now() - interval '6 month') order by
i2.datainserimento desc limit 3);


And I got this:

"Nested Loop  (cost=0.00..6383568361.87 rows=74378 width=82)"
"  ->  Seq Scan on catalog_brands b1  (cost=0.00..1.44 rows=44 width=18)"
"  ->  Index Scan using catalog_items_brands_index on catalog_items i1  
(cost=0.00..145081069.53 rows=1690 width=82)"
"Index Cond: (upper((i1.brands)::text) = upper(("outer".name)::text))"
"Filter: (subplan)"
"SubPlan"
"  ->  Limit  (cost=42906.81..42906.82 rows=1 width=16)"
"->  Sort  (cost=42906.81..42906.82 rows=1 width=16)"
"  Sort Key: i2.datainserimento"
"  ->  Nested Loop  (cost=0.00..42906.80 rows=1 width=16)"
"Join Filter: (upper(("outer".brands)::text) = 
upper(("inner".name)::text))"
"->  Seq Scan on catalog_items i2  
(cost=0.00..42904.59 rows=1 width=34)"
"  Filter: ((($0)::text = (brands)::text) AND 
(datapub > (now() - '8 mons'::interval)) AND (datainserimento > (now() - '6 
mons'::interval)))"
"->  Seq Scan on catalog_brands b2  
(cost=0.00..1.44 rows=44 width=18)"

I never waited enough to see results from the above... several
minutes over a 2xXeon 4Gb ram.


A simpler
select name, brands from catalog_items where
upper(brands)=upper('LARGEST GROUP') order by datainserimento desc
limit 3;

finishes in few seconds. Iterating over 44 groups does look to be
much faster than the more complicated query.

"Limit  (cost=9503.62..9503.63 rows=3 width=74)"
"  ->  Sort  (cost=9503.62..9512.08 rows=3381 width=74)"
"Sort Key: datainserimento"
"->  Bitmap Heap Scan on catalog_items  (cost=29.84..9305.44 rows=3381 
width=74)"
"  Recheck Cond: (upper((brands)::text) = 'CAMBRIDGE UNIVERSITY 
PRESS'::text)"
"  ->  Bitmap Index Scan on catalog_items_brands_index  
(cost=0.00..29.84 rows=3381 width=0)"
"Index Cond: (upper((brands)::text) = 'CAMBRIDGE UNIVERSITY 
PRESS'::text)"

Even
select count(*), i1.brands from catalog_items i1
inner join catalog_brands b1 on
upper(b1.name)=upper(i1.brands)
group by i1.brands order by count(*)

takes from few seconds to less than 1 sec.

I could actually loop inside plpgsql but... well I'd like to
understand how things work.


-- 
Ivan Sergio Borgonovo
http://www.webthatworks.it


-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] functional index not used, looping simpler query just faster

2008-07-10 Thread Martijn van Oosterhout
On Thu, Jul 10, 2008 at 11:40:40AM +0200, Ivan Sergio Borgonovo wrote:
> I've this:

What's basically killing you is this condition:
>   select i2.ItemID from catalog_items i2
> inner join catalog_brands b2 on upper(i2.brands)=upper(b2.name)
> where i1.brands=i2.brands   <*
> and i2.dataPub>(now() - interval '8 month') and

Is not indexable. Hence the seqscan, which makes everything slow.
In your "faster" version you test against a condition which *is*
indexable, hence it's faster.

Have a nice day,
-- 
Martijn van Oosterhout   <[EMAIL PROTECTED]>   http://svana.org/kleptog/
> Please line up in a tree and maintain the heap invariant while 
> boarding. Thank you for flying nlogn airlines.


signature.asc
Description: Digital signature


[GENERAL] Force removing Locks

2008-07-10 Thread Florian Eberle
Hello,

I've got a Problem... An Application that uses my Postgres Server always
keeps some locks open... Is there a Possibility to forcing remove the
Locks after a certain Interval or to remove them by hand? Because of
this Locks autovacuum cant work properly on this table and finally
System runs out of Disk Space...

Here is my pg_locks table:
===
postgres=# SELECT locktype, relation, pid, mode, granted FROM
pg_catalog.pg_locks;
   locktype| relation |  pid  |   mode   | granted
---+--+---+--+-
 relation  |  7691926 |  9218 | ShareUpdateExclusiveLock | t
 relation  |  7691926 | 11652 | RowShareLock | t
 relation  |  7691926 | 11652 | RowExclusiveLock | t
 virtualxid|  | 11652 | ExclusiveLock| t
 relation  |  7691931 |  9218 | RowExclusiveLock | t
 virtualxid|  | 21255 | ExclusiveLock| t
 relation  |  9681822 | 11652 | AccessShareLock  | t
 virtualxid|  |  9218 | ExclusiveLock| t
 relation  |  7691929 |  9218 | ShareUpdateExclusiveLock | t
 transactionid |  | 11652 | ExclusiveLock| t
 relation  |  9681826 | 11652 | AccessShareLock  | t
 relation  |10969 | 21255 | AccessShareLock  | t
(12 Zeilen)

=

Thank you
Regards,
Flo

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] User-Defined Variables

2008-07-10 Thread Richard Huxton

Don't forget to cc: the list

Daniel Futerman wrote:

What is the script trying to do (in a wider sense)?


The variable is used as follows:

 SET @OTHER_CONCEPT_ID = (SELECT `concept_id` FROM `concept_name` where name
= 'MRO' LIMIT 1);

(SELECT
COALESCE(f2.concept_id, @OTHER_CONCEPT_ID ) as 'concept_id'
FROM
`field` f, `field` f2, `form_field` ff, `form_field` ff2, `form`
WHERE
form.form_id = ff.form_id AND
ff.field_id = f.field_id AND
f.concept_id = obs.concept_id AND
ff.parent_form_field = ff2.form_field_id AND
ff2.field_id = f2.field_id
LIMIT 1
);


I don't see what this gets you that a subquery / join doesn't.

SELECT
  COALESCE(f2.concept_id, default_concept.concept_id) AS concept_id
FROM
  ...
  ,(SELECT concept_id FROM concept_name WHERE name='MRO') AS 
default_concept

WHERE

I've left the LIMIT 1 off since I'm assuming name is unique - if not the 
 LIMIT 1 doesn't make any sense without an ORDER BY too.


--
  Richard Huxton
  Archonet Ltd

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[GENERAL] expected O^2 looks line K^O, index problem not involved: [was] looping simpler query just faster

2008-07-10 Thread Ivan Sergio Borgonovo
On Thu, 10 Jul 2008 11:50:01 +0200
Martijn van Oosterhout <[EMAIL PROTECTED]> wrote:

> On Thu, Jul 10, 2008 at 11:40:40AM +0200, Ivan Sergio Borgonovo
> wrote:
> > I've this:
> 
> What's basically killing you is this condition:
> >   select i2.ItemID from catalog_items i2
> > inner join catalog_brands b2 on
> > upper(i2.brands)=upper(b2.name) where i1.brands=i2.brands
> > <* and i2.dataPub>(now() - interval '8 month') and
> 
> Is not indexable. Hence the seqscan, which makes everything slow.
> In your "faster" version you test against a condition which *is*
> indexable, hence it's faster.


I changed to 

where upper(i1.brands)=upper(i2.brands)

"Nested Loop  (cost=0.00..1393962681.78 rows=74378 width=82)"
"  ->  Seq Scan on catalog_brands b1  (cost=0.00..1.44 rows=44 width=18)"
"  ->  Index Scan using catalog_items_brands_index on catalog_items i1  
(cost=0.00..31680940.43 rows=1690 width=82)"
"Index Cond: (upper((i1.brands)::text) = upper(("outer".name)::text))"
"Filter: (subplan)"
"SubPlan"
"  ->  Limit  (cost=9366.40..9366.41 rows=1 width=16)"
"->  Sort  (cost=9366.40..9366.41 rows=1 width=16)"
"  Sort Key: i2.datainserimento"
"  ->  Nested Loop  (cost=29.84..9366.39 rows=1 width=16)"
"->  Bitmap Heap Scan on catalog_items i2  
(cost=29.84..9364.61 rows=1 width=34)"
"  Recheck Cond: (upper(($0)::text) = 
upper((brands)::text))"
"  Filter: ((datapub > (now() - '8 
mons'::interval)) AND (datainserimento > (now() - '6 mons'::interval)))"
"  ->  Bitmap Index Scan on 
catalog_items_brands_index  (cost=0.00..29.84 rows=3381 width=0)"
"Index Cond: (upper(($0)::text) = 
upper((brands)::text))"
"->  Seq Scan on catalog_brands b2  
(cost=0.00..1.77 rows=1 width=18)"
"  Filter: (upper(($0)::text) = 
upper((name)::text))"

but it still perform badly.
Skipping one of the two
join catalog_brands b1 on upper(i1.brands)=upper(b1.name)
doesn't improve anything...
even skipping some conditions, that I thought would actually make
the query faster, restricting the rows to sort etc... 

and i2.dataPub>(now() - interval '8 month') and
i2.datainserimento>(now() - interval '6 month')

didn't improve the speed.

And the sum of times it takes to execute the simpler statement for
each brands even without waiting the end of the above statements is
at least 1 order of magnitude faster than the more complicated query.

catalog_brands is a quite small table so
->  Seq Scan on catalog_brands b2 (cost=0.00..1.77 rows=1 width=18)"
 Filter: (upper(($0)::text) = upper((name)::text))"

shouldn't be a problem

and it seems that even the index is not playing such a big part

since this that doesn't use the index
select name, brands from catalog_items where brands='CAMBRIDGE
UNIVERSITY PRESS' order by datainserimento desc limit 3

takes less than 1 sec.

I'd say that having 44 groups and since the largest takes always
less then 1 sec with the simpler query... there should be something
else wrong with the above query that takes > 3 min.

Infact:
create temp table groupeditor as select i1.ItemID, i1.brands, i1.name, 
i1.dataPub, i1.datainserimento
  from catalog_items i1
  inner join catalog_brands b1 on upper(i1.brands)=upper(b1.name);
create index groupeditor_brands_idx on groupeditor (brands);
create index groupeditor_ItemID_idx on groupeditor (ItemID);

explain select i1.brands, i1.name, i1.dataPub, i1.datainserimento
  from groupeditor i1 where
  i1.ItemID in (
  select i2.ItemID from groupeditor i2
where
i1.brands=i2.brands
and i2.dataPub>(now() - interval '8 month') and i2.datainserimento>(now() - 
interval '6 month')
order by i2.datainserimento desc
  limit 3);

"Seq Scan on groupeditor i1  (cost=0.00..197133363.99 rows=68583 width=1048)"
"  Filter: (subplan)"
"  SubPlan"
"->  Limit  (cost=1437.15..1437.16 rows=3 width=16)"
"  ->  Sort  (cost=1437.15..1437.34 rows=76 width=16)"
"Sort Key: datainserimento"
"->  Bitmap Heap Scan on groupeditor i2  (cost=7.40..1434.78 
rows=76 width=16)"
"  Recheck Cond: (($0)::text = (brands)::text)"
"  Filter: ((datapub > (now() - '8 mons'::interval)) AND 
(datainserimento > (now() - '6 mons'::interval)))"
"  ->  Bitmap Index Scan on groupeditor_brands_idx  
(cost=0.00..7.40 rows=686 width=0)"
"Index Cond: (($0)::text = (brands)::text)"

Creating the temp table takes up 3 sec, creating the indexes 3
sec... and the new query... still forever...

Killing
i2.dataPub>(now() - interval '8 month') and
i2.datainserimento>(now() - interval '6 month')
and moving it in the creation of the temp table made the above run
in... 5 sec roughly... what too

[GENERAL] Starter

2008-07-10 Thread Guido Sagasti
Hi I want to star with postgresql and I want to know if it´s difficult the 
instalation and setting up in a desktop. I have not a IT background but work a 
lot with databases and need a little help.

Thanks and waiting recomendations on how to start,
Guido.



  

¡Buscá desde tu celular!

Yahoo! oneSEARCH ahora está en Claro

http://ar.mobile.yahoo.com/onesearch

Re: [GENERAL] Starter

2008-07-10 Thread Scott Marlowe
On Thu, Jul 10, 2008 at 6:24 AM, Guido Sagasti
<[EMAIL PROTECTED]> wrote:
> Hi I want to star with postgresql and I want to know if it´s difficult the
> instalation and setting up in a desktop. I have not a IT background but work
> a lot with databases and need a little help.

On a workstation running most linux distros you just install it and go.

Before you go into production, be sure and read ALL of the
administration docs, front to back.

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] Starter

2008-07-10 Thread Raymond O'Donnell

On 10/07/2008 13:24, Guido Sagasti wrote:
Hi I want to star with postgresql and I want to know if it´s difficult 
the instalation and setting up in a desktop. I have not a IT background 
but work a lot with databases and need a little help.


Hi there,

If you're working on Windows, the installer is pretty good - it will set 
up PG, create a user and set permissions, etc, and will also give you 
the opportunity to download other stuff that goes with it - I'd 
recommend PgAdmin, as it makes life much easier for someone new to PG.


There are also packages for various Linux distributions.

Do read the documentation thoroughly. It's excellent - comprehensive, 
well written and well organised.


Ray.

--
Raymond O'Donnell, Director of Music, Galway Cathedral, Ireland
[EMAIL PROTECTED]
Galway Cathedral Recitals: http://www.galwaycathedral.org/recitals
--

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] expected O^2 looks line K^O, index problem not involved: [was] looping simpler query just faster

2008-07-10 Thread Martijn van Oosterhout
On Thu, Jul 10, 2008 at 02:19:30PM +0200, Ivan Sergio Borgonovo wrote:
> On Thu, 10 Jul 2008 11:50:01 +0200
> Martijn van Oosterhout <[EMAIL PROTECTED]> wrote:

Hmm, I just studied your query to determine what you're trying to do.
As I understand it:

For each item
  Determine the brand
  Get the top three items for this brand
  If this item is one of them, display it

This is pretty inefficient but I can't see an efficient way to do it
either. I suppose one thing to try would be a multicolumn index on
(brand,datainserimento) to avoid the sort step. Also, the table b1 in
the original query is redundant.

It's the fact that you want the top three items that makes it
difficult, not sure how to deal with that.

Have a nice day,
-- 
Martijn van Oosterhout   <[EMAIL PROTECTED]>   http://svana.org/kleptog/
> Please line up in a tree and maintain the heap invariant while 
> boarding. Thank you for flying nlogn airlines.


signature.asc
Description: Digital signature


[GENERAL] SPACE FOR POSTGRESQL DATABASE

2008-07-10 Thread aravind chandu
Hello,



    Can
you please how much space does postgresql database occupies?



Thank You,

Aviansh




  

Re: [GENERAL] functional index not used, looping simpler query just faster

2008-07-10 Thread Tom Lane
Ivan Sergio Borgonovo <[EMAIL PROTECTED]> writes:
> Now I try this:

> explain select i1.brands, i1.name, i1.dataPub, i1.datainserimento
>   from catalog_items i1
>   inner join catalog_brands b1 on upper(i1.brands)=upper(b1.name)
>   where i1.ItemID in (
>   select i2.ItemID from catalog_items i2
> inner join catalog_brands b2 on upper(i2.brands)=upper(b2.name)
> where i1.brands=i2.brands
> and i2.dataPub>(now() - interval '8 month') and
> i2.datainserimento>(now() - interval '6 month') order by
> i2.datainserimento desc limit 3);

This sub-select is non optimizable because you've got an outer reference
in it, which compels re-evaluating it at every row of the outer query.
Try recasting as

explain select i1.brands, i1.name, i1.dataPub, i1.datainserimento
  from catalog_items i1
  inner join catalog_brands b1 on upper(i1.brands)=upper(b1.name)
  where (i1.ItemID, i1.brands) in (
  select i2.ItemID, i2.brands from catalog_items i2
inner join catalog_brands b2 on upper(i2.brands)=upper(b2.name)
where
i2.dataPub>(now() - interval '8 month') and
i2.datainserimento>(now() - interval '6 month') order by
i2.datainserimento desc limit 3);


regards, tom lane

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] SPACE FOR POSTGRESQL DATABASE

2008-07-10 Thread Lennin Caro
in this link have information about database size

http://www.postgresql.org/docs/8.1/static/functions-admin.html#FUNCTIONS-ADMIN-DBSIZE


--- On Thu, 7/10/08, aravind chandu <[EMAIL PROTECTED]> wrote:

> From: aravind chandu <[EMAIL PROTECTED]>
> Subject: [GENERAL] SPACE FOR POSTGRESQL DATABASE
> To: "postgresql Forums" 
> Date: Thursday, July 10, 2008, 2:18 PM
> Hello,
> 
> 
> 
> Can
> you please how much space does postgresql database
> occupies?
> 
> 
> 
> Thank You,
> 
> Aviansh


  


-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] expected O^2 looks line K^O, index problem not involved: [was] looping simpler query just faster

2008-07-10 Thread Ivan Sergio Borgonovo
On Thu, 10 Jul 2008 15:52:54 +0200
Martijn van Oosterhout <[EMAIL PROTECTED]> wrote:

> On Thu, Jul 10, 2008 at 02:19:30PM +0200, Ivan Sergio Borgonovo
> wrote:
> > On Thu, 10 Jul 2008 11:50:01 +0200
> > Martijn van Oosterhout <[EMAIL PROTECTED]> wrote:

> Hmm, I just studied your query to determine what you're trying to
> do. As I understand it:
> 
> For each item
>   Determine the brand
>   Get the top three items for this brand
>   If this item is one of them, display it
> 
> This is pretty inefficient but I can't see an efficient way to do
> it either. I suppose one thing to try would be a multicolumn index
> on (brand,datainserimento) to avoid the sort step. Also, the table
> b1 in the original query is redundant.

> It's the fact that you want the top three items that makes it
> difficult, not sure how to deal with that.

I'm not concerned about the fact that it is not "easy"... I'm
concerned about the fact that small changes to the query produce
unexpected results in performances.

I'd say that the filter on

and i2.dataPub>(now() - interval '8 month') and
i2.datainserimento>(now() - interval '6 month')

shouldn't play an important role... or at least have the same weight
on performance if used to build up a temporary table or directly in
the subquery.
I thought that indexes were going to play an important role but
still they don't.

I haven't been able to come up with a single statement that can get
the top N row by group in PostgreSQL that can compete with a set of
simpler statements.

There are a lot of examples pointing to a couple of standard
solution on MySQL and MS SQL[1] (the other standard solution uses
HAVING).
I didn't benchmark the same SQL on these 2 other DB but I think I
could assume that if they were performing so badly they wouldn't be
proposed so frequently.

Considering it is pretty trivial to write a stored procedure that
create a temp table, create some indexes on it, loops over groups
and pick up the top N record and that system proved to perform quite
well I'm still curious to know if there is postgresql way that
performs comparably with the just described method.

It would be nice if I could exploit further the fact that I'm going
to sort multiple times the temp table since the kernel of the
function will be something like

for _group in select group from grouptable loop
  select name, group from table where group=_group sort by
datainserimento limit 3;
  return next;
end loop;
return;


I think building the temp table already sorted could result in some
performance boost but that would depend on implementation details.


[1] excluding the ones that involve non standard functions

-- 
Ivan Sergio Borgonovo
http://www.webthatworks.it


-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] Force removing Locks

2008-07-10 Thread Tom Lane
Florian Eberle <[EMAIL PROTECTED]> writes:
> I've got a Problem... An Application that uses my Postgres Server always
> keeps some locks open... Is there a Possibility to forcing remove the
> Locks after a certain Interval or to remove them by hand?

Fix your application to close its transaction occasionally.  Leaving
a transaction open forever prevents vacuum from cleaning dead rows,
quite independently of any locking issues.

regards, tom lane

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] SPACE FOR POSTGRESQL DATABASE

2008-07-10 Thread A. Kretschmer
am  Thu, dem 10.07.2008, um  7:18:39 -0700 mailte aravind chandu folgendes:
> Hello,
> 
> Can you please how much space does postgresql database occupies?
> 
> Thank You,

Depends on the amount of data stored in the database.


Regards, Andreas
-- 
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID:   0x3FFF606C, privat 0x7F4584DA   http://wwwkeys.de.pgp.net

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] SPACE FOR POSTGRESQL DATABASE

2008-07-10 Thread Scott Marlowe
On Thu, Jul 10, 2008 at 8:18 AM, aravind chandu <[EMAIL PROTECTED]> wrote:
> Hello,
>
> Can you please how much space does postgresql database occupies?

A good rule of thumb is that it will take about 1.5 times as much
space in the db as it does in a flat file.  that's just an
approximation.  The actual size of each type etc is defined in the
other links in this thread.

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] functional index not used, looping simpler query just faster

2008-07-10 Thread Ivan Sergio Borgonovo
On Thu, 10 Jul 2008 10:46:53 -0400
Tom Lane <[EMAIL PROTECTED]> wrote:

> Ivan Sergio Borgonovo <[EMAIL PROTECTED]> writes:
> > Now I try this:
> 
> > explain select i1.brands, i1.name, i1.dataPub, i1.datainserimento
> >   from catalog_items i1
> >   inner join catalog_brands b1 on upper(i1.brands)=upper(b1.name)
> >   where i1.ItemID in (
> >   select i2.ItemID from catalog_items i2
> > inner join catalog_brands b2 on
> > upper(i2.brands)=upper(b2.name) where i1.brands=i2.brands
> > and i2.dataPub>(now() - interval '8 month') and
> > i2.datainserimento>(now() - interval '6 month') order by
> > i2.datainserimento desc limit 3);
> 
> This sub-select is non optimizable because you've got an outer
> reference in it, which compels re-evaluating it at every row of
> the outer query. Try recasting as
> 
> explain select i1.brands, i1.name, i1.dataPub, i1.datainserimento
>   from catalog_items i1
>   inner join catalog_brands b1 on upper(i1.brands)=upper(b1.name)
>   where (i1.ItemID, i1.brands) in (
>   select i2.ItemID, i2.brands from catalog_items i2
> inner join catalog_brands b2 on upper(i2.brands)=upper(b2.name)
> where
> i2.dataPub>(now() - interval '8 month') and
> i2.datainserimento>(now() - interval '6 month') order by
> i2.datainserimento desc limit 3);

It's not doing what was doing the previous.

I know the concept of the previous one was correct since once I
placed stuff in a temp I finally got results in a reasonable time.
Yours is returning 3 records and not 3 records for each brands and I
know there are more than 3 record that satisfy the query.

the inner query doesn't have any relationship with the outer... so
it returns 3 records and the outer just pick up the same returned
record.

Were you trying to write something different?

thanks

-- 
Ivan Sergio Borgonovo
http://www.webthatworks.it


-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[GENERAL] How to obtain info about the user?

2008-07-10 Thread Ismael Almaraz Ezparza

Hi there,
I'm connecting to postgres from java using the postgres driver...
and I need to get the info about the user that is connected to the DB, lets say
for example: name, groups, permisions (select, update, execute)...

Does anyone knows how can I get that info?

Also, if the user is in the group "admin", I need to geat a list of users and
the permissions of each... just like pgadmin3 does...
_
P.D. Checa las nuevas fotos de mi Space
http://home.services.spaces.live.com/
-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] How to obtain info about the user?

2008-07-10 Thread Joshua D. Drake


On Thu, 2008-07-10 at 11:08 -0500, Ismael Almaraz Ezparza wrote:
> Hi there,
> I'm connecting to postgres from java using the postgres driver...
> and I need to get the info about the user that is connected to the DB, lets 
> say
> for example: name, groups, permisions (select, update, execute)...
> 
> Does anyone knows how can I get that info?
> 
> Also, if the user is in the group "admin", I need to geat a list of users and
> the permissions of each... just like pgadmin3 does...

I suggest you turn on query logging to see how pgadmin3 does it.

Joshua D. Drake



-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] How to obtain info about the user?

2008-07-10 Thread William Leite Araújo
*SELECT* pg_has_role() , has_table_privilege(), has_database_privilege(),
has_function_privilege


On Thu, Jul 10, 2008 at 1:15 PM, Joshua D. Drake <[EMAIL PROTECTED]>
wrote:

>
>
> On Thu, 2008-07-10 at 11:08 -0500, Ismael Almaraz Ezparza wrote:
> > Hi there,
> > I'm connecting to postgres from java using the postgres driver...
> > and I need to get the info about the user that is connected to the DB,
> lets say
> > for example: name, groups, permisions (select, update, execute)...
> >
> > Does anyone knows how can I get that info?
> >
> > Also, if the user is in the group "admin", I need to geat a list of users
> and
> > the permissions of each... just like pgadmin3 does...
>
> I suggest you turn on query logging to see how pgadmin3 does it.
>
> Joshua D. Drake
>
>
>
> --
> Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>



-- 
William Leite Araújo
Pai 0.6 beta 2.1 "Dizem que agora melhora..."


Re: [GENERAL] Inaccurate row count estimation

2008-07-10 Thread Tom Lane
"Vyacheslav Kalinin" <[EMAIL PROTECTED]> writes:
> Here is the reproduce code:

After tracing through this I see that the problem is that we don't have
statistics for inheritance trees, and so you're getting a default
estimate for the selectivity of the join condition.  I'm not sure why
the similar example I tried last night didn't show a bogus-looking
rowcount estimate, but in any case the lack of stats is the real issue.

This should get fixed sometime, but don't hold your breath ...

regards, tom lane

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[GENERAL] storing latitude and longitude

2008-07-10 Thread mark
hi..
i want to store latitude and longitude in a users table.. what is the
best data type to use for this? i want to be able to find use this
info to find users within a distance..
how do i go about doing this?
thanks

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] How to obtain info about the user?

2008-07-10 Thread Ismael Almaraz Ezparza

> 
> SELECT pg_has_role() , has_table_privilege(), has_database_privilege(), 
> has_function_privilege
> 

Tanks, I'll make use of that
Only one last thing:
How do I get the users list?

> 
> On Thu, Jul 10, 2008 at 1:15 PM, Joshua D. Drake  wrote:
> 
> 
> On Thu, 2008-07-10 at 11:08 -0500, Ismael Almaraz Ezparza wrote:
>> Hi there,
>> I'm connecting to postgres from java using the postgres driver...
>> and I need to get the info about the user that is connected to the DB, lets 
>> say
>> for example: name, groups, permisions (select, update, execute)...
>>
>> Does anyone knows how can I get that info?
>>
>> Also, if the user is in the group "admin", I need to geat a list of users and
>> the permissions of each... just like pgadmin3 does...
> 
> I suggest you turn on query logging to see how pgadmin3 does it.
> 
> Joshua D. Drake
> 
> 
> 
> --
> Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
> 
> 
> 
> --
> William Leite Araújo
> Pai 0.6 beta 2.1 "Dizem que agora melhora..."

_
Los mejores conciertos en exclusiva por MSN in concert
http://video.msn.com/?mkt=es-mx
-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


{SOLVED?] Re: [GENERAL] functional index not used, looping simpler query just faster

2008-07-10 Thread Ivan Sergio Borgonovo
On Thu, 10 Jul 2008 10:46:53 -0400
Tom Lane <[EMAIL PROTECTED]> wrote:

> This sub-select is non optimizable because you've got an outer
> reference in it, which compels re-evaluating it at every row of
> the outer query. Try recasting as

> explain select i1.brands, i1.name, i1.dataPub, i1.datainserimento
>   from catalog_items i1
>   inner join catalog_brands b1 on upper(i1.brands)=upper(b1.name)
>   where (i1.ItemID, i1.brands) in (
>   select i2.ItemID, i2.brands from catalog_items i2
> inner join catalog_brands b2 on upper(i2.brands)=upper(b2.name)
> where
> i2.dataPub>(now() - interval '8 month') and
> i2.datainserimento>(now() - interval '6 month') order by
> i2.datainserimento desc limit 3);

I came up with this. I'm still curious to know if this could be done
efficiently with just one query.

create table catalog_topbybrands (
ItemID bigint not null,
Code varchar(32) not null,
Name varchar(256) not null,
Brands varchar(1024),
Authors varchar(1024),
ISBN varchar(100),
dataInserimento timestamp,
dataPub timestamp
);
create table catalog_topbybrands_working (
ItemID bigint not null,
Brands varchar(1024),
dataInserimento timestamp,
dataPub timestamp
);


create or replace function TopByBrands()
returns void
as
$$
declare
 _row catalog_brands%ROWTYPE;
begin
 truncate table catalog_topbybrands;
 truncate table catalog_topbybrands_working;
 insert into catalog_topbybrands_working
  (ItemID, Brands, dataInserimento, dataPub)
  select i.ItemID, i.Brands, dataInserimento, dataPub from
   catalog_items i
   inner join catalog_brands b on upper(b.Name)=upper(i.Brands)
   where
i.dataPub>(now() - interval '18 month')
and i.dataInserimento>(now() - interval '8 month')
and i.dataPub is not null and i.dataInserimento is not null
order by i.dataInserimento, i.dataPub;
 for _row in (select * from catalog_brands) loop
  insert into catalog_topbybrands
   (ItemID, Code, Name, Brands, Authors, ISBN, dataInserimento, dataPub)
   select i.ItemID, i.Code, i.Name, i.Brands, i.Authors, i.ISBN, 
i.dataInserimento, i.dataPub
   from catalog_topbybrands_working w
   join catalog_items i on i.ItemID=w.ItemID
   where upper(w.Brands)=upper(_row.name)
   order by dataInserimento desc,  dataPub desc limit 3;
 end loop;
 return;
end;
$$ language plpgsql volatile;

just a working prototype. In fact considering that once filtered by
date etc... the temp table is very small it may perform better
avoiding last join in the last insert.

-- 
Ivan Sergio Borgonovo
http://www.webthatworks.it


-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[GENERAL] Moving legacy application to JAVA, programming learning curve

2008-07-10 Thread MargaretGillon
I have a legacy DOS application that I am rewriting with Postgresql as the back-end. The system was written in Foxpro2.6 for DOS and uses xBase tables. The new database is set up and running on an Ubuntu server. The programs have been completed that migrate the data to the Postgresql database. Now it's time to write the interfaces. I would like to move the system to Java as a server side project instead of using the latest version of Foxpro and being tied to Microsoft Terminal server. Even moving between the DOS software and the Windows Foxpro the system will require a complete rewrite of all programs because of the move to postgresql as the data source.My question is how bad is the learning curve on Java? I've had Java programming classes and didn't have a problem with the language but I didn't use Java prior to this year so I don't know anything about Java frameworks. I've written in many languages but have not built a modern server side application. What I work on now are fat client applications and that is the thing we are trying to move away from.My goal is to decide if I need to stick with Foxpro so that I can get the data into a real database or if there's a chance the Java wouldn't take too much longer than rewriting into Visual Foxpro. The application is a production tracking system with 20 edit screens and 150 reports. The screens used on the production floor are touch driven. It will reside on a local LAN which is also accessed by VPN from another facility. This application will not be on the Internet, it is Intranet or Terminal server only.Any opinions and comments would be appreciated.*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***Margaret Gillon Senior Programmer-Analyst

[GENERAL] apache permission denied

2008-07-10 Thread Chris Cosner
Using RHEL 5, with Postgresql 8.1, Apache, mod_perl, mod_auth_pgsql, 
DBI, DBD::Pg


Perl cgi scripts that access the database get the following in httpd 
error_log:
DBI connect('dbname=db','',...) failed: could not connect to server: 
Permission denied


A direct test with a simple SQL command in the file, "command"
# sudo -u apache psql db < command
psql: FATAL:  role "apache" is not permitted to log in

At the psql command line, \z shows
apache=arwdRxt
for all tables

And httpd.conf definitely has
User apache
Group apache

I have restarted httpd and postmaster and the machine. These scripts 
work with postgresql 7x, but the grant syntax is different in 8x, so I 
wonder if the problem is how to grant apache privileges, or some extra 
step I'm missing.


--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] storing latitude and longitude

2008-07-10 Thread Ismael Almaraz Ezparza

Sorry I'm not of much help but...
did you check the data types page?
http://postgresql.mirrors-r-us.net/docs/8.2/interactive/datatype-geometric.html
http://postgresql.mirrors-r-us.net/docs/8.2/interactive/datatype-numeric.html

That mainly depends on how many digits you need to store, if that's not
enough you can always use the NUMERIC data type or create your own...


> Date: Thu, 10 Jul 2008 10:25:19 -0700
> From: [EMAIL PROTECTED]
> To: pgsql-general@postgresql.org
> Subject: [GENERAL] storing latitude and longitude
> 
> hi..
> i want to store latitude and longitude in a users table.. what is the
> best data type to use for this? i want to be able to find use this
> info to find users within a distance..
> how do i go about doing this?
> thanks
> 
> -- 
> Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general

_
Juega y gana, tenemos 3 Xbox a la semana.
http://club.prodigymsn.com/ 
-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] apache permission denied

2008-07-10 Thread Peter Eisentraut
Am Donnerstag, 10. Juli 2008 schrieb Chris Cosner:
> Using RHEL 5, with Postgresql 8.1, Apache, mod_perl, mod_auth_pgsql,
> DBI, DBD::Pg
>
> Perl cgi scripts that access the database get the following in httpd
> error_log:
> DBI connect('dbname=db','',...) failed: could not connect to server:
> Permission denied

An strace of the program would probably give definite insight, but "Permission 
denied" sounds to me like a file system error message.  Possibly, you don't 
have proper permissions (at least u+x) on the socket file (in (/tmp).  But 
you would have to have done serious "customization" to get to that state.  
Mayb you have some fancy security configured around your Apache instance?

> A direct test with a simple SQL command in the file, "command"
> # sudo -u apache psql db < command
> psql: FATAL:  role "apache" is not permitted to log in

That is a different issue, which the DBI route above would likely also 
complain about if it managed to get by the Permission denied stage.

> At the psql command line, \z shows
> apache=arwdRxt
> for all tables

That is yet another different issue :) which will only matter once the apache 
role manages to log in and try to read a table.

> And httpd.conf definitely has
> User apache
> Group apache
>
> I have restarted httpd and postmaster and the machine. These scripts
> work with postgresql 7x, but the grant syntax is different in 8x, so I
> wonder if the problem is how to grant apache privileges, or some extra
> step I'm missing.

Note that "postgresql 7x" and "8x" are about as useful classifications 
as "Linux 1" and "Linux 2".  Please be more precise.  Yes, somewhere along 
the line the syntax did change, but if that were the problem, you would get 
an error message about it.

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] pgmemcache status

2008-07-10 Thread Marc Munro
On Wed, 2008-07-09 at 20:42 -0300, [EMAIL PROTECTED]
wrote:
> > Is pgmemcache still being actively supported/developed?  I have
> > experienced a database crash with postgres 8.3.3 and pgmemcache
> 1.2beta1
> 
> Yes and no. I just joined up, and hope to be submitting some patches
> to it soon, as well as push to get a new version out the door, but
> there has not been much movement on it lately.

Greg,
I have a backtrace which follows below.  Is this the best forum for this
or would you prefer private email, a bugzilla entry, etc?

Program received signal SIGSEGV, Segmentation fault.
0xb7d1aae3 in strlen () from /lib/libc.so.6
(gdb) bt
#0  0xb7d1aae3 in strlen () from /lib/libc.so.6
#1  0x082bbf6a in MemoryContextStrdup (context=0x842f328, string=0x0)
at mcxt.c:658
#2  0x082b4bd1 in _ShowOption (record=0x83e6fb8, use_units=-48 '�')
at guc.c:5938
#3  0x082b4e45 in GetConfigOptionByNum (varnum=137, values=0xbf8fb23c, 
noshow=0xbf8fb26b "") at guc.c:5531
#4  0x082b9cbb in show_all_settings (fcinfo=0xbf8fb2c0) at guc.c:5773
#5  0x0817201b in ExecMakeTableFunctionResult (funcexpr=0x847c228, 
econtext=0x847b4b8, expectedDesc=0x847ba08, returnDesc=0xbf8fb558)
at execQual.c:1566
#6  0x0817daf0 in FunctionNext (node=0x847b698) at nodeFunctionscan.c:68
#7  0x08173424 in ExecScan (node=0x847b698, accessMtd=0x817da80
)
at execScan.c:68
#8  0x0817da79 in ExecFunctionScan (node=0x847b698) at
nodeFunctionscan.c:119
#9  0x0816cb4e in ExecProcNode (node=0x847b698) at execProcnode.c:356
#10 0x0816bd4b in ExecutorRun (queryDesc=0x847b038, 
direction=ForwardScanDirection, count=0) at execMain.c:1248
#11 0x08202cd8 in PortalRunSelect (portal=0x845d7a0, 
forward=, count=0, dest=0x846e240) at
pquery.c:943
#12 0x08203cca in PortalRun (portal=0x845d7a0, count=2147483647, 
isTopLevel=1 '\001', dest=0x846e240, altdest=0x846e240, 
completionTag=0xbf8fb7fa "") at pquery.c:797
---Type  to continue, or q  to quit---
#13 0x081ff223 in exec_simple_query (
query_string=0x8457700 "select * from pg_catalog.pg_settings;")
at postgres.c:986
#14 0x082000c6 in PostgresMain (argc=4, argv=0x83cad18, 
username=0x83cacf0 "marc") at postgres.c:3572
#15 0x081d51fc in ServerLoop () at postmaster.c:3207
#16 0x081d5eaa in PostmasterMain (argc=5, argv=0x83c7120) at
postmaster.c:1029
#17 0x0818db39 in main (argc=5, argv=0x83c7120) at main.c:188

__
Marc


signature.asc
Description: This is a digitally signed message part


Re: [GENERAL] apache permission denied

2008-07-10 Thread Chris Cosner

Peter Eisentraut wrote:

Am Donnerstag, 10. Juli 2008 schrieb Chris Cosner:

Using RHEL 5, with Postgresql 8.1, Apache, mod_perl, mod_auth_pgsql,
DBI, DBD::Pg

Perl cgi scripts that access the database get the following in httpd
error_log:
DBI connect('dbname=db','',...) failed: could not connect to server:
Permission denied


An strace of the program would probably give definite insight, but "Permission 
denied" sounds to me like a file system error message.  Possibly, you don't 
have proper permissions (at least u+x) on the socket file (in (/tmp).  But 
you would have to have done serious "customization" to get to that state.  
Mayb you have some fancy security configured around your Apache instance?




Thanks--SELinux was in fact enabled, and when I set it to permissive 
(i.e., audit only), httpd error_log now gives a login error:


DBI connect('dbname=db','',...) failed: FATAL:  role "apache" is not 
permitted to log in at /home/www/cgi-bin/db.lib line 1635


The postgresql version is 8.1.11

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[GENERAL] Regex problem

2008-07-10 Thread Scott Marlowe
I'm usually ok at Regex stuff, but this one is driving me a bit crazy.

Here's a string in a single field.  I'm trying to grab the long db query bit.

---

 initial time: 0.0001058578491210
 After _request set time: 0.0001859664916992
 Before include modules time: 0.001070976257324
 Before session_start time: 0.003780841827392
 SessionHandler read() start time: 0.004056930541992
 SessionHandler read() query finished: SELECT * FROM sessions WHERE
session_id = 'f5ca5ec95965e8ac99ec9bc31eca84c6' time:
0.00512299155
 After session start time: 0.005219936370849
 After create db time: 0.005784034729003
 before create new session time: 0.005914926528930
 session call constructor 1 time: 0.005953073501586
 session call constructor (org loaded) time: 0.008623838424682
 session call constructor (finished) time: 0.01247286796569LONG DB
QUERY (db1, 4.9376289844513): UPDATE force_session SET
last_used_timestamp = 'now'::timestamp WHERE orgid = 15723 AND
session_id = 'f5ca5ec95965e8ac99ec9bc31eca84c6New session created
time: 5.03999090194
 Session set up time: 5.040019989013
 Behavior loaded time: 5.040072917938
 Start of page body time: 5.129977941513
 End of page body time: 6.25822091102

-

I'm using this substring to grab part of it:

select substring (notes from E'LONG DB QUERY.+time: [0-9]+.[0-9]+')
from table where id=1;

And that returns this:

LONG DB QUERY (db1, 4.9376289844513): UPDATE force_session SET
last_used_timestamp = 'now'::timestamp WHERE orgid = 15723 AND
session_id = 'f5ca5ec95965e8ac99ec9bc31eca84c6New session created
time: 5.03999090194
   : Session set up time: 5.040019989013
   : Behavior loaded time: 5.040072917938
   : Start of page body time: 5.129977941513
   : End of page body time: 6.25822091102

Which is not surprising.  It's greedy.  So, I turn off the greediness
of the first + with a ? and then I get this

select substring (notes from E'LONG DB QUERY.+?time: [0-9]+.[0-9]+')
from table where id=1;

LONG DB QUERY (db1, 4.9376289844513): UPDATE force_session SET
last_used_timestamp = 'now'::timestamp WHERE orgid = 15723 AND
session_id = 'f5ca5ec95965e8ac99ec9bc31eca84c6New session created
time: 5.0

Now, I'm pretty sure that with the [0-9]+.[0-9]+ I should be getting
5.03999090194 at the end.  I know the . is a regex match for one char
there.  There's only ever one number before it, but changing the . to
\. doesn't help either.

Any ideas?  I'm guessing some old hand at regex will look at it and
see what I'm doing wrong, but I'm not seeing it.

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] apache permission denied

2008-07-10 Thread Devrim GÜNDÜZ
On Thu, 2008-07-10 at 11:49 -0700, Chris Cosner wrote:
> DBI connect('dbname=db','',...) failed: FATAL:  role "apache" is not 
> permitted to log in at /home/www/cgi-bin/db.lib line 1635

What about:

ALTER ROLE apache LOGIN;

-HTH.
-- 
Devrim GÜNDÜZ
devrim~gunduz.org, devrim~PostgreSQL.org, devrim.gunduz~linux.org.tr
   http://www.gunduz.org



signature.asc
Description: This is a digitally signed message part


Re: [GENERAL] Regex problem

2008-07-10 Thread Tom Lane
"Scott Marlowe" <[EMAIL PROTECTED]> writes:
> ...Which is not surprising.  It's greedy.  So, I turn off the greediness
> of the first + with a ? and then I get this

> select substring (notes from E'LONG DB QUERY.+?time: [0-9]+.[0-9]+')
> from table where id=1;

> LONG DB QUERY (db1, 4.9376289844513): UPDATE force_session SET
> last_used_timestamp = 'now'::timestamp WHERE orgid = 15723 AND
> session_id = 'f5ca5ec95965e8ac99ec9bc31eca84c6New session created
> time: 5.0

> Now, I'm pretty sure that with the [0-9]+.[0-9]+ I should be getting
> 5.03999090194 at the end.

You're getting bit by the fact that the initial non-greedy quantifier
makes the entire regex non-greedy --- see rules in section 9.7.3.5:
http://developer.postgresql.org/pgdocs/postgres/functions-matching.html#POSIX-MATCHING-RULES

If you know that there will always be something after the first time
value, you could do something like

E'(LONG DB QUERY.+?time: [0-9]+\\.[0-9]+)[^0-9]'

to force the issue about how much the second and third quantifiers
match.

regards, tom lane

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] Regex problem

2008-07-10 Thread Scott Marlowe
On Thu, Jul 10, 2008 at 1:22 PM, Tom Lane <[EMAIL PROTECTED]> wrote:
> "Scott Marlowe" <[EMAIL PROTECTED]> writes:
>> ...Which is not surprising.  It's greedy.  So, I turn off the greediness
>> of the first + with a ? and then I get this
>
>> select substring (notes from E'LONG DB QUERY.+?time: [0-9]+.[0-9]+')
>> from table where id=1;
>
>> LONG DB QUERY (db1, 4.9376289844513): UPDATE force_session SET
>> last_used_timestamp = 'now'::timestamp WHERE orgid = 15723 AND
>> session_id = 'f5ca5ec95965e8ac99ec9bc31eca84c6New session created
>> time: 5.0
>
>> Now, I'm pretty sure that with the [0-9]+.[0-9]+ I should be getting
>> 5.03999090194 at the end.
>
> You're getting bit by the fact that the initial non-greedy quantifier
> makes the entire regex non-greedy --- see rules in section 9.7.3.5:
> http://developer.postgresql.org/pgdocs/postgres/functions-matching.html#POSIX-MATCHING-RULES
>
> If you know that there will always be something after the first time
> value, you could do something like
>
> E'(LONG DB QUERY.+?time: [0-9]+\\.[0-9]+)[^0-9]'
>
> to force the issue about how much the second and third quantifiers
> match.

Thanks Tom, that's the exact answer I needed.  Now, it's back to the
bit mines...

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] apache permission denied

2008-07-10 Thread Chris Cosner

ALTER ROLE apache LOGIN

It now works! Thank you Devrim and Peter for your help.


Devrim GÜNDÜZ wrote:

On Thu, 2008-07-10 at 11:49 -0700, Chris Cosner wrote:
DBI connect('dbname=db','',...) failed: FATAL:  role "apache" is not 
permitted to log in at /home/www/cgi-bin/db.lib line 1635


What about:

ALTER ROLE apache LOGIN;

-HTH.




--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] storing latitude and longitude

2008-07-10 Thread Brent Wood
Hi Mark,

Look at Postgis, to do this properly. It adds full OGC spec support for 
managing spatial/querying spatial data within a Postgres database.

It is an option included with the Windows Postgres installer, but is generally 
extra packages under Linux.


Cheers,

   Brent Wood


>>> mark <[EMAIL PROTECTED]> 07/11/08 5:34 AM >>>
hi..
i want to store latitude and longitude in a users table.. what is the
best data type to use for this? i want to be able to find use this
info to find users within a distance..
how do i go about doing this?
thanks

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] storing latitude and longitude

2008-07-10 Thread Gregory Williamson
Top posting because of a challenged reader ... try 
 for packages and documentation. 

Greg Williamson
Senior DBA
DigitalGlobe Inc


-Original Message-
From: [EMAIL PROTECTED] on behalf of Brent Wood
Sent: Thu 7/10/2008 3:16 PM
To: [EMAIL PROTECTED]; pgsql-general@postgresql.org
Subject: Re: [GENERAL] storing latitude and longitude
 
Hi Mark,

Look at Postgis, to do this properly. It adds full OGC spec support for 
managing spatial/querying spatial data within a Postgres database.

It is an option included with the Windows Postgres installer, but is generally 
extra packages under Linux.


Cheers,

   Brent Wood


>>> mark <[EMAIL PROTECTED]> 07/11/08 5:34 AM >>>
hi..
i want to store latitude and longitude in a users table.. what is the
best data type to use for this? i want to be able to find use this
info to find users within a distance..
how do i go about doing this?
thanks

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



[GENERAL] Top N within groups?

2008-07-10 Thread Klint Gore
[was {SOLVED?] Re: [GENERAL] functional index not used, looping simpler 
query just faster]

Ivan Sergio Borgonovo wrote:

I'm still curious to know if this could be done
efficiently with just one query.
  

[thinking out loud]
Can someone familiar with the source for DISTINCT ON comment on how hard 
it would be to add another parameter to return more than one row? 


e.g.
To do TOP 1 within an unknown number of groups
  select distinct on (groupid) groupid, identifier, count(*)
  from somequery
  group by groupid, identifier
  order by 1,3 desc,2;

I'm thinking that, for the top 3 within each group, something like
  select distinct on (groupid) FOR 3 groupid, identifier, count(*)
  from somequery
  group by groupid, identifier
  order by 1,3 desc,2;

For Ivan's case, groupid = brand, identifer = item. The where clause 
applies the date limits.


klint.

--
Klint Gore
Database Manager
Sheep CRC
A.G.B.U.
University of New England
Armidale NSW 2350

Ph: 02 6773 3789  
Fax: 02 6773 3266

EMail: [EMAIL PROTECTED]


--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[GENERAL] A better error message for reject option in pg_hba.conf

2008-07-10 Thread Devrim GÜNDÜZ
(This is a very minor thing, but still...)

Suppose we have this line in pg_hba.conf:

local all all reject

Now:

$ psql template1 -U postgres 

psql: FATAL: no pg_hba.conf entry for host "[local]", user "postgres",
database "template1", SSL off

Actually there *is* an entry for local, user postgres and database
template1 -- but it is a reject. Should we improve this message and
return an error actually?

...or am I overlooking something?

Regards,
-- 
Devrim GÜNDÜZ
devrim~gunduz.org, devrim~PostgreSQL.org, devrim.gunduz~linux.org.tr
   http://www.gunduz.org



signature.asc
Description: This is a digitally signed message part