Re: [HACKERS] Selecting a constant question

2007-06-12 Thread Hannu Krosing
Ühel kenal päeval, E, 2007-06-11 kell 22:55, kirjutas Dann Corbit:
  -Original Message-
...
   I hope someone who truly understands database interfaces will read
   this thread and address the issue.
   For now we will have to special case postgres in our application
   until it is addressed.
  
  
  or redesign your application so that it allocates memory as needed and
  won't waste client memory by allocating maximum possible amount for each
  and every grid cell weather needed or not ;)
  
  As I understand from this discussion you are writing some kind of
  middleware (i.e. tools), and I'd expect toolmakers to do the right
  thing.
 
 In this case the middleware is:
 ODBC/JDBC/OLEDB/.NET data drivers for PostgreSQL.
 
 There are other related tools, but the above is the product for which the bug 
 needs corrected.

You mean you use some kind of Grid inside JDBC/.NET drivers , and it
needs to know max size for a column ?

can't you replace it with a dynamically allocated Grid component, which
would also work well for other expressions, not just constants ?

  allocating as much as possibly ever needed is something that would be
  excusable in quick-n-dirty end user application, but not in a tool.
 
 It's a requirement of the ODBC/JDBC/OLEDB/.NET specifications.  

Is that a requirement only for constants or for any expression, say
SELECT substring(reallybigblob, 1, random(100)) from somebigtable
?

 I suppose we could scan the 
 table twice to figure out how large a column might be, but that would make 
 the PostgreSQL 
 driver run at 1/2 speed.  Not a very appetizing solution.

by scanninc twice you find out how big the largest column _is_, not
might be .

 None of the other database vendors has any trouble reporting this information 
 correctly.

By this information you mean the max possible size of data returned by
and expression ?

-
Hannu



---(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: [HACKERS] Selecting a constant question

2007-06-12 Thread Larry McGhaw
Again, the issue is not our tool, but the deficiency in libpq/postgres ... even 
mysql gets its right  .. why not Postgres?
 
Its not hard for a database to report metadata properly.
 
if I issue a sql statement:
select '123' from any table
the database should report that the maximum length of the 1st column in the 
resultset is 3 ... it cant be any more plain than that.
 
Thanks
 
lm



From: Hannu Krosing [mailto:[EMAIL PROTECTED]
Sent: Mon 6/11/2007 10:43 PM
To: Larry McGhaw
Cc: Tom Lane; Alvaro Herrera; Dann Corbit; Gregory Stark; Martijn van 
Oosterhout; pgsql-hackers@postgresql.org
Subject: Re: [HACKERS] Selecting a constant question



Ühel kenal päeval, E, 2007-06-11 kell 22:11, kirjutas Larry McGhaw:
 As far as I am aware these statements are true.  If you have a
 specific example you could provide to the contrary that would be
 interesting.
 
 Even if there are such conditions it does not change the fact that
 libpq and/or postgresql is deficient in this area.
 
 For any query, the database should be capable of describing the
 metadata for the columns, which includes
 1) the column type
 and
 2) the column maximum length.
 
 This is such a basic database interface principle that I very
 disappointed that someone has not recognized this and simply said 
 yes, we see the issue we will work on it.
 
 Again, *all* other major relational databases do this ...  even blob
 fields have a maximum length reported from the database.
 
 I hope someone who truly understands database interfaces will read
 this thread and address the issue.
 For now we will have to special case postgres in our application
 until it is addressed.
 

or redesign your application so that it allocates memory as needed and
won't waste client memory by allocating maximum possible amount for each
and every grid cell weather needed or not ;)

As I understand from this discussion you are writing some kind of
middleware (i.e. tools), and I'd expect toolmakers to do the right
thing.

allocating as much as possibly ever needed is something that would be
excusable in quick-n-dirty end user application, but not in a tool.


Hannu








Re: [HACKERS] ecpg compile error in regression tests

2007-06-12 Thread Michael Meskes
On Mon, Jun 11, 2007 at 07:03:05PM +0200, Magnus Hagander wrote:
 I get the following error when trying to build the sql/parser.pgc test:
 c:\prog\pgbin\pgsql\bin\ecpg --regression  -o parser.c parser.pgc
 parser.pgc:26: ERROR: syntax error at or near NULLS
 
 Any pointers for where to look? (Kinda seems it could be the ecpg binary
 not being up-to-date, but I did a make clean and rebuild of it)

I get the same error IF I try using an 8.2 parser, be it in the backend
or in ecpg. With 8.3 however it works nicely.

Could it be that you have some older versions around? Yes, you did a
rebuild, but still.

Michael
-- 
Michael Meskes
Email: Michael at Fam-Meskes dot De, Michael at Meskes dot (De|Com|Net|Org)
ICQ: 179140304, AIM/Yahoo: michaelmeskes, Jabber: [EMAIL PROTECTED]
Go SF 49ers! Go Rhein Fire! Use Debian GNU/Linux! Use PostgreSQL!

---(end of broadcast)---
TIP 6: explain analyze is your friend


Re: [HACKERS] ecpg compile error in regression tests

2007-06-12 Thread Magnus Hagander
On Tue, Jun 12, 2007 at 09:57:17AM +0200, Michael Meskes wrote:
 On Mon, Jun 11, 2007 at 07:03:05PM +0200, Magnus Hagander wrote:
  I get the following error when trying to build the sql/parser.pgc test:
  c:\prog\pgbin\pgsql\bin\ecpg --regression  -o parser.c parser.pgc
  parser.pgc:26: ERROR: syntax error at or near NULLS
  
  Any pointers for where to look? (Kinda seems it could be the ecpg binary
  not being up-to-date, but I did a make clean and rebuild of it)
 
 I get the same error IF I try using an 8.2 parser, be it in the backend
 or in ecpg. With 8.3 however it works nicely.
 
 Could it be that you have some older versions around? Yes, you did a
 rebuild, but still.

I'll try to blow away my tree and do a fresh cvs checkout later. I'll go
ahead with what I for now and get it in thoguh, don't want to throw my
changes out. And since the problem is not actually with the regression test
*engine*, it's with the tests themselves.. :-)

//Magnus


---(end of broadcast)---
TIP 7: You can help support the PostgreSQL project by donating at

http://www.postgresql.org/about/donate


Re: [HACKERS] Selecting a constant question

2007-06-12 Thread Heikki Linnakangas

Larry McGhaw wrote:

Again, *all* other major relational databases do this ...  even blob fields 
have a maximum length reported from the database.


So what are you doing with the max length? Not all data types and values 
have a meaningful max length, so you have to be able to deal with 
variable length data anyway.


For blobs, exactly what max length would you like to get; 1GB? 1TB? Why, 
what good is that for?


--
  Heikki Linnakangas
  EnterpriseDB   http://www.enterprisedb.com

---(end of broadcast)---
TIP 2: Don't 'kill -9' the postmaster


Re: [HACKERS] Autovacuum launcher doesn't notice death of postmaster immediately

2007-06-12 Thread ITAGAKI Takahiro

Alvaro Herrera [EMAIL PROTECTED] wrote:

  No, I meant a while (sleep 1(or 10) and counter  longtime) check for
  exit instead of sleep longtime.
 
 Ah; yes, what I was proposing (or thought about proposing, not sure if I
 posted it or not) was putting a upper limit of 10 seconds in the sleep
 (bgwriter sleeps 10 seconds if configured to not do anything).  Though
 10 seconds may seem like an eternity for systems like the ones Peter was
 talking about, where there is a script trying to restart the server as
 soon as the postmaster dies.

Here is a patch for split-sleep of autovacuum_naptime.

There are some other issues in CVS HEAD; We use the calculation
{autovacuum_naptime * 100} in launcher_determine_sleep().
The result will be corrupted if we set autovacuum_naptime to 2147.

In another place, we use {autovacuum_naptime * 1000}, so we should
set the upper bound to INT_MAX/1000 instead of INT_MAX.
Incidentally, we've already had the same protections for 
log_min_duration_statement and log_autovacuum.

I hope this patch could fix those large-autovacuum_naptime problems.

Regards,
---
ITAGAKI Takahiro
NTT Open Source Software Center



autovacuum_naptime_overflow.patch
Description: Binary data

---(end of broadcast)---
TIP 7: You can help support the PostgreSQL project by donating at

http://www.postgresql.org/about/donate


Re: [HACKERS] Selecting a constant question

2007-06-12 Thread Zeugswetter Andreas ADI SD

  Again, *all* other major relational databases do this ...  
 even blob fields have a maximum length reported from the database.
 
 So what are you doing with the max length? Not all data types 
 and values have a meaningful max length, so you have to be 
 able to deal with variable length data anyway.

Imho it has a lot to do with optimizing the interface.
If you know, that the max length is e.g. 16 bytes in UTF-8 for the 3
chars, you will probably not want any on the fly allocation smarts and
preallocate and bind those 16 bytes. When the max length value gets
larger, and it is a variable lenght type, the overhead of varlen
allocation smarts starts to pay off.

A generic interface should keep the sql parsing smarts at a minimum,
thus it cannot know that a returned column is actually a text constant.

Imho the request for a max length is very reasonable, but has no value
once it exceeds a certain size e.g. 64k.

Andreas

---(end of broadcast)---
TIP 6: explain analyze is your friend


Re: [HACKERS] Autovacuum launcher doesn't notice death of postmaster immediately

2007-06-12 Thread Zdenek Kotala

Alvaro Herrera wrote:

Zeugswetter Andreas ADI SD escribió:

The launcher is set up to wake up in autovacuum_naptime
seconds 

at most.

Imho the fix is usually to have a sleep loop.
This is what we have.  The sleep time depends on the schedule 
of next vacuum for the closest database in time.  If naptime 
is high, the sleep time will be high (depending on number of 
databases needing attention).

No, I meant a while (sleep 1(or 10) and counter  longtime) check for
exit instead of sleep longtime.


Ah; yes, what I was proposing (or thought about proposing, not sure if I
posted it or not) was putting a upper limit of 10 seconds in the sleep
(bgwriter sleeps 10 seconds if configured to not do anything).  Though
10 seconds may seem like an eternity for systems like the ones Peter was
talking about, where there is a script trying to restart the server as
soon as the postmaster dies.


