Re: [PATCHES] Add remove duplicate slashes to canonicalize_path()

2004-11-07 Thread Reini Urban
Bruce Momjian schrieb:
The following applied patch removes duplicate slashes from the path in
canonicalize_path().  It preserve double leading slashes on Win32.
e.g.	ab = /a/b
snip
   *o  make Win32 path use Unix slashes
   *o  remove trailing quote on Win32
   *o  remove trailing slash
   *o  remove trailing '.'
   *o  process trailing '..' ourselves
At the first glance I thought this will break Win95 (via cygwin), but it 
really is ok, 'cause all the paths go through cygwin.
--
Reini Urban
http://xarch.tu-graz.ac.at/home/rurban/

---(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] contrib/xml2: add function xml_encode_special_chars

2004-11-07 Thread Simon Riggs
On Sat, 2004-11-06 at 23:42, Markus Bertheau wrote:
  , 06.11.2004,  23:13, Simon Riggs :
  On Sat, 2004-11-06 at 00:36, Markus Bertheau wrote:
, 06.11.2004,  01:24, Peter Eisentraut :
Markus Bertheau wrote:
 attached is a patch that adds the function xml_encode_special_chars
 to the xml2 contrib module. It's against 8.0beta4. It's intended for
 commit.

Would you also tell us what this function does?
   
   It calls the similarly named function from libxml2. It replaces
   characters that carry a special meaning in XML (, , ,  and \r) with
   their respective XML entities.
  
  Wow! Hadn't noticed xml2 didn't do that. Thats pretty important...
 
 What do you mean, it didn't do that? Where had you expected it to do
 that?

eh? I'm agreeing that your patch is important... 

-- 
Best Regards, Simon Riggs


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

   http://www.postgresql.org/docs/faqs/FAQ.html


[PATCHES] pgxs under Win32 for PL/Java

2004-11-07 Thread Fabien COELHO

Dear Thomas,

 I'm trying to change the Makefile system for PL/Java so that it uses
 PGXS instead of compiling using a complete PostgreSQL source tree. As it
 turns out, the directory include/port/win32 is not present in the
 PostgreSQL binary installation. Without it, it's not possible to compile
 on win32.

