Re: [PATCHES] psql - missing tab-completion support for tablespaces

2004-08-10 Thread Stefan Kaltenbrunner
Bruce Momjian wrote:
Stefan Kaltenbrunner wrote:
When looking through the code I found that there seem to be much more
places where the tabcomplete-code is not 100% in sync with what the
doc's show as possible syntax.
Is there interest in fixing those up (ie qualifing as BUGS that can get
fixed during BETA) ? If so I could take a look at those in the next days ...

Yes, please send in any tab completion improvements you can make.
Hi!
attached is a patch that adds/fixes several smaller things in the 
psql-tabcomplete code. This diff inculdes the TABLESPACE tab-complete 
patches I sent earlier.
Since we are in Beta now and I'm by no means a programmer, I want to 
know if this is something that is needed - or if I'm completely off-way 
with what I'm doing here and wasting your and my time ...

below is a list of the things I have changed with this patch.
*) add tablespace support for CREATE/DROP/ALTER and \db
*) sync the list of possible commands following ALTER with the docs (by 
adding 
AGGREGATE,CONVERSATION,DOMAIN,FUNCTION,LANGUAGE,OPERATOR,SEQUENCE,TABLESPACE 
and TYPE)
*) provide a list of valid users in every occurence of "OWNER TO"
*) tab-complete support for ALTER (AGGREGATE|CONVERSION|FUNCTION)
*) basic tab-complete support for ALTER DOMAIN
*) provide a list of suitable indexes following ALTER TABLE  
CLUSTER ON(?)
*) add "CLUSTER ON" and "SET" to the ALTER TABLE  - tab-complete 
list(fixes incorrect/wrong tab-complete with ALTER TABLE  SET 
+ too)
*) provide a list of possible indexes following ALTER TABLE  CLUSTER ON
*) provide list of possible commands(WITHOUT CLUSTER,WITHOUT OIDS, 
TABLESPACE) following ALTER TABLE  SET
*) sync "COMMENT ON" with docs by adding "CAST","CONVERSION","FUNCTION"
*) add ABSOLUT to the list of possible commands after FETCH
*) "END" was missing from the sql-commands overview (though it had 
completion support!) - i know it's depreciated but we have ABORT and 
others still in ...
*) fixes small buglet with ALTER (TRIGGER|CLUSTER) ON autocomplete 
(CLUSTER ON + would produce CLUSTER ON ON - same for TRIGGER ON)

and some random things I noticed that are either still missing or need 
some thought:

*) provide a list of conversions after ALTER CONVERSION (?)
*) tabcomplete-support for ALTER SEQUENCE
*) add RENAME TO to ALTER TRIGGER
*) add OWNER TO to ALTER TYPE
*) tab-completesupport for ALTER USER
*) fix ALTER (GROUP|DOMAIN|...)  DROP - autocomplete
*) RENAME TO support for ALTER LANGUAGE 
*) more complete support for COPY
*) more complete ALTER TABLE - support
Stefan
Index: src/bin/psql/tab-complete.c
===
RCS file: /projects/cvsroot/pgsql-server/src/bin/psql/tab-complete.c,v
retrieving revision 1.109
diff -u -r1.109 tab-complete.c
--- src/bin/psql/tab-complete.c 28 Jul 2004 14:23:30 -  1.109
+++ src/bin/psql/tab-complete.c 10 Aug 2004 08:24:18 -
@@ -328,6 +328,10 @@
 "SELECT pg_catalog.quote_ident(datname) FROM pg_catalog.pg_database "\
 " WHERE substring(pg_catalog.quote_ident(datname),1,%d)='%s'"
 
+#define Query_for_list_of_tablespaces \
+"SELECT pg_catalog.quote_ident(spcname) FROM pg_catalog.pg_tablespace "\
+" WHERE substring(pg_catalog.quote_ident(spcname),1,%d)='%s'"
+
 #define Query_for_list_of_encodings \
 " SELECT DISTINCT pg_catalog.pg_encoding_to_char(conforencoding) "\
 "   FROM pg_catalog.pg_conversion "\