There is also one wild solution. Postmaster and bgwriter will connect 
 with socket/pipe and select command will be used instead sleep. If 
connection unexpectedly fails, select finish immediately and we are able 
to handle this issue asap. This socket should be used also in some 
special case when we need wake up it faster.



Zdenek


---(end of broadcast)---
TIP 2: Don't 'kill -9' the postmaster


Re: [HACKERS] Selecting a constant question

2007-06-12 Thread Gregory Stark
Larry McGhaw [EMAIL PROTECTED] writes:

 The database *knows* this size of the char constant (obviously), and
 should report the size via a metadata call, as all other relational
 databases do.

I'm not even clear whether you and Dan are talking about the same thing. He's
talking about the number of bytes required hold the constant. You seem to be
talking about the character length of strings.


-- 
  Gregory Stark
  EnterpriseDB  http://www.enterprisedb.com


---(end of broadcast)---
TIP 7: You can help support the PostgreSQL project by donating at

http://www.postgresql.org/about/donate


Re: [HACKERS] Selecting a constant question

2007-06-12 Thread Florian G. Pflug

Dann Corbit wrote:

-Original Message-
From: Hannu Krosing [mailto:[EMAIL PROTECTED]

Since libpq function PQfsize returns -2 for all constant character
strings in SQL statements ... What is the proper procedure to determine
the length of a constant character column after query execution but
before fetching the first row of data?

Why not just get the first row and determine the width from it before
you actually use any of tha data ?


What if the second row is 1000x longer?


Thats exactly the point. Consider
select mytext from mytable ;

How can PostgreSQL possibly know the maximum length
of the returned values *before* it has scanned the
whole table?

greetings, Florian Pflug


---(end of broadcast)---
TIP 4: Have you searched our list archives?

  http://archives.postgresql.org


Re: [HACKERS] Autovacuum launcher doesn't notice death of postmaster immediately

2007-06-12 Thread Magnus Hagander
On Tue, Jun 12, 2007 at 12:23:50PM +0200, Zdenek Kotala wrote:
 Alvaro Herrera wrote:
 Zeugswetter Andreas ADI SD escribió:
 The launcher is set up to wake up in autovacuum_naptime
 seconds 
 at most.
 Imho the fix is usually to have a sleep loop.
 This is what we have.  The sleep time depends on the schedule 
 of next vacuum for the closest database in time.  If naptime 
 is high, the sleep time will be high (depending on number of 
 databases needing attention).
 No, I meant a while (sleep 1(or 10) and counter  longtime) check for
 exit instead of sleep longtime.
 
 Ah; yes, what I was proposing (or thought about proposing, not sure if I
 posted it or not) was putting a upper limit of 10 seconds in the sleep
 (bgwriter sleeps 10 seconds if configured to not do anything).  Though
 10 seconds may seem like an eternity for systems like the ones Peter was
 talking about, where there is a script trying to restart the server as
 soon as the postmaster dies.
 
 There is also one wild solution. Postmaster and bgwriter will connect 
  with socket/pipe and select command will be used instead sleep. If 
 connection unexpectedly fails, select finish immediately and we are able 
 to handle this issue asap. This socket should be used also in some 
 special case when we need wake up it faster.

Given the amount of problems we've had with pipes on win32, let's try to
avoid adding extra ones unless they're really necessary. If split-sleep
works, that seems a safer bet.

//Magnus

---(end of broadcast)---
TIP 6: explain analyze is your friend


Re: [HACKERS] Selecting a constant question

2007-06-12 Thread Zeugswetter Andreas ADI SD

 Thats exactly the point. Consider
 select mytext from mytable ;
 
 How can PostgreSQL possibly know the maximum length of the 
 returned values *before* it has scanned the whole table?

I think this focuses too much on those cases where it is not possible.
When it is not feasible like with a text column, clients deal with it
already (obviously some better than others). 
It is for those cases where it would be feasible, like constants (or
concateneted columns), where the max length if properly returned could
be used to improve performance.

Andreas

---(end of broadcast)---
TIP 1: if posting/reading through Usenet, please send an appropriate
   subscribe-nomail command to [EMAIL PROTECTED] so that your
   message can get through to the mailing list cleanly


Re: [HACKERS] Selecting a constant question

2007-06-12 Thread Heikki Linnakangas

Zeugswetter Andreas ADI SD wrote:

Thats exactly the point. Consider
select mytext from mytable ;

How can PostgreSQL possibly know the maximum length of the 
returned values *before* it has scanned the whole table?


I think this focuses too much on those cases where it is not possible.
When it is not feasible like with a text column, clients deal with it
already (obviously some better than others). 
It is for those cases where it would be feasible, like constants (or

concateneted columns), where the max length if properly returned could
be used to improve performance.


I doubt there's any measurable performance benefit here. You might as 
well allocate a buffer of say 128 bytes, and enlarge it from there when 
you see a value larger than that. Even in the worst case, you'll only 
need to enlarge the buffer a few times per query until you reach the 
real max length.


Actually, if you're in such a high throughput, client-side CPU-intensive 
 situation that this makes any difference, why are you copying the 
value to another buffer in the first place? Just access it directly in 
the libpq buffer returned by PQgetvalue, and move on.


--
  Heikki Linnakangas
  EnterpriseDB   http://www.enterprisedb.com

---(end of broadcast)---
TIP 7: You can help support the PostgreSQL project by donating at

   http://www.postgresql.org/about/donate


Re: [HACKERS] Selecting a constant question

2007-06-12 Thread Dave Page
Heikki Linnakangas wrote:
 Actually, if you're in such a high throughput, client-side CPU-intensive
  situation that this makes any difference, why are you copying the value
 to another buffer in the first place? Just access it directly in the
 libpq buffer returned by PQgetvalue, and move on.

That's a *very* good point. The original design for the pgAdmin query
tool made it's own copy of the data to display in the grid which is
exactly why we used to get complaints about having a query time and a
display time.

The modern versions use a virtual table which enables the grid to
retrieve the data directly from the libpq buffer when it needs to draw
each cell which has effectively eliminated that display time.

Regards, Dave.

---(end of broadcast)---
TIP 2: Don't 'kill -9' the postmaster


Re: [HACKERS] Autovacuum launcher doesn't notice death of postmaster immediately

2007-06-12 Thread Zdenek Kotala

Magnus Hagander wrote:

On Tue, Jun 12, 2007 at 12:23:50PM +0200, Zdenek Kotala wrote:

Alvaro Herrera wrote:

Zeugswetter Andreas ADI SD escribió:

The launcher is set up to wake up in autovacuum_naptime
seconds 

at most.

Imho the fix is usually to have a sleep loop.
This is what we have.  The sleep time depends on the schedule 
of next vacuum for the closest database in time.  If naptime 
is high, the sleep time will be high (depending on number of 
databases needing attention).

No, I meant a while (sleep 1(or 10) and counter  longtime) check for
exit instead of sleep longtime.

Ah; yes, what I was proposing (or thought about proposing, not sure if I
posted it or not) was putting a upper limit of 10 seconds in the sleep
(bgwriter sleeps 10 seconds if configured to not do anything).  Though
10 seconds may seem like an eternity for systems like the ones Peter was
talking about, where there is a script trying to restart the server as
soon as the postmaster dies.
There is also one wild solution. Postmaster and bgwriter will connect 
 with socket/pipe and select command will be used instead sleep. If 
connection unexpectedly fails, select finish immediately and we are able 
to handle this issue asap. This socket should be used also in some 
special case when we need wake up it faster.


Given the amount of problems we've had with pipes on win32, let's try to
avoid adding extra ones unless they're really necessary. If split-sleep
works, that seems a safer bet.


Ok It should be problem. But I'm afraid split-sleep is not good solution 
as well. It should generate a lot of race condition in start/stop 
scripts and monitoring tools. Much better should be improve pg_ctl to 
perform clean up (pg_ctl cleanup) when postmaster fails.


I think we must offer deterministic way to packagers integrator how to 
handle this issue.


Zdenek

---(end of broadcast)---
TIP 1: if posting/reading through Usenet, please send an appropriate
  subscribe-nomail command to [EMAIL PROTECTED] so that your
  message can get through to the mailing list cleanly


[HACKERS] comparing index columns

2007-06-12 Thread Pavan Deolasee

Hi,

As per HOT design, a necessary condition to do HOT updates is
that an index column must not be updated. I am invoking the type
specific equality operator to compare two index columns, something
like this (which I think I had copied from ri_KeysEqual(), but that too have
changed now):

   typeid = SPI_gettypeid(relation-rd_att, attrnum);
   typentry = lookup_type_cache(typeid, TYPECACHE_EQ_OPR_FINFO);

   if (!OidIsValid(typentry-eq_opr_finfo.fn_oid))
   ereport(ERROR,
   (errcode(ERRCODE_UNDEFINED_FUNCTION),
   errmsg(could not identify an equality
operator 
   for type %s, format_type_be(typeid;

   /*
* Call the type specific '=' function
*/
   if (!DatumGetBool(FunctionCall2((typentry-eq_opr_finfo),
 oldvalue, newvalue)))
   return true;

Heikki pointed out that this may not work correctly with operator classes
where we should actually be using the operator from the given operator class
instead of the default operator of the type.

I don't have much insight into the operator classes and operator families
and how they work. Where should I look for the related code ? Is there
anything else we should be worried about as well ?

Any help is appreciated.


Thanks,
Pavan

--
Pavan Deolasee
EnterpriseDB http://www.enterprisedb.com


Re: [HACKERS] Selecting a constant question

2007-06-12 Thread Martijn van Oosterhout
On Tue, Jun 12, 2007 at 12:47:55PM +0200, Zeugswetter Andreas ADI SD wrote:
 I think this focuses too much on those cases where it is not possible.
 When it is not feasible like with a text column, clients deal with it
 already (obviously some better than others). 
 It is for those cases where it would be feasible, like constants (or
 concateneted columns), where the max length if properly returned could
 be used to improve performance.

For constants there is a basic problem that Postgres, if at all
possible, doesn't even analyse the string at all. If it's not part of a
join or sort, then in every likelyhood it's passed through the entire
execution untouched and comes out the other end as type unknown. The
length indicator of -2 indicates a null-terminated string, postgres
never even bothered calculating the length of it.

For the situation of concatinating varchar columns, it's a fairly
special case. The typmod, in the *special case* of varchar is the
maximum length, but for other types it means something else.
Additionally, the planner doesn't know that || is concatination, a
consequence of the user-defined operators. So to make this work you
need to change the planner so that:

1. It special cases varchar to know what the typmod means
2. It special cases the || operator to add the typmods together.
3. Has to take special care not to break user-defined operators

All a pile of hacks and special cases to handle something that, to be
honest, the vast majority of people never notice.

So no, no patch is going to be accepted to handle this special case,
because it's far too hacky for a corner case. On the other hand, if you
can piggyback it into something like the user-defined typmod stuff,
it may have a better chance, though I really think the first problem is
basically won't fix from an optimisation point of view.

Hope this clarifies things a bit,
-- 
Martijn van Oosterhout   [EMAIL PROTECTED]   http://svana.org/kleptog/
 From each according to his ability. To each according to his ability to 
 litigate.


signature.asc
Description: Digital signature


Re: [HACKERS] Selecting a constant question

2007-06-12 Thread Andrew Dunstan



Larry McGhaw wrote:
Again, the issue is not our tool, but the deficiency in libpq/postgres 
... even mysql gets its right  .. why not Postgres?
 
Its not hard for a database to report metadata properly.
 
if I issue a sql statement:

select '123' from any table
the database should report that the maximum length of the 1st column 
in the resultset is 3 ... it cant be any more plain than that.
 





Making assertions like this does not make your case for you. If you 
think it's that easy then send in a patch. I suspect that doing what you 
want in the cases where it could be supported would require a protocol 
change, with possibly an extra field in the RowDescription object. If 
that's true you'd need to make a very good and compelling case indeed 
for such a change. If this is so vital I'm curious to know why driver 
authors haven't been screaming about it until now. I'm not dismissing 
what you want, but just waving your hand and saying it's not hard 
really won't do.


cheers

andrew



---(end of broadcast)---
TIP 2: Don't 'kill -9' the postmaster


Re: [HACKERS] Command tags in create/drop scripts

2007-06-12 Thread Zdenek Kotala

David Fetter wrote:

On Fri, Jun 08, 2007 at 08:12:22PM -0500, Jim C. Nasby wrote:

On Tue, Jun 05, 2007 at 05:52:39PM -, Andrew Hammond wrote:

On Jun 5, 9:19 am, [EMAIL PROTECTED] (Alvaro Herrera) wrote:

Zdenek Kotala wrote:

Tom Lane wrote:

Bruce Momjian [EMAIL PROTECTED] writes:

Is this a TODO?

I don't think so; there is no demand from anybody but Zdenek to remove
those programs.  Has it ever even come up before?

Personally I found really strange to have createuser and createdb
shipped by Postgres when I started using it.  I just didn't complain.

+1. Given the prevalence of the pg_foo convention, those names are
clunky. So is initdb. I'm less creative than Zdenek, so I'd suggest
simply renaming to pg_createuser and friends with the same command
line options as the originals. Have the binaries check $0 and emit a
warning about using the deprecated name to STDERR if called by a name
that doesn't have the pg_ prefix. Default to symlinking the old names
for backwards compatibility until 9.0.

+1


+1

It's a lot easier just to prefix the names than to do something
clever.


I agree that it is easier to implement. But my original idea was create 
 one command which should be easy expandable. For example  add LIST 
command which it allow to get list of users, roles, langs, databases 
(instead of psql -l). There is also no way how to create table space? 
Will we add command pg_createtablespace ? I think better is keep it in 
one binary instead extend list of deliverable object.


I think for people is better to remember pg_cmd --help instead looking 
for pg_something command. And a lot of code is share anyway. The nice 
example is ZFS implementation. You need only know two commands (ZPOOL 
and ZFS) to configure everything include NFS sharing.



Zdenek

---(end of broadcast)---
TIP 2: Don't 'kill -9' the postmaster


Re: [HACKERS] comparing index columns

2007-06-12 Thread Tom Lane
Pavan Deolasee [EMAIL PROTECTED] writes:
 I don't have much insight into the operator classes and operator families
 and how they work. Where should I look for the related code ?

Primary opclass members are stored right in the Relation data struct for
you.  Since (I trust) you're only supporting this for btree, you could
just use rd_supportinfo[0] which will not even cost an fmgr lookup.
See index_getprocinfo() and callers.

regards, tom lane

---(end of broadcast)---
TIP 4: Have you searched our list archives?

   http://archives.postgresql.org


[HACKERS] regress changes

2007-06-12 Thread Alvaro Herrera
Hi,

Quick report from the front lines.

I've been IM'ing with Magnus and he already fixed most problems with the
regression tests.  The buildfarm should slowly start turning green
again.

There is a remaining problem though, which is that it doesn't work at
all on VPATH builds.  The problem seems to be that we are neglecting to
symlink the files into the builddirs.  I am looking into that.

I failed to notice this previously because my regular cleanup procedure
left the symlinks in place.  I think this is something that we should
hack make distclean to remove.  I'll have a look at that as well.

-- 
Alvaro Herrera   Valdivia, Chile   ICBM: S 39º 49' 18.1, W 73º 13' 56.4
No hay hombre que no aspire a la plenitud, es decir,
la suma de experiencias de que un hombre es capaz

---(end of broadcast)---
TIP 3: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faq


Re: [HACKERS] regress changes

2007-06-12 Thread Alvaro Herrera
Alvaro Herrera wrote:

 There is a remaining problem though, which is that it doesn't work at
 all on VPATH builds.  The problem seems to be that we are neglecting to
 symlink the files into the builddirs.  I am looking into that.

The problem is that the files are only symlinked on make install,
and I had forgotten to do that.  So this is just pilot error.  I did
correct a minor buglet in the ecpg makefile.

Everything seems to be working now, and all tests (main, contrib, pl and
ecpg) pass on my machine.

Thanks to Joachim and Magnus for reworking this stuff.

-- 
Alvaro Herrera   http://www.PlanetPostgreSQL.org/
No deja de ser humillante para una persona de ingenio saber
que no hay tonto que no le pueda enseñar algo. (Jean B. Say)

---(end of broadcast)---
TIP 1: if posting/reading through Usenet, please send an appropriate
   subscribe-nomail command to [EMAIL PROTECTED] so that your
   message can get through to the mailing list cleanly


[HACKERS] regression driver changes vs resultmap

2007-06-12 Thread Tom Lane
This patch appears to have randomly changed the format of the resultmap
file.  Please either undo that, or update the documentation
(regress.sgml) to describe what it is now.

regards, tom lane

---(end of broadcast)---
TIP 3: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faq


Re: [HACKERS] regression driver changes vs resultmap

2007-06-12 Thread Magnus Hagander
Tom Lane wrote:
 This patch appears to have randomly changed the format of the resultmap
 file.  Please either undo that, or update the documentation
 (regress.sgml) to describe what it is now.

Not randomly - it needs to be able to use paths including /, so it can't
be a separator anymore.

Will update docs - missed that they were there. Sorry about that.

//Magnus


---(end of broadcast)---
TIP 7: You can help support the PostgreSQL project by donating at

http://www.postgresql.org/about/donate


Re: [HACKERS] Selecting a constant question

2007-06-12 Thread Larry McGhaw
I'm really frustrated by this process I'm not trying to attack anyone
here.  I'm just surprised that no one will even entertain the idea that
this is an issue that needs to be addressed.

Instead nearly all of the responses have been attacking the applications
that rely on the metadata.

Let me back up and explain the situation.

This issue came to light for us when we were using a query tool to
examine performance of postgres queries.

We were not only measuring the performance of the database itself, but
also the TCP/IP transport,
And the rendering of the data .. Comparing SQL Server, Oracle, and
Postgres head to head with the same queries.

We noticed inexplicably that when we used a constant with a postgres
query, our records per second dropped
From 60,000 records per second to 600 records per second, so we started
digging into the issue.

We discovered that libpq was not describing the metadata properly for
the constant column, and it appears
That the 3rd party grid control was relying on that metadata somehow  ..
The bottom line is that there was
A huge performance drag.

* OK ... I agree that the memory handling in the grid control could be
better, but I would imagine that 
this issue is not an isolated to this one particular control, and that
other applications and controls that rely
on resultset metadata may have this issue.

Bottom line,  we only reported this problem because we thought you would
be interested in doing everything possible to make postgres more
mainstream and conform to SQL standards.  In the past such suggestions
have been absorbed with zeal.

I have no vested interest in you improving the interface or not, and I'm
not going to plead a case for you
To do something that every other commercial database has done out of the
box.  

It is in your hands now :)

Thanks

lm

-Original Message-
From: Andrew Dunstan [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, June 12, 2007 4:50 AM
To: Larry McGhaw
Cc: Hannu Krosing; Tom Lane; Alvaro Herrera; Dann Corbit; Gregory Stark;
Martijn van Oosterhout; pgsql-hackers@postgresql.org
Subject: Re: [HACKERS] Selecting a constant question



Larry McGhaw wrote:
 Again, the issue is not our tool, but the deficiency in libpq/postgres

 ... even mysql gets its right  .. why not Postgres?
  
 Its not hard for a database to report metadata properly.
  
 if I issue a sql statement:
 select '123' from any table
 the database should report that the maximum length of the 1st column 
 in the resultset is 3 ... it cant be any more plain than that.
  



Making assertions like this does not make your case for you. If you
think it's that easy then send in a patch. I suspect that doing what you
want in the cases where it could be supported would require a protocol
change, with possibly an extra field in the RowDescription object. If
that's true you'd need to make a very good and compelling case indeed
for such a change. If this is so vital I'm curious to know why driver
authors haven't been screaming about it until now. I'm not dismissing
what you want, but just waving your hand and saying it's not hard 
really won't do.

cheers

andrew



---(end of broadcast)---
TIP 3: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faq


Re: [HACKERS] Selecting a constant question

2007-06-12 Thread Martijn van Oosterhout
Hi,

Nobody is tring to attack anyone, but we're all surprised this is an
issue since you're the first person to have mentioned it. I have some
a query to test below:

On Tue, Jun 12, 2007 at 10:21:09AM -0700, Larry McGhaw wrote:
 We noticed inexplicably that when we used a constant with a postgres
 query, our records per second dropped
 From 60,000 records per second to 600 records per second, so we started
 digging into the issue.
 
 We discovered that libpq was not describing the metadata properly for
 the constant column, and it appears
 That the 3rd party grid control was relying on that metadata somehow  ..
 The bottom line is that there was
 A huge performance drag.

What I don't understand is *why* it's complaining about the constant
column and not, for example, any other variable length column. There
are a very small number of cases where a useful length is returned, 99%
of the time it doesn't, yet you're obviously not get any performance
problems there.

Just a quick test, does the problem go away if you do:

SELECT '1'::varchar FROM table;

If that fixes it then the bug is (probably) that the middleware thinks
that a length of -2 means it's 65534 bytes long. Note, in the test
query I gave, it will return -1 for the length. I don't want to blame
the middleware, but I want to make sure we're diagnosing the problem
correctly.

If that query has the same problem, then we really need to think of
something else.

Have a nice day,
-- 
Martijn van Oosterhout   [EMAIL PROTECTED]   http://svana.org/kleptog/
 From each according to his ability. To each according to his ability to 
 litigate.


signature.asc
Description: Digital signature


Re: [HACKERS] Selecting a constant question

2007-06-12 Thread Brian Hurt

Larry McGhaw wrote:


I'm really frustrated by this process I'm not trying to attack anyone
here.  I'm just surprised that no one will even entertain the idea that
this is an issue that needs to be addressed.

Instead nearly all of the responses have been attacking the applications
that rely on the metadata.
 

Having been following this debate, I think what people have really been 
attacking is the idea that the metadata for:


SELECT '1' AS varchar_column;

should be different from the metadata for:

SELECT varchar_column FROM really_big_table;

or for:

SELECT varchar_column FROM really_small_table;

Or at least that's what I've taken away from the dicussion- it's not so 
much that the metadata shouldn't be relied on, it's that the metadata 
may be more generic than theoretically necessary.  And that the metadata 
may not contain the length of a variable length field even when that 
length is known.


Brian


---(end of broadcast)---
TIP 1: if posting/reading through Usenet, please send an appropriate
  subscribe-nomail command to [EMAIL PROTECTED] so that your
  message can get through to the mailing list cleanly


Re: [HACKERS] Selecting a constant question

2007-06-12 Thread Larry McGhaw
 What I don't understand is *why* it's complaining about the constant
column 
 and not, for example, any other variable length column. There are a
very small 
 number of cases where a useful length is returned, 99% of the time it
doesn't, 
 yet you're obviously not get any performance problems there.

The statement above is contrary to my actual results.  The proper length
is returned in all non-const cases.

Here is a specific example:

test=# create table test1 ( a varchar(20), b char(10), c integer );
CREATE TABLE
test=#

Note .. The table is empty, and contains no data at this point:

Select a, b, c, '123' , '123'::char(3), '123'::varchar(3) from test1

For column a libpq returns the following:
Pqfsize returns -1
Pqfmod (-4) returns 20 

For column b libpq returns the following:
Pqfsize returns -1
Pqfmod (-4) returns 10 

For column c libpq returns the following:
Pqfsize returns 4

For constant '123' libpq returns the following:
Pqfsize returns -2
Pqfmod returns -1 

For constant '123'::char(3) libpq returns the following:
Pqfsize returns -1
Pqfmod (-4) returns 3

For constant '123'::varchar(3) libpq returns the following:
Pqfsize returns -1
Pqfmod returns -1 

Thanks

lm 

-Original Message-
From: Brian Hurt [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, June 12, 2007 11:09 AM
To: Larry McGhaw
Cc: pgsql-hackers@postgresql.org
Subject: Re: [HACKERS] Selecting a constant question

Larry McGhaw wrote:

I'm really frustrated by this process I'm not trying to attack anyone 
here.  I'm just surprised that no one will even entertain the idea that

this is an issue that needs to be addressed.

Instead nearly all of the responses have been attacking the 
applications that rely on the metadata.
  

Having been following this debate, I think what people have really been
attacking is the idea that the metadata for:

SELECT '1' AS varchar_column;

should be different from the metadata for:

SELECT varchar_column FROM really_big_table;

or for:

SELECT varchar_column FROM really_small_table;

Or at least that's what I've taken away from the dicussion- it's not so
much that the metadata shouldn't be relied on, it's that the metadata
may be more generic than theoretically necessary.  And that the metadata
may not contain the length of a variable length field even when that
length is known.

Brian


---(end of broadcast)---
TIP 2: Don't 'kill -9' the postmaster


Re: [HACKERS] one click install?

2007-06-12 Thread Andrew Hammond

The problem here is that there aren't really very many defined
defaults, or that these defaults vary (sometimes greatly) between the
different flavors of UNIX. For example, please tell me:

1) Where should PGDATA default to?
2) How do you want to handle logging output from the postmaster? There
are plenty of options...
3) Where should those log files get written?
4) For 1 and 3, will that support multiple major versions of
PostgreSQL? (ie, can I have 8.2.latest and 8.1.latest installed at the
same time)
5) How about multiple postmasters (on different ports)?

I think that the community would be well served by standardizing on
these things, at least for basic installations.



On 6/11/07, Timasmith [EMAIL PROTECTED] wrote:

Hi,

I can probably figure it out on linux but I would like to do a one
click install based upon defined defaults for the Postgresql database
(creating it as a service and load my sql file which creates the
database) - has anyone written such a how to?

thanks

Tim


---(end of broadcast)---
TIP 7: You can help support the PostgreSQL project by donating at

http://www.postgresql.org/about/donate



---(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: [HACKERS] Selecting a constant question

2007-06-12 Thread Andrew Dunstan



Larry McGhaw wrote:

For constant '123'::varchar(3) libpq returns the following:
Pqfsize returns -1
Pqfmod returns -1 

  


That one certainly looks odd.

cheers

andrew

---(end of broadcast)---
TIP 3: Have you checked our extensive FAQ?

  http://www.postgresql.org/docs/faq


Re: [HACKERS] Selecting a constant question

2007-06-12 Thread Larry McGhaw
That one surprised me as well.

Thanks

lm 

-Original Message-
From: Andrew Dunstan [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, June 12, 2007 12:00 PM
To: Larry McGhaw
Cc: Brian Hurt; pgsql-hackers@postgresql.org
Subject: Re: [HACKERS] Selecting a constant question



Larry McGhaw wrote:
 For constant '123'::varchar(3) libpq returns the following:
 Pqfsize returns -1
 Pqfmod returns -1

   

That one certainly looks odd.

cheers

andrew

---(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: [HACKERS] Selecting a constant question

2007-06-12 Thread Gregory Stark

Larry McGhaw [EMAIL PROTECTED] writes:

 The statement above is contrary to my actual results.  The proper length
 is returned in all non-const cases.

 Here is a specific example:

 test=# create table test1 ( a varchar(20), b char(10), c integer );
 CREATE TABLE

It's not returning a length at all though. It's returning the typmod, ie, the
thing in the parentheses above. In that respect it's perfectly correct to
return -1 for the '123' case as well since it's interpreted as an unbounded
string and has no maximum length. It happens to only be three characters but
then the values in the table could happen to be much less than the 10 or 20
characters you declared them as.

The reason you might want to get this has more to do with understanding the
semantics of the data you're receiving than optimizing storage. If you queried
a Numeric column you would get something very different from the length from
which you could extract the maximum precision and scale. This might help you
display or work with the results maintaining the precision and scale a user
expects.

One reason why it might be useful to add an actual measure of the expected
length (Postgres does make guesses about the length for planning purposes)
would be to so a driver could size buffers appropriately. For example, in psql
where we use cursors to process rows, we might want to automatically use a
fetch count calculated to be large enough to receive approximately one
ethernet frame of data.

-- 
  Gregory Stark
  EnterpriseDB  http://www.enterprisedb.com


---(end of broadcast)---
TIP 1: if posting/reading through Usenet, please send an appropriate
   subscribe-nomail command to [EMAIL PROTECTED] so that your
   message can get through to the mailing list cleanly


Re: [HACKERS] .conf File Organization

2007-06-12 Thread Josh Berkus
Tom,

 Do you have a better organizing principle than what's there now?

It's mostly detail stuff: putting VACUUM and Autovac together, breaking up 
some subsections that now have too many options in them into grouped. 

Client Connection Defaults has somehow become a catchall secton for *any* 
USERSET variable, regardless of purpose.  I'd like to trim it back down and 
assign some of those variables to appropriate sections. 

On the more hypothetical basis I was thinking of adding a section at the top 
with the 7-9 most common options that people *need* to set; this would make 
PostgreSQL.conf much more accessable but would result in duplicate options 
which might cause some issues.

-- 
Josh Berkus
PostgreSQL @ Sun
San Francisco

---(end of broadcast)---
TIP 4: Have you searched our list archives?

   http://archives.postgresql.org


Re: [HACKERS] .conf File Organization

2007-06-12 Thread Tom Lane
Josh Berkus [EMAIL PROTECTED] writes:
 On the more hypothetical basis I was thinking of adding a section at the top 
 with the 7-9 most common options that people *need* to set; this would make 
 PostgreSQL.conf much more accessable but would result in duplicate options 
 which might cause some issues.

Doesn't sound like a good idea, but maybe there's a case for a comment
there saying these are the most important ones to look at?

regards, tom lane

---(end of broadcast)---
TIP 2: Don't 'kill -9' the postmaster


Re: [HACKERS] Avoiding legal email signatures

2007-06-12 Thread Josh Berkus
All,

 Perhaps we make a policy that corporate-style (disclaimered) mail
 is encouraged to seek support via corporate-style channels (e.g. is
 pointed at the commercial support companies).  I'm uncomfortable with
 such a policy, but it'd be better than ignore these nasty corporate
 victims, which is what the proposal so far sounds like to me.

First off, I'm not clear on why we're discussing this on -hackers; -www would 
be the appropriate list.  So I'm cross posting; please reply any additional 
messages to -www.

Second, I'm not sure why we care.  I don't believe that e-mail confidentiality 
notices are in fact enforceable, or at least they haven't been in some 
high-profile cases which made the news.  IANAL, of course.

However:

 Haven't we been over this at least once before? Greg is right, just
 document the point and leave it alone. If you want to get really picky
 about, make the confirmation email from the subscription process
 specifically state that confirming subscription is an acceptance of the
 PostgreSQL.Org usage policies which can be found here (insert link).

This is a good idea anyway.  We should have a list usage policy, and we should 
link to if from the subscribe confirmation and from the web subscription 
page.  In addition to letting people know that e-mail confidentiality footers 
will be ignored, we can tell them how the lists are moderated, how to 
unsubscribe (can't have this in enough places), not to use HTML mail, etc.

So, who wants to write it?

The only additional idea I have is that we ought to simply strip away any 
e-mail footer over 4 lines from the archives.   Not only would this purge the 
confidentiality footers, it would save us some space in general.

-- 
Josh Berkus
PostgreSQL @ Sun
San Francisco

---(end of broadcast)---
TIP 3: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faq


Re: [HACKERS] .conf File Organization

2007-06-12 Thread Josh Berkus
Tom,

 Doesn't sound like a good idea, but maybe there's a case for a comment
 there saying these are the most important ones to look at?

Yeah, probably need to do that.  Seems user-unfriendly, but loading a foot gun 
by having some options appear twice in the file seems much worse.  I'll also 
add some notes on how to set these values.

-- 
Josh Berkus
PostgreSQL @ Sun
San Francisco

---(end of broadcast)---
TIP 2: Don't 'kill -9' the postmaster


Re: [HACKERS] one click install?

2007-06-12 Thread Andrej Ricnik-Bay

On 6/13/07, Andrew Hammond [EMAIL PROTECTED] wrote:

The problem here is that there aren't really very many defined
defaults, or that these defaults vary (sometimes greatly) between the
different flavors of UNIX. For example, please tell me:

1) Where should PGDATA default to?
2) How do you want to handle logging output from the postmaster? There
are plenty of options...
3) Where should those log files get written?
4) For 1 and 3, will that support multiple major versions of
PostgreSQL? (ie, can I have 8.2.latest and 8.1.latest installed at the
same time)
5) How about multiple postmasters (on different ports)?