Please find enclosed a patch which attempts to fix your use of pgxs under
win32:
- install port/* includes
- install libpostgres.a by default (it seems to require MAKE_DLL=true)
- fix include path under win32 portname

The specific win32 fixes are performed in the Makefile.win32 file.

I have no mean to test that on a win32 machine. Could you do it?

I'm wondering whether the MAKE_DLL fix should also be done under cygwin.
Any opinion?

Thanks in advance,

-- 
Fabien Coelho - [EMAIL PROTECTED]*** ./src/include/Makefile.orig Wed Nov  3 10:32:29 2004
--- ./src/include/Makefile  Sun Nov  7 11:14:52 2004
***
*** 18,24 
  
  # Subdirectories containing headers for server-side dev
  SUBDIRS = access bootstrap catalog commands executor lib libpq mb \
!   nodes optimizer parser port regex rewrite storage tcop utils
  
  # Install all headers
  install: all installdirs remove-old-headers
--- 18,25 
  
  # Subdirectories containing headers for server-side dev
  SUBDIRS = access bootstrap catalog commands executor lib libpq mb \
!   nodes optimizer parser port regex rewrite storage tcop utils \
!   port port/win32 port/win32/arpa port/win32/netinet port/win32/sys
  
  # Install all headers
  install: all installdirs remove-old-headers
*** ./src/makefiles/Makefile.win32.orig Thu Oct 28 08:24:17 2004
--- ./src/makefiles/Makefile.win32  Sun Nov  7 10:44:58 2004
***
*** 35,37 
--- 35,48 
  ifneq (,$(findstring src/pl/plpython,$(subdir)))
  override CPPFLAGS+= -DUSE_DL_IMPORT
  endif
+ 
+ # special win32 headers are provided here
+ ifdef PGXS
+ override CPPFLAGS+= $(includedir_server)/port/win32
+ endif
+ 
+ # it is better to install shared-libraries anyway?
+ # may be overriden with make MAKE_DLL=false install
+ ifndef MAKE_DLL
+ MAKE_DLL  = true
+ endif

---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send unregister YourEmailAddressHere to [EMAIL PROTECTED])


Re: [PATCHES] pgxs under Win32 for PL/Java

2004-11-07 Thread Thomas Hallgren
Fabien COELHO wrote:
I have no mean to test that on a win32 machine. Could you do it?
 

Sure, I'll test it sometime tomorrow or the day after. I'll get back to you.
I'm wondering whether the MAKE_DLL fix should also be done under cygwin.
Any opinion?
 

I can test cygwin too. But just out of curiosity; why would anyone want 
to use cygwin with 8.0?

Regards,
Thomas Hallgren

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


Re: [PATCHES] GiST: memory allocation, cleanup

2004-11-07 Thread Neil Conway
Tom Lane wrote:
I think you can assume that noplace else in the backend will invoke the
sk_func, period.
Great, thanks for the info.
- mark the array that indicates NULLs that is passed to
index_formtuple() as 'const', and fix the resulting fallout
I'm a bit dubious about this, mainly because you did not likewise
const-ify the other input arguments; it seems confusing to do a partial
const-ification.
Well, partial const-ification is the rule rather than the exception in 
the backend right now. I'll take a look at adding more const qualifiers, 
but I don't really see why partial const-ification is confusing.

The only thing I don't like about this is that it's not apparent that
the function would close the heap  index relations, so the calling code
will now look like it's leaking the relation references.  Maybe call it
IndexCloseAndUpdateStats or something like that?
Good point -- I'll make that change.
-Neil
---(end of broadcast)---
TIP 6: Have you searched our list archives?
  http://archives.postgresql.org


Re: [PATCHES] pgxs under Win32 for PL/Java

2004-11-07 Thread Magnus Hagander
I can test cygwin too. But just out of curiosity; why would 
anyone want 
to use cygwin with 8.0?

It runs on 9x, native requires NT. There are still a lot of ppl on 9x. I
wouldn't expect a production server on 9x (indeed not a server at all),
but certainly some desktops that are using it.

//Magnus

---(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] contrib/xml2: add function xml_encode_special_chars

2004-11-07 Thread Simon Riggs
On Sun, 2004-11-07 at 12:56, Markus Bertheau wrote:
  , 07.11.2004,  09:33, Simon Riggs :
  On Sat, 2004-11-06 at 23:42, Markus Bertheau wrote:
, 06.11.2004,  23:13, Simon Riggs :
On Sat, 2004-11-06 at 00:36, Markus Bertheau wrote:
  , 06.11.2004,  01:24, Peter Eisentraut :
  Markus Bertheau wrote:
   attached is a patch that adds the function 
   xml_encode_special_chars
   to the xml2 contrib module. It's against 8.0beta4. It's intended 
   for
   commit.
  
  Would you also tell us what this function does?
 
 It calls the similarly named function from libxml2. It replaces
 characters that carry a special meaning in XML (, , ,  and \r) 
 with
 their respective XML entities.

Wow! Hadn't noticed xml2 didn't do that. Thats pretty important...
   
   What do you mean, it didn't do that? Where had you expected it to do
   that?
  
  eh? I'm agreeing that your patch is important... 
 
 I didn't question that :) I just don't understand what you mean with
 xml2 doesn't do that - do you mean that you thought that that function
 was already there? Or that special character encoding already takes
 place somewhere else in xml2? I can't imagine where that would be, so I
 asked :)

I mistakenly assumed that the special character encoding took place
automatically, without calling a specific function.

It's pretty fragile without that, but you could go a long way before the
lack of it hit you in the face, then no further.

-- 
Best Regards, Simon Riggs


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


[PATCHES] regression alternative for float8/openbsd

2004-11-07 Thread Andrew Dunstan
The attached alternative regression test result should fix the 
regression test problem seen here on OpenBSD:

http://www.pgbuildfarm.org/cgi-bin/show_log.pl?nm=emudt=2004-11-07%2011:35:03
cheers
andrew

--
-- FLOAT8
--
CREATE TABLE FLOAT8_TBL(f1 float8);
INSERT INTO FLOAT8_TBL(f1) VALUES ('0.0   ');
INSERT INTO FLOAT8_TBL(f1) VALUES ('1004.30  ');
INSERT INTO FLOAT8_TBL(f1) VALUES ('   -34.84');
INSERT INTO FLOAT8_TBL(f1) VALUES ('1.2345678901234e+200');
INSERT INTO FLOAT8_TBL(f1) VALUES ('1.2345678901234e-200');
-- test for underflow and overflow handling
SELECT '10e400'::float8;
ERROR:  10e400 is out of range for type double precision
SELECT '-10e400'::float8;
ERROR:  -10e400 is out of range for type double precision
SELECT '10e-400'::float8;
 float8 

 0
(1 row)

SELECT '-10e-400'::float8;
 float8 

 0
(1 row)

-- bad input
INSERT INTO FLOAT8_TBL(f1) VALUES (' ');
ERROR:  invalid input syntax for type double precision:  
INSERT INTO FLOAT8_TBL(f1) VALUES ('xyz');
ERROR:  invalid input syntax for type double precision: xyz
INSERT INTO FLOAT8_TBL(f1) VALUES ('5.0.0');
ERROR:  invalid input syntax for type double precision: 5.0.0
INSERT INTO FLOAT8_TBL(f1) VALUES ('5 . 0');
ERROR:  invalid input syntax for type double precision: 5 . 0
INSERT INTO FLOAT8_TBL(f1) VALUES ('5.   0');
ERROR:  invalid input syntax for type double precision: 5.   0
INSERT INTO FLOAT8_TBL(f1) VALUES ('- 3');
ERROR:  invalid input syntax for type double precision: - 3
INSERT INTO FLOAT8_TBL(f1) VALUES ('123   5');
ERROR:  invalid input syntax for type double precision: 123   5
-- special inputs
SELECT 'NaN'::float8;
 float8 

NaN
(1 row)

SELECT 'nan'::float8;
 float8 

NaN
(1 row)

SELECT '   NAN  '::float8;
 float8 

NaN
(1 row)

SELECT 'infinity'::float8;
  float8  
--
 Infinity
(1 row)

SELECT '  -INFINiTY   '::float8;
  float8   
---
 -Infinity
(1 row)

-- bad special inputs
SELECT 'N A N'::float8;
ERROR:  invalid input syntax for type double precision: N A N
SELECT 'NaN x'::float8;
ERROR:  invalid input syntax for type double precision: NaN x
SELECT ' INFINITYx'::float8;
ERROR:  invalid input syntax for type double precision:  INFINITYx
SELECT 'Infinity'::float8 + 100.0;
ERROR:  type double precision value out of range: overflow
SELECT 'Infinity'::float8 / 'Infinity'::float8;
 ?column? 
--
  NaN
(1 row)

SELECT 'nan'::float8 / 'nan'::float8;
 ?column? 
--
  NaN
(1 row)

SELECT '' AS five, FLOAT8_TBL.*;
 five |  f1  
--+--
  |0
  |   1004.3
  |   -34.84
  | 1.2345678901234e+200
  | 1.2345678901234e-200
(5 rows)

SELECT '' AS four, f.* FROM FLOAT8_TBL f WHERE f.f1  '1004.3';
 four |  f1  
--+--
  |0
  |   -34.84
  | 1.2345678901234e+200
  | 1.2345678901234e-200
(4 rows)

SELECT '' AS one, f.* FROM FLOAT8_TBL f WHERE f.f1 = '1004.3';
 one |   f1   
-+
 | 1004.3
(1 row)

SELECT '' AS three, f.* FROM FLOAT8_TBL f WHERE '1004.3'  f.f1;
 three |  f1  
---+--
   |0
   |   -34.84
   | 1.2345678901234e-200
(3 rows)

SELECT '' AS three, f.* FROM FLOAT8_TBL f WHERE  f.f1  '1004.3';
 three |  f1  
---+--
   |0
   |   -34.84
   | 1.2345678901234e-200
(3 rows)

SELECT '' AS four, f.* FROM FLOAT8_TBL f WHERE '1004.3' = f.f1;
 four |  f1  
--+--
  |0
  |   1004.3
  |   -34.84
  | 1.2345678901234e-200
(4 rows)

SELECT '' AS four, f.* FROM FLOAT8_TBL f WHERE  f.f1 = '1004.3';
 four |  f1  
--+--
  |0
  |   1004.3
  |   -34.84
  | 1.2345678901234e-200
(4 rows)

SELECT '' AS three, f.f1, f.f1 * '-10' AS x 
   FROM FLOAT8_TBL f
   WHERE f.f1  '0.0';
 three |  f1  |   x   
---+--+---
   |   1004.3 |-10043
   | 1.2345678901234e+200 | -1.2345678901234e+201
   | 1.2345678901234e-200 | -1.2345678901234e-199
(3 rows)

SELECT '' AS three, f.f1, f.f1 + '-10' AS x
   FROM FLOAT8_TBL f
   WHERE f.f1  '0.0';
 three |  f1  |  x   
---+--+--
   |   1004.3 |994.3
   | 1.2345678901234e+200 | 1.2345678901234e+200
   | 1.2345678901234e-200 |  -10
(3 rows)

SELECT '' AS three, f.f1, f.f1 / '-10' AS x
   FROM FLOAT8_TBL f
   WHERE f.f1  '0.0';
 three |  f1  |   x   

[PATCHES] New translation for 8.0: Romanian

2004-11-07 Thread Alin Vaida
As this is a  new translation, please make sure that it gets added to 
src/initdb/nls.mk

Thank you,
Alin Vaida


initdb-ro.po
Description: application/gettext

---(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] GiST: memory allocation, cleanup

2004-11-07 Thread Tom Lane
Neil Conway [EMAIL PROTECTED] writes:
 Tom Lane wrote:
 I'm a bit dubious about this, mainly because you did not likewise
 const-ify the other input arguments; it seems confusing to do a partial
 const-ification.

 Well, partial const-ification is the rule rather than the exception in 
 the backend right now. I'll take a look at adding more const qualifiers, 
 but I don't really see why partial const-ification is confusing.

In this particular case I think it's confusing because the Datum and
nulls arrays are really two halves of a single data structure.
Const-ifying just one of them obscures that fact.  I'd be happy if you
marked both of them const.

regards, tom lane

---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send unregister YourEmailAddressHere to [EMAIL PROTECTED])


[PATCHES] calling currval() before nextval() patch adding currval_isset()

2004-11-07 Thread John Hansen
Hi list,

attached, cvs context diff that adds currval_isset('sequence_name');

This avoids the warning messages you get when calling currval before
nextval in situations where the program flow does not allow you to
predetermine if the current session has called nexval yet.

I have for example, a general db_insert function, that needs to return
the currval value, or 0 if the table that was inserted on doesn't have a
sequence (sortof emulating mysql's last_insert_id function).

With this patch, I can now call currval_isset to determine if I need to
call currval. Previously, I just called currval, but with the result of
filling up the server log with warnings.

Kind Regards,

John Hansen

PS I picked OID 1295 for this function, as it's currently available
according to unused_oids.

===
RCS file: /projects/cvsroot/pgsql/src/backend/commands/sequence.c,v
retrieving revision 1.117
diff -c -r1.117 sequence.c
*** src/backend/commands/sequence.c 16 Sep 2004 16:58:28 -  1.117
--- src/backend/commands/sequence.c 7 Nov 2004 22:05:01 -
***
*** 608,613 
--- 608,642 
PG_RETURN_INT64(result);
  }
  
+ Datum
+ currval_isset(PG_FUNCTION_ARGS)
+ {
+   text   *seqin = PG_GETARG_TEXT_P(0);
+   RangeVar   *sequence;
+   SeqTableelm;
+   Relationseqrel;
+ 
+   sequence = makeRangeVarFromNameList(textToQualifiedNameList(seqin,
+currval));
+ 
+   /* open and AccessShareLock sequence */
+   init_sequence(sequence, elm, seqrel);
+ 
+   if (pg_class_aclcheck(elm-relid, GetUserId(), ACL_SELECT) != ACLCHECK_OK)
+   ereport(ERROR,
+   (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+errmsg(permission denied for sequence %s,
+   sequence-relname)));
+ 
+   if (elm-increment == 0) {  /* nextval/read_info were not called */
+   relation_close(seqrel, NoLock);
+   PG_RETURN_BOOL(false);
+   }
+ 
+   relation_close(seqrel, NoLock);
+   PG_RETURN_BOOL(true);
+ }
+ 
  /*
   * Main internal procedure that handles 2  3 arg forms of SETVAL.
   *
Index: src/include/catalog/pg_proc.h
===
RCS file: /projects/cvsroot/pgsql/src/include/catalog/pg_proc.h,v
retrieving revision 1.348
diff -c -r1.348 pg_proc.h
*** src/include/catalog/pg_proc.h   7 Oct 2004 18:38:50 -   1.348
--- src/include/catalog/pg_proc.h   7 Nov 2004 22:05:02 -
***
*** 2034,2039 
--- 2034,2041 
  DESCR(sequence next value);
  DATA(insert OID = 1575 (  currval PGNSP PGUID 12 f f t f v 1 20 25 _null_   currval - _null_ ));
  DESCR(sequence current value);
+ DATA(insert OID = 1295 (  currval_isset   PGNSP PGUID 12 f f t f v 1 16 25 _null_   currval_isset - _null_ ));
+ DESCR(sequence has current value);
  DATA(insert OID = 1576 (  setval  PGNSP PGUID 12 f f t f v 2 20 25 20 _null_  setval - _null_ ));
  DESCR(set sequence value);
  DATA(insert OID = 1765 (  setval  PGNSP PGUID 12 f f t f v 3 20 25 20 16 _null_ setval_and_iscalled - _null_ ));
Index: src/include/commands/sequence.h
===
RCS file: /projects/cvsroot/pgsql/src/include/commands/sequence.h,v
retrieving revision 1.29
diff -c -r1.29 sequence.h
*** src/include/commands/sequence.h 29 Aug 2004 04:13:05 -  1.29
--- src/include/commands/sequence.h 7 Nov 2004 22:05:02 -
***
*** 82,87 
--- 82,88 
  
  extern Datum nextval(PG_FUNCTION_ARGS);
  extern Datum currval(PG_FUNCTION_ARGS);
+ extern Datum currval_isset(PG_FUNCTION_ARGS);
  extern Datum setval(PG_FUNCTION_ARGS);
  extern Datum setval_and_iscalled(PG_FUNCTION_ARGS);
  

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

   http://archives.postgresql.org


[PATCHES] win32 cleanup

2004-11-07 Thread Andrew Dunstan
The attached patch adds a few prototypes and does a typecast, thus 
removing some harmless but annoying compile warnings on Win32.

cheers
andrew
Index: src/backend/port/dynloader/win32.c
===
RCS file: /home/cvsmirror/pgsql/src/backend/port/dynloader/win32.c,v
retrieving revision 1.3
diff -c -r1.3 win32.c
*** src/backend/port/dynloader/win32.c	29 Nov 2003 19:51:54 -	1.3
--- src/backend/port/dynloader/win32.c	7 Nov 2004 22:22:09 -
***
*** 2,7 
--- 2,12 
  
  #include windows.h
  
+ char * dlerror(void);
+ int dlclose(void * handle);
+ void * dlsym(void * habdle, const char *symbol);
+ void * dlopen(const char *path, int mode);
+ 
  char *
  dlerror(void)
  {
Index: src/backend/postmaster/postmaster.c
===
RCS file: /home/cvsmirror/pgsql/src/backend/postmaster/postmaster.c,v
retrieving revision 1.436
diff -c -r1.436 postmaster.c
*** src/backend/postmaster/postmaster.c	2 Nov 2004 03:34:50 -	1.436
--- src/backend/postmaster/postmaster.c	7 Nov 2004 22:22:10 -
***
*** 3735,3741 
  	 */
  	ereport(FATAL,
  			(errmsg_internal(failed to get exit code for child %lu,
! 		   win32_childPIDArray[index])));
  }
  *exitstatus = (int) exitCode;
  return win32_childPIDArray[index];