@@ -365,6 +369,15 @@
 "   and pg_catalog.quote_ident(c2.relname)='%s'"\
 "   and pg_catalog.pg_table_is_visible(c2.oid)"
 
+/* the silly-looking length condition is just to eat up the current word */
+#define Query_for_index_of_table \
+"SELECT pg_catalog.quote_ident(c2.relname) "\
+"  FROM pg_catalog.pg_class c1, pg_catalog.pg_class c2, pg_catalog.pg_index i"\
+" WHERE c1.oid=i.indrelid and i.indexrelid=c2.oid"\
+"   and (%d = length('%s'))"\
+"   and pg_catalog.quote_ident(c1.relname)='%s'"\
+"   and pg_catalog.pg_table_is_visible(c2.oid)"
+
 /*
  * This is a list of all "things" in Pgsql, which can show up after CREATE or
  * DROP; and there is also a query to get a list of them.
@@ -394,6 +407,7 @@
{"SCHEMA", Query_for_list_of_schemas},
{"SEQUENCE", NULL, &Query_for_list_of_sequences},
{"TABLE", NULL, &Query_for_list_of_tables},
+   {"TABLESPACE", Query_for_list_of_tablespaces},
{"TEMP", NULL, NULL},   /* for CREATE TEMP TABLE ... */
{"TRIGGER", "SELECT pg_catalog.quote_ident(tgname) FROM pg_catalog.pg_trigger 
WHERE substring(pg_catalog.quote_ident(tgname),1,%d)='%s'"},
{"TYPE", NULL, &Query_for_list_of_datatypes},
@@ -461,7 +475,7 @@
 
static const char * const sql_commands[] = {
"ABORT", "ALTER", "ANALYZE", "BEGIN", "CHECKPOINT", "CLOSE", 
"CLUSTER", "COMMENT",
-   "COMMIT", "COPY", "CREATE", "DEALLOCATE", "DECLARE", "DELETE", "DROP", 
"EXECUTE",
+   "COMMIT", "COPY", "CREATE", "DEALLOCATE", "DECLARE", "DELETE", "DROP", 
"END", "EXECUTE",
"

Re: [PATCHES] fix schema ownership on first connection preliminary

2004-08-10 Thread Fabien COELHO

> > I have added the v2 version of this patch to the patch queue (attached).
>
> I do apologize for not having looked at this patch sooner, but it's been
> at the bottom of the priority queue :-(

No need to apoligize.

> In general I do not like the approach of using SPI for this. [...]

Ok.

Well, my actual motivation for using SPI is to write 3 lines of SQL were
the intent is obvious instead of 60 lines of obscure C. I'm just lazy.

> Also, since we already have AlterSchemaOwner coded at the C level,
> the original rationale of not wanting to add code has been rendered
> moot.

Well, I did not noticed this good function.

> I do not like the hardwired assumption that userID 1 exists and is
> a superuser.

With UNIX, there is a pretty hard assumption that root is number 0, and I
assumed - wrongly - that the same line of reasonning applied to pg.

> The code is also broken to assume that ID 1 is the owner of the public
> schema in the source database (though this part is at least easy to fix,
> and would go away anyway if using AlterSchemaOwner).

My implicit assumption was that if it is not 1, it means that someone
decide to give some template1 schemas to someone, and I don't have to
change that.

> However, enough about implementation deficiencies.

Anyway, it is good to know.

> Did we really have consensus that the system should do this in the first
> place?

I'm convinced that the current status is not appropriate, but that does
not mean that what the patch suggests a good fix.

The current status is that when you do "CREATE DATABASE foo WITH OWNER
calvin", user calvin which "owns" the database is prevented from
manipulating the "public" schema...

The underlying question is "what is a database owner?". My feeling is that
it is like a unix-directory owner, that is someone who can do whatever it
likes at home, but cannot change the system (/bin, /lib).

> I was only about halfway sold on the notion of changing public's
> ownership. I especially dislike the detail that it will alter the
> ownership of *all* non-builtin schemas, not only "public".  If someone
> has added special-purpose schemas to template1, it seems unlikely that
> this is the behavior they'd want.

Mmm... my assumption here was that either it is a "system" schema, and it
is special, or it is not, and then it is not special. But it is only an
assumption, which makes sense with the "unix-like" owner approach.

> I think we should leave the behavior alone, at least for this release
> cycle.

Ok. Thanks for your comments.

-- 
Fabien Coelho - [EMAIL PROTECTED]

---(end of broadcast)---
TIP 3: 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: [PATCHES] fix schema ownership on first connection preliminary

2004-08-10 Thread Fabien COELHO

Dear Bruce,

> Is there a TODO here?

I think yes. I would suggest an open entry like:

. decide what a "database owner" is expected to be able do (esp. wrt acls)
  on non-system schema, e.g. "public", and then implement it.
  - should the database owner own the "public" schema by default?
  - what about other non-system schemas?
  - what about other objects?

ISTM that it reflects that although the "what" is unclear, there is an
issue somewhere;-)

-- 
Fabien Coelho - [EMAIL PROTECTED]

---(end of broadcast)---
TIP 3: 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: [PATCHES] [BUGS] Bug: century/millenium still broken

2004-08-10 Thread Fabien COELHO

Dear Tom,

> After all that about numbering centuries and millenia correctly,
> why does CVS tip still give me
>
> regression=# select extract(century from now());
>  date_part
> ---
> 20
> (1 row)
> [ ... looks in code ... ]
>
> Apparently it's because you fixed only timestamp_part, and not
> timestamptz_part.  I'm not too sure about what timestamp_trunc or
> timestamptz_trunc should do, but they may be wrong as well.

Sigh... as usual, what is not tested does not work:-(


> Could we have a more complete patch?

Please find a submission attached. I hope it really fixes all decade,
century and millenium issues for extract and *_trunc functions on interval
and other timestamp types. If someone could check that the results
are reasonnable, it would be great.

I indeed overlooked the fact that there were two functions. The patch
fixes the code so that both variants agree.

I added comments to interval extractions, because it relies on the C
division to have a negative remainder: -7/10 = 0 and remains -7.

As for *_trunc functions, I have chosen to put the first year of the
century or millennium: -100, 1, 101... 1001 2001 etc. Indeed, I don't
think it would make sense to put 2000 (last year of the 2nd millennium)
for rounding all years of the third millenium.

I also fixed the code so that all decades last 10 years and decade 199
means the 1990's.

I have added some tests that are relevant to deal with tricky cases. The
formula may be simplified, but all these cases must pass. Please keep
them.

Have a nice day,

-- 
Fabien Coelho - [EMAIL PROTECTED]*** ./src/backend/utils/adt/timestamp.c.origFri Jun  4 15:50:58 2004
--- ./src/backend/utils/adt/timestamp.c Tue Aug 10 16:31:41 2004
***
*** 2727,2737 
fsec = 0;
break;
case DTK_MILLENNIUM:
!   tm->tm_year = (tm->tm_year / 1000) * 1000;
case DTK_CENTURY:
!   tm->tm_year = (tm->tm_year / 100) * 100;
case DTK_DECADE:
!   tm->tm_year = (tm->tm_year / 10) * 10;
case DTK_YEAR:
tm->tm_mon = 1;
case DTK_QUARTER:
--- 2727,2752 
fsec = 0;
break;
case DTK_MILLENNIUM:
!   /* see comments in timestamptz_trunc */
!   if (tm->tm_year > 0)
!   tm->tm_year = ((tm->tm_year+999) / 1000) * 
1000 - 999;
!   else
!   tm->tm_year = - ((999 - (tm->tm_year-1))/1000) 
* 1000 + 1;
case DTK_CENTURY:
!   /* see comments in timestamptz_trunc */
!   if (tm->tm_year > 0)
!   tm->tm_year = ((tm->tm_year+99) / 100) * 100 - 
99;
!   else
!   tm->tm_year = - ((99 - (tm->tm_year-1))/100) * 
100 + 1;
case DTK_DECADE:
!   /* see comments in timestamptz_trunc */
!   if (val != DTK_MILLENNIUM && val != DTK_CENTURY)
!   {
!   if (tm->tm_year > 0)
!   tm->tm_year = (tm->tm_year / 10) * 10;
!   else
!   tm->tm_year = - ((8-(tm->tm_year-1)) / 
10) * 10;
!   }
case DTK_YEAR:
tm->tm_mon = 1;
case DTK_QUARTER:
***
*** 2830,2841 
tm->tm_sec = 0;
fsec = 0;
break;
case DTK_MILLENNIUM:
!   tm->tm_year = (tm->tm_year / 1000) * 1000;
case DTK_CENTURY:
!   tm->tm_year = (tm->tm_year / 100) * 100;
case DTK_DECADE:
!   tm->tm_year = (tm->tm_year / 10) * 10;
case DTK_YEAR:
tm->tm_mon = 1;
case DTK_QUARTER:
--- 2845,2877 
tm->tm_sec = 0;
fsec = 0;
break;
+   /* one may consider DTK_THOUSAND and DTK_HUNDRED... */
case DTK_MILLENNIUM:
!   /* truncating to the millennium? what is this supposed 
to mean?
!* let us put the first year of the millennium... 
!

Re: [PATCHES] pg_dump, initdb, pg_ctl i18n-zh_CN

2004-08-10 Thread Peter Eisentraut
Weiping wrote:
> all for current source, please apply,
> thank you!

Done.

-- 
Peter Eisentraut
http://developer.postgresql.org/~petere/


---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


Re: [PATCHES] po files for libpq, psql and scripts

2004-08-10 Thread Peter Eisentraut
Weiping wrote:
> all for current code, please apply, thanks!
>
> regards laser

Done.

-- 
Peter Eisentraut
http://developer.postgresql.org/~petere/


---(end of broadcast)---
TIP 9: the planner will ignore your desire to choose an index scan if your
  joining column's datatypes do not match


Re: [PATCHES] pg_controldata i18n Zh_CN

2004-08-10 Thread Peter Eisentraut
Weiping wrote:
> please apply, thanks!
>
> regards laser

Done.

-- 
Peter Eisentraut
http://developer.postgresql.org/~petere/


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


Re: [PATCHES] Russian translation updates for 8.0

2004-08-10 Thread Peter Eisentraut
Serguei Mokhov wrote:
> This is a quick update for most files with fuzzy
> and new translations and some fixed messages.
> These are not 100% complete compared to the current CVS,
> but I started these some time ago and need them to be
> applied to easily grab the updated versions from your
> page and fix the rest.

Installed.

-- 
Peter Eisentraut
http://developer.postgresql.org/~petere/


---(end of broadcast)---
TIP 3: 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: [PATCHES] Translation updates for 7.4/8.0: postgres-ru.po.gz

2004-08-10 Thread Peter Eisentraut
Serguei Mokhov wrote:
> A few more backend translations. Please apply this
> to both, 7.4 and CVS HEAD.

Both done.

-- 
Peter Eisentraut
http://developer.postgresql.org/~petere/


---(end of broadcast)---
TIP 9: the planner will ignore your desire to choose an index scan if your
  joining column's datatypes do not match


Re: [PATCHES]postgres-zh_TW.po for current

2004-08-10 Thread Peter Eisentraut
Zhenbang Wei wrote:
> Translate 100 messages from JiaYun.

Installed.

-- 
Peter Eisentraut
http://developer.postgresql.org/~petere/


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

   http://archives.postgresql.org


Re: [PATCHES]pg_dump-zh_TW.po for current

2004-08-10 Thread Peter Eisentraut
Zhenbang Wei wrote:
> New messages translated.

Installed.

-- 
Peter Eisentraut
http://developer.postgresql.org/~petere/


---(end of broadcast)---
TIP 7: don't forget to increase your free space map settings


[PATCHES] PQserverVersion

2004-08-10 Thread Greg Sabino Mullane

Index: doc/src/sgml/libpq.sgml
===
RCS file: /projects/cvsroot/pgsql-server/doc/src/sgml/libpq.sgml,v
retrieving revision 1.157
diff -c -r1.157 libpq.sgml
*** doc/src/sgml/libpq.sgml 8 Jun 2004 13:49:22 -   1.157
--- doc/src/sgml/libpq.sgml 10 Aug 2004 15:48:59 -
***
*** 894,899 
--- 894,916 
  
  
  
+ 
+ 
PQserverVersionPQserverVersion
+ 
+ 
+  Returns an integer representing the backend version.
+ 
+ int PQseverVersion(const PGconn *conn);
+ 
+ Applications may use this to determine which version of the database they are 
+ connecting to. The number is formed by converting the major, minor, and revision 
+ numbers into two digit numbers and appending them together. For example, version 
+ 7.4.2 will be returned as 70402, and version 8.1 will be returned as 80100 
+ (leading zeroes are not shown).
+ 
+ 
+ 
+ 
  
   
PQerrorMessagePQerrorMessage
   
Index: src/interfaces/libpq/blibpqdll.def
===
RCS file: /projects/cvsroot/pgsql-server/src/interfaces/libpq/blibpqdll.def,v
retrieving revision 1.9
diff -c -r1.9 blibpqdll.def
*** src/interfaces/libpq/blibpqdll.def  13 Aug 2003 16:29:03 -  1.9
--- src/interfaces/libpq/blibpqdll.def  10 Aug 2004 15:49:00 -
***
*** 113,118 
--- 113,120 
  _PQfformat   @ 109
  _PQexecPrepared  @ 110
  _PQsendQueryPrepared @ 111
+ _PQdsplen@ 112
+ _PQseverVersion  @ 113
  
  ; Aliases for MS compatible names
  PQconnectdb = _PQconnectdb
***
*** 226,228 
--- 228,232 
  PQfformat   = _PQfformat
  PQexecPrepared  = _PQexecPrepared
  PQsendQueryPrepared = _PQsendQueryPrepared
+ PQdsplen= _PQdsplen
+ PQserverVersion = _PQserverVersion
Index: src/interfaces/libpq/fe-connect.c
===
RCS file: /projects/cvsroot/pgsql-server/src/interfaces/libpq/fe-connect.c,v
retrieving revision 1.278
diff -c -r1.278 fe-connect.c
*** src/interfaces/libpq/fe-connect.c   12 Jul 2004 14:23:28 -  1.278
--- src/interfaces/libpq/fe-connect.c   10 Aug 2004 15:49:00 -
***
*** 2872,2877 
--- 2872,2887 
return PG_PROTOCOL_MAJOR(conn->pversion);
  }
  
+ int
+ PQserverVersion(const PGconn *conn)
+ {
+   if (!conn)
+   return 0;
+   if (conn->status == CONNECTION_BAD)
+   return 0;
+   return conn->sversion;
+ }
+ 
  char *
  PQerrorMessage(const PGconn *conn)
  {
Index: src/interfaces/libpq/libpq-fe.h
===
RCS file: /projects/cvsroot/pgsql-server/src/interfaces/libpq/libpq-fe.h,v
retrieving revision 1.104
diff -c -r1.104 libpq-fe.h
*** src/interfaces/libpq/libpq-fe.h 24 Mar 2004 03:44:59 -  1.104
--- src/interfaces/libpq/libpq-fe.h 10 Aug 2004 15:49:00 -
***
*** 248,253 
--- 248,254 
  extern const char *PQparameterStatus(const PGconn *conn,
  const char *paramName);
  extern intPQprotocolVersion(const PGconn *conn);
+ extern int  PQserverVersion(const PGconn *conn);
  extern char *PQerrorMessage(const PGconn *conn);
  extern intPQsocket(const PGconn *conn);
  extern intPQbackendPID(const PGconn *conn);
Index: src/interfaces/libpq/libpqddll.def
===
RCS file: /projects/cvsroot/pgsql-server/src/interfaces/libpq/libpqddll.def,v
retrieving revision 1.1
diff -c -r1.1 libpqddll.def
*** src/interfaces/libpq/libpqddll.def  9 Mar 2004 04:53:37 -   1.1
--- src/interfaces/libpq/libpqddll.def  10 Aug 2004 15:49:00 -
***
*** 113,115 
--- 113,117 
  PQfformat   @ 109
  PQexecPrepared  @ 110
  PQsendQueryPrepared @ 111
+ PQdsplen@ 112
+ PQserverVersion @ 113
Index: src/interfaces/libpq/libpqdll.def
===
RCS file: /projects/cvsroot/pgsql-server/src/interfaces/libpq/libpqdll.def,v
retrieving revision 1.25
diff -c -r1.25 libpqdll.def
*** src/interfaces/libpq/libpqdll.def   5 Apr 2004 03:16:21 -   1.25
--- src/interfaces/libpq/libpqdll.def   10 Aug 2004 15:49:00 -
***
*** 114,116 
--- 114,117 
  PQexecPrepared  @ 110
  PQsendQueryPrepared @ 111
  PQdsplen@ 112
+ PQserverVersion @ 113




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


[PATCHES] Forwarded mail....

2004-08-10 Thread Jon Jensen
Committers,

I just installed PostgreSQL 8.0 beta 1 and found that initdb isn't
supporting the -s alias for the --show option as it claims to. The
trivial patch below fixes that and little misspellings in a comment.

Jon

-- 
Jon Jensen
End Point Corporation
http://www.endpoint.com/
Software development with Interchange, Perl, PostgreSQL, Apache, Linux, ...



--- postgresql-8.0.0beta1/src/bin/initdb/initdb.c   2004-08-01 06:19:23.0 
+
+++ ../postgresql-8.0.0beta1/src/bin/initdb/initdb.c2004-08-11 04:42:13.0 
+
@@ -2049,7 +2049,7 @@
 
/* process command-line options */
 
-   while ((c = getopt_long(argc, argv, "dD:E:L:nU:WA:", long_options, 
&option_index)) != -1)
+   while ((c = getopt_long(argc, argv, "dD:E:L:nU:WA:s", long_options, 
&option_index)) != -1)
{
switch (c)
{
@@ -2198,8 +2198,8 @@
 
/*
 * we have to set PGDATA for postgres rather than pass it on the
-* commnd line to avoid dumb quoting problems on Windows, and we would
-* expecially need quotes otherwise on Windows because paths there are
+* command line to avoid dumb quoting problems on Windows, and we would
+* especially need quotes otherwise on Windows because paths there are
 * most likely to have embedded spaces.
 */
pgdenv = xmalloc(8 + strlen(pg_data));

---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


[PATCHES] Translation updates: pg_ctl-ru.po.gz

2004-08-10 Thread Serguei Mokhov
Hello Peter,

Forgot to attach translated pg_ctl last time.
Please, install.

Thank you,

-s

 pg_ctl-ru.po.gz

pg_ctl-ru.po.gz
Description: GNU Zip compressed data

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

   http://archives.postgresql.org