Exactly :} ... all very good points... and then there's still the
ownerships of processes and directories/files, and their perms.
And integration with the init-scripts.  And how e.g. the environment
variables for users should be handled.


I think that the community would be well served by standardizing on
these things, at least for basic installations.

But whose decision should that be?
The postgres' developers?
I think that the defaults that the configure script suggests are
quite sane, and happily use them in my Slackware installations.

Linux File system Hierarchy standards?  Which major distro(s)? And
what about the BSDs (or the commercial Unices supported)?

And while at it: who would define what a basic installation is? :)



-- Cheers,
  Andrej

---(end of broadcast)---
TIP 7: You can help support the PostgreSQL project by donating at

   http://www.postgresql.org/about/donate


Re: [pgsql-www] [HACKERS] Avoiding legal email signatures

2007-06-12 Thread Dave Page
Josh Berkus wrote:
 The only additional idea I have is that we ought to simply strip away any 
 e-mail footer over 4 lines from the archives.   Not only would this purge the 
 confidentiality footers, it would save us some space in general.

The effort it would take to write some code to extract the messages from
the archive mboxes, break up the messages into their component parts,
strip excess sig lines, reconstruct the messages, reconstruct the mboxes
and then regenerate the archives would probably equate in dollar value
to the disk space required for another 40 or 50 years worth of archives.