--- 3735,3741 
  	 */
  	ereport(FATAL,
  			(errmsg_internal(failed to get exit code for child %lu,
! 		   (unsigned long) win32_childPIDArray[index])));
  }
  *exitstatus = (int) exitCode;
  return win32_childPIDArray[index];
Index: src/port/open.c
===
RCS file: /home/cvsmirror/pgsql/src/port/open.c,v
retrieving revision 1.5
diff -c -r1.5 open.c
*** src/port/open.c	17 Oct 2004 23:53:30 -	1.5
--- src/port/open.c	7 Nov 2004 22:22:11 -
***
*** 18,23 
--- 18,25 
  #include errno.h
  #include assert.h
  
+ int win32_open(const char *fileName, int fileFlags, ...);
+ 
  static int
  openFlagsToCreateFileFlags(int openFlags)
  {

---(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 8.0: postgres-tr

2004-11-07 Thread Peter Eisentraut
Nicolai Tufar wrote:
 Attached is postgres-tr.po about 65% finished.

$ msgfmt -o /dev/null -c -v postgres-tr.po
postgres-tr.po:1:2: parse error
msgfmt: found 1 fatal error

Please correct that.

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


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


Re: [PATCHES] French translation updates for 8.0

2004-11-07 Thread Peter Eisentraut
Guillaume LELARGE wrote:
 Thanks. Here is the last one.

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] New translation for 8.0: Romanian

2004-11-07 Thread Peter Eisentraut
Alin Vaida wrote:
 As this is a  new translation, please make sure that it gets added to
 src/initdb/nls.mk

Done.

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


---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send unregister YourEmailAddressHere to [EMAIL PROTECTED])


Re: [PATCHES] Translation updates

2004-11-07 Thread Peter Eisentraut
Alvaro Herrera wrote:
 Attached are translation updates for libpq, psql and pg_ctl, and a
 new translation for pg_config.

Installed.

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


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


Re: [PATCHES] calling currval() before nextval() patch adding

2004-11-07 Thread Rod Taylor
On Sun, 2004-11-07 at 17:21, John Hansen wrote:
 Hi list,
 
 attached, cvs context diff that adds currval_isset('sequence_name');


 With this patch, I can now call currval_isset to determine if I need to
 call currval. Previously, I just called currval, but with the result of
 filling up the server log with warnings.

This might do what you're looking for on 8.0.

CREATE OR REPLACE FUNCTION currval_isset(text) RETURNS bigint AS '
DECLARE
  var integer;
BEGIN
  SELECT currval($1) INTO var;

  RETURN var;

EXCEPTION
  WHEN  OBJECT_NOT_IN_PREREQUISITE_STATE THEN
RETURN 0;
END;
' LANGUAGE plpgsql;

SELECT isset('tst_seq');



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


Re: [PATCHES] calling currval() before nextval() patch adding currval_isset()

2004-11-07 Thread Tom Lane
John Hansen [EMAIL PROTECTED] writes:
 attached, cvs context diff that adds currval_isset('sequence_name');

 This avoids the warning messages you get when calling currval before
 nextval in situations where the program flow does not allow you to
 predetermine if the current session has called nexval yet.