I vote 'lets not bother'

:-)

/D


---(end of broadcast)---
TIP 4: Have you searched our list archives?

   http://archives.postgresql.org


Re: [pgsql-www] [HACKERS] Avoiding legal email signatures

2007-06-12 Thread Tom Lane
Dave Page [EMAIL PROTECTED] writes:
 Josh Berkus wrote:
 The only additional idea I have is that we ought to simply strip away any 
 e-mail footer over 4 lines from the archives.   Not only would this purge 
 the 
 confidentiality footers, it would save us some space in general.

 The effort it would take to write some code to extract the messages from
 the archive mboxes, break up the messages into their component parts,
 strip excess sig lines, reconstruct the messages, reconstruct the mboxes
 and then regenerate the archives would probably equate in dollar value
 to the disk space required for another 40 or 50 years worth of archives.

A more serious objection is that any automated tool would probably get it
wrong sometimes, and strip important text.

 I vote 'lets not bother'

Right.  I agree with Josh's idea about mentioning list policies in the
subscription confirmation message, though.

regards, tom lane

---(end of broadcast)---
TIP 3: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faq


Re: [HACKERS] Selecting a constant question

2007-06-12 Thread Larry McGhaw
For what its worth .. Your statement about why we are the first people
to mention this problem really got me thinking.  Anyone who would
attempt to write an ODBC driver for Postgres would run into the exact
same issue.   So I installed the official Postgres ODBC driver, and ran
the identical query and here are my results:

I probably should have looked at this first  There is a whole
Postgres ODBC dialog dedicated to the very subject of this thread:
Handling of unknown data sizes.   The pgodbc driver is configured to
treat unknowns as varchar(255) by default,
As shown by my example below.  This can be configured up or down as
desired.

SQLExecDirect:
In: hstmt = 0x003C18E0, szSqlStr = Select a,b,c, '123' ,
'123'::char(3), '123'::varchar(3) from..., cbSqlStr = -3
Return: SQL_SUCCESS=0

Describe Column All: 
icol, szColName, *pcbColName, *pfSqlType, *pcbColDef, *pibScale,
*pfNullable 
1, a, 1, SQL_VARCHAR=12, 20, 0, SQL_NULLABLE=1 
2, b, 1, SQL_CHAR=1, 10, 0, SQL_NULLABLE=1 
3, c, 1, SQL_INTEGER=4, 10, 0, SQL_NULLABLE=1 
4, ?column?, 8, SQL_VARCHAR=12, 255, 0, SQL_NULLABLE=1 
5, bpchar, 6, SQL_CHAR=1, 3, 0, SQL_NULLABLE=1 
6, varchar, 7, SQL_VARCHAR=12, 255, 0, SQL_NULLABLE=1 

From psqlodbc.h

#define MAX_VARCHAR_SIZE255 /* default maximum size
of
 * varchar fields (not
including null term) */

So I guess the bottom line is that we are not the first to encounter
this problem .. Its just been covered up by assigning
An arbitrary maximum size .. So I guess we will do the same and make it
configurable like the official postgres driver.

Thanks

lm