I would argue that a program written that way is broken by definition,
and we should not encourage programmers to write broken applications.

regards, tom lane

---(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] calling currval() before nextval() patch adding

2004-11-07 Thread John Hansen
 This might do what you're looking for on 8.0.
 
 CREATE OR REPLACE FUNCTION currval_isset(text) RETURNS bigint AS '
 DECLARE
   var integer;
 BEGIN
   SELECT currval($1) INTO var;
 
   RETURN var;
 
 EXCEPTION
   WHENOBJECT_NOT_IN_PREREQUISITE_STATE THEN
 RETURN 0;
 END;
 ' LANGUAGE plpgsql;
 
 SELECT isset('tst_seq');
 

k, i don't actually have an 8.0 installation to play with here,. but
won't this still produce a warning?


---(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] calling currval() before nextval() patch adding

2004-11-07 Thread John Hansen

 I would argue that a program written that way is broken by definition,
 and we should not encourage programmers to write broken applications.

Hmmm, is mysql's last_insert_id behaviour really that much to ask
for?

This is basically what I'm trying to emulate, to make porting mysql
applications easier. That is, to ADD postgresql support to applications,
that have backend specific code abstracted Many such applications
use this particular method of getting the id. the function doing the
insert only knows the tablename (by parsing the query string).

Agreed those applications should probably be completely rewritten, but
for many, including myself, that would be an effort that goes in to the
too hard basket, and thus will never see support for postgresql. Which
in my opinion is a shame.

Should there maybe instead be a .conf option that allows you to supress
the warning message given by a call to currval() before nextval() ?

currval_no_warning = true ?

... John



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


Re: [PATCHES] calling currval() before nextval() patch adding

2004-11-07 Thread John Hansen
 Hmmm, is mysql's last_insert_id behaviour really that much to ask
 for?

Come to think of it, maybe the attached last_insert_id() patch is a
better option. Actually copying the behaviour of mysql's counterpart.

... John
Index: doc/src/sgml/func.sgml
===
RCS file: /projects/cvsroot/pgsql/doc/src/sgml/func.sgml,v
retrieving revision 1.221
diff -c -r1.221 func.sgml
*** doc/src/sgml/func.sgml	26 Oct 2004 22:16:11 -	1.221
--- doc/src/sgml/func.sgml	8 Nov 2004 01:48:33 -
***
*** 6348,6353 
--- 6348,6356 
 primarycurrval/primary
/indexterm
indexterm
+primarylast_insert_id/primary
+   /indexterm
+   indexterm
 primarysetval/primary
/indexterm
  
***
*** 6382,6387 
--- 6385,6395 
  	entryReturn value most recently obtained with functionnextval/function/entry
/row
row
+ 	entryliteralfunctionlast_insert_id/function()/literal/entry
+ 	entrytypeint64/type/entry
+ 	entryReturn value generated by functionnextval/function in the current session for ANY sequence./entry
+   /row
+   row
  	entryliteralfunctionsetval/function(typetext/type, typebigint/type)/literal/entry
  	entrytypebigint/type/entry
  	entrySet sequence's current value/entry
***
*** 6447,6452 
--- 6455,6470 
   /varlistentry
  
   varlistentry
+   termfunctionlast_insert_id/function/term
+   listitem
+para
+ Return the value of last number generated by functionnextval/function for ANY sequence.
+ 	called in the current session.
+/para
+   /listitem
+  /varlistentry
+ 
+  varlistentry
termfunctionsetval/function/term
listitem
 para
Index: doc/src/sgml/ref/create_sequence.sgml
===
RCS file: /projects/cvsroot/pgsql/doc/src/sgml/ref/create_sequence.sgml,v
retrieving revision 1.41
diff -c -r1.41 create_sequence.sgml
*** doc/src/sgml/ref/create_sequence.sgml	12 Jul 2004 05:36:56 -	1.41
--- doc/src/sgml/ref/create_sequence.sgml	8 Nov 2004 01:48:33 -
***
*** 49,55 
para
 After a sequence is created, you use the functions
 functionnextval/function,
!functioncurrval/function, and
 functionsetval/function
 to operate on the sequence.  These functions are documented in
 xref linkend=functions-sequence.
--- 49,56 
para
 After a sequence is created, you use the functions
 functionnextval/function,
!functioncurrval/function,
!functionlast_insert_id/function, and
 functionsetval/function
 to operate on the sequence.  These functions are documented in
 xref linkend=functions-sequence.
Index: src/backend/commands/sequence.c
===
RCS file: /projects/cvsroot/pgsql/src/backend/commands/sequence.c,v
retrieving revision 1.117
diff -c -r1.117 sequence.c
*** src/backend/commands/sequence.c	16 Sep 2004 16:58:28 -	1.117
--- src/backend/commands/sequence.c	8 Nov 2004 01:48:33 -
***
*** 68,73 
--- 68,74 
  
  static SeqTable seqtab = NULL;	/* Head of list of SeqTable items */
  
+ static int64 _last_insert_id = 0;
  
  static void init_sequence(RangeVar *relation,
  			  SeqTable *p_elm, Relation *p_rel);
***
*** 407,412 
--- 408,414 
  	{
  		elm-last += elm-increment;
  		relation_close(seqrel, NoLock);
+ 		_last_insert_id = elm-last;
  		PG_RETURN_INT64(elm-last);
  	}
  