-Original Message-
From: Martijn van Oosterhout [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, June 12, 2007 10:43 AM
To: Larry McGhaw
Cc: Andrew Dunstan; Hannu Krosing; Tom Lane; Alvaro Herrera; Dann
Corbit; Gregory Stark; pgsql-hackers@postgresql.org
Subject: Re: [HACKERS] Selecting a constant question

Hi,

Nobody is tring to attack anyone, but we're all surprised this is an
issue since you're the first person to have mentioned it. I have some a
query to test below:

On Tue, Jun 12, 2007 at 10:21:09AM -0700, Larry McGhaw wrote:
 We noticed inexplicably that when we used a constant with a postgres 
 query, our records per second dropped From 60,000 records per second 
 to 600 records per second, so we started digging into the issue.
 
 We discovered that libpq was not describing the metadata properly for 
 the constant column, and it appears That the 3rd party grid control 
 was relying on that metadata somehow  ..
 The bottom line is that there was
 A huge performance drag.

What I don't understand is *why* it's complaining about the constant
column and not, for example, any other variable length column. There are
a very small number of cases where a useful length is returned, 99% of
the time it doesn't, yet you're obviously not get any performance
problems there.

Just a quick test, does the problem go away if you do:

SELECT '1'::varchar FROM table;

If that fixes it then the bug is (probably) that the middleware thinks
that a length of -2 means it's 65534 bytes long. Note, in the test query
I gave, it will return -1 for the length. I don't want to blame the
middleware, but I want to make sure we're diagnosing the problem
correctly.

If that query has the same problem, then we really need to think of
something else.

Have a nice day,
-- 
Martijn van Oosterhout   [EMAIL PROTECTED]   http://svana.org/kleptog/
 From each according to his ability. To each according to his ability
to litigate.

---(end of broadcast)---
TIP 1: if posting/reading through Usenet, please send an appropriate
   subscribe-nomail command to [EMAIL PROTECTED] so that your
   message can get through to the mailing list cleanly


[HACKERS] Selecting a constant question: A summary

2007-06-12 Thread Dann Corbit
First a comment:

At CONNX Solutions Inc., we believe sincerely that we should do whatever
is necessary to make our customers prosper.  This means creation of
excellent tools and being responsive to customer needs.  Secondly, we
believe that we should treat the customers the way that we want to be
treated.

I think that the PostgreSQL group has managed the first objective, but
not the second.  Of course, that is only an opinion, but I think that
success hinges on both factors.  Our objective in this issue has also
been to improve PostgreSQL so that it can become more useful to the end
users and not to denigrate the work of the engineers that have toiled on
it.  I will also admit that frustration has caused our tone to become
sharp at times.  This is clearly a mistake on our part and for this, I
apologize.

 

Next, the problem:

According to SQL/CLI and ODBC 3.5, we should bind the length of a
character column.

 

Here are some references from the relevant documentation (SQL/CLI and
ODBC are clones of one another):


==

ANSI/ISO/IEC 9075-3-1999

for Information Technology

Database Language SQL 

Part 3: Call-Level Interface (SQL/CLI)

Section 6.5 BindCol

 

Along with function SQLBindCol from the ODBC specification

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/ht
m/odbcsqlbindcol.asp

 

 

This bit should be sufficient to explain what we are after:

BufferLength [Input]

Length of the *TargetValuePtr buffer in bytes.

 

The driver uses BufferLength to avoid writing past the end of the
*TargetValuePtr buffer when returning variable-length data, such as
character or binary data. Note that the driver counts the
null-termination character when returning character data to
*TargetValuePtr. *TargetValuePtr must therefore contain space for the
null-termination character or the driver will truncate the data.

When the driver returns fixed-length data, such as an integer or a date
structure, the driver ignores BufferLength and assumes the buffer is
large enough to hold the data. It is therefore important for the
application to allocate a large enough buffer for fixed-length data or
the driver will write past the end of the buffer.

 

SQLBindCol returns SQLSTATE HY090 (Invalid string or buffer length) when
BufferLength is less than 0 but not when BufferLength is 0. However, if
TargetType specifies a character type, an application should not set
BufferLength to 0, because ISO CLI-compliant drivers return SQLSTATE
HY090 (Invalid string or buffer length) in that case.


==

 

Now, there are times when (according to the spec) we have to defer
binding.  However, this causes great problems for end user tools and
should only be done in what is basically a dire emergency.

In the case of a SELECT query that selects a fixed constant of any sort,
it would be a definite improvement for PostgreSQL to give some sort of
upper maximum.

For example:

 

SELECT Eastern Division, sum(Inventory_level),
sum(Inventory_backorder), Manager_last_name FROM table_name WHERE
division_id = 9 GROUP BY Manager_last_name

 

Will return 3 columns of data.  The first column is of unknown length.
Imagine if you are a spreadsheet in OpenOffice:

http://www.openoffice.org/

which happens to support ODBC connections.  You would like to fill out a
report for the president of your company.  Unfortunately, the first
column is of unknown length

 

That makes it a bit difficult to format this spreadsheet.

 

Now, I will admit that we may not know a-priori if Eastern Division is
character or Unicode or MBCS.  But in the worst case scenario it will be
(16 + 1) * element_width bytes in length.  For some Unicode character
sets, element_width can be as much as 4, so that leaves 68 octets as an
upper possible maximum.

Now, you might protest, 68 bytes might be much too large.  That is true,
but I know that if I allocate 68 bytes we will not have data truncation.
It is no worse than a varchar(255) field that has a largest item 15
characters wide in it.  The grid will successfully bind and we will be
able to produce the report.

Generally speaking, grids are smart enough to automatically resize
themselves to max_length(grid_column_title, grid_column_data) and so the
report will look very nice.

 

It is also true that it is possible for us to work around the problem.
We certainly can know the exact type information about the constants in
our queries and reformat the PostgreSQL queries to decorate them with
things like:

SELECT Eastern Division::char(16),
sum(Inventory_level)::Numeric(16,4), sum(Inventory_backorder)
::Numeric(16,4), Manager_last_name FROM table_name WHERE division_id =
9 GROUP BY Manager_last_name

 

But it would be very nice if the database could provide a good estimate
for us so that PostgreSQL could work like all of the other database
systems.  Code full of 

Re: [HACKERS] Selecting a constant question

2007-06-12 Thread Dann Corbit
 -Original Message-
 From: Larry McGhaw
 Sent: Tuesday, June 12, 2007 1:40 PM
 To: Martijn van Oosterhout
 Cc: Andrew Dunstan; Hannu Krosing; Tom Lane; Alvaro Herrera; Dann
Corbit;
 Gregory Stark; pgsql-hackers@postgresql.org
 Subject: RE: [HACKERS] Selecting a constant question
 
 For what its worth .. Your statement about why we are the first people
to
 mention this problem really got me thinking.  Anyone who would attempt
to
 write an ODBC driver for Postgres would run into the exact same issue.
 So I installed the official Postgres ODBC driver, and ran the
identical
 query and here are my results:
 
 I probably should have looked at this first  There is a whole
Postgres
 ODBC dialog dedicated to the very subject of this thread:
 Handling of unknown data sizes.   The pgodbc driver is configured to
 treat unknowns as varchar(255) by default,
 As shown by my example below.  This can be configured up or down as
 desired.
 
 SQLExecDirect:
 In: hstmt = 0x003C18E0, szSqlStr = Select a,b,c, '123' ,
'123'::char(3),
 '123'::varchar(3) from..., cbSqlStr = -3
 Return:   SQL_SUCCESS=0
 
 Describe Column All:
 icol, szColName, *pcbColName, *pfSqlType, *pcbColDef, *pibScale,
 *pfNullable
 1, a, 1, SQL_VARCHAR=12, 20, 0, SQL_NULLABLE=1
 2, b, 1, SQL_CHAR=1, 10, 0, SQL_NULLABLE=1
 3, c, 1, SQL_INTEGER=4, 10, 0, SQL_NULLABLE=1
 4, ?column?, 8, SQL_VARCHAR=12, 255, 0, SQL_NULLABLE=1
 5, bpchar, 6, SQL_CHAR=1, 3, 0, SQL_NULLABLE=1
 6, varchar, 7, SQL_VARCHAR=12, 255, 0, SQL_NULLABLE=1
 
 From psqlodbc.h
 
 #define MAX_VARCHAR_SIZE  255 /* default maximum size
of
* varchar fields (not
including null
 term) */
 
 So I guess the bottom line is that we are not the first to encounter
this
 problem .. Its just been covered up by assigning
 An arbitrary maximum size .. So I guess we will do the same and make
it
 configurable like the official postgres driver.

Of course, the downside here is that choosing a default will truncate
the data when the actual data is larger than the default chosen.


---(end of broadcast)---
TIP 7: You can help support the PostgreSQL project by donating at

http://www.postgresql.org/about/donate


Re: [HACKERS] Selecting a constant question: A summary

2007-06-12 Thread Joshua D. Drake

Dann Corbit wrote:

First a comment:

At CONNX Solutions Inc., we believe sincerely that we should do whatever 
is necessary to make our customers prosper.  This means creation of 
excellent tools and being responsive to customer needs.  Secondly, we 
believe that we should treat the customers the way that we want to be 
treated.


I think that the PostgreSQL group has managed the first objective, but 
not the second.  Of course, that is only an opinion, but I think that 
success hinges on both factors.  Our objective in this issue has also 
been to improve PostgreSQL so that it can become more useful to the end 
users and not to denigrate the work of the engineers that have toiled on 
it.  I will also admit that frustration has caused our tone to become 
sharp at times.  This is clearly a mistake on our part and for this, I 
apologize.


Woah, now this is interesting. This morning, I read this whole thread, 
wondering what in the world could possibly be taking so long ;).


I will admit that many of us in the community tend to try to provide a 
solution without actually understanding the problem. I think it kind of 
comes with the territory, a lot of times it seems like FOSS is all about 
the work around versus the solution because the solution takes longer.


Perception is a powerful thing. Personally, I didn't see any of the 
community doing anything but trying their best to help you with the 
problem you were experiencing.


What I did see, is a lot of tenseness from your side, to what basically 
amounts to free support. Remember that we are here, at no cost to you.


Lastly, the PostgreSQL community doesn't have customer. You have 
customer, CMD has customers, the PostgreSQL community does not.


The best correlation I can give you is this. We (the community) are all 
a team. You are part of that team. We are not your vendor.


Sincerely,

Joshua D. Drake


--

  === The PostgreSQL Company: Command Prompt, Inc. ===
Sales/Support: +1.503.667.4564 || 24x7/Emergency: +1.800.492.2240
Providing the most comprehensive  PostgreSQL solutions since 1997
 http://www.commandprompt.com/

Donate to the PostgreSQL Project: http://www.postgresql.org/about/donate
PostgreSQL Replication: http://www.commandprompt.com/products/


---(end of broadcast)---
TIP 3: Have you checked our extensive FAQ?

  http://www.postgresql.org/docs/faq


Re: [HACKERS] Selecting a constant question: A summary

2007-06-12 Thread Josh Berkus
Dan,

 Secondly, we
 believe that we should treat the customers the way that we want to be
 treated.
 I think that the PostgreSQL group has managed the first objective, but
 not the second. 

I just read this whole thread, and I feel that the sort of comment above is 
completely unjustified, and counterproductive to your goal of adding a 
feature to PostgreSQL which will make your driver work better.  You'll be a 
lot more likely to persuade people in the community to work with you if 
you're not trying to convince them to change the project culture at the same 
time.

You are on the developer mailing list for an open, community-based open source 
project and *not* a commercial company.  Therefore we do not have customers 
and your paradigm is wrong.  The PostgreSQL developers *are* treating you 
exactly has they expect to be treated; as a developer, meaning that you argue 
things out and defend your desire for a change.  If you read anybody else's 
discussion on this list you'll see that's how everyone else interacts.

If anything you've gotten more than your fair share of attention ... 40+ posts 
from 1/2 dozen senior developers in less than 48 hours!

If you would prefer a more formal customer-vendor relationship, then I suggest 
that you sign up as a customer of EnterpriseDB, Red Hat, Sun, Command Prompt, 
SRA etc. or similar.

Now, that aside:

 According to SQL/CLI and ODBC 3.5, we should bind the length of a
 character column.

This is a much better approach.  Standards are always nice.

 But it would be very nice if the database could provide a good estimate
 for us so that PostgreSQL could work like all of the other database
 systems.  Code full of kludges is harder to maintain.

Do you have any information about how binding works in other databases?  A 
clear roadmap would make it easier for eventual developer implementation, and 
obviously this is a solved problem elsewhere.

 And so I hope that we can get off on a better foot this time.  If the
 answer is No, the priority for this sort of thing is low, and we do not
 consider it important for our customers.

Again, we don't have customers.   So your desire to implement a change in 
behavior is dependant on:
1. Getting this list to agree on the specification;
2. Convincing an *individual* PostgreSQL developer or contributing company 
that this issue is in their high priority interest to fix, 
   OR
  Fixing it yourself and submitting the patch to PostgreSQL.org.

 Then we will have to work 
 around it.  Hopefully, at least, it will get put into a queue of future
 enhancements.

Getting it on the TODO list is a good first step.  However, that doesn't get 
it implemented until it becomes some other developer's problem as well.

-- 
Josh Berkus
PostgreSQL @ Sun
San Francisco

---(end of broadcast)---
TIP 2: Don't 'kill -9' the postmaster


Re: [pgsql-www] [HACKERS] Avoiding legal email signatures

2007-06-12 Thread Andrew Hammond

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 6/12/07, Tom Lane  wrote:

A more serious objection is that any automated tool would probably get it
wrong sometimes, and strip important text.

 I vote 'lets not bother'

Right.  I agree with Josh's idea about mentioning list policies in the
subscription confirmation message, though.


Why? If the legal mumbo-jumbo has already got some precedence as being
un-enforcable (even if it's only in a handful of jurisdictions), why
give it even a patina of credibility by addressing it in a policy?
Saying that it's not applicable here implies that is is applicable
elsewhere. To quote Ghandi first they laugh at you, then they ignore
you, then they fight you, then you win. I say we stick with the
laughing. To that end, I propose should have a policy about being
pelted with scathing sarcasm when the signal to boilerplate ratio
drops below 10:1.

Andrew
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.7 (Darwin)

iD8DBQFGbxln+zlEYLc6JJgRAuaNAJsECSRrgIqR1f5c15P7OszVa34lVgCghWSb
io55WHyChKGQVHCQ9R+z2ec=
=KNyQ
-END PGP SIGNATURE-

---(end of broadcast)---
TIP 6: explain analyze is your friend


Re: [HACKERS] Selecting a constant question: A summary

2007-06-12 Thread Tom Lane
Dann Corbit [EMAIL PROTECTED] writes:
 In the case of a SELECT query that selects a fixed constant of any sort,
 it would be a definite improvement for PostgreSQL to give some sort of
 upper maximum.

What's the point?  You keep reminding us that your code is middleware
that can't assume anything much about the queries you're dealing with.
Therefore, I see no real value in fixing up one corner case.  Your
argument about space allocation falls to the ground unless we can
provide a guaranteed, and usefully tight, upper bound on the column
width in *every* situation.  If we cannot (which we can't), you're still
going to need those client-side kluges.

In my opinion, variable-length data is a fact of life and you should
endeavor to make your code deal with it gracefully.  There are bits of
the SQL spec that assume fixed-width data specifications are useful,
but to be blunt that's all a holdover from 1960s 80-column-punch-card
thinking.  It's no way to design a modern application.

BTW, the reason I'm resistant to even thinking about this is that
Postgres is designed as an extensible system.  Trying to do what you
want is not a matter of fixing literal constants and concatenation
and one or two other places --- it's a matter of imposing a new and
potentially hard-to-meet requirement on every datatype under the sun,
including a lot of user-written code that we don't control and would
break by adding such a requirement.  So it's not even likely that we'd
think very hard about making this work, let alone actually do it.

regards, tom lane

---(end of broadcast)---
TIP 7: You can help support the PostgreSQL project by donating at

http://www.postgresql.org/about/donate


Re: [pgsql-www] [HACKERS] Avoiding legal email signatures

2007-06-12 Thread Joshua D. Drake

Andrew Hammond wrote:

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 6/12/07, Tom Lane  wrote:

A more serious objection is that any automated tool would probably get it
wrong sometimes, and strip important text.

 I vote 'lets not bother'

Right.  I agree with Josh's idea about mentioning list policies in the
subscription confirmation message, though.


Why? If the legal mumbo-jumbo has already got some precedence as being
un-enforcable (even if it's only in a handful of jurisdictions), why
give it even a patina of credibility by addressing it in a policy?


We are addressing the whole using postgresql.org mailing lists issue. 
The legality issue is only part of it.


It is always a good idea to document against stuff like this, just in case.

Joshua D. Drake




Saying that it's not applicable here implies that is is applicable
elsewhere. To quote Ghandi first they laugh at you, then they ignore
you, then they fight you, then you win. I say we stick with the
laughing. To that end, I propose should have a policy about being
pelted with scathing sarcasm when the signal to boilerplate ratio
drops below 10:1.

Andrew
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.7 (Darwin)

iD8DBQFGbxln+zlEYLc6JJgRAuaNAJsECSRrgIqR1f5c15P7OszVa34lVgCghWSb
io55WHyChKGQVHCQ9R+z2ec=
=KNyQ
-END PGP SIGNATURE-

---(end of broadcast)---
TIP 4: Have you searched our list archives?

  http://archives.postgresql.org




--

  === The PostgreSQL Company: Command Prompt, Inc. ===
Sales/Support: +1.503.667.4564 || 24x7/Emergency: +1.800.492.2240
Providing the most comprehensive  PostgreSQL solutions since 1997
 http://www.commandprompt.com/

Donate to the PostgreSQL Project: http://www.postgresql.org/about/donate
PostgreSQL Replication: http://www.commandprompt.com/products/


---(end of broadcast)---
TIP 4: Have you searched our list archives?

  http://archives.postgresql.org


Re: [HACKERS] one click install?

2007-06-12 Thread Andrew Hammond

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 6/12/07, Andrej Ricnik-Bay  wrote:

On 6/13/07, Andrew Hammond  wrote:
 The problem here is that there aren't really very many defined
 defaults, or that these defaults vary (sometimes greatly) between the
 different flavors of UNIX. For example, please tell me:

 1) Where should PGDATA default to?
 2) How do you want to handle logging output from the postmaster? There
 are plenty of options...
 3) Where should those log files get written?
 4) For 1 and 3, will that support multiple major versions of
 PostgreSQL? (ie, can I have 8.2.latest and 8.1.latest installed at the
 same time)
 5) How about multiple postmasters (on different ports)?
Exactly :} ... all very good points... and then there's still the
ownerships of processes and directories/files, and their perms.
And integration with the init-scripts.  And how e.g. the environment
variables for users should be handled.

 I think that the community would be well served by standardizing on
 these things, at least for basic installations.
But whose decision should that be?
The postgres' developers?
I think that the defaults that the configure script suggests are
quite sane, and happily use them in my Slackware installations.


They're reasonable for a system which only wants a single version of
the binaries installed at any given time. Generally I want to have at
least two binaries on a production server at any given time: the one
I'm running and either the one I'm upgrading to or the one I just
upgraded from. Adding slony into the mix makes things even more
complicated along those lines.


Linux File system Hierarchy standards?  Which major distro(s)? And
what about the BSDs (or the commercial Unices supported)?


I think a cage match would be a good way to settle this, and we could
use money collected by selling the even to pay-per-view to fund
development of Optimizer Hints.

Seriously though, just having some suggestions about where these
things belong in the docs wouldn't hurt and might actually lead to
some convergence.


And while at it: who would define what a basic installation is? :)


I'd be willing to take a stab at that one (since it's pretty easy).

A basic installation is any install where the person or software doing
the install doesn't care about anything more than getting postgres
running (NB: no mention of version numbers, performance requirements,
or... well... anything a serious use would care about).

Andrew
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.7 (Darwin)

iD8DBQFGbxz3+zlEYLc6JJgRAnEQAJ9o24X5zzn6CK05G3DpBF2j5ckQiwCginrc
SjIbaI5I80rzWpicvtQR4Yo=
=R4hG
-END PGP SIGNATURE-

---(end of broadcast)---
TIP 2: Don't 'kill -9' the postmaster


Re: [HACKERS] Selecting a constant question: A summary

2007-06-12 Thread Larry McGhaw
As Dann pointed out we were one of the first companies to port Postgres
to windows many many years ago (7.1 days), and part of that porting work
is in the current postgresql product.

As I pointed out in a prior post, for the ODBC specification at least
(probably others), a maximum upper bound on returned data *must* be
reported and determined ahead of time when using binding ... A technique
where the client application allocates memory for the data and supplies
a pointer to that memory location for the driver.

Postgres unlike other databases shifts the burden of determining this
maximum size to the client and/or driver.  Our company specializes in
access to wide variety of databases, both relational and non relational,
including SQL Server, Oracle, DB2, Sybase, Informix, etc.  Postgres
sticks out as the only database that we have encountered with this
behavior .. Which is why we posted the original message.

Also as Dann pointed out even if this issue was addressed, it does not
help us because every existing installation of Postgres has the metadata
bug, so we *have* to bandaid it at the client/driver level anyway.

At least we have a record of the issue, so the next time a developer in
the community runs across the same oddity hopefully they will find this
and won't be scratching their heads like we were for a bit :)

Thanks

lm 