***
*** 570,576 
  	WriteBuffer(buf);
  
  	relation_close(seqrel, NoLock);
! 
  	PG_RETURN_INT64(result);
  }
  
--- 572,579 
  	WriteBuffer(buf);
  
  	relation_close(seqrel, NoLock);
! 
! 	_last_insert_id = result;
  	PG_RETURN_INT64(result);
  }
  
***
*** 608,613 
--- 611,622 
  	PG_RETURN_INT64(result);
  }
  
+ Datum
+ last_insert_id(PG_FUNCTION_ARGS)
+ {
+ 	PG_RETURN_INT64(_last_insert_id);
+ }
+ 
  /*
   * Main internal procedure that handles 2  3 arg forms of SETVAL.
   *
Index: src/include/catalog/pg_proc.h
===
RCS file: /projects/cvsroot/pgsql/src/include/catalog/pg_proc.h,v
retrieving revision 1.348
diff -c -r1.348 pg_proc.h
*** src/include/catalog/pg_proc.h	7 Oct 2004 18:38:50 -	1.348
--- src/include/catalog/pg_proc.h	8 Nov 2004 01:48:44 -
***
*** 2034,2039 
--- 2034,2041 
  DESCR(sequence next value);
  DATA(insert OID = 1575 (  currval			PGNSP PGUID 12 f f t f v 1 20 25 _null_	currval - _null_ ));
  DESCR(sequence current value);
+ DATA(insert OID = 1295 (  last_insert_id		PGNSP PGUID 12 f f t f v 0 20  _null_	last_insert_id - _null_ ));
+ DESCR(last generated sequence value);
  DATA(insert OID = 1576 (  setval			PGNSP PGUID 12 f f t f v 2 20 25 20 _null_  setval - _null_ ));
  DESCR(set sequence value);
  DATA(insert OID = 1765 (  setval			PGNSP 

Re: [PATCHES] calling currval() before nextval() patch adding currval_isset()

2004-11-07 Thread John Hansen
 Hi list,
 
 attached, cvs context diff that adds currval_isset('sequence_name');
 

Updated patch attached, didn't think to update the docs. Thanks oicu!

Kind Regards,

John Hansen
Index: doc/src/sgml/func.sgml
===
RCS file: /projects/cvsroot/pgsql/doc/src/sgml/func.sgml,v
retrieving revision 1.221
diff -c -r1.221 func.sgml
*** doc/src/sgml/func.sgml	26 Oct 2004 22:16:11 -	1.221
--- doc/src/sgml/func.sgml	7 Nov 2004 22:49:04 -
***
*** 6348,6353 
--- 6348,6356 
 primarycurrval/primary
/indexterm
indexterm
+primarycurrval_isset/primary
+   /indexterm
+   indexterm
 primarysetval/primary
/indexterm
  
***
*** 6382,6387 
--- 6385,6395 
  	entryReturn value most recently obtained with functionnextval/function/entry
/row
row
+ 	entryliteralfunctioncurrval_isset/function(typetext/type)/literal/entry
+ 	entrytypebool/type/entry
+ 	entryTrue if functionnextval/function has been called in the current session, indicating that functioncurrval/function would return a value./entry
+   /row
+   row
  	entryliteralfunctionsetval/function(typetext/type, typebigint/type)/literal/entry
  	entrytypebigint/type/entry
  	entrySet sequence's current value/entry
***
*** 6447,6452 
--- 6455,6472 
   /varlistentry
  
   varlistentry
+   termfunctioncurrval_isset/function/term
+   listitem
+para
+ Return true if functionnextval/function for this sequence has been
+ 	called in the current session.  Notice that because this is returning
+ 	a response based on a session-local value, it gives a predictable answer
+ 	even if other sessions are executing functionnextval/function meanwhile.
+/para
+   /listitem
+  /varlistentry
+ 
+  varlistentry
termfunctionsetval/function/term
listitem
 para
Index: doc/src/sgml/ref/create_sequence.sgml
===
RCS file: /projects/cvsroot/pgsql/doc/src/sgml/ref/create_sequence.sgml,v
retrieving revision 1.41
diff -c -r1.41 create_sequence.sgml
*** doc/src/sgml/ref/create_sequence.sgml	12 Jul 2004 05:36:56 -	1.41
--- doc/src/sgml/ref/create_sequence.sgml	7 Nov 2004 22:49:04 -
***
*** 49,55 
para
 After a sequence is created, you use the functions
 functionnextval/function,
!functioncurrval/function, and
 functionsetval/function
 to operate on the sequence.  These functions are documented in
 xref linkend=functions-sequence.
--- 49,56 
para
 After a sequence is created, you use the functions
 functionnextval/function,
!functioncurrval/function,
!functioncurrval_isset/function, and
 functionsetval/function
 to operate on the sequence.  These functions are documented in
 xref linkend=functions-sequence.
Index: src/backend/commands/sequence.c
===
RCS file: /projects/cvsroot/pgsql/src/backend/commands/sequence.c,v
retrieving revision 1.117
diff -c -r1.117 sequence.c
*** src/backend/commands/sequence.c	16 Sep 2004 16:58:28 -	1.117
--- src/backend/commands/sequence.c	7 Nov 2004 22:49:04 -
***
*** 608,613 
--- 608,642 
  	PG_RETURN_INT64(result);
  }
  
+ Datum
+ currval_isset(PG_FUNCTION_ARGS)
+ {
+ 	text	   *seqin = PG_GETARG_TEXT_P(0);
+ 	RangeVar   *sequence;
+ 	SeqTable	elm;
+ 	Relation	seqrel;
+ 
+ 	sequence = makeRangeVarFromNameList(textToQualifiedNameList(seqin,
+ 			 currval));
+ 
+ 	/* open and AccessShareLock sequence */
+ 	init_sequence(sequence, elm, seqrel);
+ 
+ 	if (pg_class_aclcheck(elm-relid, GetUserId(), ACL_SELECT) != ACLCHECK_OK)
+ 		ereport(ERROR,
+ (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+  errmsg(permission denied for sequence %s,
+ 		sequence-relname)));
+ 
+ 	if (elm-increment == 0) {	/* nextval/read_info were not called */
+ 	relation_close(seqrel, NoLock);
+ 	PG_RETURN_BOOL(false);
+ 	}
+ 
+ 	relation_close(seqrel, NoLock);
+ 	PG_RETURN_BOOL(true);
+ }
+ 
  /*
   * Main internal procedure that handles 2  3 arg forms of SETVAL.
   *
Index: src/include/catalog/pg_proc.h
===
RCS file: /projects/cvsroot/pgsql/src/include/catalog/pg_proc.h,v
retrieving revision 1.348
diff -c -r1.348 pg_proc.h
*** src/include/catalog/pg_proc.h	7 Oct 2004 18:38:50 -	1.348
--- src/include/catalog/pg_proc.h	7 Nov 2004 22:49:05 -
***
*** 2034,2039 
--- 2034,2041 
  DESCR(sequence next value);
  DATA(insert OID = 1575 (  currval			PGNSP PGUID 12 f f t f v 1 20 25 _null_	currval - _null_ ));
  DESCR(sequence current value);
+ DATA(insert OID = 1295 (  currval_isset			PGNSP PGUID 12 f f t f v 1 16 25 _null_	currval_isset - _null_ ));
+ DESCR(sequence has current value);
  DATA(insert OID = 1576 (  

[PATCHES] pgxs patch for win32 (v2)

2004-11-07 Thread Fabien COELHO
Dear patchers,
please find attached a very small patch which:
 - install win32 headers on make install
 - install libpostgres.a library under win32 by default (MAKE_DLL=true)
 - fix CPPFLAGS under win32 to look for these added header under PGXS
it was tested by Thomas Hallgren to build PL/Java with pgxs.
it may interfere a little bit with Alvaro's patch about 
the now useless remove-all-headers target in src/include/Makefile

still open question:
 - should the MAKE_DLL macro be set by default under cygwin?
 - what is the rationnal for this macro? is it still needed?
Have a nice day,
--
Fabien Coelho - [EMAIL PROTECTED]*** ./src/include/Makefile.orig Wed Nov  3 10:32:29 2004
--- ./src/include/Makefile  Sun Nov  7 11:14:52 2004
***
*** 18,24 
  
  # Subdirectories containing headers for server-side dev
  SUBDIRS = access bootstrap catalog commands executor lib libpq mb \
!   nodes optimizer parser port regex rewrite storage tcop utils
  
  # Install all headers
  install: all installdirs remove-old-headers
--- 18,25 
  
  # Subdirectories containing headers for server-side dev
  SUBDIRS = access bootstrap catalog commands executor lib libpq mb \
!   nodes optimizer parser port regex rewrite storage tcop utils \
!   port port/win32 port/win32/arpa port/win32/netinet port/win32/sys
  
  # Install all headers
  install: all installdirs remove-old-headers
*** ./src/makefiles/Makefile.win32.orig Thu Oct 28 08:24:17 2004
--- ./src/makefiles/Makefile.win32  Sun Nov  7 10:44:58 2004
***
*** 35,37 
--- 35,48 
  ifneq (,$(findstring src/pl/plpython,$(subdir)))
  override CPPFLAGS+= -DUSE_DL_IMPORT
  endif
+ 
+ # special win32 headers are provided here
+ ifdef PGXS
+ override CPPFLAGS+= -I$(includedir_server)/port/win32
+ endif
+ 
+ # it is better to install shared-libraries anyway?
+ # may be overriden with make MAKE_DLL=false install
+ ifndef MAKE_DLL
+ MAKE_DLL  = true
+ endif

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