-Original Message-
From: Tom Lane [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, June 12, 2007 3:11 PM
To: Dann Corbit
Cc: pgsql-hackers@postgresql.org; Larry McGhaw
Subject: Re: [HACKERS] Selecting a constant question: A summary 

Dann Corbit [EMAIL PROTECTED] writes:
 In the case of a SELECT query that selects a fixed constant of any 
 sort, it would be a definite improvement for PostgreSQL to give some 
 sort of upper maximum.

What's the point?  You keep reminding us that your code is middleware
that can't assume anything much about the queries you're dealing with.
Therefore, I see no real value in fixing up one corner case.  Your
argument about space allocation falls to the ground unless we can
provide a guaranteed, and usefully tight, upper bound on the column
width in *every* situation.  If we cannot (which we can't), you're still
going to need those client-side kluges.

In my opinion, variable-length data is a fact of life and you should
endeavor to make your code deal with it gracefully.  There are bits of
the SQL spec that assume fixed-width data specifications are useful, but
to be blunt that's all a holdover from 1960s 80-column-punch-card
thinking.  It's no way to design a modern application.

BTW, the reason I'm resistant to even thinking about this is that
Postgres is designed as an extensible system.  Trying to do what you
want is not a matter of fixing literal constants and concatenation and
one or two other places --- it's a matter of imposing a new and
potentially hard-to-meet requirement on every datatype under the sun,
including a lot of user-written code that we don't control and would
break by adding such a requirement.  So it's not even likely that we'd
think very hard about making this work, let alone actually do it.

regards, tom lane

---(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: [pgsql-www] [HACKERS] Avoiding legal email signatures

2007-06-12 Thread Tom Lane
Joshua D. Drake [EMAIL PROTECTED] writes:
 Andrew Hammond wrote:
 Why? If the legal mumbo-jumbo has already got some precedence as being
 un-enforcable (even if it's only in a handful of jurisdictions), why
 give it even a patina of credibility by addressing it in a policy?

 It is always a good idea to document against stuff like this, just in case.

If push came to shove, which I sure hope it never does, being able to
say you agreed to these terms of use of the mailing lists would be
an excellent defense.  They'd have to argue that's not binding because
we didn't legally agree, whereupon we could reply sure, and your
disclaimer is equally not binding because we didn't agree to it.
Whereupon they slink away quietly.  Without such a reply they might
manage to get a court to listen for awhile before throwing them out.

If there's anything I've learned about matters legalistic, it's that
it's always better to have more than one line of defense.

regards, tom lane

---(end of broadcast)---
TIP 1: if posting/reading through Usenet, please send an appropriate
   subscribe-nomail command to [EMAIL PROTECTED] so that your
   message can get through to the mailing list cleanly


Re: [HACKERS] Selecting a constant question: A summary

2007-06-12 Thread Andrew Hammond

On 6/12/07, Josh Berkus [EMAIL PROTECTED] wrote:

Tom,

 What's the point?  You keep reminding us that your code is middleware
 that can't assume anything much about the queries you're dealing with.
 Therefore, I see no real value in fixing up one corner case.  Your
 argument about space allocation falls to the ground unless we can
 provide a guaranteed, and usefully tight, upper bound on the column
 width in *every* situation.  If we cannot (which we can't), you're still
 going to need those client-side kluges.

Hmmm?  I thought that Dann was just talking about constants, and not column
results.  Am I confused?

 BTW, the reason I'm resistant to even thinking about this is that
 Postgres is designed as an extensible system.  Trying to do what you
 want is not a matter of fixing literal constants and concatenation
 and one or two other places --- it's a matter of imposing a new and
 potentially hard-to-meet requirement on every datatype under the sun,
 including a lot of user-written code that we don't control and would
 break by adding such a requirement.  So it's not even likely that we'd
 think very hard about making this work, let alone actually do it.

I'd think it would be possible to do this in an abstract way ... having a
DisplayLength() call for each data type and value.  That would require
casting the constant, though, or computing all uncast constants as text.


The simplest formulation of this problem appears to be that constant
strings that are uncast are treated as type unknown. The connx guys
seem to think that they should be implicitly cast to char(n) where n
is the length of the string. Is that a reasonable description, or are
you guys looking for something more general?

If you're just talking about the strings, then here are the thoughts
I've gleaned from the preceding thread.

- This makes possible some performance tweaks for drivers
- It achieves spec compliance (albeit for a stupid part of the spec)
- Implicit casting of unknown to char(n) or anything else seems rather
sketchy to me, but I can't see any specific objection, except that...
- I don't know when the right time to do the cast is. And doing it too
early seems obviously wrong.
- This only helps in corner case of string constants that are
 1. not already cast and
 2. not manipulated in any way
And that seems like a very small corner case with little or no
practical use. I guess if you have some code that turns query output
into some flavor of pretty-print, it'd make sense to have a constant
column as output of a CASE statement or something.
- The corner case must already be correctly handled by the general
case for arbitrary sized text, or alternatively phrased: there is no
way to conform to the standard while supporting arbitrary sized text.
Unless you're willing to pay the cost of scanning twice, or
maintaining biggest entry data for each variable length column.
- I don't know how much effort it would require to implement this, nor
how much complexity it would add to the code base. Clearly both of
these would be non-zero values.

Given the above, I agree with Tom: this seems like corner case where
the returns are marginal at best, compared to the cost to implement
and maintain.

Is there something I'm getting wrong in this summary?

Andrew

---(end of broadcast)---
TIP 3: Have you checked our extensive FAQ?

  http://www.postgresql.org/docs/faq


Re: [HACKERS] Selecting a constant question: A summary

2007-06-12 Thread Tom Lane
Josh Berkus [EMAIL PROTECTED] writes:
 What's the point?  You keep reminding us that your code is middleware
 that can't assume anything much about the queries you're dealing with.

 Hmmm?  I thought that Dann was just talking about constants, and not column 
 results.  Am I confused?

Well, the specific example he was on about was a constant, but I don't
think it does him any good for us to fix just that one case.  He'll
still have to deal with columns of indeterminate width in a whole lot of
other cases.  If there were a reasonable path for us to report a useful
width bound in *every* case, then I could see spending time on it ...
but there's not.

BTW, it would certainly be trivial to extend libpq to report the actual
max width of a column within an already-retrieved PGresult.  This isn't
anything the client code can't compute for itself, of course, but libpq
could get it in somewhat fewer cycles.  However, I'm under the
impression that Dann wants the number at statement prepare time, and
we simply haven't got the information then.

 I'd think it would be possible to do this in an abstract way ... having a 
 DisplayLength() call for each data type and value.  That would require 
 casting the constant, though, or computing all uncast constants as text.

No, the point is about predicting the max width of a column of a query
result in advance of actually running the query.  After you've got the
values in hand, it's not a very interesting problem.  Before, well,
consider these examples:

select repeat(text_col, int_col) from my_table;
select repeat(text_col, int_col * random()) from my_table;
select repeat(text_col, some_user_defined_function(int_col)) from my_table;

The problem's really not soluble unless you want to dumb Postgres down
to approximately the capabilities of SQL89 -- no user-defined functions,
let alone user-defined types, plus pull out a whole lot of the built-in
functions that don't have readily predictable result widths.

regards, tom lane

---(end of broadcast)---
TIP 4: Have you searched our list archives?

   http://archives.postgresql.org


Re: [HACKERS] Selecting a constant question: A summary

2007-06-12 Thread Tom Lane
Andrew Hammond [EMAIL PROTECTED] writes:
 - Implicit casting of unknown to char(n) or anything else seems rather
 sketchy to me, but I can't see any specific objection, except that...
 - I don't know when the right time to do the cast is. And doing it too
 early seems obviously wrong.

Well, I don't see any reason that we'd consider an implicit cast to
char(N) without context to drive us in that direction.  The system is
currently biased to prefer casts to text.  You could make a reasonable
case for forcing a cast to text if the constant's type is still
unresolved at the end of parsing, and indeed people have proposed that
off and on just so that clients would have one less type to think about.
In itself it doesn't do anything for Dann's problem though, because
unspecified width is unspecified width.

I've been thinking lately about trying harder to unify the text and
varchar types; I'm not sure about details yet, except that text should
be *exactly* the same thing as unconstrained-width varchar, rather than
almost the same except we claim it's a different type.  The reason I'd
been thinking about this was mainly to get rid of the complexity and
runtime overhead that comes from having RelabelType nodes all over the
place when someone uses varchar instead of text.  But if we did that,
we could also arrange that unknown literals coerce to varchar(N) with
N equal to their actual width, rather than coercing to text, and not
create any weird corner-case behaviors in the type system.

But at the end of the day this all would only solve Dann's problem for
the specific case of a SELECT with an undecorated literal constant in
its target list.  He's still going to have to deal with unknown-width
columns in an enormous variety of cases, and so I completely fail to see
the point of changing the system's behavior for this one case.

regards, tom lane

---(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: [HACKERS] Selecting a constant question

2007-06-12 Thread Hannu Krosing
Ühel kenal päeval, T, 2007-06-12 kell 13:40, kirjutas Larry McGhaw:
 For what its worth .. Your statement about why we are the first people
 to mention this problem really got me thinking.  Anyone who would
 attempt to write an ODBC driver for Postgres would run into the exact
 same issue.   So I installed the official Postgres ODBC driver, and ran
 the identical query and here are my results:
 
 I probably should have looked at this first  There is a whole
 Postgres ODBC dialog dedicated to the very subject of this thread:
 Handling of unknown data sizes.   The pgodbc driver is configured to
 treat unknowns as varchar(255) by default,
 As shown by my example below.  This can be configured up or down as
 desired.

BTW, what is the reason you are writing your own ODBC driver ? 

What problems in the official one are you trying to solve ?

--
Hannu



---(end of broadcast)---
TIP 3: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faq


Re: [HACKERS] Selecting a constant question: A summary

2007-06-12 Thread Chuck McDevitt
Just a curiosity question:  Why is the type of a literal '1' unknown
instead of varchar(1)?
Wouldn't varchar(1) cast properly to any use of the literal '1'?

What is the benefit of assuming it's an unknown?




---(end of broadcast)---
TIP 7: You can help support the PostgreSQL project by donating at

http://www.postgresql.org/about/donate


Re: [HACKERS] Selecting a constant question: A summary

2007-06-12 Thread Tom Lane
Chuck McDevitt [EMAIL PROTECTED] writes:
 Just a curiosity question:  Why is the type of a literal '1' unknown
 instead of varchar(1)?

Because, for instance, it might be intended as an integer or float or
numeric value.  Change the content a little, like '(1,2)' or '12:34',
and maybe it's a point or time value.  There are plenty of contexts in
which the intended type of a literal is obviously not text/varchar.

We assign unknown initially as a way of flagging that the type
assignment is uncertain.  Once we have a value that we think is varchar
(a table column for instance), the rules for deciding to cast it to a
different type get a lot more stringent.

regards, tom lane

---(end of broadcast)---
TIP 3: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faq


Re: [HACKERS] Selecting a constant question

2007-06-12 Thread Joshua D. Drake

Hannu Krosing wrote:

Ühel kenal päeval, T, 2007-06-12 kell 13:40, kirjutas Larry McGhaw:

For what its worth .. Your statement about why we are the first people
to mention this problem really got me thinking.  Anyone who would
attempt to write an ODBC driver for Postgres would run into the exact
same issue.   So I installed the official Postgres ODBC driver, and ran
the identical query and here are my results:

I probably should have looked at this first  There is a whole
Postgres ODBC dialog dedicated to the very subject of this thread:
Handling of unknown data sizes.   The pgodbc driver is configured to
treat unknowns as varchar(255) by default,
As shown by my example below.  This can be configured up or down as
desired.


BTW, what is the reason you are writing your own ODBC driver ? 


They aren't I don't think. I think they are using the ODBC driver as an 
example.


Joshua D. Drake



What problems in the official one are you trying to solve ?

--
Hannu



---(end of broadcast)---
TIP 3: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faq




--

  === The PostgreSQL Company: Command Prompt, Inc. ===
Sales/Support: +1.503.667.4564 || 24x7/Emergency: +1.800.492.2240
Providing the most comprehensive  PostgreSQL solutions since 1997
 http://www.commandprompt.com/

Donate to the PostgreSQL Project: http://www.postgresql.org/about/donate
PostgreSQL Replication: http://www.commandprompt.com/products/



---(end of broadcast)---
TIP 1: if posting/reading through Usenet, please send an appropriate
  subscribe-nomail command to [EMAIL PROTECTED] so that your
  message can get through to the mailing list cleanly