as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
/* -----------------------------------------------------------------------
|
|
|
|
* formatting.c
|
|
|
|
*
|
2010-09-20 22:08:53 +02:00
|
|
|
* src/backend/utils/adt/formatting.c
|
2000-02-08 16:57:01 +01:00
|
|
|
*
|
|
|
|
*
|
2016-01-02 19:33:40 +01:00
|
|
|
* Portions Copyright (c) 1999-2016, PostgreSQL Global Development Group
|
2000-02-08 16:57:01 +01:00
|
|
|
*
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
*
|
2000-04-12 19:17:23 +02:00
|
|
|
* TO_CHAR(); TO_TIMESTAMP(); TO_DATE(); TO_NUMBER();
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
*
|
2000-04-12 19:17:23 +02:00
|
|
|
* The PostgreSQL routines for a timestamp/int/float/numeric formatting,
|
2002-09-20 05:54:57 +02:00
|
|
|
* inspired by the Oracle TO_CHAR() / TO_DATE() / TO_NUMBER() routines.
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
*
|
|
|
|
*
|
2000-04-12 19:17:23 +02:00
|
|
|
* Cache & Memory:
|
|
|
|
* Routines use (itself) internal cache for format pictures.
|
|
|
|
*
|
2007-02-17 02:51:42 +01:00
|
|
|
* The cache uses a static buffer and is persistent across transactions. If
|
|
|
|
* the format-picture is bigger than the cache buffer, the parser is called
|
|
|
|
* always.
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
*
|
2000-04-12 19:17:23 +02:00
|
|
|
* NOTE for Number version:
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* All in this version is implemented as keywords ( => not used
|
2000-04-12 19:17:23 +02:00
|
|
|
* suffixes), because a format picture is for *one* item (number)
|
|
|
|
* only. It not is as a timestamp version, where each keyword (can)
|
|
|
|
* has suffix.
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
*
|
2000-04-12 19:17:23 +02:00
|
|
|
* NOTE for Timestamp routines:
|
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:26:26 +01:00
|
|
|
* In this module the POSIX 'struct tm' type is *not* used, but rather
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* PgSQL type, which has tm_mon based on one (*non* zero) and
|
2000-04-12 19:17:23 +02:00
|
|
|
* year *not* based on 1900, but is used full year number.
|
2000-04-07 21:17:51 +02:00
|
|
|
* Module supports AD / BC / AM / PM.
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
*
|
2000-04-12 19:17:23 +02:00
|
|
|
* Supported types for to_char():
|
|
|
|
*
|
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:26:26 +01:00
|
|
|
* Timestamp, Numeric, int4, int8, float4, float8
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
*
|
2000-04-12 19:17:23 +02:00
|
|
|
* Supported types for reverse conversion:
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
*
|
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:26:26 +01:00
|
|
|
* Timestamp - to_timestamp()
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* Date - to_date()
|
2000-04-12 19:17:23 +02:00
|
|
|
* Numeric - to_number()
|
|
|
|
*
|
|
|
|
*
|
2000-07-03 18:01:33 +02:00
|
|
|
* Karel Zak
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
*
|
2001-10-25 07:50:21 +02:00
|
|
|
* TODO
|
|
|
|
* - better number building (formatting) / parsing, now it isn't
|
|
|
|
* ideal code
|
2001-09-12 06:01:57 +02:00
|
|
|
* - use Assert()
|
2000-12-15 20:15:09 +01:00
|
|
|
* - add support for abstime
|
|
|
|
* - add support for roman number to standard number conversion
|
|
|
|
* - add support for number spelling
|
|
|
|
* - add support for string to string formatting (we must be better
|
2001-03-22 05:01:46 +01:00
|
|
|
* than Oracle :-),
|
|
|
|
* to_char('Hello', 'X X X X X') -> 'H e l l o'
|
|
|
|
*
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* -----------------------------------------------------------------------
|
|
|
|
*/
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2009-02-07 15:16:46 +01:00
|
|
|
#ifdef DEBUG_TO_FROM_CHAR
|
2002-03-06 07:10:59 +01:00
|
|
|
#define DEBUG_elog_output DEBUG3
|
2009-02-07 15:16:46 +01:00
|
|
|
#endif
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
2001-06-25 23:11:45 +02:00
|
|
|
#include "postgres.h"
|
|
|
|
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <math.h>
|
2000-01-26 07:33:49 +01:00
|
|
|
#include <float.h>
|
2007-06-29 03:51:35 +02:00
|
|
|
#include <limits.h>
|
2008-05-19 20:08:16 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* towlower() and friends should be in <wctype.h>, but some pre-C99 systems
|
|
|
|
* declare them in <wchar.h>.
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_WCHAR_H
|
|
|
|
#include <wchar.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_WCTYPE_H
|
|
|
|
#include <wctype.h>
|
|
|
|
#endif
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
2011-02-08 22:04:18 +01:00
|
|
|
#include "catalog/pg_collation.h"
|
2009-08-10 22:16:05 +02:00
|
|
|
#include "mb/pg_wchar.h"
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
#include "utils/builtins.h"
|
2000-07-01 23:27:14 +02:00
|
|
|
#include "utils/date.h"
|
|
|
|
#include "utils/datetime.h"
|
2000-07-01 16:10:32 +02:00
|
|
|
#include "utils/formatting.h"
|
2000-07-01 23:27:14 +02:00
|
|
|
#include "utils/int8.h"
|
2001-06-25 23:11:45 +02:00
|
|
|
#include "utils/numeric.h"
|
2000-07-01 23:27:14 +02:00
|
|
|
#include "utils/pg_locale.h"
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
|
|
|
/* ----------
|
|
|
|
* Routines type
|
|
|
|
* ----------
|
|
|
|
*/
|
2000-04-12 19:17:23 +02:00
|
|
|
#define DCH_TYPE 1 /* DATE-TIME version */
|
|
|
|
#define NUM_TYPE 2 /* NUMBER version */
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
|
|
|
/* ----------
|
|
|
|
* KeyWord Index (ascii from position 32 (' ') to 126 (~))
|
|
|
|
* ----------
|
|
|
|
*/
|
2000-04-07 21:17:51 +02:00
|
|
|
#define KeyWord_INDEX_SIZE ('~' - ' ')
|
|
|
|
#define KeyWord_INDEX_FILTER(_c) ((_c) <= ' ' || (_c) >= '~' ? 0 : 1)
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
|
|
|
/* ----------
|
2000-04-12 19:17:23 +02:00
|
|
|
* Maximal length of one node
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* ----------
|
|
|
|
*/
|
2015-02-02 16:00:45 +01:00
|
|
|
#define DCH_MAX_ITEM_SIZ 12 /* max localized day name */
|
2000-04-12 19:17:23 +02:00
|
|
|
#define NUM_MAX_ITEM_SIZ 8 /* roman number (RN has 15 chars) */
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
2015-03-23 03:56:52 +01:00
|
|
|
/* ----------
|
|
|
|
* More is in float.c
|
|
|
|
* ----------
|
|
|
|
*/
|
|
|
|
#define MAXFLOATWIDTH 60
|
|
|
|
#define MAXDOUBLEWIDTH 500
|
|
|
|
|
2007-02-08 19:19:33 +01:00
|
|
|
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
/* ----------
|
2000-04-12 19:17:23 +02:00
|
|
|
* Format parser structs
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* ----------
|
|
|
|
*/
|
2000-04-12 19:17:23 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
char *name; /* suffix string */
|
|
|
|
int len, /* suffix length */
|
|
|
|
id, /* used in node->suffix */
|
|
|
|
type; /* prefix / postfix */
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
} KeySuffix;
|
|
|
|
|
2008-09-11 19:32:34 +02:00
|
|
|
/* ----------
|
|
|
|
* FromCharDateMode
|
|
|
|
* ----------
|
|
|
|
*
|
|
|
|
* This value is used to nominate one of several distinct (and mutually
|
|
|
|
* exclusive) date conventions that a keyword can belong to.
|
|
|
|
*/
|
|
|
|
typedef enum
|
|
|
|
{
|
2009-06-11 16:49:15 +02:00
|
|
|
FROM_CHAR_DATE_NONE = 0, /* Value does not affect date mode. */
|
|
|
|
FROM_CHAR_DATE_GREGORIAN, /* Gregorian (day, month, year) style date */
|
|
|
|
FROM_CHAR_DATE_ISOWEEK /* ISO 8601 week date */
|
2008-09-11 19:32:34 +02:00
|
|
|
} FromCharDateMode;
|
|
|
|
|
2004-10-13 03:25:13 +02:00
|
|
|
typedef struct FormatNode FormatNode;
|
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
2008-03-22 23:32:19 +01:00
|
|
|
const char *name;
|
|
|
|
int len;
|
|
|
|
int id;
|
|
|
|
bool is_digit;
|
2008-09-11 19:32:34 +02:00
|
|
|
FromCharDateMode date_mode;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
} KeyWord;
|
|
|
|
|
2004-10-13 03:25:13 +02:00
|
|
|
struct FormatNode
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
int type; /* node type */
|
2005-03-26 01:41:31 +01:00
|
|
|
const KeyWord *key; /* if node type is KEYWORD */
|
2008-03-22 23:32:19 +01:00
|
|
|
char character; /* if node type is CHAR */
|
|
|
|
int suffix; /* keyword suffix */
|
2004-10-13 03:25:13 +02:00
|
|
|
};
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
|
|
|
#define NODE_TYPE_END 1
|
2000-04-12 19:17:23 +02:00
|
|
|
#define NODE_TYPE_ACTION 2
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
#define NODE_TYPE_CHAR 3
|
|
|
|
|
|
|
|
#define SUFFTYPE_PREFIX 1
|
|
|
|
#define SUFFTYPE_POSTFIX 2
|
|
|
|
|
2009-02-07 15:16:46 +01:00
|
|
|
#define CLOCK_24_HOUR 0
|
|
|
|
#define CLOCK_12_HOUR 1
|
|
|
|
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
|
|
|
/* ----------
|
|
|
|
* Full months
|
|
|
|
* ----------
|
|
|
|
*/
|
2014-01-18 22:04:11 +01:00
|
|
|
static const char *const months_full[] = {
|
2000-04-12 19:17:23 +02:00
|
|
|
"January", "February", "March", "April", "May", "June", "July",
|
|
|
|
"August", "September", "October", "November", "December", NULL
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
};
|
|
|
|
|
2014-01-18 22:04:11 +01:00
|
|
|
static const char *const days_short[] = {
|
2006-02-12 05:44:15 +01:00
|
|
|
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", NULL
|
|
|
|
};
|
|
|
|
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
/* ----------
|
2008-03-22 23:32:19 +01:00
|
|
|
* AD / BC
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* ----------
|
2005-08-18 06:37:08 +02:00
|
|
|
* There is no 0 AD. Years go from 1 BC to 1 AD, so we make it
|
|
|
|
* positive and map year == -1 to year zero, and shift all negative
|
|
|
|
* years up one. For interval years, we just return the year.
|
|
|
|
*/
|
|
|
|
#define ADJUST_YEAR(year, is_interval) ((is_interval) ? (year) : ((year) <= 0 ? -((year) - 1) : (year)))
|
2000-04-07 21:17:51 +02:00
|
|
|
|
|
|
|
#define A_D_STR "A.D."
|
|
|
|
#define a_d_STR "a.d."
|
|
|
|
#define AD_STR "AD"
|
|
|
|
#define ad_STR "ad"
|
|
|
|
|
|
|
|
#define B_C_STR "B.C."
|
|
|
|
#define b_c_STR "b.c."
|
|
|
|
#define BC_STR "BC"
|
|
|
|
#define bc_STR "bc"
|
|
|
|
|
2009-02-07 15:16:46 +01:00
|
|
|
/*
|
|
|
|
* AD / BC strings for seq_search.
|
|
|
|
*
|
|
|
|
* These are given in two variants, a long form with periods and a standard
|
|
|
|
* form without.
|
|
|
|
*
|
|
|
|
* The array is laid out such that matches for AD have an even index, and
|
|
|
|
* matches for BC have an odd index. So the boolean value for BC is given by
|
|
|
|
* taking the array index of the match, modulo 2.
|
|
|
|
*/
|
2014-01-18 22:04:11 +01:00
|
|
|
static const char *const adbc_strings[] = {ad_STR, bc_STR, AD_STR, BC_STR, NULL};
|
|
|
|
static const char *const adbc_strings_long[] = {a_d_STR, b_c_STR, A_D_STR, B_C_STR, NULL};
|
2000-04-07 21:17:51 +02:00
|
|
|
|
|
|
|
/* ----------
|
|
|
|
* AM / PM
|
|
|
|
* ----------
|
|
|
|
*/
|
|
|
|
#define A_M_STR "A.M."
|
|
|
|
#define a_m_STR "a.m."
|
|
|
|
#define AM_STR "AM"
|
|
|
|
#define am_STR "am"
|
|
|
|
|
|
|
|
#define P_M_STR "P.M."
|
|
|
|
#define p_m_STR "p.m."
|
|
|
|
#define PM_STR "PM"
|
|
|
|
#define pm_STR "pm"
|
|
|
|
|
2009-02-07 15:16:46 +01:00
|
|
|
/*
|
|
|
|
* AM / PM strings for seq_search.
|
|
|
|
*
|
|
|
|
* These are given in two variants, a long form with periods and a standard
|
|
|
|
* form without.
|
|
|
|
*
|
|
|
|
* The array is laid out such that matches for AM have an even index, and
|
|
|
|
* matches for PM have an odd index. So the boolean value for PM is given by
|
|
|
|
* taking the array index of the match, modulo 2.
|
|
|
|
*/
|
2014-01-18 22:04:11 +01:00
|
|
|
static const char *const ampm_strings[] = {am_STR, pm_STR, AM_STR, PM_STR, NULL};
|
|
|
|
static const char *const ampm_strings_long[] = {a_m_STR, p_m_STR, A_M_STR, P_M_STR, NULL};
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
/* ----------
|
|
|
|
* Months in roman-numeral
|
2008-03-22 23:32:19 +01:00
|
|
|
* (Must be in reverse order for seq_search (in FROM_CHAR), because
|
|
|
|
* 'VIII' must have higher precedence than 'V')
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* ----------
|
|
|
|
*/
|
2014-01-18 22:04:11 +01:00
|
|
|
static const char *const rm_months_upper[] =
|
2000-04-12 19:17:23 +02:00
|
|
|
{"XII", "XI", "X", "IX", "VIII", "VII", "VI", "V", "IV", "III", "II", "I", NULL};
|
2000-04-07 21:17:51 +02:00
|
|
|
|
2014-01-18 22:04:11 +01:00
|
|
|
static const char *const rm_months_lower[] =
|
2000-04-12 19:17:23 +02:00
|
|
|
{"xii", "xi", "x", "ix", "viii", "vii", "vi", "v", "iv", "iii", "ii", "i", NULL};
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
|
|
|
/* ----------
|
|
|
|
* Roman numbers
|
|
|
|
* ----------
|
|
|
|
*/
|
2014-01-18 22:04:11 +01:00
|
|
|
static const char *const rm1[] = {"I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", NULL};
|
|
|
|
static const char *const rm10[] = {"X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC", NULL};
|
|
|
|
static const char *const rm100[] = {"C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM", NULL};
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
/* ----------
|
|
|
|
* Ordinal postfixes
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* ----------
|
|
|
|
*/
|
2014-01-18 22:04:11 +01:00
|
|
|
static const char *const numTH[] = {"ST", "ND", "RD", "TH", NULL};
|
|
|
|
static const char *const numth[] = {"st", "nd", "rd", "th", NULL};
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
/* ----------
|
|
|
|
* Flags & Options:
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* ----------
|
|
|
|
*/
|
2009-06-11 16:49:15 +02:00
|
|
|
#define ONE_UPPER 1 /* Name */
|
|
|
|
#define ALL_UPPER 2 /* NAME */
|
|
|
|
#define ALL_LOWER 3 /* name */
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
2009-02-07 15:16:46 +01:00
|
|
|
#define FULL_SIZ 0
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
2009-02-07 15:16:46 +01:00
|
|
|
#define MAX_MONTH_LEN 9
|
|
|
|
#define MAX_MON_LEN 3
|
|
|
|
#define MAX_DAY_LEN 9
|
|
|
|
#define MAX_DY_LEN 3
|
|
|
|
#define MAX_RM_LEN 4
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
2009-02-07 15:16:46 +01:00
|
|
|
#define TH_UPPER 1
|
|
|
|
#define TH_LOWER 2
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
|
|
|
/* ----------
|
|
|
|
* Number description struct
|
|
|
|
* ----------
|
|
|
|
*/
|
2000-04-12 19:17:23 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
int pre, /* (count) numbers before decimal */
|
|
|
|
post, /* (count) numbers after decimal */
|
|
|
|
lsign, /* want locales sign */
|
2003-03-10 23:28:22 +01:00
|
|
|
flag, /* number parameters */
|
2001-03-22 05:01:46 +01:00
|
|
|
pre_lsign_num, /* tmp value for lsign */
|
|
|
|
multi, /* multiplier for 'V' */
|
|
|
|
zero_start, /* position of first zero */
|
|
|
|
zero_end, /* position of last zero */
|
|
|
|
need_locale; /* needs it locale */
|
2014-09-13 02:42:19 +02:00
|
|
|
} NUMDesc;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
|
|
|
/* ----------
|
2000-04-12 19:17:23 +02:00
|
|
|
* Flags for NUMBER version
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* ----------
|
|
|
|
*/
|
2003-03-27 17:35:31 +01:00
|
|
|
#define NUM_F_DECIMAL (1 << 1)
|
|
|
|
#define NUM_F_LDECIMAL (1 << 2)
|
2005-05-25 23:40:43 +02:00
|
|
|
#define NUM_F_ZERO (1 << 3)
|
2003-08-04 02:43:34 +02:00
|
|
|
#define NUM_F_BLANK (1 << 4)
|
2003-03-27 17:35:31 +01:00
|
|
|
#define NUM_F_FILLMODE (1 << 5)
|
2003-08-04 02:43:34 +02:00
|
|
|
#define NUM_F_LSIGN (1 << 6)
|
2003-03-27 17:35:31 +01:00
|
|
|
#define NUM_F_BRACKET (1 << 7)
|
2003-08-04 02:43:34 +02:00
|
|
|
#define NUM_F_MINUS (1 << 8)
|
2005-05-25 23:40:43 +02:00
|
|
|
#define NUM_F_PLUS (1 << 9)
|
2003-08-04 02:43:34 +02:00
|
|
|
#define NUM_F_ROMAN (1 << 10)
|
2005-05-25 23:40:43 +02:00
|
|
|
#define NUM_F_MULTI (1 << 11)
|
2003-08-04 02:43:34 +02:00
|
|
|
#define NUM_F_PLUS_POST (1 << 12)
|
2003-03-27 17:35:31 +01:00
|
|
|
#define NUM_F_MINUS_POST (1 << 13)
|
2009-08-10 20:29:27 +02:00
|
|
|
#define NUM_F_EEEE (1 << 14)
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
2005-07-27 14:44:10 +02:00
|
|
|
#define NUM_LSIGN_PRE (-1)
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
#define NUM_LSIGN_POST 1
|
|
|
|
#define NUM_LSIGN_NONE 0
|
|
|
|
|
|
|
|
/* ----------
|
|
|
|
* Tests
|
|
|
|
* ----------
|
|
|
|
*/
|
2000-04-12 19:17:23 +02:00
|
|
|
#define IS_DECIMAL(_f) ((_f)->flag & NUM_F_DECIMAL)
|
|
|
|
#define IS_LDECIMAL(_f) ((_f)->flag & NUM_F_LDECIMAL)
|
2001-03-22 05:01:46 +01:00
|
|
|
#define IS_ZERO(_f) ((_f)->flag & NUM_F_ZERO)
|
2000-04-12 19:17:23 +02:00
|
|
|
#define IS_BLANK(_f) ((_f)->flag & NUM_F_BLANK)
|
|
|
|
#define IS_FILLMODE(_f) ((_f)->flag & NUM_F_FILLMODE)
|
|
|
|
#define IS_BRACKET(_f) ((_f)->flag & NUM_F_BRACKET)
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
#define IS_MINUS(_f) ((_f)->flag & NUM_F_MINUS)
|
2000-02-08 16:57:01 +01:00
|
|
|
#define IS_LSIGN(_f) ((_f)->flag & NUM_F_LSIGN)
|
2001-03-22 05:01:46 +01:00
|
|
|
#define IS_PLUS(_f) ((_f)->flag & NUM_F_PLUS)
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
#define IS_ROMAN(_f) ((_f)->flag & NUM_F_ROMAN)
|
|
|
|
#define IS_MULTI(_f) ((_f)->flag & NUM_F_MULTI)
|
2009-08-10 20:29:27 +02:00
|
|
|
#define IS_EEEE(_f) ((_f)->flag & NUM_F_EEEE)
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
2000-03-16 02:35:41 +01:00
|
|
|
/* ----------
|
2000-04-12 19:17:23 +02:00
|
|
|
* Format picture cache
|
2000-07-03 18:01:33 +02:00
|
|
|
* (cache size:
|
2001-03-22 05:01:46 +01:00
|
|
|
* Number part = NUM_CACHE_SIZE * NUM_CACHE_FIELDS
|
2000-03-16 02:35:41 +01:00
|
|
|
* Date-time part = DCH_CACHE_SIZE * DCH_CACHE_FIELDS
|
|
|
|
* )
|
|
|
|
* ----------
|
|
|
|
*/
|
2000-04-12 19:17:23 +02:00
|
|
|
#define NUM_CACHE_SIZE 64
|
2000-03-16 02:35:41 +01:00
|
|
|
#define NUM_CACHE_FIELDS 16
|
|
|
|
#define DCH_CACHE_SIZE 128
|
|
|
|
#define DCH_CACHE_FIELDS 16
|
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
FormatNode format[DCH_CACHE_SIZE + 1];
|
|
|
|
char str[DCH_CACHE_SIZE + 1];
|
2001-03-22 05:01:46 +01:00
|
|
|
int age;
|
2000-03-16 02:35:41 +01:00
|
|
|
} DCHCacheEntry;
|
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
FormatNode format[NUM_CACHE_SIZE + 1];
|
|
|
|
char str[NUM_CACHE_SIZE + 1];
|
2001-03-22 05:01:46 +01:00
|
|
|
int age;
|
2014-09-13 02:42:19 +02:00
|
|
|
NUMDesc Num;
|
2000-03-16 02:35:41 +01:00
|
|
|
} NUMCacheEntry;
|
|
|
|
|
2000-07-03 18:01:33 +02:00
|
|
|
/* global cache for --- date/time part */
|
2001-03-22 05:01:46 +01:00
|
|
|
static DCHCacheEntry DCHCache[DCH_CACHE_FIELDS + 1];
|
2000-07-03 18:01:33 +02:00
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
static int n_DCHCache = 0; /* number of entries */
|
|
|
|
static int DCHCounter = 0;
|
2000-03-16 02:35:41 +01:00
|
|
|
|
2000-07-03 18:01:33 +02:00
|
|
|
/* global cache for --- number part */
|
2001-03-22 05:01:46 +01:00
|
|
|
static NUMCacheEntry NUMCache[NUM_CACHE_FIELDS + 1];
|
2000-07-03 18:01:33 +02:00
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
static int n_NUMCache = 0; /* number of entries */
|
|
|
|
static int NUMCounter = 0;
|
2009-03-12 01:53:25 +01:00
|
|
|
static NUMCacheEntry *last_NUMCacheEntry = NUMCache + 0;
|
2000-03-16 02:35:41 +01:00
|
|
|
|
2000-07-03 18:01:33 +02:00
|
|
|
/* ----------
|
|
|
|
* For char->date/time conversion
|
|
|
|
* ----------
|
|
|
|
*/
|
2001-03-22 05:01:46 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
2008-09-11 19:32:34 +02:00
|
|
|
FromCharDateMode mode;
|
2001-03-22 05:01:46 +01:00
|
|
|
int hh,
|
|
|
|
pm,
|
|
|
|
mi,
|
|
|
|
ss,
|
|
|
|
ssss,
|
2012-09-04 04:52:34 +02:00
|
|
|
d, /* stored as 1-7, Sunday = 1, 0 means missing */
|
2001-03-22 05:01:46 +01:00
|
|
|
dd,
|
|
|
|
ddd,
|
|
|
|
mm,
|
2001-09-06 05:22:42 +02:00
|
|
|
ms,
|
2002-01-02 23:09:23 +01:00
|
|
|
year,
|
2001-03-22 05:01:46 +01:00
|
|
|
bc,
|
|
|
|
ww,
|
2001-10-25 07:50:21 +02:00
|
|
|
w,
|
2001-03-22 05:01:46 +01:00
|
|
|
cc,
|
2001-09-06 05:22:42 +02:00
|
|
|
j,
|
2005-03-25 17:08:40 +01:00
|
|
|
us,
|
2009-06-11 16:49:15 +02:00
|
|
|
yysz, /* is it YY or YYYY ? */
|
|
|
|
clock; /* 12 or 24 hour clock? */
|
2000-07-03 18:01:33 +02:00
|
|
|
} TmFromChar;
|
|
|
|
|
2005-07-27 14:44:10 +02:00
|
|
|
#define ZERO_tmfc(_X) memset(_X, 0, sizeof(TmFromChar))
|
2000-07-03 18:01:33 +02:00
|
|
|
|
2001-09-06 05:22:42 +02:00
|
|
|
/* ----------
|
|
|
|
* Debug
|
|
|
|
* ----------
|
|
|
|
*/
|
2000-07-03 18:01:33 +02:00
|
|
|
#ifdef DEBUG_TO_FROM_CHAR
|
2005-07-27 14:44:10 +02:00
|
|
|
#define DEBUG_TMFC(_X) \
|
2009-02-07 15:16:46 +01:00
|
|
|
elog(DEBUG_elog_output, "TMFC:\nmode %d\nhh %d\npm %d\nmi %d\nss %d\nssss %d\nd %d\ndd %d\nddd %d\nmm %d\nms: %d\nyear %d\nbc %d\nww %d\nw %d\ncc %d\nj %d\nus: %d\nyysz: %d\nclock: %d", \
|
|
|
|
(_X)->mode, (_X)->hh, (_X)->pm, (_X)->mi, (_X)->ss, (_X)->ssss, \
|
|
|
|
(_X)->d, (_X)->dd, (_X)->ddd, (_X)->mm, (_X)->ms, (_X)->year, \
|
|
|
|
(_X)->bc, (_X)->ww, (_X)->w, (_X)->cc, (_X)->j, (_X)->us, \
|
|
|
|
(_X)->yysz, (_X)->clock);
|
2005-07-27 14:44:10 +02:00
|
|
|
#define DEBUG_TM(_X) \
|
2000-07-03 18:01:33 +02:00
|
|
|
elog(DEBUG_elog_output, "TM:\nsec %d\nyear %d\nmin %d\nwday %d\nhour %d\nyday %d\nmday %d\nnisdst %d\nmon %d\n",\
|
2001-09-06 05:22:42 +02:00
|
|
|
(_X)->tm_sec, (_X)->tm_year,\
|
|
|
|
(_X)->tm_min, (_X)->tm_wday, (_X)->tm_hour, (_X)->tm_yday,\
|
|
|
|
(_X)->tm_mday, (_X)->tm_isdst, (_X)->tm_mon)
|
|
|
|
#else
|
2005-07-27 14:44:10 +02:00
|
|
|
#define DEBUG_TMFC(_X)
|
|
|
|
#define DEBUG_TM(_X)
|
2000-07-03 18:01:33 +02:00
|
|
|
#endif
|
|
|
|
|
2001-09-06 05:22:42 +02:00
|
|
|
/* ----------
|
|
|
|
* Datetime to char conversion
|
|
|
|
* ----------
|
|
|
|
*/
|
|
|
|
typedef struct TmToChar
|
|
|
|
{
|
2004-08-29 07:07:03 +02:00
|
|
|
struct pg_tm tm; /* classic 'tm' struct */
|
2002-04-21 21:52:18 +02:00
|
|
|
fsec_t fsec; /* fractional seconds */
|
2012-03-15 20:17:19 +01:00
|
|
|
const char *tzn; /* timezone */
|
2001-09-06 05:22:42 +02:00
|
|
|
} TmToChar;
|
|
|
|
|
|
|
|
#define tmtcTm(_X) (&(_X)->tm)
|
2001-10-25 07:50:21 +02:00
|
|
|
#define tmtcTzn(_X) ((_X)->tzn)
|
2001-09-06 05:22:42 +02:00
|
|
|
#define tmtcFsec(_X) ((_X)->fsec)
|
|
|
|
|
2005-07-27 14:44:10 +02:00
|
|
|
#define ZERO_tm(_X) \
|
2005-08-18 15:43:08 +02:00
|
|
|
do { \
|
|
|
|
(_X)->tm_sec = (_X)->tm_year = (_X)->tm_min = (_X)->tm_wday = \
|
|
|
|
(_X)->tm_hour = (_X)->tm_yday = (_X)->tm_isdst = 0; \
|
|
|
|
(_X)->tm_mday = (_X)->tm_mon = 1; \
|
|
|
|
} while(0)
|
2000-07-03 18:01:33 +02:00
|
|
|
|
2005-07-27 14:44:10 +02:00
|
|
|
#define ZERO_tmtc(_X) \
|
2005-08-18 15:43:08 +02:00
|
|
|
do { \
|
|
|
|
ZERO_tm( tmtcTm(_X) ); \
|
|
|
|
tmtcFsec(_X) = 0; \
|
|
|
|
tmtcTzn(_X) = NULL; \
|
|
|
|
} while(0)
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
2005-12-03 17:45:06 +01:00
|
|
|
/*
|
|
|
|
* to_char(time) appears to to_char() as an interval, so this check
|
|
|
|
* is really for interval and time data types.
|
|
|
|
*/
|
2005-08-18 06:37:08 +02:00
|
|
|
#define INVALID_FOR_INTERVAL \
|
2005-08-18 15:43:08 +02:00
|
|
|
do { \
|
|
|
|
if (is_interval) \
|
|
|
|
ereport(ERROR, \
|
|
|
|
(errcode(ERRCODE_INVALID_DATETIME_FORMAT), \
|
|
|
|
errmsg("invalid format specification for an interval value"), \
|
|
|
|
errhint("Intervals are not tied to specific calendar dates."))); \
|
|
|
|
} while(0)
|
2005-10-15 04:49:52 +02:00
|
|
|
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
/*****************************************************************************
|
2008-03-22 23:32:19 +01:00
|
|
|
* KeyWord definitions
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
*****************************************************************************/
|
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
/* ----------
|
|
|
|
* Suffixes:
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* ----------
|
|
|
|
*/
|
2000-04-12 19:17:23 +02:00
|
|
|
#define DCH_S_FM 0x01
|
|
|
|
#define DCH_S_TH 0x02
|
|
|
|
#define DCH_S_th 0x04
|
|
|
|
#define DCH_S_SP 0x08
|
2006-02-12 05:44:15 +01:00
|
|
|
#define DCH_S_TM 0x10
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
/* ----------
|
|
|
|
* Suffix tests
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* ----------
|
|
|
|
*/
|
2005-05-25 23:40:43 +02:00
|
|
|
#define S_THth(_s) ((((_s) & DCH_S_TH) || ((_s) & DCH_S_th)) ? 1 : 0)
|
|
|
|
#define S_TH(_s) (((_s) & DCH_S_TH) ? 1 : 0)
|
|
|
|
#define S_th(_s) (((_s) & DCH_S_th) ? 1 : 0)
|
|
|
|
#define S_TH_TYPE(_s) (((_s) & DCH_S_TH) ? TH_UPPER : TH_LOWER)
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
2010-02-16 22:18:02 +01:00
|
|
|
/* Oracle toggles FM behavior, we don't; see docs. */
|
2005-05-25 23:40:43 +02:00
|
|
|
#define S_FM(_s) (((_s) & DCH_S_FM) ? 1 : 0)
|
|
|
|
#define S_SP(_s) (((_s) & DCH_S_SP) ? 1 : 0)
|
2006-02-12 05:44:15 +01:00
|
|
|
#define S_TM(_s) (((_s) & DCH_S_TM) ? 1 : 0)
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
|
|
|
/* ----------
|
|
|
|
* Suffixes definition for DATE-TIME TO/FROM CHAR
|
|
|
|
* ----------
|
|
|
|
*/
|
2015-02-02 16:00:45 +01:00
|
|
|
#define TM_SUFFIX_LEN 2
|
|
|
|
|
2014-01-18 22:04:11 +01:00
|
|
|
static const KeySuffix DCH_suff[] = {
|
2000-04-12 19:17:23 +02:00
|
|
|
{"FM", 2, DCH_S_FM, SUFFTYPE_PREFIX},
|
|
|
|
{"fm", 2, DCH_S_FM, SUFFTYPE_PREFIX},
|
2015-02-02 16:00:45 +01:00
|
|
|
{"TM", TM_SUFFIX_LEN, DCH_S_TM, SUFFTYPE_PREFIX},
|
2006-02-12 05:44:15 +01:00
|
|
|
{"tm", 2, DCH_S_TM, SUFFTYPE_PREFIX},
|
2000-04-12 19:17:23 +02:00
|
|
|
{"TH", 2, DCH_S_TH, SUFFTYPE_POSTFIX},
|
|
|
|
{"th", 2, DCH_S_th, SUFFTYPE_POSTFIX},
|
|
|
|
{"SP", 2, DCH_S_SP, SUFFTYPE_POSTFIX},
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
/* last */
|
2000-04-12 19:17:23 +02:00
|
|
|
{NULL, 0, 0, 0}
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
};
|
|
|
|
|
2015-02-02 16:00:45 +01:00
|
|
|
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
/* ----------
|
|
|
|
* Format-pictures (KeyWord).
|
2000-04-12 19:17:23 +02:00
|
|
|
*
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* The KeyWord field; alphabetic sorted, *BUT* strings alike is sorted
|
2000-04-12 19:17:23 +02:00
|
|
|
* complicated -to-> easy:
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
*
|
2000-04-12 19:17:23 +02:00
|
|
|
* (example: "DDD","DD","Day","D" )
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
*
|
|
|
|
* (this specific sort needs the algorithm for sequential search for strings,
|
2000-04-12 19:17:23 +02:00
|
|
|
* which not has exact end; -> How keyword is in "HH12blabla" ? - "HH"
|
|
|
|
* or "HH12"? You must first try "HH12", because "HH" is in string, but
|
|
|
|
* it is not good.
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
*
|
2000-04-12 19:17:23 +02:00
|
|
|
* (!)
|
2003-03-10 23:28:22 +01:00
|
|
|
* - Position for the keyword is similar as position in the enum DCH/NUM_poz.
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* (!)
|
|
|
|
*
|
2000-04-12 19:17:23 +02:00
|
|
|
* For fast search is used the 'int index[]', index is ascii table from position
|
|
|
|
* 32 (' ') to 126 (~), in this index is DCH_ / NUM_ enums for each ASCII
|
|
|
|
* position or -1 if char is not used in the KeyWord. Search example for
|
2000-02-08 16:57:01 +01:00
|
|
|
* string "MM":
|
2000-04-12 19:17:23 +02:00
|
|
|
* 1) see in index to index['M' - 32],
|
2007-02-16 04:39:46 +01:00
|
|
|
* 2) take keywords position (enum DCH_MI) from index
|
2000-04-12 19:17:23 +02:00
|
|
|
* 3) run sequential search in keywords[] from this position
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
*
|
|
|
|
* ----------
|
|
|
|
*/
|
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
typedef enum
|
|
|
|
{
|
2001-10-28 07:26:15 +01:00
|
|
|
DCH_A_D,
|
|
|
|
DCH_A_M,
|
|
|
|
DCH_AD,
|
|
|
|
DCH_AM,
|
|
|
|
DCH_B_C,
|
|
|
|
DCH_BC,
|
|
|
|
DCH_CC,
|
|
|
|
DCH_DAY,
|
|
|
|
DCH_DDD,
|
|
|
|
DCH_DD,
|
|
|
|
DCH_DY,
|
|
|
|
DCH_Day,
|
|
|
|
DCH_Dy,
|
|
|
|
DCH_D,
|
|
|
|
DCH_FX, /* global suffix */
|
|
|
|
DCH_HH24,
|
|
|
|
DCH_HH12,
|
|
|
|
DCH_HH,
|
2007-02-16 04:39:46 +01:00
|
|
|
DCH_IDDD,
|
|
|
|
DCH_ID,
|
2001-10-28 07:26:15 +01:00
|
|
|
DCH_IW,
|
2003-12-25 04:36:24 +01:00
|
|
|
DCH_IYYY,
|
|
|
|
DCH_IYY,
|
|
|
|
DCH_IY,
|
|
|
|
DCH_I,
|
2001-10-28 07:26:15 +01:00
|
|
|
DCH_J,
|
|
|
|
DCH_MI,
|
|
|
|
DCH_MM,
|
|
|
|
DCH_MONTH,
|
|
|
|
DCH_MON,
|
|
|
|
DCH_MS,
|
|
|
|
DCH_Month,
|
|
|
|
DCH_Mon,
|
2013-07-01 19:40:18 +02:00
|
|
|
DCH_OF,
|
2001-10-28 07:26:15 +01:00
|
|
|
DCH_P_M,
|
|
|
|
DCH_PM,
|
|
|
|
DCH_Q,
|
|
|
|
DCH_RM,
|
|
|
|
DCH_SSSS,
|
|
|
|
DCH_SS,
|
|
|
|
DCH_TZ,
|
|
|
|
DCH_US,
|
|
|
|
DCH_WW,
|
|
|
|
DCH_W,
|
|
|
|
DCH_Y_YYY,
|
|
|
|
DCH_YYYY,
|
|
|
|
DCH_YYY,
|
|
|
|
DCH_YY,
|
|
|
|
DCH_Y,
|
|
|
|
DCH_a_d,
|
|
|
|
DCH_a_m,
|
|
|
|
DCH_ad,
|
|
|
|
DCH_am,
|
|
|
|
DCH_b_c,
|
|
|
|
DCH_bc,
|
|
|
|
DCH_cc,
|
|
|
|
DCH_day,
|
|
|
|
DCH_ddd,
|
|
|
|
DCH_dd,
|
|
|
|
DCH_dy,
|
|
|
|
DCH_d,
|
|
|
|
DCH_fx,
|
|
|
|
DCH_hh24,
|
|
|
|
DCH_hh12,
|
|
|
|
DCH_hh,
|
2007-02-16 04:39:46 +01:00
|
|
|
DCH_iddd,
|
|
|
|
DCH_id,
|
2001-10-28 07:26:15 +01:00
|
|
|
DCH_iw,
|
2003-12-25 04:36:24 +01:00
|
|
|
DCH_iyyy,
|
|
|
|
DCH_iyy,
|
|
|
|
DCH_iy,
|
|
|
|
DCH_i,
|
2001-10-28 07:26:15 +01:00
|
|
|
DCH_j,
|
|
|
|
DCH_mi,
|
|
|
|
DCH_mm,
|
|
|
|
DCH_month,
|
|
|
|
DCH_mon,
|
|
|
|
DCH_ms,
|
|
|
|
DCH_p_m,
|
|
|
|
DCH_pm,
|
|
|
|
DCH_q,
|
|
|
|
DCH_rm,
|
|
|
|
DCH_ssss,
|
|
|
|
DCH_ss,
|
|
|
|
DCH_tz,
|
|
|
|
DCH_us,
|
|
|
|
DCH_ww,
|
|
|
|
DCH_w,
|
|
|
|
DCH_y_yyy,
|
|
|
|
DCH_yyyy,
|
|
|
|
DCH_yyy,
|
|
|
|
DCH_yy,
|
|
|
|
DCH_y,
|
2000-04-07 21:17:51 +02:00
|
|
|
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
/* last */
|
2001-10-28 07:26:15 +01:00
|
|
|
_DCH_last_
|
2011-04-10 17:42:00 +02:00
|
|
|
} DCH_poz;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
typedef enum
|
|
|
|
{
|
2001-10-28 07:26:15 +01:00
|
|
|
NUM_COMMA,
|
|
|
|
NUM_DEC,
|
|
|
|
NUM_0,
|
|
|
|
NUM_9,
|
|
|
|
NUM_B,
|
|
|
|
NUM_C,
|
|
|
|
NUM_D,
|
|
|
|
NUM_E,
|
|
|
|
NUM_FM,
|
|
|
|
NUM_G,
|
|
|
|
NUM_L,
|
|
|
|
NUM_MI,
|
|
|
|
NUM_PL,
|
|
|
|
NUM_PR,
|
|
|
|
NUM_RN,
|
|
|
|
NUM_SG,
|
|
|
|
NUM_SP,
|
|
|
|
NUM_S,
|
|
|
|
NUM_TH,
|
|
|
|
NUM_V,
|
|
|
|
NUM_b,
|
|
|
|
NUM_c,
|
|
|
|
NUM_d,
|
|
|
|
NUM_e,
|
|
|
|
NUM_fm,
|
|
|
|
NUM_g,
|
|
|
|
NUM_l,
|
|
|
|
NUM_mi,
|
|
|
|
NUM_pl,
|
|
|
|
NUM_pr,
|
|
|
|
NUM_rn,
|
|
|
|
NUM_sg,
|
|
|
|
NUM_sp,
|
|
|
|
NUM_s,
|
|
|
|
NUM_th,
|
|
|
|
NUM_v,
|
2000-04-12 19:17:23 +02:00
|
|
|
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
/* last */
|
2001-10-28 07:26:15 +01:00
|
|
|
_NUM_last_
|
2011-04-10 17:42:00 +02:00
|
|
|
} NUM_poz;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
|
|
|
/* ----------
|
|
|
|
* KeyWords for DATE-TIME version
|
|
|
|
* ----------
|
|
|
|
*/
|
2005-03-26 01:41:31 +01:00
|
|
|
static const KeyWord DCH_keywords[] = {
|
2008-09-11 19:32:34 +02:00
|
|
|
/* name, len, id, is_digit, date_mode */
|
2009-06-11 16:49:15 +02:00
|
|
|
{"A.D.", 4, DCH_A_D, FALSE, FROM_CHAR_DATE_NONE}, /* A */
|
2008-09-11 19:32:34 +02:00
|
|
|
{"A.M.", 4, DCH_A_M, FALSE, FROM_CHAR_DATE_NONE},
|
2009-03-15 21:31:19 +01:00
|
|
|
{"AD", 2, DCH_AD, FALSE, FROM_CHAR_DATE_NONE},
|
2008-09-11 19:32:34 +02:00
|
|
|
{"AM", 2, DCH_AM, FALSE, FROM_CHAR_DATE_NONE},
|
2009-06-11 16:49:15 +02:00
|
|
|
{"B.C.", 4, DCH_B_C, FALSE, FROM_CHAR_DATE_NONE}, /* B */
|
2009-03-15 21:31:19 +01:00
|
|
|
{"BC", 2, DCH_BC, FALSE, FROM_CHAR_DATE_NONE},
|
2009-06-11 16:49:15 +02:00
|
|
|
{"CC", 2, DCH_CC, TRUE, FROM_CHAR_DATE_NONE}, /* C */
|
|
|
|
{"DAY", 3, DCH_DAY, FALSE, FROM_CHAR_DATE_NONE}, /* D */
|
2008-09-11 19:32:34 +02:00
|
|
|
{"DDD", 3, DCH_DDD, TRUE, FROM_CHAR_DATE_GREGORIAN},
|
|
|
|
{"DD", 2, DCH_DD, TRUE, FROM_CHAR_DATE_GREGORIAN},
|
|
|
|
{"DY", 2, DCH_DY, FALSE, FROM_CHAR_DATE_NONE},
|
|
|
|
{"Day", 3, DCH_Day, FALSE, FROM_CHAR_DATE_NONE},
|
|
|
|
{"Dy", 2, DCH_Dy, FALSE, FROM_CHAR_DATE_NONE},
|
|
|
|
{"D", 1, DCH_D, TRUE, FROM_CHAR_DATE_GREGORIAN},
|
2009-06-11 16:49:15 +02:00
|
|
|
{"FX", 2, DCH_FX, FALSE, FROM_CHAR_DATE_NONE}, /* F */
|
|
|
|
{"HH24", 4, DCH_HH24, TRUE, FROM_CHAR_DATE_NONE}, /* H */
|
2008-09-11 19:32:34 +02:00
|
|
|
{"HH12", 4, DCH_HH12, TRUE, FROM_CHAR_DATE_NONE},
|
|
|
|
{"HH", 2, DCH_HH, TRUE, FROM_CHAR_DATE_NONE},
|
2009-06-11 16:49:15 +02:00
|
|
|
{"IDDD", 4, DCH_IDDD, TRUE, FROM_CHAR_DATE_ISOWEEK}, /* I */
|
2008-09-11 19:32:34 +02:00
|
|
|
{"ID", 2, DCH_ID, TRUE, FROM_CHAR_DATE_ISOWEEK},
|
|
|
|
{"IW", 2, DCH_IW, TRUE, FROM_CHAR_DATE_ISOWEEK},
|
|
|
|
{"IYYY", 4, DCH_IYYY, TRUE, FROM_CHAR_DATE_ISOWEEK},
|
|
|
|
{"IYY", 3, DCH_IYY, TRUE, FROM_CHAR_DATE_ISOWEEK},
|
|
|
|
{"IY", 2, DCH_IY, TRUE, FROM_CHAR_DATE_ISOWEEK},
|
|
|
|
{"I", 1, DCH_I, TRUE, FROM_CHAR_DATE_ISOWEEK},
|
2009-06-11 16:49:15 +02:00
|
|
|
{"J", 1, DCH_J, TRUE, FROM_CHAR_DATE_NONE}, /* J */
|
|
|
|
{"MI", 2, DCH_MI, TRUE, FROM_CHAR_DATE_NONE}, /* M */
|
2008-09-11 19:32:34 +02:00
|
|
|
{"MM", 2, DCH_MM, TRUE, FROM_CHAR_DATE_GREGORIAN},
|
|
|
|
{"MONTH", 5, DCH_MONTH, FALSE, FROM_CHAR_DATE_GREGORIAN},
|
|
|
|
{"MON", 3, DCH_MON, FALSE, FROM_CHAR_DATE_GREGORIAN},
|
|
|
|
{"MS", 2, DCH_MS, TRUE, FROM_CHAR_DATE_NONE},
|
|
|
|
{"Month", 5, DCH_Month, FALSE, FROM_CHAR_DATE_GREGORIAN},
|
|
|
|
{"Mon", 3, DCH_Mon, FALSE, FROM_CHAR_DATE_GREGORIAN},
|
2013-07-01 19:40:18 +02:00
|
|
|
{"OF", 2, DCH_OF, FALSE, FROM_CHAR_DATE_NONE}, /* O */
|
2009-06-11 16:49:15 +02:00
|
|
|
{"P.M.", 4, DCH_P_M, FALSE, FROM_CHAR_DATE_NONE}, /* P */
|
2008-09-11 19:32:34 +02:00
|
|
|
{"PM", 2, DCH_PM, FALSE, FROM_CHAR_DATE_NONE},
|
2009-06-11 16:49:15 +02:00
|
|
|
{"Q", 1, DCH_Q, TRUE, FROM_CHAR_DATE_NONE}, /* Q */
|
|
|
|
{"RM", 2, DCH_RM, FALSE, FROM_CHAR_DATE_GREGORIAN}, /* R */
|
|
|
|
{"SSSS", 4, DCH_SSSS, TRUE, FROM_CHAR_DATE_NONE}, /* S */
|
2008-09-11 19:32:34 +02:00
|
|
|
{"SS", 2, DCH_SS, TRUE, FROM_CHAR_DATE_NONE},
|
2009-06-11 16:49:15 +02:00
|
|
|
{"TZ", 2, DCH_TZ, FALSE, FROM_CHAR_DATE_NONE}, /* T */
|
|
|
|
{"US", 2, DCH_US, TRUE, FROM_CHAR_DATE_NONE}, /* U */
|
|
|
|
{"WW", 2, DCH_WW, TRUE, FROM_CHAR_DATE_GREGORIAN}, /* W */
|
2008-09-11 19:32:34 +02:00
|
|
|
{"W", 1, DCH_W, TRUE, FROM_CHAR_DATE_GREGORIAN},
|
2009-06-11 16:49:15 +02:00
|
|
|
{"Y,YYY", 5, DCH_Y_YYY, TRUE, FROM_CHAR_DATE_GREGORIAN}, /* Y */
|
2008-09-11 19:32:34 +02:00
|
|
|
{"YYYY", 4, DCH_YYYY, TRUE, FROM_CHAR_DATE_GREGORIAN},
|
|
|
|
{"YYY", 3, DCH_YYY, TRUE, FROM_CHAR_DATE_GREGORIAN},
|
|
|
|
{"YY", 2, DCH_YY, TRUE, FROM_CHAR_DATE_GREGORIAN},
|
|
|
|
{"Y", 1, DCH_Y, TRUE, FROM_CHAR_DATE_GREGORIAN},
|
2009-06-11 16:49:15 +02:00
|
|
|
{"a.d.", 4, DCH_a_d, FALSE, FROM_CHAR_DATE_NONE}, /* a */
|
2008-09-11 19:32:34 +02:00
|
|
|
{"a.m.", 4, DCH_a_m, FALSE, FROM_CHAR_DATE_NONE},
|
2009-03-15 21:31:19 +01:00
|
|
|
{"ad", 2, DCH_ad, FALSE, FROM_CHAR_DATE_NONE},
|
2008-09-11 19:32:34 +02:00
|
|
|
{"am", 2, DCH_am, FALSE, FROM_CHAR_DATE_NONE},
|
2009-06-11 16:49:15 +02:00
|
|
|
{"b.c.", 4, DCH_b_c, FALSE, FROM_CHAR_DATE_NONE}, /* b */
|
2009-03-15 21:31:19 +01:00
|
|
|
{"bc", 2, DCH_bc, FALSE, FROM_CHAR_DATE_NONE},
|
2009-06-11 16:49:15 +02:00
|
|
|
{"cc", 2, DCH_CC, TRUE, FROM_CHAR_DATE_NONE}, /* c */
|
|
|
|
{"day", 3, DCH_day, FALSE, FROM_CHAR_DATE_NONE}, /* d */
|
2008-09-11 19:32:34 +02:00
|
|
|
{"ddd", 3, DCH_DDD, TRUE, FROM_CHAR_DATE_GREGORIAN},
|
|
|
|
{"dd", 2, DCH_DD, TRUE, FROM_CHAR_DATE_GREGORIAN},
|
|
|
|
{"dy", 2, DCH_dy, FALSE, FROM_CHAR_DATE_NONE},
|
|
|
|
{"d", 1, DCH_D, TRUE, FROM_CHAR_DATE_GREGORIAN},
|
2009-06-11 16:49:15 +02:00
|
|
|
{"fx", 2, DCH_FX, FALSE, FROM_CHAR_DATE_NONE}, /* f */
|
|
|
|
{"hh24", 4, DCH_HH24, TRUE, FROM_CHAR_DATE_NONE}, /* h */
|
2008-09-11 19:32:34 +02:00
|
|
|
{"hh12", 4, DCH_HH12, TRUE, FROM_CHAR_DATE_NONE},
|
|
|
|
{"hh", 2, DCH_HH, TRUE, FROM_CHAR_DATE_NONE},
|
2009-06-11 16:49:15 +02:00
|
|
|
{"iddd", 4, DCH_IDDD, TRUE, FROM_CHAR_DATE_ISOWEEK}, /* i */
|
2008-09-11 19:32:34 +02:00
|
|
|
{"id", 2, DCH_ID, TRUE, FROM_CHAR_DATE_ISOWEEK},
|
|
|
|
{"iw", 2, DCH_IW, TRUE, FROM_CHAR_DATE_ISOWEEK},
|
|
|
|
{"iyyy", 4, DCH_IYYY, TRUE, FROM_CHAR_DATE_ISOWEEK},
|
|
|
|
{"iyy", 3, DCH_IYY, TRUE, FROM_CHAR_DATE_ISOWEEK},
|
|
|
|
{"iy", 2, DCH_IY, TRUE, FROM_CHAR_DATE_ISOWEEK},
|
|
|
|
{"i", 1, DCH_I, TRUE, FROM_CHAR_DATE_ISOWEEK},
|
2009-06-11 16:49:15 +02:00
|
|
|
{"j", 1, DCH_J, TRUE, FROM_CHAR_DATE_NONE}, /* j */
|
|
|
|
{"mi", 2, DCH_MI, TRUE, FROM_CHAR_DATE_NONE}, /* m */
|
2008-09-11 19:32:34 +02:00
|
|
|
{"mm", 2, DCH_MM, TRUE, FROM_CHAR_DATE_GREGORIAN},
|
|
|
|
{"month", 5, DCH_month, FALSE, FROM_CHAR_DATE_GREGORIAN},
|
|
|
|
{"mon", 3, DCH_mon, FALSE, FROM_CHAR_DATE_GREGORIAN},
|
|
|
|
{"ms", 2, DCH_MS, TRUE, FROM_CHAR_DATE_NONE},
|
2009-06-11 16:49:15 +02:00
|
|
|
{"p.m.", 4, DCH_p_m, FALSE, FROM_CHAR_DATE_NONE}, /* p */
|
2008-09-11 19:32:34 +02:00
|
|
|
{"pm", 2, DCH_pm, FALSE, FROM_CHAR_DATE_NONE},
|
2009-06-11 16:49:15 +02:00
|
|
|
{"q", 1, DCH_Q, TRUE, FROM_CHAR_DATE_NONE}, /* q */
|
|
|
|
{"rm", 2, DCH_rm, FALSE, FROM_CHAR_DATE_GREGORIAN}, /* r */
|
|
|
|
{"ssss", 4, DCH_SSSS, TRUE, FROM_CHAR_DATE_NONE}, /* s */
|
2008-09-11 19:32:34 +02:00
|
|
|
{"ss", 2, DCH_SS, TRUE, FROM_CHAR_DATE_NONE},
|
2009-06-11 16:49:15 +02:00
|
|
|
{"tz", 2, DCH_tz, FALSE, FROM_CHAR_DATE_NONE}, /* t */
|
|
|
|
{"us", 2, DCH_US, TRUE, FROM_CHAR_DATE_NONE}, /* u */
|
|
|
|
{"ww", 2, DCH_WW, TRUE, FROM_CHAR_DATE_GREGORIAN}, /* w */
|
2008-09-11 19:32:34 +02:00
|
|
|
{"w", 1, DCH_W, TRUE, FROM_CHAR_DATE_GREGORIAN},
|
2009-06-11 16:49:15 +02:00
|
|
|
{"y,yyy", 5, DCH_Y_YYY, TRUE, FROM_CHAR_DATE_GREGORIAN}, /* y */
|
2008-09-11 19:32:34 +02:00
|
|
|
{"yyyy", 4, DCH_YYYY, TRUE, FROM_CHAR_DATE_GREGORIAN},
|
|
|
|
{"yyy", 3, DCH_YYY, TRUE, FROM_CHAR_DATE_GREGORIAN},
|
|
|
|
{"yy", 2, DCH_YY, TRUE, FROM_CHAR_DATE_GREGORIAN},
|
|
|
|
{"y", 1, DCH_Y, TRUE, FROM_CHAR_DATE_GREGORIAN},
|
2008-03-22 23:32:19 +01:00
|
|
|
|
|
|
|
/* last */
|
2008-09-11 19:32:34 +02:00
|
|
|
{NULL, 0, 0, 0, 0}
|
2008-03-22 23:32:19 +01:00
|
|
|
};
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
|
|
|
/* ----------
|
2008-09-11 19:32:34 +02:00
|
|
|
* KeyWords for NUMBER version
|
|
|
|
*
|
|
|
|
* The is_digit and date_mode fields are not relevant here.
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* ----------
|
|
|
|
*/
|
2005-03-26 01:41:31 +01:00
|
|
|
static const KeyWord NUM_keywords[] = {
|
2008-03-22 23:32:19 +01:00
|
|
|
/* name, len, id is in Index */
|
2009-06-11 16:49:15 +02:00
|
|
|
{",", 1, NUM_COMMA}, /* , */
|
|
|
|
{".", 1, NUM_DEC}, /* . */
|
|
|
|
{"0", 1, NUM_0}, /* 0 */
|
|
|
|
{"9", 1, NUM_9}, /* 9 */
|
|
|
|
{"B", 1, NUM_B}, /* B */
|
|
|
|
{"C", 1, NUM_C}, /* C */
|
|
|
|
{"D", 1, NUM_D}, /* D */
|
2009-08-10 20:29:27 +02:00
|
|
|
{"EEEE", 4, NUM_E}, /* E */
|
2009-06-11 16:49:15 +02:00
|
|
|
{"FM", 2, NUM_FM}, /* F */
|
|
|
|
{"G", 1, NUM_G}, /* G */
|
|
|
|
{"L", 1, NUM_L}, /* L */
|
|
|
|
{"MI", 2, NUM_MI}, /* M */
|
|
|
|
{"PL", 2, NUM_PL}, /* P */
|
2008-03-22 23:32:19 +01:00
|
|
|
{"PR", 2, NUM_PR},
|
2009-06-11 16:49:15 +02:00
|
|
|
{"RN", 2, NUM_RN}, /* R */
|
|
|
|
{"SG", 2, NUM_SG}, /* S */
|
2008-03-22 23:32:19 +01:00
|
|
|
{"SP", 2, NUM_SP},
|
|
|
|
{"S", 1, NUM_S},
|
2009-06-11 16:49:15 +02:00
|
|
|
{"TH", 2, NUM_TH}, /* T */
|
|
|
|
{"V", 1, NUM_V}, /* V */
|
|
|
|
{"b", 1, NUM_B}, /* b */
|
|
|
|
{"c", 1, NUM_C}, /* c */
|
|
|
|
{"d", 1, NUM_D}, /* d */
|
2009-08-10 20:29:27 +02:00
|
|
|
{"eeee", 4, NUM_E}, /* e */
|
2009-06-11 16:49:15 +02:00
|
|
|
{"fm", 2, NUM_FM}, /* f */
|
|
|
|
{"g", 1, NUM_G}, /* g */
|
|
|
|
{"l", 1, NUM_L}, /* l */
|
|
|
|
{"mi", 2, NUM_MI}, /* m */
|
|
|
|
{"pl", 2, NUM_PL}, /* p */
|
2008-03-22 23:32:19 +01:00
|
|
|
{"pr", 2, NUM_PR},
|
2009-06-11 16:49:15 +02:00
|
|
|
{"rn", 2, NUM_rn}, /* r */
|
|
|
|
{"sg", 2, NUM_SG}, /* s */
|
2008-03-22 23:32:19 +01:00
|
|
|
{"sp", 2, NUM_SP},
|
|
|
|
{"s", 1, NUM_S},
|
2009-06-11 16:49:15 +02:00
|
|
|
{"th", 2, NUM_th}, /* t */
|
|
|
|
{"v", 1, NUM_V}, /* v */
|
2008-03-22 23:32:19 +01:00
|
|
|
|
|
|
|
/* last */
|
|
|
|
{NULL, 0, 0}
|
|
|
|
};
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* ----------
|
|
|
|
* KeyWords index for DATE-TIME version
|
|
|
|
* ----------
|
|
|
|
*/
|
2005-10-15 04:49:52 +02:00
|
|
|
static const int DCH_index[KeyWord_INDEX_SIZE] = {
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
/*
|
|
|
|
0 1 2 3 4 5 6 7 8 9
|
|
|
|
*/
|
2003-03-10 23:28:22 +01:00
|
|
|
/*---- first 0..31 chars are skipped ----*/
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
-1, -1, -1, -1, -1, -1, -1, -1,
|
|
|
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
|
|
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
|
|
|
-1, -1, -1, -1, -1, DCH_A_D, DCH_B_C, DCH_CC, DCH_DAY, -1,
|
2013-07-01 19:40:18 +02:00
|
|
|
DCH_FX, -1, DCH_HH24, DCH_IDDD, DCH_J, -1, -1, DCH_MI, -1, DCH_OF,
|
2001-09-06 05:22:42 +02:00
|
|
|
DCH_P_M, DCH_Q, DCH_RM, DCH_SSSS, DCH_TZ, DCH_US, -1, DCH_WW, -1, DCH_Y_YYY,
|
2000-04-12 19:17:23 +02:00
|
|
|
-1, -1, -1, -1, -1, -1, -1, DCH_a_d, DCH_b_c, DCH_cc,
|
2007-02-16 04:39:46 +01:00
|
|
|
DCH_day, -1, DCH_fx, -1, DCH_hh24, DCH_iddd, DCH_j, -1, -1, DCH_mi,
|
2001-09-06 05:22:42 +02:00
|
|
|
-1, -1, DCH_p_m, DCH_q, DCH_rm, DCH_ssss, DCH_tz, DCH_us, -1, DCH_ww,
|
2000-04-12 19:17:23 +02:00
|
|
|
-1, DCH_y_yyy, -1, -1, -1, -1
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
2008-03-22 23:32:19 +01:00
|
|
|
/*---- chars over 126 are skipped ----*/
|
2000-04-12 19:17:23 +02:00
|
|
|
};
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
|
|
|
/* ----------
|
|
|
|
* KeyWords index for NUMBER version
|
|
|
|
* ----------
|
|
|
|
*/
|
2005-10-15 04:49:52 +02:00
|
|
|
static const int NUM_index[KeyWord_INDEX_SIZE] = {
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
/*
|
|
|
|
0 1 2 3 4 5 6 7 8 9
|
|
|
|
*/
|
2008-03-22 23:32:19 +01:00
|
|
|
/*---- first 0..31 chars are skipped ----*/
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
-1, -1, -1, -1, -1, -1, -1, -1,
|
|
|
|
-1, -1, -1, -1, NUM_COMMA, -1, NUM_DEC, -1, NUM_0, -1,
|
|
|
|
-1, -1, -1, -1, -1, -1, -1, NUM_9, -1, -1,
|
|
|
|
-1, -1, -1, -1, -1, -1, NUM_B, NUM_C, NUM_D, NUM_E,
|
|
|
|
NUM_FM, NUM_G, -1, -1, -1, -1, NUM_L, NUM_MI, -1, -1,
|
|
|
|
NUM_PL, -1, NUM_RN, NUM_SG, NUM_TH, -1, NUM_V, -1, -1, -1,
|
|
|
|
-1, -1, -1, -1, -1, -1, -1, -1, NUM_b, NUM_c,
|
|
|
|
NUM_d, NUM_e, NUM_fm, NUM_g, -1, -1, -1, -1, NUM_l, NUM_mi,
|
|
|
|
-1, -1, NUM_pl, -1, NUM_rn, NUM_sg, NUM_th, -1, NUM_v, -1,
|
|
|
|
-1, -1, -1, -1, -1, -1
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
2008-03-22 23:32:19 +01:00
|
|
|
/*---- chars over 126 are skipped ----*/
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/* ----------
|
|
|
|
* Number processor struct
|
|
|
|
* ----------
|
|
|
|
*/
|
|
|
|
typedef struct NUMProc
|
|
|
|
{
|
2005-08-17 23:47:55 +02:00
|
|
|
bool is_to_char;
|
2014-09-13 02:42:19 +02:00
|
|
|
NUMDesc *Num; /* number description */
|
2001-03-22 05:01:46 +01:00
|
|
|
|
|
|
|
int sign, /* '-' or '+' */
|
|
|
|
sign_wrote, /* was sign write */
|
|
|
|
num_count, /* number of write digits */
|
|
|
|
num_in, /* is inside number */
|
|
|
|
num_curr, /* current position in number */
|
2015-05-24 03:35:49 +02:00
|
|
|
out_pre_spaces, /* spaces before first digit */
|
2001-03-22 05:01:46 +01:00
|
|
|
|
|
|
|
read_dec, /* to_number - was read dec. point */
|
2004-10-28 20:55:08 +02:00
|
|
|
read_post, /* to_number - number of dec. digit */
|
|
|
|
read_pre; /* to_number - number non-dec. digit */
|
2001-03-22 05:01:46 +01:00
|
|
|
|
2014-09-13 02:42:19 +02:00
|
|
|
char *number, /* string with number */
|
|
|
|
*number_p, /* pointer to current number position */
|
2001-03-22 05:01:46 +01:00
|
|
|
*inout, /* in / out buffer */
|
2003-03-10 23:28:22 +01:00
|
|
|
*inout_p, /* pointer to current inout position */
|
2005-10-15 04:49:52 +02:00
|
|
|
*last_relevant, /* last relevant number after decimal point */
|
2001-03-22 05:01:46 +01:00
|
|
|
|
2001-10-28 07:26:15 +01:00
|
|
|
*L_negative_sign, /* Locale */
|
2001-03-22 05:01:46 +01:00
|
|
|
*L_positive_sign,
|
|
|
|
*decimal,
|
|
|
|
*L_thousands_sep,
|
|
|
|
*L_currency_symbol;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
} NUMProc;
|
|
|
|
|
|
|
|
|
|
|
|
/* ----------
|
|
|
|
* Functions
|
|
|
|
* ----------
|
|
|
|
*/
|
2005-03-26 01:41:31 +01:00
|
|
|
static const KeyWord *index_seq_search(char *str, const KeyWord *kw,
|
2005-10-15 04:49:52 +02:00
|
|
|
const int *index);
|
2014-01-18 22:04:11 +01:00
|
|
|
static const KeySuffix *suff_search(char *str, const KeySuffix *suf, int type);
|
2014-09-13 02:42:19 +02:00
|
|
|
static void NUMDesc_prepare(NUMDesc *num, FormatNode *n);
|
2005-03-26 01:41:31 +01:00
|
|
|
static void parse_format(FormatNode *node, char *str, const KeyWord *kw,
|
2014-09-13 02:42:19 +02:00
|
|
|
const KeySuffix *suf, const int *index, int ver, NUMDesc *Num);
|
2008-03-22 23:32:19 +01:00
|
|
|
|
|
|
|
static void DCH_to_char(FormatNode *node, bool is_interval,
|
2011-02-08 22:04:18 +01:00
|
|
|
TmToChar *in, char *out, Oid collid);
|
2008-03-22 23:32:19 +01:00
|
|
|
static void DCH_from_char(FormatNode *node, char *in, TmFromChar *out);
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
|
|
|
#ifdef DEBUG_TO_FROM_CHAR
|
2005-03-26 01:41:31 +01:00
|
|
|
static void dump_index(const KeyWord *k, const int *index);
|
2000-04-12 19:17:23 +02:00
|
|
|
static void dump_node(FormatNode *node, int max);
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
#endif
|
|
|
|
|
2014-01-18 22:04:11 +01:00
|
|
|
static const char *get_th(char *num, int type);
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
static char *str_numth(char *dest, char *num, int type);
|
2011-09-07 15:47:51 +02:00
|
|
|
static int adjust_partial_year_to_2020(int year);
|
2006-04-19 20:49:09 +02:00
|
|
|
static int strspace_len(char *str);
|
2001-10-25 07:50:21 +02:00
|
|
|
static int strdigits_len(char *str);
|
2008-09-11 19:32:34 +02:00
|
|
|
static void from_char_set_mode(TmFromChar *tmfc, const FromCharDateMode mode);
|
|
|
|
static void from_char_set_int(int *dest, const int value, const FormatNode *node);
|
|
|
|
static int from_char_parse_int_len(int *dest, char **src, const int len, FormatNode *node);
|
|
|
|
static int from_char_parse_int(int *dest, char **src, FormatNode *node);
|
2014-01-18 22:04:11 +01:00
|
|
|
static int seq_search(char *name, const char *const * array, int type, int max, int *len);
|
|
|
|
static int from_char_seq_search(int *dest, char **src, const char *const * array, int type, int max, FormatNode *node);
|
2003-08-25 18:13:27 +02:00
|
|
|
static void do_to_timestamp(text *date_txt, text *fmt,
|
2005-10-15 04:49:52 +02:00
|
|
|
struct pg_tm * tm, fsec_t *fsec);
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
static char *fill_str(char *str, int c, int max);
|
2014-09-13 02:42:19 +02:00
|
|
|
static FormatNode *NUM_cache(int len, NUMDesc *Num, text *pars_str, bool *shouldFree);
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
static char *int_to_roman(int number);
|
|
|
|
static void NUM_prepare_locale(NUMProc *Np);
|
2000-02-08 16:57:01 +01:00
|
|
|
static char *get_last_relevant_decnum(char *num);
|
2014-09-05 15:52:31 +02:00
|
|
|
static void NUM_numpart_from_char(NUMProc *Np, int id, int input_len);
|
2000-04-12 19:17:23 +02:00
|
|
|
static void NUM_numpart_to_char(NUMProc *Np, int id);
|
2014-09-13 02:42:19 +02:00
|
|
|
static char *NUM_processor(FormatNode *node, NUMDesc *Num, char *inout,
|
2015-05-24 03:35:49 +02:00
|
|
|
char *number, int from_char_input_len, int to_char_out_pre_spaces,
|
2014-09-05 15:52:31 +02:00
|
|
|
int sign, bool is_to_char, Oid collid);
|
2000-04-12 19:17:23 +02:00
|
|
|
static DCHCacheEntry *DCH_cache_search(char *str);
|
|
|
|
static DCHCacheEntry *DCH_cache_getnew(char *str);
|
2000-12-15 20:15:09 +01:00
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
static NUMCacheEntry *NUM_cache_search(char *str);
|
|
|
|
static NUMCacheEntry *NUM_cache_getnew(char *str);
|
2000-12-15 20:15:09 +01:00
|
|
|
static void NUM_cache_remove(NUMCacheEntry *ent);
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
2007-02-08 19:19:33 +01:00
|
|
|
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
/* ----------
|
|
|
|
* Fast sequential search, use index for data selection which
|
2002-09-20 05:54:57 +02:00
|
|
|
* go to seq. cycle (it is very fast for unwanted strings)
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* (can't be used binary search in format parsing)
|
|
|
|
* ----------
|
|
|
|
*/
|
2005-03-26 01:41:31 +01:00
|
|
|
static const KeyWord *
|
|
|
|
index_seq_search(char *str, const KeyWord *kw, const int *index)
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
{
|
2000-04-12 19:17:23 +02:00
|
|
|
int poz;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
if (!KeyWord_INDEX_FILTER(*str))
|
2004-01-07 19:56:30 +01:00
|
|
|
return NULL;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
if ((poz = *(index + (*str - ' '))) > -1)
|
|
|
|
{
|
2005-03-26 01:41:31 +01:00
|
|
|
const KeyWord *k = kw + poz;
|
2000-04-12 19:17:23 +02:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2011-12-27 20:19:09 +01:00
|
|
|
if (strncmp(str, k->name, k->len) == 0)
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
return k;
|
|
|
|
k++;
|
|
|
|
if (!k->name)
|
2004-01-07 19:56:30 +01:00
|
|
|
return NULL;
|
2000-04-12 19:17:23 +02:00
|
|
|
} while (*str == *k->name);
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
}
|
2004-01-07 19:56:30 +01:00
|
|
|
return NULL;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
}
|
|
|
|
|
2014-01-18 22:04:11 +01:00
|
|
|
static const KeySuffix *
|
|
|
|
suff_search(char *str, const KeySuffix *suf, int type)
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
{
|
2014-01-18 22:04:11 +01:00
|
|
|
const KeySuffix *s;
|
2000-04-12 19:17:23 +02:00
|
|
|
|
|
|
|
for (s = suf; s->name != NULL; s++)
|
|
|
|
{
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
if (s->type != type)
|
|
|
|
continue;
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2011-12-27 20:19:09 +01:00
|
|
|
if (strncmp(str, s->name, s->len) == 0)
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
return s;
|
|
|
|
}
|
2004-01-07 19:56:30 +01:00
|
|
|
return NULL;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------
|
2014-09-13 02:42:19 +02:00
|
|
|
* Prepare NUMDesc (number description struct) via FormatNode struct
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* ----------
|
|
|
|
*/
|
2000-04-12 19:17:23 +02:00
|
|
|
static void
|
2014-09-13 02:42:19 +02:00
|
|
|
NUMDesc_prepare(NUMDesc *num, FormatNode *n)
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
{
|
|
|
|
if (n->type != NODE_TYPE_ACTION)
|
|
|
|
return;
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2009-08-10 22:16:05 +02:00
|
|
|
/*
|
|
|
|
* In case of an error, we need to remove the numeric from the cache. Use
|
|
|
|
* a PG_TRY block to ensure that this happens.
|
|
|
|
*/
|
|
|
|
PG_TRY();
|
2009-08-10 20:29:27 +02:00
|
|
|
{
|
2014-09-13 02:42:19 +02:00
|
|
|
if (IS_EEEE(num) && n->key->id != NUM_E)
|
2010-02-26 03:01:40 +01:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_SYNTAX_ERROR),
|
|
|
|
errmsg("\"EEEE\" must be the last pattern used")));
|
2009-08-10 20:29:27 +02:00
|
|
|
|
2010-02-26 03:01:40 +01:00
|
|
|
switch (n->key->id)
|
|
|
|
{
|
|
|
|
case NUM_9:
|
2014-09-13 02:42:19 +02:00
|
|
|
if (IS_BRACKET(num))
|
2010-02-26 03:01:40 +01:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_SYNTAX_ERROR),
|
|
|
|
errmsg("\"9\" must be ahead of \"PR\"")));
|
2014-09-13 02:42:19 +02:00
|
|
|
if (IS_MULTI(num))
|
2010-02-26 03:01:40 +01:00
|
|
|
{
|
2014-09-13 02:42:19 +02:00
|
|
|
++num->multi;
|
2010-02-26 03:01:40 +01:00
|
|
|
break;
|
|
|
|
}
|
2014-09-13 02:42:19 +02:00
|
|
|
if (IS_DECIMAL(num))
|
|
|
|
++num->post;
|
2010-02-26 03:01:40 +01:00
|
|
|
else
|
2014-09-13 02:42:19 +02:00
|
|
|
++num->pre;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
break;
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2010-02-26 03:01:40 +01:00
|
|
|
case NUM_0:
|
2014-09-13 02:42:19 +02:00
|
|
|
if (IS_BRACKET(num))
|
2010-02-26 03:01:40 +01:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_SYNTAX_ERROR),
|
|
|
|
errmsg("\"0\" must be ahead of \"PR\"")));
|
2014-09-13 02:42:19 +02:00
|
|
|
if (!IS_ZERO(num) && !IS_DECIMAL(num))
|
2010-02-26 03:01:40 +01:00
|
|
|
{
|
2014-09-13 02:42:19 +02:00
|
|
|
num->flag |= NUM_F_ZERO;
|
|
|
|
num->zero_start = num->pre + 1;
|
2010-02-26 03:01:40 +01:00
|
|
|
}
|
2014-09-13 02:42:19 +02:00
|
|
|
if (!IS_DECIMAL(num))
|
|
|
|
++num->pre;
|
2010-02-26 03:01:40 +01:00
|
|
|
else
|
2014-09-13 02:42:19 +02:00
|
|
|
++num->post;
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2014-09-13 02:42:19 +02:00
|
|
|
num->zero_end = num->pre + num->post;
|
2010-02-26 03:01:40 +01:00
|
|
|
break;
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2010-02-26 03:01:40 +01:00
|
|
|
case NUM_B:
|
2014-09-13 02:42:19 +02:00
|
|
|
if (num->pre == 0 && num->post == 0 && (!IS_ZERO(num)))
|
|
|
|
num->flag |= NUM_F_BLANK;
|
2010-02-26 03:01:40 +01:00
|
|
|
break;
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2010-02-26 03:01:40 +01:00
|
|
|
case NUM_D:
|
2014-09-13 02:42:19 +02:00
|
|
|
num->flag |= NUM_F_LDECIMAL;
|
|
|
|
num->need_locale = TRUE;
|
2012-03-12 19:55:09 +01:00
|
|
|
/* FALLTHROUGH */
|
2010-02-26 03:01:40 +01:00
|
|
|
case NUM_DEC:
|
2014-09-13 02:42:19 +02:00
|
|
|
if (IS_DECIMAL(num))
|
2010-02-26 03:01:40 +01:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_SYNTAX_ERROR),
|
|
|
|
errmsg("multiple decimal points")));
|
2014-09-13 02:42:19 +02:00
|
|
|
if (IS_MULTI(num))
|
2010-02-26 03:01:40 +01:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_SYNTAX_ERROR),
|
2005-10-15 04:49:52 +02:00
|
|
|
errmsg("cannot use \"V\" and decimal point together")));
|
2014-09-13 02:42:19 +02:00
|
|
|
num->flag |= NUM_F_DECIMAL;
|
2010-02-26 03:01:40 +01:00
|
|
|
break;
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2010-02-26 03:01:40 +01:00
|
|
|
case NUM_FM:
|
2014-09-13 02:42:19 +02:00
|
|
|
num->flag |= NUM_F_FILLMODE;
|
2010-02-26 03:01:40 +01:00
|
|
|
break;
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2010-02-26 03:01:40 +01:00
|
|
|
case NUM_S:
|
2014-09-13 02:42:19 +02:00
|
|
|
if (IS_LSIGN(num))
|
2010-02-26 03:01:40 +01:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_SYNTAX_ERROR),
|
|
|
|
errmsg("cannot use \"S\" twice")));
|
2014-09-13 02:42:19 +02:00
|
|
|
if (IS_PLUS(num) || IS_MINUS(num) || IS_BRACKET(num))
|
2010-02-26 03:01:40 +01:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_SYNTAX_ERROR),
|
|
|
|
errmsg("cannot use \"S\" and \"PL\"/\"MI\"/\"SG\"/\"PR\" together")));
|
2014-09-13 02:42:19 +02:00
|
|
|
if (!IS_DECIMAL(num))
|
2010-02-26 03:01:40 +01:00
|
|
|
{
|
2014-09-13 02:42:19 +02:00
|
|
|
num->lsign = NUM_LSIGN_PRE;
|
|
|
|
num->pre_lsign_num = num->pre;
|
|
|
|
num->need_locale = TRUE;
|
|
|
|
num->flag |= NUM_F_LSIGN;
|
2010-02-26 03:01:40 +01:00
|
|
|
}
|
2014-09-13 02:42:19 +02:00
|
|
|
else if (num->lsign == NUM_LSIGN_NONE)
|
2010-02-26 03:01:40 +01:00
|
|
|
{
|
2014-09-13 02:42:19 +02:00
|
|
|
num->lsign = NUM_LSIGN_POST;
|
|
|
|
num->need_locale = TRUE;
|
|
|
|
num->flag |= NUM_F_LSIGN;
|
2010-02-26 03:01:40 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NUM_MI:
|
2014-09-13 02:42:19 +02:00
|
|
|
if (IS_LSIGN(num))
|
2010-02-26 03:01:40 +01:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_SYNTAX_ERROR),
|
|
|
|
errmsg("cannot use \"S\" and \"MI\" together")));
|
2014-09-13 02:42:19 +02:00
|
|
|
num->flag |= NUM_F_MINUS;
|
|
|
|
if (IS_DECIMAL(num))
|
|
|
|
num->flag |= NUM_F_MINUS_POST;
|
2010-02-26 03:01:40 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NUM_PL:
|
2014-09-13 02:42:19 +02:00
|
|
|
if (IS_LSIGN(num))
|
2010-02-26 03:01:40 +01:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_SYNTAX_ERROR),
|
|
|
|
errmsg("cannot use \"S\" and \"PL\" together")));
|
2014-09-13 02:42:19 +02:00
|
|
|
num->flag |= NUM_F_PLUS;
|
|
|
|
if (IS_DECIMAL(num))
|
|
|
|
num->flag |= NUM_F_PLUS_POST;
|
2010-02-26 03:01:40 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NUM_SG:
|
2014-09-13 02:42:19 +02:00
|
|
|
if (IS_LSIGN(num))
|
2010-02-26 03:01:40 +01:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_SYNTAX_ERROR),
|
|
|
|
errmsg("cannot use \"S\" and \"SG\" together")));
|
2014-09-13 02:42:19 +02:00
|
|
|
num->flag |= NUM_F_MINUS;
|
|
|
|
num->flag |= NUM_F_PLUS;
|
2010-02-26 03:01:40 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NUM_PR:
|
2014-09-13 02:42:19 +02:00
|
|
|
if (IS_LSIGN(num) || IS_PLUS(num) || IS_MINUS(num))
|
2010-02-26 03:01:40 +01:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_SYNTAX_ERROR),
|
|
|
|
errmsg("cannot use \"PR\" and \"S\"/\"PL\"/\"MI\"/\"SG\" together")));
|
2014-09-13 02:42:19 +02:00
|
|
|
num->flag |= NUM_F_BRACKET;
|
2010-02-26 03:01:40 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NUM_rn:
|
|
|
|
case NUM_RN:
|
2014-09-13 02:42:19 +02:00
|
|
|
num->flag |= NUM_F_ROMAN;
|
2010-02-26 03:01:40 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NUM_L:
|
|
|
|
case NUM_G:
|
2014-09-13 02:42:19 +02:00
|
|
|
num->need_locale = TRUE;
|
2010-02-26 03:01:40 +01:00
|
|
|
break;
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2010-02-26 03:01:40 +01:00
|
|
|
case NUM_V:
|
2014-09-13 02:42:19 +02:00
|
|
|
if (IS_DECIMAL(num))
|
2010-02-26 03:01:40 +01:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_SYNTAX_ERROR),
|
2005-10-15 04:49:52 +02:00
|
|
|
errmsg("cannot use \"V\" and decimal point together")));
|
2014-09-13 02:42:19 +02:00
|
|
|
num->flag |= NUM_F_MULTI;
|
2010-02-26 03:01:40 +01:00
|
|
|
break;
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2010-02-26 03:01:40 +01:00
|
|
|
case NUM_E:
|
2014-09-13 02:42:19 +02:00
|
|
|
if (IS_EEEE(num))
|
2010-02-26 03:01:40 +01:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_SYNTAX_ERROR),
|
|
|
|
errmsg("cannot use \"EEEE\" twice")));
|
2014-09-13 02:42:19 +02:00
|
|
|
if (IS_BLANK(num) || IS_FILLMODE(num) || IS_LSIGN(num) ||
|
|
|
|
IS_BRACKET(num) || IS_MINUS(num) || IS_PLUS(num) ||
|
|
|
|
IS_ROMAN(num) || IS_MULTI(num))
|
2010-02-26 03:01:40 +01:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_SYNTAX_ERROR),
|
|
|
|
errmsg("\"EEEE\" is incompatible with other formats"),
|
|
|
|
errdetail("\"EEEE\" may only be used together with digit and decimal point patterns.")));
|
2014-09-13 02:42:19 +02:00
|
|
|
num->flag |= NUM_F_EEEE;
|
2010-02-26 03:01:40 +01:00
|
|
|
break;
|
|
|
|
}
|
2009-08-10 22:16:05 +02:00
|
|
|
}
|
|
|
|
PG_CATCH();
|
|
|
|
{
|
|
|
|
NUM_cache_remove(last_NUMCacheEntry);
|
|
|
|
PG_RE_THROW();
|
|
|
|
}
|
|
|
|
PG_END_TRY();
|
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------
|
2000-04-12 19:17:23 +02:00
|
|
|
* Format parser, search small keywords and keyword's suffixes, and make
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* format-node tree.
|
|
|
|
*
|
2000-04-12 19:17:23 +02:00
|
|
|
* for DATE-TIME & NUMBER version
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* ----------
|
|
|
|
*/
|
2000-04-12 19:17:23 +02:00
|
|
|
static void
|
2005-03-26 01:41:31 +01:00
|
|
|
parse_format(FormatNode *node, char *str, const KeyWord *kw,
|
2014-09-13 02:42:19 +02:00
|
|
|
const KeySuffix *suf, const int *index, int ver, NUMDesc *Num)
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
{
|
2014-01-18 22:04:11 +01:00
|
|
|
const KeySuffix *s;
|
2001-03-22 05:01:46 +01:00
|
|
|
FormatNode *n;
|
|
|
|
int node_set = 0,
|
|
|
|
suffix,
|
|
|
|
last = 0;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
|
|
|
#ifdef DEBUG_TO_FROM_CHAR
|
2003-07-27 06:53:12 +02:00
|
|
|
elog(DEBUG_elog_output, "to_char/number(): run parser");
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
n = node;
|
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
while (*str)
|
|
|
|
{
|
|
|
|
suffix = 0;
|
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
2000-04-12 19:17:23 +02:00
|
|
|
* Prefix
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
*/
|
2000-04-12 19:17:23 +02:00
|
|
|
if (ver == DCH_TYPE && (s = suff_search(str, suf, SUFFTYPE_PREFIX)) != NULL)
|
|
|
|
{
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
suffix |= s->id;
|
|
|
|
if (s->len)
|
|
|
|
str += s->len;
|
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
2000-04-12 19:17:23 +02:00
|
|
|
* Keyword
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
*/
|
2000-04-12 19:17:23 +02:00
|
|
|
if (*str && (n->key = index_seq_search(str, kw, index)) != NULL)
|
|
|
|
{
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
n->type = NODE_TYPE_ACTION;
|
|
|
|
n->suffix = 0;
|
2000-04-12 19:17:23 +02:00
|
|
|
node_set = 1;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
if (n->key->len)
|
|
|
|
str += n->key->len;
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
2014-09-13 02:42:19 +02:00
|
|
|
* NUM version: Prepare global NUMDesc struct
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
*/
|
2000-04-12 19:17:23 +02:00
|
|
|
if (ver == NUM_TYPE)
|
2014-09-13 02:42:19 +02:00
|
|
|
NUMDesc_prepare(Num, n);
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* Postfix
|
|
|
|
*/
|
2000-04-12 19:17:23 +02:00
|
|
|
if (ver == DCH_TYPE && *str && (s = suff_search(str, suf, SUFFTYPE_POSTFIX)) != NULL)
|
|
|
|
{
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
suffix |= s->id;
|
|
|
|
if (s->len)
|
|
|
|
str += s->len;
|
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
|
|
|
else if (*str)
|
|
|
|
{
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
2000-04-12 19:17:23 +02:00
|
|
|
* Special characters '\' and '"'
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
*/
|
2000-04-12 19:17:23 +02:00
|
|
|
if (*str == '"' && last != '\\')
|
|
|
|
{
|
|
|
|
int x = 0;
|
|
|
|
|
|
|
|
while (*(++str))
|
|
|
|
{
|
|
|
|
if (*str == '"' && x != '\\')
|
|
|
|
{
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
str++;
|
|
|
|
break;
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
|
|
|
else if (*str == '\\' && x != '\\')
|
|
|
|
{
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
x = '\\';
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
n->type = NODE_TYPE_CHAR;
|
|
|
|
n->character = *str;
|
2004-01-07 19:56:30 +01:00
|
|
|
n->key = NULL;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
n->suffix = 0;
|
|
|
|
++n;
|
2000-04-12 19:17:23 +02:00
|
|
|
x = *str;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
}
|
|
|
|
node_set = 0;
|
|
|
|
suffix = 0;
|
|
|
|
last = 0;
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
|
|
|
else if (*str && *str == '\\' && last != '\\' && *(str + 1) == '"')
|
|
|
|
{
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
last = *str;
|
|
|
|
str++;
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
|
|
|
else if (*str)
|
|
|
|
{
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
n->type = NODE_TYPE_CHAR;
|
|
|
|
n->character = *str;
|
2004-01-07 19:56:30 +01:00
|
|
|
n->key = NULL;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
node_set = 1;
|
|
|
|
last = 0;
|
|
|
|
str++;
|
|
|
|
}
|
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
|
|
|
|
/* end */
|
|
|
|
if (node_set)
|
|
|
|
{
|
|
|
|
if (n->type == NODE_TYPE_ACTION)
|
|
|
|
n->suffix = suffix;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
++n;
|
|
|
|
|
|
|
|
n->suffix = 0;
|
|
|
|
node_set = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
n->type = NODE_TYPE_END;
|
|
|
|
n->suffix = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------
|
|
|
|
* DEBUG: Dump the FormatNode Tree (debug)
|
|
|
|
* ----------
|
|
|
|
*/
|
|
|
|
#ifdef DEBUG_TO_FROM_CHAR
|
|
|
|
|
|
|
|
#define DUMP_THth(_suf) (S_TH(_suf) ? "TH" : (S_th(_suf) ? "th" : " "))
|
|
|
|
#define DUMP_FM(_suf) (S_FM(_suf) ? "FM" : " ")
|
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
static void
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
dump_node(FormatNode *node, int max)
|
|
|
|
{
|
2000-04-12 19:17:23 +02:00
|
|
|
FormatNode *n;
|
|
|
|
int a;
|
|
|
|
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
elog(DEBUG_elog_output, "to_from-char(): DUMP FORMAT");
|
2000-04-12 19:17:23 +02:00
|
|
|
|
|
|
|
for (a = 0, n = node; a <= max; n++, a++)
|
|
|
|
{
|
|
|
|
if (n->type == NODE_TYPE_ACTION)
|
|
|
|
elog(DEBUG_elog_output, "%d:\t NODE_TYPE_ACTION '%s'\t(%s,%s)",
|
2005-10-15 04:49:52 +02:00
|
|
|
a, n->key->name, DUMP_THth(n->suffix), DUMP_FM(n->suffix));
|
2000-04-12 19:17:23 +02:00
|
|
|
else if (n->type == NODE_TYPE_CHAR)
|
|
|
|
elog(DEBUG_elog_output, "%d:\t NODE_TYPE_CHAR '%c'", a, n->character);
|
|
|
|
else if (n->type == NODE_TYPE_END)
|
|
|
|
{
|
|
|
|
elog(DEBUG_elog_output, "%d:\t NODE_TYPE_END", a);
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
return;
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
|
|
|
else
|
2003-07-27 06:53:12 +02:00
|
|
|
elog(DEBUG_elog_output, "%d:\t unknown NODE!", a);
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
}
|
|
|
|
}
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* DEBUG */
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
|
|
|
/*****************************************************************************
|
2000-04-12 19:17:23 +02:00
|
|
|
* Private utils
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
/* ----------
|
2000-04-12 19:17:23 +02:00
|
|
|
* Return ST/ND/RD/TH for simple (1..9) numbers
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* type --> 0 upper, 1 lower
|
2000-04-12 19:17:23 +02:00
|
|
|
* ----------
|
|
|
|
*/
|
2014-01-18 22:04:11 +01:00
|
|
|
static const char *
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
get_th(char *num, int type)
|
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
int len = strlen(num),
|
|
|
|
last,
|
|
|
|
seclast;
|
2000-04-12 19:17:23 +02:00
|
|
|
|
|
|
|
last = *(num + (len - 1));
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
if (!isdigit((unsigned char) last))
|
2003-07-27 06:53:12 +02:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
|
|
|
|
errmsg("\"%s\" is not a number", num)));
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2000-07-01 23:27:14 +02:00
|
|
|
/*
|
2001-03-22 05:01:46 +01:00
|
|
|
* All "teens" (<x>1[0-9]) get 'TH/th', while <x>[02-9][123] still get
|
|
|
|
* 'ST/st', 'ND/nd', 'RD/rd', respectively
|
2000-07-01 23:27:14 +02:00
|
|
|
*/
|
2001-03-22 05:01:46 +01:00
|
|
|
if ((len > 1) && ((seclast = num[len - 2]) == '1'))
|
2000-04-12 19:17:23 +02:00
|
|
|
last = 0;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
switch (last)
|
|
|
|
{
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
case '1':
|
2000-04-12 19:17:23 +02:00
|
|
|
if (type == TH_UPPER)
|
|
|
|
return numTH[0];
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
return numth[0];
|
|
|
|
case '2':
|
2000-04-12 19:17:23 +02:00
|
|
|
if (type == TH_UPPER)
|
|
|
|
return numTH[1];
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
return numth[1];
|
|
|
|
case '3':
|
2000-04-12 19:17:23 +02:00
|
|
|
if (type == TH_UPPER)
|
|
|
|
return numTH[2];
|
|
|
|
return numth[2];
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
default:
|
2000-04-12 19:17:23 +02:00
|
|
|
if (type == TH_UPPER)
|
|
|
|
return numTH[3];
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
return numth[3];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------
|
2000-04-12 19:17:23 +02:00
|
|
|
* Convert string-number to ordinal string-number
|
|
|
|
* type --> 0 upper, 1 lower
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* ----------
|
|
|
|
*/
|
|
|
|
static char *
|
|
|
|
str_numth(char *dest, char *num, int type)
|
|
|
|
{
|
2005-01-13 02:40:13 +01:00
|
|
|
if (dest != num)
|
|
|
|
strcpy(dest, num);
|
|
|
|
strcat(dest, get_th(num, type));
|
2000-04-12 19:17:23 +02:00
|
|
|
return dest;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
}
|
|
|
|
|
2011-04-23 18:35:41 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* upper/lower/initcap functions
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2008-06-23 21:27:19 +02:00
|
|
|
/*
|
|
|
|
* If the system provides the needed functions for wide-character manipulation
|
|
|
|
* (which are all standardized by C99), then we implement upper/lower/initcap
|
|
|
|
* using wide-character functions, if necessary. Otherwise we use the
|
|
|
|
* traditional <ctype.h> functions, which of course will not work as desired
|
|
|
|
* in multibyte character sets. Note that in either case we are effectively
|
|
|
|
* assuming that the database character encoding matches the encoding implied
|
|
|
|
* by LC_CTYPE.
|
2011-03-20 17:43:39 +01:00
|
|
|
*
|
|
|
|
* If the system provides locale_t and associated functions (which are
|
|
|
|
* standardized by Open Group's XBD), we can support collations that are
|
|
|
|
* neither default nor C. The code is written to handle both combinations
|
|
|
|
* of have-wide-characters and have-locale_t, though it's rather unlikely
|
|
|
|
* a platform would have the latter without the former.
|
2008-06-23 21:27:19 +02:00
|
|
|
*/
|
|
|
|
|
2008-07-12 02:44:38 +02:00
|
|
|
/*
|
2011-03-20 17:43:39 +01:00
|
|
|
* collation-aware, wide-character-aware lower function
|
2008-07-12 02:44:38 +02:00
|
|
|
*
|
2008-06-23 21:27:19 +02:00
|
|
|
* We pass the number of bytes so we can pass varlena and char*
|
2008-07-12 02:44:38 +02:00
|
|
|
* to this function. The result is a palloc'd, null-terminated string.
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
*/
|
2008-06-23 21:27:19 +02:00
|
|
|
char *
|
2011-02-08 22:04:18 +01:00
|
|
|
str_tolower(const char *buff, size_t nbytes, Oid collid)
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2009-06-11 16:49:15 +02:00
|
|
|
char *result;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
2002-09-20 05:54:57 +02:00
|
|
|
if (!buff)
|
|
|
|
return NULL;
|
|
|
|
|
2011-03-20 17:43:39 +01:00
|
|
|
/* C/POSIX collations use this path regardless of database encoding */
|
|
|
|
if (lc_ctype_is_c(collid))
|
|
|
|
{
|
2013-03-05 19:02:30 +01:00
|
|
|
result = asc_tolower(buff, nbytes);
|
2011-03-20 17:43:39 +01:00
|
|
|
}
|
2008-05-19 20:08:16 +02:00
|
|
|
#ifdef USE_WIDE_UPPER_LOWER
|
2011-03-20 17:43:39 +01:00
|
|
|
else if (pg_database_encoding_max_length() > 1)
|
2008-06-23 21:27:19 +02:00
|
|
|
{
|
2011-04-10 17:42:00 +02:00
|
|
|
pg_locale_t mylocale = 0;
|
2009-06-11 16:49:15 +02:00
|
|
|
wchar_t *workspace;
|
2008-12-15 15:55:50 +01:00
|
|
|
size_t curr_char;
|
|
|
|
size_t result_size;
|
|
|
|
|
2011-03-20 17:43:39 +01:00
|
|
|
if (collid != DEFAULT_COLLATION_OID)
|
2011-03-22 21:55:32 +01:00
|
|
|
{
|
|
|
|
if (!OidIsValid(collid))
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* This typically means that the parser could not resolve a
|
|
|
|
* conflict of implicit collations, so report it that way.
|
|
|
|
*/
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_INDETERMINATE_COLLATION),
|
|
|
|
errmsg("could not determine which collation to use for lower() function"),
|
|
|
|
errhint("Use the COLLATE clause to set the collation explicitly.")));
|
|
|
|
}
|
2011-03-20 17:43:39 +01:00
|
|
|
mylocale = pg_newlocale_from_collation(collid);
|
2011-03-22 21:55:32 +01:00
|
|
|
}
|
2011-03-20 17:43:39 +01:00
|
|
|
|
2008-12-15 15:55:50 +01:00
|
|
|
/* Overflow paranoia */
|
|
|
|
if ((nbytes + 1) > (INT_MAX / sizeof(wchar_t)))
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_OUT_OF_MEMORY),
|
|
|
|
errmsg("out of memory")));
|
2008-06-23 21:27:19 +02:00
|
|
|
|
|
|
|
/* Output workspace cannot have more codes than input bytes */
|
|
|
|
workspace = (wchar_t *) palloc((nbytes + 1) * sizeof(wchar_t));
|
|
|
|
|
2011-04-23 18:35:41 +02:00
|
|
|
char2wchar(workspace, nbytes + 1, buff, nbytes, mylocale);
|
2008-06-23 21:27:19 +02:00
|
|
|
|
|
|
|
for (curr_char = 0; workspace[curr_char] != 0; curr_char++)
|
2011-03-20 17:43:39 +01:00
|
|
|
{
|
2011-02-08 22:04:18 +01:00
|
|
|
#ifdef HAVE_LOCALE_T
|
|
|
|
if (mylocale)
|
|
|
|
workspace[curr_char] = towlower_l(workspace[curr_char], mylocale);
|
|
|
|
else
|
|
|
|
#endif
|
2011-03-20 17:43:39 +01:00
|
|
|
workspace[curr_char] = towlower(workspace[curr_char]);
|
|
|
|
}
|
2008-06-23 21:27:19 +02:00
|
|
|
|
|
|
|
/* Make result large enough; case change might change number of bytes */
|
2008-12-15 15:55:50 +01:00
|
|
|
result_size = curr_char * pg_database_encoding_max_length() + 1;
|
|
|
|
result = palloc(result_size);
|
2008-06-23 21:27:19 +02:00
|
|
|
|
2011-04-23 18:35:41 +02:00
|
|
|
wchar2char(result, workspace, result_size, mylocale);
|
2008-06-23 21:27:19 +02:00
|
|
|
pfree(workspace);
|
|
|
|
}
|
2009-06-11 16:49:15 +02:00
|
|
|
#endif /* USE_WIDE_UPPER_LOWER */
|
2011-03-20 17:43:39 +01:00
|
|
|
else
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2011-12-11 00:15:15 +01:00
|
|
|
#ifdef HAVE_LOCALE_T
|
2011-04-10 17:42:00 +02:00
|
|
|
pg_locale_t mylocale = 0;
|
2011-12-11 00:15:15 +01:00
|
|
|
#endif
|
2009-06-11 16:49:15 +02:00
|
|
|
char *p;
|
2008-05-19 20:08:16 +02:00
|
|
|
|
2011-03-20 17:43:39 +01:00
|
|
|
if (collid != DEFAULT_COLLATION_OID)
|
2011-03-22 21:55:32 +01:00
|
|
|
{
|
|
|
|
if (!OidIsValid(collid))
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* This typically means that the parser could not resolve a
|
|
|
|
* conflict of implicit collations, so report it that way.
|
|
|
|
*/
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_INDETERMINATE_COLLATION),
|
|
|
|
errmsg("could not determine which collation to use for lower() function"),
|
|
|
|
errhint("Use the COLLATE clause to set the collation explicitly.")));
|
|
|
|
}
|
2011-12-11 00:15:15 +01:00
|
|
|
#ifdef HAVE_LOCALE_T
|
2011-03-20 17:43:39 +01:00
|
|
|
mylocale = pg_newlocale_from_collation(collid);
|
2011-12-11 00:15:15 +01:00
|
|
|
#endif
|
2011-03-22 21:55:32 +01:00
|
|
|
}
|
2011-03-20 17:43:39 +01:00
|
|
|
|
2008-06-23 21:27:19 +02:00
|
|
|
result = pnstrdup(buff, nbytes);
|
2008-05-19 20:08:16 +02:00
|
|
|
|
2011-03-20 17:43:39 +01:00
|
|
|
/*
|
|
|
|
* Note: we assume that tolower_l() will not be so broken as to need
|
|
|
|
* an isupper_l() guard test. When using the default collation, we
|
|
|
|
* apply the traditional Postgres behavior that forces ASCII-style
|
|
|
|
* treatment of I/i, but in non-default collations you get exactly
|
|
|
|
* what the collation says.
|
|
|
|
*/
|
2008-05-19 20:08:16 +02:00
|
|
|
for (p = result; *p; p++)
|
2011-03-20 17:43:39 +01:00
|
|
|
{
|
|
|
|
#ifdef HAVE_LOCALE_T
|
|
|
|
if (mylocale)
|
|
|
|
*p = tolower_l((unsigned char) *p, mylocale);
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
*p = pg_tolower((unsigned char) *p);
|
|
|
|
}
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
}
|
2007-02-08 19:19:33 +01:00
|
|
|
|
2008-05-19 20:08:16 +02:00
|
|
|
return result;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
}
|
|
|
|
|
2008-07-12 02:44:38 +02:00
|
|
|
/*
|
2011-03-20 17:43:39 +01:00
|
|
|
* collation-aware, wide-character-aware upper function
|
2008-07-12 02:44:38 +02:00
|
|
|
*
|
2008-06-23 21:27:19 +02:00
|
|
|
* We pass the number of bytes so we can pass varlena and char*
|
2008-07-12 02:44:38 +02:00
|
|
|
* to this function. The result is a palloc'd, null-terminated string.
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
*/
|
2008-06-23 21:27:19 +02:00
|
|
|
char *
|
2011-02-08 22:04:18 +01:00
|
|
|
str_toupper(const char *buff, size_t nbytes, Oid collid)
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2009-06-11 16:49:15 +02:00
|
|
|
char *result;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
2002-09-20 05:54:57 +02:00
|
|
|
if (!buff)
|
|
|
|
return NULL;
|
|
|
|
|
2011-03-20 17:43:39 +01:00
|
|
|
/* C/POSIX collations use this path regardless of database encoding */
|
|
|
|
if (lc_ctype_is_c(collid))
|
|
|
|
{
|
2013-03-05 19:02:30 +01:00
|
|
|
result = asc_toupper(buff, nbytes);
|
2011-03-20 17:43:39 +01:00
|
|
|
}
|
2008-05-19 20:08:16 +02:00
|
|
|
#ifdef USE_WIDE_UPPER_LOWER
|
2011-03-20 17:43:39 +01:00
|
|
|
else if (pg_database_encoding_max_length() > 1)
|
2008-06-23 21:27:19 +02:00
|
|
|
{
|
2011-04-10 17:42:00 +02:00
|
|
|
pg_locale_t mylocale = 0;
|
2009-06-11 16:49:15 +02:00
|
|
|
wchar_t *workspace;
|
2008-12-15 15:55:50 +01:00
|
|
|
size_t curr_char;
|
|
|
|
size_t result_size;
|
|
|
|
|
2011-03-20 17:43:39 +01:00
|
|
|
if (collid != DEFAULT_COLLATION_OID)
|
2011-03-22 21:55:32 +01:00
|
|
|
{
|
|
|
|
if (!OidIsValid(collid))
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* This typically means that the parser could not resolve a
|
|
|
|
* conflict of implicit collations, so report it that way.
|
|
|
|
*/
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_INDETERMINATE_COLLATION),
|
|
|
|
errmsg("could not determine which collation to use for upper() function"),
|
|
|
|
errhint("Use the COLLATE clause to set the collation explicitly.")));
|
|
|
|
}
|
2011-03-20 17:43:39 +01:00
|
|
|
mylocale = pg_newlocale_from_collation(collid);
|
2011-03-22 21:55:32 +01:00
|
|
|
}
|
2011-03-20 17:43:39 +01:00
|
|
|
|
2008-12-15 15:55:50 +01:00
|
|
|
/* Overflow paranoia */
|
|
|
|
if ((nbytes + 1) > (INT_MAX / sizeof(wchar_t)))
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_OUT_OF_MEMORY),
|
|
|
|
errmsg("out of memory")));
|
2008-06-23 21:27:19 +02:00
|
|
|
|
|
|
|
/* Output workspace cannot have more codes than input bytes */
|
|
|
|
workspace = (wchar_t *) palloc((nbytes + 1) * sizeof(wchar_t));
|
|
|
|
|
2011-04-23 18:35:41 +02:00
|
|
|
char2wchar(workspace, nbytes + 1, buff, nbytes, mylocale);
|
2008-06-23 21:27:19 +02:00
|
|
|
|
|
|
|
for (curr_char = 0; workspace[curr_char] != 0; curr_char++)
|
2011-03-20 17:43:39 +01:00
|
|
|
{
|
2011-02-08 22:04:18 +01:00
|
|
|
#ifdef HAVE_LOCALE_T
|
|
|
|
if (mylocale)
|
|
|
|
workspace[curr_char] = towupper_l(workspace[curr_char], mylocale);
|
|
|
|
else
|
|
|
|
#endif
|
2011-03-20 17:43:39 +01:00
|
|
|
workspace[curr_char] = towupper(workspace[curr_char]);
|
|
|
|
}
|
2008-06-23 21:27:19 +02:00
|
|
|
|
|
|
|
/* Make result large enough; case change might change number of bytes */
|
2008-12-15 15:55:50 +01:00
|
|
|
result_size = curr_char * pg_database_encoding_max_length() + 1;
|
|
|
|
result = palloc(result_size);
|
2008-06-23 21:27:19 +02:00
|
|
|
|
2011-04-23 18:35:41 +02:00
|
|
|
wchar2char(result, workspace, result_size, mylocale);
|
2008-06-23 21:27:19 +02:00
|
|
|
pfree(workspace);
|
|
|
|
}
|
2009-06-11 16:49:15 +02:00
|
|
|
#endif /* USE_WIDE_UPPER_LOWER */
|
2011-03-20 17:43:39 +01:00
|
|
|
else
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2011-12-11 00:15:15 +01:00
|
|
|
#ifdef HAVE_LOCALE_T
|
2011-04-10 17:42:00 +02:00
|
|
|
pg_locale_t mylocale = 0;
|
2011-12-11 00:15:15 +01:00
|
|
|
#endif
|
2009-06-11 16:49:15 +02:00
|
|
|
char *p;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
2011-03-20 17:43:39 +01:00
|
|
|
if (collid != DEFAULT_COLLATION_OID)
|
2011-03-22 21:55:32 +01:00
|
|
|
{
|
|
|
|
if (!OidIsValid(collid))
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* This typically means that the parser could not resolve a
|
|
|
|
* conflict of implicit collations, so report it that way.
|
|
|
|
*/
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_INDETERMINATE_COLLATION),
|
|
|
|
errmsg("could not determine which collation to use for upper() function"),
|
|
|
|
errhint("Use the COLLATE clause to set the collation explicitly.")));
|
|
|
|
}
|
2011-12-11 00:15:15 +01:00
|
|
|
#ifdef HAVE_LOCALE_T
|
2011-03-20 17:43:39 +01:00
|
|
|
mylocale = pg_newlocale_from_collation(collid);
|
2011-12-11 00:15:15 +01:00
|
|
|
#endif
|
2011-03-22 21:55:32 +01:00
|
|
|
}
|
2011-03-20 17:43:39 +01:00
|
|
|
|
2008-06-23 21:27:19 +02:00
|
|
|
result = pnstrdup(buff, nbytes);
|
2007-02-08 19:19:33 +01:00
|
|
|
|
2011-03-20 17:43:39 +01:00
|
|
|
/*
|
|
|
|
* Note: we assume that toupper_l() will not be so broken as to need
|
|
|
|
* an islower_l() guard test. When using the default collation, we
|
|
|
|
* apply the traditional Postgres behavior that forces ASCII-style
|
|
|
|
* treatment of I/i, but in non-default collations you get exactly
|
|
|
|
* what the collation says.
|
|
|
|
*/
|
2008-05-19 20:08:16 +02:00
|
|
|
for (p = result; *p; p++)
|
2011-03-20 17:43:39 +01:00
|
|
|
{
|
|
|
|
#ifdef HAVE_LOCALE_T
|
|
|
|
if (mylocale)
|
|
|
|
*p = toupper_l((unsigned char) *p, mylocale);
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
*p = pg_toupper((unsigned char) *p);
|
|
|
|
}
|
2008-05-19 20:08:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2008-06-23 21:27:19 +02:00
|
|
|
|
2008-07-12 02:44:38 +02:00
|
|
|
/*
|
2011-03-20 17:43:39 +01:00
|
|
|
* collation-aware, wide-character-aware initcap function
|
2008-07-12 02:44:38 +02:00
|
|
|
*
|
2008-06-23 21:27:19 +02:00
|
|
|
* We pass the number of bytes so we can pass varlena and char*
|
2008-07-12 02:44:38 +02:00
|
|
|
* to this function. The result is a palloc'd, null-terminated string.
|
2007-02-08 19:19:33 +01:00
|
|
|
*/
|
2008-06-23 21:27:19 +02:00
|
|
|
char *
|
2011-02-08 22:04:18 +01:00
|
|
|
str_initcap(const char *buff, size_t nbytes, Oid collid)
|
2007-02-08 19:19:33 +01:00
|
|
|
{
|
2009-06-11 16:49:15 +02:00
|
|
|
char *result;
|
2008-10-06 07:03:27 +02:00
|
|
|
int wasalnum = false;
|
2008-05-19 20:08:16 +02:00
|
|
|
|
2007-02-08 19:19:33 +01:00
|
|
|
if (!buff)
|
|
|
|
return NULL;
|
|
|
|
|
2011-03-20 17:43:39 +01:00
|
|
|
/* C/POSIX collations use this path regardless of database encoding */
|
|
|
|
if (lc_ctype_is_c(collid))
|
|
|
|
{
|
2013-03-05 19:02:30 +01:00
|
|
|
result = asc_initcap(buff, nbytes);
|
2011-03-20 17:43:39 +01:00
|
|
|
}
|
2008-05-19 20:08:16 +02:00
|
|
|
#ifdef USE_WIDE_UPPER_LOWER
|
2011-03-20 17:43:39 +01:00
|
|
|
else if (pg_database_encoding_max_length() > 1)
|
2007-02-08 19:19:33 +01:00
|
|
|
{
|
2011-04-10 17:42:00 +02:00
|
|
|
pg_locale_t mylocale = 0;
|
2009-06-11 16:49:15 +02:00
|
|
|
wchar_t *workspace;
|
2008-12-15 15:55:50 +01:00
|
|
|
size_t curr_char;
|
|
|
|
size_t result_size;
|
|
|
|
|
2011-03-20 17:43:39 +01:00
|
|
|
if (collid != DEFAULT_COLLATION_OID)
|
2011-03-22 21:55:32 +01:00
|
|
|
{
|
|
|
|
if (!OidIsValid(collid))
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* This typically means that the parser could not resolve a
|
|
|
|
* conflict of implicit collations, so report it that way.
|
|
|
|
*/
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_INDETERMINATE_COLLATION),
|
|
|
|
errmsg("could not determine which collation to use for initcap() function"),
|
|
|
|
errhint("Use the COLLATE clause to set the collation explicitly.")));
|
|
|
|
}
|
2011-03-20 17:43:39 +01:00
|
|
|
mylocale = pg_newlocale_from_collation(collid);
|
2011-03-22 21:55:32 +01:00
|
|
|
}
|
2011-03-20 17:43:39 +01:00
|
|
|
|
2008-12-15 15:55:50 +01:00
|
|
|
/* Overflow paranoia */
|
|
|
|
if ((nbytes + 1) > (INT_MAX / sizeof(wchar_t)))
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_OUT_OF_MEMORY),
|
|
|
|
errmsg("out of memory")));
|
2008-06-23 21:27:19 +02:00
|
|
|
|
|
|
|
/* Output workspace cannot have more codes than input bytes */
|
|
|
|
workspace = (wchar_t *) palloc((nbytes + 1) * sizeof(wchar_t));
|
2008-05-19 20:08:16 +02:00
|
|
|
|
2011-04-23 18:35:41 +02:00
|
|
|
char2wchar(workspace, nbytes + 1, buff, nbytes, mylocale);
|
2007-02-08 19:19:33 +01:00
|
|
|
|
2008-06-23 21:27:19 +02:00
|
|
|
for (curr_char = 0; workspace[curr_char] != 0; curr_char++)
|
2007-02-08 19:19:33 +01:00
|
|
|
{
|
2011-02-08 22:04:18 +01:00
|
|
|
#ifdef HAVE_LOCALE_T
|
|
|
|
if (mylocale)
|
|
|
|
{
|
|
|
|
if (wasalnum)
|
|
|
|
workspace[curr_char] = towlower_l(workspace[curr_char], mylocale);
|
|
|
|
else
|
|
|
|
workspace[curr_char] = towupper_l(workspace[curr_char], mylocale);
|
|
|
|
wasalnum = iswalnum_l(workspace[curr_char], mylocale);
|
|
|
|
}
|
2008-05-19 20:08:16 +02:00
|
|
|
else
|
2011-02-08 22:04:18 +01:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
if (wasalnum)
|
|
|
|
workspace[curr_char] = towlower(workspace[curr_char]);
|
|
|
|
else
|
|
|
|
workspace[curr_char] = towupper(workspace[curr_char]);
|
|
|
|
wasalnum = iswalnum(workspace[curr_char]);
|
|
|
|
}
|
2007-02-08 19:19:33 +01:00
|
|
|
}
|
|
|
|
|
2008-06-23 21:27:19 +02:00
|
|
|
/* Make result large enough; case change might change number of bytes */
|
2008-12-15 15:55:50 +01:00
|
|
|
result_size = curr_char * pg_database_encoding_max_length() + 1;
|
|
|
|
result = palloc(result_size);
|
2007-02-08 19:19:33 +01:00
|
|
|
|
2011-04-23 18:35:41 +02:00
|
|
|
wchar2char(result, workspace, result_size, mylocale);
|
2008-05-19 20:08:16 +02:00
|
|
|
pfree(workspace);
|
|
|
|
}
|
2009-06-11 16:49:15 +02:00
|
|
|
#endif /* USE_WIDE_UPPER_LOWER */
|
2011-03-20 17:43:39 +01:00
|
|
|
else
|
2007-02-08 19:19:33 +01:00
|
|
|
{
|
2011-12-11 00:15:15 +01:00
|
|
|
#ifdef HAVE_LOCALE_T
|
2011-04-10 17:42:00 +02:00
|
|
|
pg_locale_t mylocale = 0;
|
2011-12-11 00:15:15 +01:00
|
|
|
#endif
|
2009-06-11 16:49:15 +02:00
|
|
|
char *p;
|
2007-02-08 19:19:33 +01:00
|
|
|
|
2011-03-20 17:43:39 +01:00
|
|
|
if (collid != DEFAULT_COLLATION_OID)
|
2011-03-22 21:55:32 +01:00
|
|
|
{
|
|
|
|
if (!OidIsValid(collid))
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* This typically means that the parser could not resolve a
|
|
|
|
* conflict of implicit collations, so report it that way.
|
|
|
|
*/
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_INDETERMINATE_COLLATION),
|
|
|
|
errmsg("could not determine which collation to use for initcap() function"),
|
|
|
|
errhint("Use the COLLATE clause to set the collation explicitly.")));
|
|
|
|
}
|
2011-12-11 00:15:15 +01:00
|
|
|
#ifdef HAVE_LOCALE_T
|
2011-03-20 17:43:39 +01:00
|
|
|
mylocale = pg_newlocale_from_collation(collid);
|
2011-12-11 00:15:15 +01:00
|
|
|
#endif
|
2011-03-22 21:55:32 +01:00
|
|
|
}
|
2011-03-20 17:43:39 +01:00
|
|
|
|
2008-06-23 21:27:19 +02:00
|
|
|
result = pnstrdup(buff, nbytes);
|
2008-05-19 20:08:16 +02:00
|
|
|
|
2011-03-20 17:43:39 +01:00
|
|
|
/*
|
|
|
|
* Note: we assume that toupper_l()/tolower_l() will not be so broken
|
2014-05-06 18:12:18 +02:00
|
|
|
* as to need guard tests. When using the default collation, we apply
|
2011-03-20 17:43:39 +01:00
|
|
|
* the traditional Postgres behavior that forces ASCII-style treatment
|
|
|
|
* of I/i, but in non-default collations you get exactly what the
|
|
|
|
* collation says.
|
|
|
|
*/
|
2008-05-19 20:08:16 +02:00
|
|
|
for (p = result; *p; p++)
|
2007-02-08 19:19:33 +01:00
|
|
|
{
|
2011-03-20 17:43:39 +01:00
|
|
|
#ifdef HAVE_LOCALE_T
|
|
|
|
if (mylocale)
|
|
|
|
{
|
|
|
|
if (wasalnum)
|
|
|
|
*p = tolower_l((unsigned char) *p, mylocale);
|
|
|
|
else
|
|
|
|
*p = toupper_l((unsigned char) *p, mylocale);
|
|
|
|
wasalnum = isalnum_l((unsigned char) *p, mylocale);
|
|
|
|
}
|
2008-05-19 20:08:16 +02:00
|
|
|
else
|
2011-03-20 17:43:39 +01:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
if (wasalnum)
|
|
|
|
*p = pg_tolower((unsigned char) *p);
|
|
|
|
else
|
|
|
|
*p = pg_toupper((unsigned char) *p);
|
|
|
|
wasalnum = isalnum((unsigned char) *p);
|
|
|
|
}
|
2007-02-08 19:19:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-19 20:08:16 +02:00
|
|
|
return result;
|
2007-02-08 19:19:33 +01:00
|
|
|
}
|
|
|
|
|
2013-03-05 19:02:30 +01:00
|
|
|
/*
|
|
|
|
* ASCII-only lower function
|
|
|
|
*
|
|
|
|
* We pass the number of bytes so we can pass varlena and char*
|
|
|
|
* to this function. The result is a palloc'd, null-terminated string.
|
|
|
|
*/
|
|
|
|
char *
|
|
|
|
asc_tolower(const char *buff, size_t nbytes)
|
|
|
|
{
|
|
|
|
char *result;
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
if (!buff)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
result = pnstrdup(buff, nbytes);
|
|
|
|
|
|
|
|
for (p = result; *p; p++)
|
|
|
|
*p = pg_ascii_tolower((unsigned char) *p);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ASCII-only upper function
|
|
|
|
*
|
|
|
|
* We pass the number of bytes so we can pass varlena and char*
|
|
|
|
* to this function. The result is a palloc'd, null-terminated string.
|
|
|
|
*/
|
|
|
|
char *
|
|
|
|
asc_toupper(const char *buff, size_t nbytes)
|
|
|
|
{
|
|
|
|
char *result;
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
if (!buff)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
result = pnstrdup(buff, nbytes);
|
|
|
|
|
|
|
|
for (p = result; *p; p++)
|
|
|
|
*p = pg_ascii_toupper((unsigned char) *p);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ASCII-only initcap function
|
|
|
|
*
|
|
|
|
* We pass the number of bytes so we can pass varlena and char*
|
|
|
|
* to this function. The result is a palloc'd, null-terminated string.
|
|
|
|
*/
|
|
|
|
char *
|
|
|
|
asc_initcap(const char *buff, size_t nbytes)
|
|
|
|
{
|
|
|
|
char *result;
|
|
|
|
char *p;
|
|
|
|
int wasalnum = false;
|
|
|
|
|
|
|
|
if (!buff)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
result = pnstrdup(buff, nbytes);
|
|
|
|
|
|
|
|
for (p = result; *p; p++)
|
|
|
|
{
|
|
|
|
char c;
|
|
|
|
|
|
|
|
if (wasalnum)
|
|
|
|
*p = c = pg_ascii_tolower((unsigned char) *p);
|
|
|
|
else
|
|
|
|
*p = c = pg_ascii_toupper((unsigned char) *p);
|
|
|
|
/* we don't trust isalnum() here */
|
|
|
|
wasalnum = ((c >= 'A' && c <= 'Z') ||
|
|
|
|
(c >= 'a' && c <= 'z') ||
|
|
|
|
(c >= '0' && c <= '9'));
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2008-07-12 02:44:38 +02:00
|
|
|
/* convenience routines for when the input is null-terminated */
|
|
|
|
|
|
|
|
static char *
|
2011-02-08 22:04:18 +01:00
|
|
|
str_tolower_z(const char *buff, Oid collid)
|
2008-07-12 02:44:38 +02:00
|
|
|
{
|
2011-02-08 22:04:18 +01:00
|
|
|
return str_tolower(buff, strlen(buff), collid);
|
2008-07-12 02:44:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
2011-02-08 22:04:18 +01:00
|
|
|
str_toupper_z(const char *buff, Oid collid)
|
2008-07-12 02:44:38 +02:00
|
|
|
{
|
2011-02-08 22:04:18 +01:00
|
|
|
return str_toupper(buff, strlen(buff), collid);
|
2008-07-12 02:44:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
2011-02-08 22:04:18 +01:00
|
|
|
str_initcap_z(const char *buff, Oid collid)
|
2008-07-12 02:44:38 +02:00
|
|
|
{
|
2011-02-08 22:04:18 +01:00
|
|
|
return str_initcap(buff, strlen(buff), collid);
|
2008-07-12 02:44:38 +02:00
|
|
|
}
|
|
|
|
|
2013-03-05 19:02:30 +01:00
|
|
|
static char *
|
|
|
|
asc_tolower_z(const char *buff)
|
|
|
|
{
|
|
|
|
return asc_tolower(buff, strlen(buff));
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
asc_toupper_z(const char *buff)
|
|
|
|
{
|
|
|
|
return asc_toupper(buff, strlen(buff));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* asc_initcap_z is not currently needed */
|
|
|
|
|
2008-07-12 02:44:38 +02:00
|
|
|
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
/* ----------
|
2008-09-11 19:32:34 +02:00
|
|
|
* Skip TM / th in FROM_CHAR
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* ----------
|
|
|
|
*/
|
2008-09-11 19:32:34 +02:00
|
|
|
#define SKIP_THth(_suf) (S_THth(_suf) ? 2 : 0)
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
|
|
|
#ifdef DEBUG_TO_FROM_CHAR
|
|
|
|
/* -----------
|
2000-04-12 19:17:23 +02:00
|
|
|
* DEBUG: Call for debug and for index checking; (Show ASCII char
|
|
|
|
* and defined keyword for each used position
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* ----------
|
2000-04-12 19:17:23 +02:00
|
|
|
*/
|
|
|
|
static void
|
2005-03-26 01:41:31 +01:00
|
|
|
dump_index(const KeyWord *k, const int *index)
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
int i,
|
|
|
|
count = 0,
|
|
|
|
free_i = 0;
|
2000-04-12 19:17:23 +02:00
|
|
|
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
elog(DEBUG_elog_output, "TO-FROM_CHAR: Dump KeyWord Index:");
|
2000-04-12 19:17:23 +02:00
|
|
|
|
|
|
|
for (i = 0; i < KeyWord_INDEX_SIZE; i++)
|
|
|
|
{
|
|
|
|
if (index[i] != -1)
|
|
|
|
{
|
|
|
|
elog(DEBUG_elog_output, "\t%c: %s, ", i + 32, k[index[i]].name);
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
count++;
|
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
free_i++;
|
|
|
|
elog(DEBUG_elog_output, "\t(%d) %c %d", i, i + 32, index[i]);
|
|
|
|
}
|
|
|
|
}
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
elog(DEBUG_elog_output, "\n\t\tUsed positions: %d,\n\t\tFree positions: %d",
|
2000-04-12 19:17:23 +02:00
|
|
|
count, free_i);
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
}
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* DEBUG */
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
2000-11-25 06:00:33 +01:00
|
|
|
/* ----------
|
|
|
|
* Return TRUE if next format picture is not digit value
|
|
|
|
* ----------
|
|
|
|
*/
|
|
|
|
static bool
|
|
|
|
is_next_separator(FormatNode *n)
|
|
|
|
{
|
|
|
|
if (n->type == NODE_TYPE_END)
|
|
|
|
return FALSE;
|
2001-03-22 05:01:46 +01:00
|
|
|
|
2000-11-25 06:00:33 +01:00
|
|
|
if (n->type == NODE_TYPE_ACTION && S_THth(n->suffix))
|
|
|
|
return TRUE;
|
2001-03-22 05:01:46 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Next node
|
2000-11-25 06:00:33 +01:00
|
|
|
*/
|
2001-03-22 05:01:46 +01:00
|
|
|
n++;
|
|
|
|
|
2008-12-01 18:11:18 +01:00
|
|
|
/* end of format string is treated like a non-digit separator */
|
2000-11-25 06:00:33 +01:00
|
|
|
if (n->type == NODE_TYPE_END)
|
2008-12-01 18:11:18 +01:00
|
|
|
return TRUE;
|
2001-03-22 05:01:46 +01:00
|
|
|
|
2000-11-25 06:00:33 +01:00
|
|
|
if (n->type == NODE_TYPE_ACTION)
|
|
|
|
{
|
2008-03-22 23:32:19 +01:00
|
|
|
if (n->key->is_digit)
|
2000-11-25 06:00:33 +01:00
|
|
|
return FALSE;
|
2001-03-22 05:01:46 +01:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2000-12-03 21:45:40 +01:00
|
|
|
else if (isdigit((unsigned char) n->character))
|
2000-11-25 06:00:33 +01:00
|
|
|
return FALSE;
|
2001-03-22 05:01:46 +01:00
|
|
|
|
|
|
|
return TRUE; /* some non-digit input (separator) */
|
2000-11-25 06:00:33 +01:00
|
|
|
}
|
|
|
|
|
2011-09-07 15:47:51 +02:00
|
|
|
|
|
|
|
static int
|
|
|
|
adjust_partial_year_to_2020(int year)
|
|
|
|
{
|
|
|
|
/*
|
2012-07-02 17:35:21 +02:00
|
|
|
* Adjust all dates toward 2020; this is effectively what happens when we
|
2012-06-10 21:20:04 +02:00
|
|
|
* assume '70' is 1970 and '69' is 2069.
|
2011-09-07 15:47:51 +02:00
|
|
|
*/
|
|
|
|
/* Force 0-69 into the 2000's */
|
|
|
|
if (year < 70)
|
|
|
|
return year + 2000;
|
|
|
|
/* Force 70-99 into the 1900's */
|
2012-07-02 17:35:21 +02:00
|
|
|
else if (year < 100)
|
2011-09-07 15:47:51 +02:00
|
|
|
return year + 1900;
|
|
|
|
/* Force 100-519 into the 2000's */
|
2012-07-02 17:35:21 +02:00
|
|
|
else if (year < 520)
|
2011-09-07 15:47:51 +02:00
|
|
|
return year + 2000;
|
|
|
|
/* Force 520-999 into the 1000's */
|
2012-07-02 17:35:21 +02:00
|
|
|
else if (year < 1000)
|
2011-09-07 15:47:51 +02:00
|
|
|
return year + 1000;
|
|
|
|
else
|
|
|
|
return year;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-19 20:49:09 +02:00
|
|
|
static int
|
|
|
|
strspace_len(char *str)
|
|
|
|
{
|
|
|
|
int len = 0;
|
|
|
|
|
|
|
|
while (*str && isspace((unsigned char) *str))
|
|
|
|
{
|
|
|
|
str++;
|
|
|
|
len++;
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2001-09-06 05:22:42 +02:00
|
|
|
static int
|
|
|
|
strdigits_len(char *str)
|
|
|
|
{
|
2001-10-25 07:50:21 +02:00
|
|
|
char *p = str;
|
2006-04-19 20:49:09 +02:00
|
|
|
int len;
|
2001-10-25 07:50:21 +02:00
|
|
|
|
2006-04-19 20:49:09 +02:00
|
|
|
len = strspace_len(str);
|
|
|
|
p += len;
|
2006-10-04 02:30:14 +02:00
|
|
|
|
2001-10-25 07:50:21 +02:00
|
|
|
while (*p && isdigit((unsigned char) *p) && len <= DCH_MAX_ITEM_SIZ)
|
2001-09-06 05:22:42 +02:00
|
|
|
{
|
|
|
|
len++;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2008-09-11 19:32:34 +02:00
|
|
|
/*
|
|
|
|
* Set the date mode of a from-char conversion.
|
|
|
|
*
|
|
|
|
* Puke if the date mode has already been set, and the caller attempts to set
|
|
|
|
* it to a conflicting mode.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
from_char_set_mode(TmFromChar *tmfc, const FromCharDateMode mode)
|
|
|
|
{
|
|
|
|
if (mode != FROM_CHAR_DATE_NONE)
|
|
|
|
{
|
|
|
|
if (tmfc->mode == FROM_CHAR_DATE_NONE)
|
|
|
|
tmfc->mode = mode;
|
|
|
|
else if (tmfc->mode != mode)
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
|
|
|
|
errmsg("invalid combination of date conventions"),
|
|
|
|
errhint("Do not mix Gregorian and ISO week date "
|
|
|
|
"conventions in a formatting template.")));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the integer pointed to by 'dest' to the given value.
|
|
|
|
*
|
|
|
|
* Puke if the destination integer has previously been set to some other
|
|
|
|
* non-zero value.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
from_char_set_int(int *dest, const int value, const FormatNode *node)
|
|
|
|
{
|
|
|
|
if (*dest != 0 && *dest != value)
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
|
2009-06-11 16:49:15 +02:00
|
|
|
errmsg("conflicting values for \"%s\" field in formatting string",
|
|
|
|
node->key->name),
|
2008-09-11 19:32:34 +02:00
|
|
|
errdetail("This value contradicts a previous setting for "
|
|
|
|
"the same field type.")));
|
|
|
|
*dest = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read a single integer from the source string, into the int pointed to by
|
2008-11-10 18:36:53 +01:00
|
|
|
* 'dest'. If 'dest' is NULL, the result is discarded.
|
2008-09-11 19:32:34 +02:00
|
|
|
*
|
|
|
|
* In fixed-width mode (the node does not have the FM suffix), consume at most
|
2009-06-22 19:54:30 +02:00
|
|
|
* 'len' characters. However, any leading whitespace isn't counted in 'len'.
|
2008-09-11 19:32:34 +02:00
|
|
|
*
|
|
|
|
* We use strtol() to recover the integer value from the source string, in
|
|
|
|
* accordance with the given FormatNode.
|
|
|
|
*
|
|
|
|
* If the conversion completes successfully, src will have been advanced to
|
|
|
|
* point at the character immediately following the last character used in the
|
|
|
|
* conversion.
|
|
|
|
*
|
|
|
|
* Return the number of characters consumed.
|
|
|
|
*
|
|
|
|
* Note that from_char_parse_int() provides a more convenient wrapper where
|
|
|
|
* the length of the field is the same as the length of the format keyword (as
|
|
|
|
* with DD and MI).
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
from_char_parse_int_len(int *dest, char **src, const int len, FormatNode *node)
|
|
|
|
{
|
|
|
|
long result;
|
2009-02-07 15:16:46 +01:00
|
|
|
char copy[DCH_MAX_ITEM_SIZ + 1];
|
2008-09-11 19:32:34 +02:00
|
|
|
char *init = *src;
|
2009-02-07 15:16:46 +01:00
|
|
|
int used;
|
|
|
|
|
2009-06-22 19:54:30 +02:00
|
|
|
/*
|
|
|
|
* Skip any whitespace before parsing the integer.
|
|
|
|
*/
|
|
|
|
*src += strspace_len(*src);
|
|
|
|
|
2009-02-07 15:16:46 +01:00
|
|
|
Assert(len <= DCH_MAX_ITEM_SIZ);
|
|
|
|
used = (int) strlcpy(copy, *src, len + 1);
|
2008-09-11 19:32:34 +02:00
|
|
|
|
|
|
|
if (S_FM(node->suffix) || is_next_separator(node))
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* This node is in Fill Mode, or the next node is known to be a
|
2009-06-11 16:49:15 +02:00
|
|
|
* non-digit value, so we just slurp as many characters as we can get.
|
2008-09-11 19:32:34 +02:00
|
|
|
*/
|
|
|
|
errno = 0;
|
|
|
|
result = strtol(init, src, 10);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* We need to pull exactly the number of characters given in 'len' out
|
|
|
|
* of the string, and convert those.
|
|
|
|
*/
|
2009-06-11 16:49:15 +02:00
|
|
|
char *last;
|
2008-09-11 19:32:34 +02:00
|
|
|
|
2009-02-07 15:16:46 +01:00
|
|
|
if (used < len)
|
2008-09-11 19:32:34 +02:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
|
2009-06-11 16:49:15 +02:00
|
|
|
errmsg("source string too short for \"%s\" formatting field",
|
|
|
|
node->key->name),
|
2008-09-11 19:32:34 +02:00
|
|
|
errdetail("Field requires %d characters, but only %d "
|
|
|
|
"remain.",
|
2009-02-07 15:16:46 +01:00
|
|
|
len, used),
|
2008-09-11 19:32:34 +02:00
|
|
|
errhint("If your source string is not fixed-width, try "
|
|
|
|
"using the \"FM\" modifier.")));
|
|
|
|
|
|
|
|
errno = 0;
|
2009-02-07 15:16:46 +01:00
|
|
|
result = strtol(copy, &last, 10);
|
|
|
|
used = last - copy;
|
2008-09-11 19:32:34 +02:00
|
|
|
|
|
|
|
if (used > 0 && used < len)
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
|
2009-06-11 16:49:15 +02:00
|
|
|
errmsg("invalid value \"%s\" for \"%s\"",
|
|
|
|
copy, node->key->name),
|
2008-09-11 19:32:34 +02:00
|
|
|
errdetail("Field requires %d characters, but only %d "
|
2009-06-11 16:49:15 +02:00
|
|
|
"could be parsed.", len, used),
|
2008-09-11 19:32:34 +02:00
|
|
|
errhint("If your source string is not fixed-width, try "
|
2009-06-11 16:49:15 +02:00
|
|
|
"using the \"FM\" modifier.")));
|
2008-09-11 19:32:34 +02:00
|
|
|
|
|
|
|
*src += used;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*src == init)
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
|
2009-02-07 15:16:46 +01:00
|
|
|
errmsg("invalid value \"%s\" for \"%s\"",
|
2009-06-11 16:49:15 +02:00
|
|
|
copy, node->key->name),
|
2008-09-11 19:32:34 +02:00
|
|
|
errdetail("Value must be an integer.")));
|
|
|
|
|
|
|
|
if (errno == ERANGE || result < INT_MIN || result > INT_MAX)
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
|
|
|
|
errmsg("value for \"%s\" in source string is out of range",
|
2009-06-11 16:49:15 +02:00
|
|
|
node->key->name),
|
2008-09-11 19:32:34 +02:00
|
|
|
errdetail("Value must be in the range %d to %d.",
|
|
|
|
INT_MIN, INT_MAX)));
|
|
|
|
|
2008-11-10 18:36:53 +01:00
|
|
|
if (dest != NULL)
|
|
|
|
from_char_set_int(dest, (int) result, node);
|
2008-09-11 19:32:34 +02:00
|
|
|
return *src - init;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call from_char_parse_int_len(), using the length of the format keyword as
|
|
|
|
* the expected length of the field.
|
|
|
|
*
|
|
|
|
* Don't call this function if the field differs in length from the format
|
|
|
|
* keyword (as with HH24; the keyword length is 4, but the field length is 2).
|
|
|
|
* In such cases, call from_char_parse_int_len() instead to specify the
|
2012-04-24 04:43:09 +02:00
|
|
|
* required length explicitly.
|
2008-09-11 19:32:34 +02:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
from_char_parse_int(int *dest, char **src, FormatNode *node)
|
|
|
|
{
|
|
|
|
return from_char_parse_int_len(dest, src, node->key->len, node);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------
|
|
|
|
* Sequential search with to upper/lower conversion
|
|
|
|
* ----------
|
|
|
|
*/
|
|
|
|
static int
|
2014-01-18 22:04:11 +01:00
|
|
|
seq_search(char *name, const char *const * array, int type, int max, int *len)
|
2008-09-11 19:32:34 +02:00
|
|
|
{
|
2014-01-18 22:04:11 +01:00
|
|
|
const char *p;
|
|
|
|
const char *const * a;
|
|
|
|
char *n;
|
2008-09-11 19:32:34 +02:00
|
|
|
int last,
|
|
|
|
i;
|
|
|
|
|
|
|
|
*len = 0;
|
|
|
|
|
|
|
|
if (!*name)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* set first char */
|
|
|
|
if (type == ONE_UPPER || type == ALL_UPPER)
|
|
|
|
*name = pg_toupper((unsigned char) *name);
|
|
|
|
else if (type == ALL_LOWER)
|
|
|
|
*name = pg_tolower((unsigned char) *name);
|
|
|
|
|
|
|
|
for (last = 0, a = array; *a != NULL; a++)
|
|
|
|
{
|
|
|
|
/* comperate first chars */
|
|
|
|
if (*name != **a)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (i = 1, p = *a + 1, n = name + 1;; n++, p++, i++)
|
|
|
|
{
|
|
|
|
/* search fragment (max) only */
|
|
|
|
if (max && i == max)
|
|
|
|
{
|
|
|
|
*len = i;
|
|
|
|
return a - array;
|
|
|
|
}
|
|
|
|
/* full size */
|
|
|
|
if (*p == '\0')
|
|
|
|
{
|
|
|
|
*len = i;
|
|
|
|
return a - array;
|
|
|
|
}
|
|
|
|
/* Not found in array 'a' */
|
|
|
|
if (*n == '\0')
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert (but convert new chars only)
|
|
|
|
*/
|
|
|
|
if (i > last)
|
|
|
|
{
|
|
|
|
if (type == ONE_UPPER || type == ALL_LOWER)
|
|
|
|
*n = pg_tolower((unsigned char) *n);
|
|
|
|
else if (type == ALL_UPPER)
|
|
|
|
*n = pg_toupper((unsigned char) *n);
|
|
|
|
last = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG_TO_FROM_CHAR
|
2009-02-07 15:16:46 +01:00
|
|
|
elog(DEBUG_elog_output, "N: %c, P: %c, A: %s (%s)",
|
|
|
|
*n, *p, *a, name);
|
2008-09-11 19:32:34 +02:00
|
|
|
#endif
|
|
|
|
if (*n != *p)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Perform a sequential search in 'array' for text matching the first 'max'
|
2009-06-11 16:49:15 +02:00
|
|
|
* characters of the source string.
|
2008-09-11 19:32:34 +02:00
|
|
|
*
|
|
|
|
* If a match is found, copy the array index of the match into the integer
|
|
|
|
* pointed to by 'dest', advance 'src' to the end of the part of the string
|
|
|
|
* which matched, and return the number of characters consumed.
|
|
|
|
*
|
|
|
|
* If the string doesn't match, throw an error.
|
|
|
|
*/
|
|
|
|
static int
|
2014-01-18 22:04:11 +01:00
|
|
|
from_char_seq_search(int *dest, char **src, const char *const * array, int type, int max,
|
2008-09-11 19:32:34 +02:00
|
|
|
FormatNode *node)
|
|
|
|
{
|
2009-06-11 16:49:15 +02:00
|
|
|
int len;
|
2008-09-11 19:32:34 +02:00
|
|
|
|
2009-02-07 15:16:46 +01:00
|
|
|
*dest = seq_search(*src, array, type, max, &len);
|
2008-09-11 19:32:34 +02:00
|
|
|
if (len <= 0)
|
2009-02-07 15:16:46 +01:00
|
|
|
{
|
2009-06-11 16:49:15 +02:00
|
|
|
char copy[DCH_MAX_ITEM_SIZ + 1];
|
2009-02-07 15:16:46 +01:00
|
|
|
|
|
|
|
Assert(max <= DCH_MAX_ITEM_SIZ);
|
|
|
|
strlcpy(copy, *src, max + 1);
|
|
|
|
|
2008-09-11 19:32:34 +02:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
|
2009-02-07 15:16:46 +01:00
|
|
|
errmsg("invalid value \"%s\" for \"%s\"",
|
2009-06-11 16:49:15 +02:00
|
|
|
copy, node->key->name),
|
2008-09-11 19:32:34 +02:00
|
|
|
errdetail("The given value did not match any of the allowed "
|
2009-06-11 16:49:15 +02:00
|
|
|
"values for this field.")));
|
2009-02-07 15:16:46 +01:00
|
|
|
}
|
2008-09-11 19:32:34 +02:00
|
|
|
*src += len;
|
|
|
|
return len;
|
|
|
|
}
|
2008-03-22 23:32:19 +01:00
|
|
|
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
/* ----------
|
2008-03-22 23:32:19 +01:00
|
|
|
* Process a TmToChar struct as denoted by a list of FormatNodes.
|
|
|
|
* The formatted data is written to the string pointed to by 'out'.
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* ----------
|
|
|
|
*/
|
2008-03-22 23:32:19 +01:00
|
|
|
static void
|
2011-02-08 22:04:18 +01:00
|
|
|
DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid collid)
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
{
|
2008-03-22 23:32:19 +01:00
|
|
|
FormatNode *n;
|
|
|
|
char *s;
|
|
|
|
struct pg_tm *tm = &in->tm;
|
|
|
|
int i;
|
2001-09-06 05:22:42 +02:00
|
|
|
|
2008-05-19 20:08:16 +02:00
|
|
|
/* cache localized days and months */
|
|
|
|
cache_locale_time();
|
|
|
|
|
2008-03-22 23:32:19 +01:00
|
|
|
s = out;
|
|
|
|
for (n = node; n->type != NODE_TYPE_END; n++)
|
2001-09-06 05:22:42 +02:00
|
|
|
{
|
2008-03-22 23:32:19 +01:00
|
|
|
if (n->type != NODE_TYPE_ACTION)
|
|
|
|
{
|
|
|
|
*s = n->character;
|
|
|
|
s++;
|
|
|
|
continue;
|
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2008-03-22 23:32:19 +01:00
|
|
|
switch (n->key->id)
|
|
|
|
{
|
|
|
|
case DCH_A_M:
|
|
|
|
case DCH_P_M:
|
|
|
|
strcpy(s, (tm->tm_hour % HOURS_PER_DAY >= HOURS_PER_DAY / 2)
|
2005-12-03 17:45:06 +01:00
|
|
|
? P_M_STR : A_M_STR);
|
2008-03-22 23:32:19 +01:00
|
|
|
s += strlen(s);
|
|
|
|
break;
|
|
|
|
case DCH_AM:
|
|
|
|
case DCH_PM:
|
|
|
|
strcpy(s, (tm->tm_hour % HOURS_PER_DAY >= HOURS_PER_DAY / 2)
|
2005-12-03 17:45:06 +01:00
|
|
|
? PM_STR : AM_STR);
|
2008-03-22 23:32:19 +01:00
|
|
|
s += strlen(s);
|
|
|
|
break;
|
|
|
|
case DCH_a_m:
|
|
|
|
case DCH_p_m:
|
|
|
|
strcpy(s, (tm->tm_hour % HOURS_PER_DAY >= HOURS_PER_DAY / 2)
|
2005-12-03 17:45:06 +01:00
|
|
|
? p_m_STR : a_m_STR);
|
2008-03-22 23:32:19 +01:00
|
|
|
s += strlen(s);
|
|
|
|
break;
|
|
|
|
case DCH_am:
|
|
|
|
case DCH_pm:
|
|
|
|
strcpy(s, (tm->tm_hour % HOURS_PER_DAY >= HOURS_PER_DAY / 2)
|
2005-12-03 17:45:06 +01:00
|
|
|
? pm_STR : am_STR);
|
2008-03-22 23:32:19 +01:00
|
|
|
s += strlen(s);
|
|
|
|
break;
|
|
|
|
case DCH_HH:
|
|
|
|
case DCH_HH12:
|
2010-02-26 03:01:40 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* display time as shown on a 12-hour clock, even for
|
|
|
|
* intervals
|
|
|
|
*/
|
2015-10-06 02:51:46 +02:00
|
|
|
sprintf(s, "%0*d", S_FM(n->suffix) ? 0 : (tm->tm_hour >= 0) ? 2 : 3,
|
2011-04-10 17:42:00 +02:00
|
|
|
tm->tm_hour % (HOURS_PER_DAY / 2) == 0 ? HOURS_PER_DAY / 2 :
|
2010-02-23 17:14:26 +01:00
|
|
|
tm->tm_hour % (HOURS_PER_DAY / 2));
|
2008-03-22 23:32:19 +01:00
|
|
|
if (S_THth(n->suffix))
|
2009-07-06 21:11:39 +02:00
|
|
|
str_numth(s, s, S_TH_TYPE(n->suffix));
|
2008-03-22 23:32:19 +01:00
|
|
|
s += strlen(s);
|
|
|
|
break;
|
|
|
|
case DCH_HH24:
|
2015-10-06 02:51:46 +02:00
|
|
|
sprintf(s, "%0*d", S_FM(n->suffix) ? 0 : (tm->tm_hour >= 0) ? 2 : 3,
|
|
|
|
tm->tm_hour);
|
2008-03-22 23:32:19 +01:00
|
|
|
if (S_THth(n->suffix))
|
|
|
|
str_numth(s, s, S_TH_TYPE(n->suffix));
|
|
|
|
s += strlen(s);
|
|
|
|
break;
|
|
|
|
case DCH_MI:
|
2015-10-06 02:51:46 +02:00
|
|
|
sprintf(s, "%0*d", S_FM(n->suffix) ? 0 : (tm->tm_min >= 0) ? 2 : 3,
|
|
|
|
tm->tm_min);
|
2008-03-22 23:32:19 +01:00
|
|
|
if (S_THth(n->suffix))
|
|
|
|
str_numth(s, s, S_TH_TYPE(n->suffix));
|
|
|
|
s += strlen(s);
|
|
|
|
break;
|
|
|
|
case DCH_SS:
|
2015-10-06 02:51:46 +02:00
|
|
|
sprintf(s, "%0*d", S_FM(n->suffix) ? 0 : (tm->tm_sec >= 0) ? 2 : 3,
|
|
|
|
tm->tm_sec);
|
2008-03-22 23:32:19 +01:00
|
|
|
if (S_THth(n->suffix))
|
|
|
|
str_numth(s, s, S_TH_TYPE(n->suffix));
|
|
|
|
s += strlen(s);
|
|
|
|
break;
|
2009-06-11 16:49:15 +02:00
|
|
|
case DCH_MS: /* millisecond */
|
2008-03-22 23:32:19 +01:00
|
|
|
#ifdef HAVE_INT64_TIMESTAMP
|
|
|
|
sprintf(s, "%03d", (int) (in->fsec / INT64CONST(1000)));
|
|
|
|
#else
|
|
|
|
/* No rint() because we can't overflow and we might print US */
|
|
|
|
sprintf(s, "%03d", (int) (in->fsec * 1000));
|
|
|
|
#endif
|
|
|
|
if (S_THth(n->suffix))
|
|
|
|
str_numth(s, s, S_TH_TYPE(n->suffix));
|
|
|
|
s += strlen(s);
|
|
|
|
break;
|
2009-06-11 16:49:15 +02:00
|
|
|
case DCH_US: /* microsecond */
|
2008-03-22 23:32:19 +01:00
|
|
|
#ifdef HAVE_INT64_TIMESTAMP
|
|
|
|
sprintf(s, "%06d", (int) in->fsec);
|
|
|
|
#else
|
|
|
|
/* don't use rint() because we can't overflow 1000 */
|
|
|
|
sprintf(s, "%06d", (int) (in->fsec * 1000000));
|
|
|
|
#endif
|
|
|
|
if (S_THth(n->suffix))
|
|
|
|
str_numth(s, s, S_TH_TYPE(n->suffix));
|
|
|
|
s += strlen(s);
|
|
|
|
break;
|
|
|
|
case DCH_SSSS:
|
|
|
|
sprintf(s, "%d", tm->tm_hour * SECS_PER_HOUR +
|
|
|
|
tm->tm_min * SECS_PER_MINUTE +
|
|
|
|
tm->tm_sec);
|
|
|
|
if (S_THth(n->suffix))
|
|
|
|
str_numth(s, s, S_TH_TYPE(n->suffix));
|
|
|
|
s += strlen(s);
|
|
|
|
break;
|
|
|
|
case DCH_tz:
|
|
|
|
INVALID_FOR_INTERVAL;
|
|
|
|
if (tmtcTzn(in))
|
|
|
|
{
|
2013-03-05 19:02:30 +01:00
|
|
|
/* We assume here that timezone names aren't localized */
|
|
|
|
char *p = asc_tolower_z(tmtcTzn(in));
|
2008-03-22 23:32:19 +01:00
|
|
|
|
2008-07-12 02:44:38 +02:00
|
|
|
strcpy(s, p);
|
2008-03-22 23:32:19 +01:00
|
|
|
pfree(p);
|
|
|
|
s += strlen(s);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DCH_TZ:
|
|
|
|
INVALID_FOR_INTERVAL;
|
|
|
|
if (tmtcTzn(in))
|
|
|
|
{
|
|
|
|
strcpy(s, tmtcTzn(in));
|
|
|
|
s += strlen(s);
|
|
|
|
}
|
|
|
|
break;
|
2013-07-01 19:40:18 +02:00
|
|
|
case DCH_OF:
|
|
|
|
INVALID_FOR_INTERVAL;
|
2015-10-06 02:51:46 +02:00
|
|
|
sprintf(s, "%+0*d", S_FM(n->suffix) ? 0 : (tm->tm_gmtoff >= 0) ? 3 : 4,
|
|
|
|
(int) tm->tm_gmtoff / SECS_PER_HOUR);
|
2013-07-01 19:40:18 +02:00
|
|
|
s += strlen(s);
|
2015-05-04 05:44:52 +02:00
|
|
|
if ((int) tm->tm_gmtoff % SECS_PER_HOUR != 0)
|
2013-07-01 19:40:18 +02:00
|
|
|
{
|
2015-05-04 05:44:52 +02:00
|
|
|
sprintf(s, ":%02d", abs((int) tm->tm_gmtoff % SECS_PER_HOUR) / SECS_PER_MINUTE);
|
2013-07-01 19:40:18 +02:00
|
|
|
s += strlen(s);
|
|
|
|
}
|
|
|
|
break;
|
2008-03-22 23:32:19 +01:00
|
|
|
case DCH_A_D:
|
|
|
|
case DCH_B_C:
|
|
|
|
INVALID_FOR_INTERVAL;
|
|
|
|
strcpy(s, (tm->tm_year <= 0 ? B_C_STR : A_D_STR));
|
|
|
|
s += strlen(s);
|
|
|
|
break;
|
|
|
|
case DCH_AD:
|
|
|
|
case DCH_BC:
|
|
|
|
INVALID_FOR_INTERVAL;
|
|
|
|
strcpy(s, (tm->tm_year <= 0 ? BC_STR : AD_STR));
|
|
|
|
s += strlen(s);
|
|
|
|
break;
|
|
|
|
case DCH_a_d:
|
|
|
|
case DCH_b_c:
|
|
|
|
INVALID_FOR_INTERVAL;
|
|
|
|
strcpy(s, (tm->tm_year <= 0 ? b_c_STR : a_d_STR));
|
|
|
|
s += strlen(s);
|
|
|
|
break;
|
|
|
|
case DCH_ad:
|
|
|
|
case DCH_bc:
|
|
|
|
INVALID_FOR_INTERVAL;
|
|
|
|
strcpy(s, (tm->tm_year <= 0 ? bc_STR : ad_STR));
|
|
|
|
s += strlen(s);
|
|
|
|
break;
|
|
|
|
case DCH_MONTH:
|
|
|
|
INVALID_FOR_INTERVAL;
|
|
|
|
if (!tm->tm_mon)
|
|
|
|
break;
|
|
|
|
if (S_TM(n->suffix))
|
2015-02-02 16:00:45 +01:00
|
|
|
{
|
2015-05-24 03:35:49 +02:00
|
|
|
char *str = str_toupper_z(localized_full_months[tm->tm_mon - 1], collid);
|
2015-02-02 16:00:45 +01:00
|
|
|
|
2015-02-07 05:39:52 +01:00
|
|
|
if (strlen(str) <= (n->key->len + TM_SUFFIX_LEN) * DCH_MAX_ITEM_SIZ)
|
2015-02-02 16:00:45 +01:00
|
|
|
strcpy(s, str);
|
|
|
|
else
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
|
2015-05-24 03:35:49 +02:00
|
|
|
errmsg("localized string format value too long")));
|
2015-02-02 16:00:45 +01:00
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
else
|
2008-06-23 21:27:19 +02:00
|
|
|
sprintf(s, "%*s", S_FM(n->suffix) ? 0 : -9,
|
2013-05-29 22:58:43 +02:00
|
|
|
asc_toupper_z(months_full[tm->tm_mon - 1]));
|
2008-03-22 23:32:19 +01:00
|
|
|
s += strlen(s);
|
|
|
|
break;
|
|
|
|
case DCH_Month:
|
|
|
|
INVALID_FOR_INTERVAL;
|
|
|
|
if (!tm->tm_mon)
|
|
|
|
break;
|
|
|
|
if (S_TM(n->suffix))
|
2015-02-02 16:00:45 +01:00
|
|
|
{
|
2015-05-24 03:35:49 +02:00
|
|
|
char *str = str_initcap_z(localized_full_months[tm->tm_mon - 1], collid);
|
2015-02-02 16:00:45 +01:00
|
|
|
|
2015-02-07 05:39:52 +01:00
|
|
|
if (strlen(str) <= (n->key->len + TM_SUFFIX_LEN) * DCH_MAX_ITEM_SIZ)
|
2015-02-02 16:00:45 +01:00
|
|
|
strcpy(s, str);
|
|
|
|
else
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
|
2015-05-24 03:35:49 +02:00
|
|
|
errmsg("localized string format value too long")));
|
2015-02-02 16:00:45 +01:00
|
|
|
}
|
2008-03-22 23:32:19 +01:00
|
|
|
else
|
2013-03-05 19:02:30 +01:00
|
|
|
sprintf(s, "%*s", S_FM(n->suffix) ? 0 : -9,
|
|
|
|
months_full[tm->tm_mon - 1]);
|
2008-03-22 23:32:19 +01:00
|
|
|
s += strlen(s);
|
|
|
|
break;
|
|
|
|
case DCH_month:
|
|
|
|
INVALID_FOR_INTERVAL;
|
|
|
|
if (!tm->tm_mon)
|
|
|
|
break;
|
|
|
|
if (S_TM(n->suffix))
|
2015-02-02 16:00:45 +01:00
|
|
|
{
|
2015-05-24 03:35:49 +02:00
|
|
|
char *str = str_tolower_z(localized_full_months[tm->tm_mon - 1], collid);
|
2015-02-02 16:00:45 +01:00
|
|
|
|
2015-02-07 05:39:52 +01:00
|
|
|
if (strlen(str) <= (n->key->len + TM_SUFFIX_LEN) * DCH_MAX_ITEM_SIZ)
|
2015-02-02 16:00:45 +01:00
|
|
|
strcpy(s, str);
|
|
|
|
else
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
|
2015-05-24 03:35:49 +02:00
|
|
|
errmsg("localized string format value too long")));
|
2015-02-02 16:00:45 +01:00
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
else
|
2013-03-05 19:02:30 +01:00
|
|
|
sprintf(s, "%*s", S_FM(n->suffix) ? 0 : -9,
|
|
|
|
asc_tolower_z(months_full[tm->tm_mon - 1]));
|
2008-03-22 23:32:19 +01:00
|
|
|
s += strlen(s);
|
|
|
|
break;
|
|
|
|
case DCH_MON:
|
|
|
|
INVALID_FOR_INTERVAL;
|
|
|
|
if (!tm->tm_mon)
|
|
|
|
break;
|
|
|
|
if (S_TM(n->suffix))
|
2015-02-02 16:00:45 +01:00
|
|
|
{
|
2015-05-24 03:35:49 +02:00
|
|
|
char *str = str_toupper_z(localized_abbrev_months[tm->tm_mon - 1], collid);
|
2015-02-02 16:00:45 +01:00
|
|
|
|
2015-02-07 05:39:52 +01:00
|
|
|
if (strlen(str) <= (n->key->len + TM_SUFFIX_LEN) * DCH_MAX_ITEM_SIZ)
|
2015-02-02 16:00:45 +01:00
|
|
|
strcpy(s, str);
|
|
|
|
else
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
|
2015-05-24 03:35:49 +02:00
|
|
|
errmsg("localized string format value too long")));
|
2015-02-02 16:00:45 +01:00
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
else
|
2013-03-05 19:02:30 +01:00
|
|
|
strcpy(s, asc_toupper_z(months[tm->tm_mon - 1]));
|
2008-03-22 23:32:19 +01:00
|
|
|
s += strlen(s);
|
|
|
|
break;
|
|
|
|
case DCH_Mon:
|
|
|
|
INVALID_FOR_INTERVAL;
|
|
|
|
if (!tm->tm_mon)
|
|
|
|
break;
|
|
|
|
if (S_TM(n->suffix))
|
2015-02-02 16:00:45 +01:00
|
|
|
{
|
2015-05-24 03:35:49 +02:00
|
|
|
char *str = str_initcap_z(localized_abbrev_months[tm->tm_mon - 1], collid);
|
2015-02-02 16:00:45 +01:00
|
|
|
|
2015-02-07 05:39:52 +01:00
|
|
|
if (strlen(str) <= (n->key->len + TM_SUFFIX_LEN) * DCH_MAX_ITEM_SIZ)
|
2015-02-02 16:00:45 +01:00
|
|
|
strcpy(s, str);
|
|
|
|
else
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
|
2015-05-24 03:35:49 +02:00
|
|
|
errmsg("localized string format value too long")));
|
2015-02-02 16:00:45 +01:00
|
|
|
}
|
2008-03-22 23:32:19 +01:00
|
|
|
else
|
|
|
|
strcpy(s, months[tm->tm_mon - 1]);
|
|
|
|
s += strlen(s);
|
|
|
|
break;
|
|
|
|
case DCH_mon:
|
|
|
|
INVALID_FOR_INTERVAL;
|
|
|
|
if (!tm->tm_mon)
|
|
|
|
break;
|
|
|
|
if (S_TM(n->suffix))
|
2015-02-02 16:00:45 +01:00
|
|
|
{
|
2015-05-24 03:35:49 +02:00
|
|
|
char *str = str_tolower_z(localized_abbrev_months[tm->tm_mon - 1], collid);
|
2015-02-02 16:00:45 +01:00
|
|
|
|
2015-02-07 05:39:52 +01:00
|
|
|
if (strlen(str) <= (n->key->len + TM_SUFFIX_LEN) * DCH_MAX_ITEM_SIZ)
|
2015-02-02 16:00:45 +01:00
|
|
|
strcpy(s, str);
|
|
|
|
else
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
|
2015-05-24 03:35:49 +02:00
|
|
|
errmsg("localized string format value too long")));
|
2015-02-02 16:00:45 +01:00
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
else
|
2013-03-05 19:02:30 +01:00
|
|
|
strcpy(s, asc_tolower_z(months[tm->tm_mon - 1]));
|
2008-03-22 23:32:19 +01:00
|
|
|
s += strlen(s);
|
|
|
|
break;
|
|
|
|
case DCH_MM:
|
2015-10-06 02:51:46 +02:00
|
|
|
sprintf(s, "%0*d", S_FM(n->suffix) ? 0 : (tm->tm_mon >= 0) ? 2 : 3,
|
|
|
|
tm->tm_mon);
|
2008-03-22 23:32:19 +01:00
|
|
|
if (S_THth(n->suffix))
|
|
|
|
str_numth(s, s, S_TH_TYPE(n->suffix));
|
|
|
|
s += strlen(s);
|
|
|
|
break;
|
|
|
|
case DCH_DAY:
|
|
|
|
INVALID_FOR_INTERVAL;
|
|
|
|
if (S_TM(n->suffix))
|
2015-02-02 16:00:45 +01:00
|
|
|
{
|
2015-05-24 03:35:49 +02:00
|
|
|
char *str = str_toupper_z(localized_full_days[tm->tm_wday], collid);
|
2015-02-02 16:00:45 +01:00
|
|
|
|
2015-02-07 05:39:52 +01:00
|
|
|
if (strlen(str) <= (n->key->len + TM_SUFFIX_LEN) * DCH_MAX_ITEM_SIZ)
|
2015-02-02 16:00:45 +01:00
|
|
|
strcpy(s, str);
|
|
|
|
else
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
|
2015-05-24 03:35:49 +02:00
|
|
|
errmsg("localized string format value too long")));
|
2015-02-02 16:00:45 +01:00
|
|
|
}
|
2001-10-25 07:50:21 +02:00
|
|
|
else
|
2008-06-23 21:27:19 +02:00
|
|
|
sprintf(s, "%*s", S_FM(n->suffix) ? 0 : -9,
|
2013-03-05 19:02:30 +01:00
|
|
|
asc_toupper_z(days[tm->tm_wday]));
|
2008-03-22 23:32:19 +01:00
|
|
|
s += strlen(s);
|
|
|
|
break;
|
|
|
|
case DCH_Day:
|
|
|
|
INVALID_FOR_INTERVAL;
|
|
|
|
if (S_TM(n->suffix))
|
2015-02-02 16:00:45 +01:00
|
|
|
{
|
2015-05-24 03:35:49 +02:00
|
|
|
char *str = str_initcap_z(localized_full_days[tm->tm_wday], collid);
|
2015-02-02 16:00:45 +01:00
|
|
|
|
2015-02-07 05:39:52 +01:00
|
|
|
if (strlen(str) <= (n->key->len + TM_SUFFIX_LEN) * DCH_MAX_ITEM_SIZ)
|
2015-02-02 16:00:45 +01:00
|
|
|
strcpy(s, str);
|
|
|
|
else
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
|
2015-05-24 03:35:49 +02:00
|
|
|
errmsg("localized string format value too long")));
|
2015-02-02 16:00:45 +01:00
|
|
|
}
|
2008-03-22 23:32:19 +01:00
|
|
|
else
|
2013-03-05 19:02:30 +01:00
|
|
|
sprintf(s, "%*s", S_FM(n->suffix) ? 0 : -9,
|
|
|
|
days[tm->tm_wday]);
|
2008-03-22 23:32:19 +01:00
|
|
|
s += strlen(s);
|
|
|
|
break;
|
|
|
|
case DCH_day:
|
|
|
|
INVALID_FOR_INTERVAL;
|
|
|
|
if (S_TM(n->suffix))
|
2015-02-02 16:00:45 +01:00
|
|
|
{
|
2015-05-24 03:35:49 +02:00
|
|
|
char *str = str_tolower_z(localized_full_days[tm->tm_wday], collid);
|
2015-02-02 16:00:45 +01:00
|
|
|
|
2015-02-07 05:39:52 +01:00
|
|
|
if (strlen(str) <= (n->key->len + TM_SUFFIX_LEN) * DCH_MAX_ITEM_SIZ)
|
2015-02-02 16:00:45 +01:00
|
|
|
strcpy(s, str);
|
|
|
|
else
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
|
2015-05-24 03:35:49 +02:00
|
|
|
errmsg("localized string format value too long")));
|
2015-02-02 16:00:45 +01:00
|
|
|
}
|
2001-10-25 07:50:21 +02:00
|
|
|
else
|
2013-03-05 19:02:30 +01:00
|
|
|
sprintf(s, "%*s", S_FM(n->suffix) ? 0 : -9,
|
|
|
|
asc_tolower_z(days[tm->tm_wday]));
|
2008-03-22 23:32:19 +01:00
|
|
|
s += strlen(s);
|
|
|
|
break;
|
|
|
|
case DCH_DY:
|
|
|
|
INVALID_FOR_INTERVAL;
|
|
|
|
if (S_TM(n->suffix))
|
2015-02-02 16:00:45 +01:00
|
|
|
{
|
2015-05-24 03:35:49 +02:00
|
|
|
char *str = str_toupper_z(localized_abbrev_days[tm->tm_wday], collid);
|
2015-02-02 16:00:45 +01:00
|
|
|
|
2015-02-07 05:39:52 +01:00
|
|
|
if (strlen(str) <= (n->key->len + TM_SUFFIX_LEN) * DCH_MAX_ITEM_SIZ)
|
2015-02-02 16:00:45 +01:00
|
|
|
strcpy(s, str);
|
|
|
|
else
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
|
2015-05-24 03:35:49 +02:00
|
|
|
errmsg("localized string format value too long")));
|
2015-02-02 16:00:45 +01:00
|
|
|
}
|
2000-11-25 06:00:33 +01:00
|
|
|
else
|
2013-03-05 19:02:30 +01:00
|
|
|
strcpy(s, asc_toupper_z(days_short[tm->tm_wday]));
|
2008-03-22 23:32:19 +01:00
|
|
|
s += strlen(s);
|
|
|
|
break;
|
|
|
|
case DCH_Dy:
|
|
|
|
INVALID_FOR_INTERVAL;
|
|
|
|
if (S_TM(n->suffix))
|
2015-02-02 16:00:45 +01:00
|
|
|
{
|
2015-05-24 03:35:49 +02:00
|
|
|
char *str = str_initcap_z(localized_abbrev_days[tm->tm_wday], collid);
|
2015-02-02 16:00:45 +01:00
|
|
|
|
2015-02-07 05:39:52 +01:00
|
|
|
if (strlen(str) <= (n->key->len + TM_SUFFIX_LEN) * DCH_MAX_ITEM_SIZ)
|
2015-02-02 16:00:45 +01:00
|
|
|
strcpy(s, str);
|
|
|
|
else
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
|
2015-05-24 03:35:49 +02:00
|
|
|
errmsg("localized string format value too long")));
|
2015-02-02 16:00:45 +01:00
|
|
|
}
|
2001-03-22 05:01:46 +01:00
|
|
|
else
|
2008-03-22 23:32:19 +01:00
|
|
|
strcpy(s, days_short[tm->tm_wday]);
|
|
|
|
s += strlen(s);
|
|
|
|
break;
|
|
|
|
case DCH_dy:
|
|
|
|
INVALID_FOR_INTERVAL;
|
|
|
|
if (S_TM(n->suffix))
|
2015-02-02 16:00:45 +01:00
|
|
|
{
|
2015-05-24 03:35:49 +02:00
|
|
|
char *str = str_tolower_z(localized_abbrev_days[tm->tm_wday], collid);
|
2015-02-02 16:00:45 +01:00
|
|
|
|
2015-02-07 05:39:52 +01:00
|
|
|
if (strlen(str) <= (n->key->len + TM_SUFFIX_LEN) * DCH_MAX_ITEM_SIZ)
|
2015-02-02 16:00:45 +01:00
|
|
|
strcpy(s, str);
|
|
|
|
else
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
|
2015-05-24 03:35:49 +02:00
|
|
|
errmsg("localized string format value too long")));
|
2015-02-02 16:00:45 +01:00
|
|
|
}
|
2008-03-22 23:32:19 +01:00
|
|
|
else
|
2013-03-05 19:02:30 +01:00
|
|
|
strcpy(s, asc_tolower_z(days_short[tm->tm_wday]));
|
2008-03-22 23:32:19 +01:00
|
|
|
s += strlen(s);
|
|
|
|
break;
|
|
|
|
case DCH_DDD:
|
|
|
|
case DCH_IDDD:
|
|
|
|
sprintf(s, "%0*d", S_FM(n->suffix) ? 0 : 3,
|
|
|
|
(n->key->id == DCH_DDD) ?
|
|
|
|
tm->tm_yday :
|
2009-06-11 16:49:15 +02:00
|
|
|
date2isoyearday(tm->tm_year, tm->tm_mon, tm->tm_mday));
|
2008-03-22 23:32:19 +01:00
|
|
|
if (S_THth(n->suffix))
|
|
|
|
str_numth(s, s, S_TH_TYPE(n->suffix));
|
|
|
|
s += strlen(s);
|
|
|
|
break;
|
|
|
|
case DCH_DD:
|
|
|
|
sprintf(s, "%0*d", S_FM(n->suffix) ? 0 : 2, tm->tm_mday);
|
|
|
|
if (S_THth(n->suffix))
|
|
|
|
str_numth(s, s, S_TH_TYPE(n->suffix));
|
|
|
|
s += strlen(s);
|
|
|
|
break;
|
|
|
|
case DCH_D:
|
|
|
|
INVALID_FOR_INTERVAL;
|
|
|
|
sprintf(s, "%d", tm->tm_wday + 1);
|
|
|
|
if (S_THth(n->suffix))
|
|
|
|
str_numth(s, s, S_TH_TYPE(n->suffix));
|
|
|
|
s += strlen(s);
|
|
|
|
break;
|
|
|
|
case DCH_ID:
|
|
|
|
INVALID_FOR_INTERVAL;
|
|
|
|
sprintf(s, "%d", (tm->tm_wday == 0) ? 7 : tm->tm_wday);
|
|
|
|
if (S_THth(n->suffix))
|
|
|
|
str_numth(s, s, S_TH_TYPE(n->suffix));
|
|
|
|
s += strlen(s);
|
|
|
|
break;
|
|
|
|
case DCH_WW:
|
|
|
|
sprintf(s, "%0*d", S_FM(n->suffix) ? 0 : 2,
|
|
|
|
(tm->tm_yday - 1) / 7 + 1);
|
|
|
|
if (S_THth(n->suffix))
|
|
|
|
str_numth(s, s, S_TH_TYPE(n->suffix));
|
|
|
|
s += strlen(s);
|
|
|
|
break;
|
|
|
|
case DCH_IW:
|
|
|
|
sprintf(s, "%0*d", S_FM(n->suffix) ? 0 : 2,
|
|
|
|
date2isoweek(tm->tm_year, tm->tm_mon, tm->tm_mday));
|
|
|
|
if (S_THth(n->suffix))
|
|
|
|
str_numth(s, s, S_TH_TYPE(n->suffix));
|
|
|
|
s += strlen(s);
|
|
|
|
break;
|
|
|
|
case DCH_Q:
|
|
|
|
if (!tm->tm_mon)
|
|
|
|
break;
|
|
|
|
sprintf(s, "%d", (tm->tm_mon - 1) / 3 + 1);
|
|
|
|
if (S_THth(n->suffix))
|
|
|
|
str_numth(s, s, S_TH_TYPE(n->suffix));
|
|
|
|
s += strlen(s);
|
|
|
|
break;
|
|
|
|
case DCH_CC:
|
2009-06-11 16:49:15 +02:00
|
|
|
if (is_interval) /* straight calculation */
|
2008-03-22 23:32:19 +01:00
|
|
|
i = tm->tm_year / 100;
|
2012-08-07 19:34:44 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (tm->tm_year > 0)
|
|
|
|
/* Century 20 == 1901 - 2000 */
|
|
|
|
i = (tm->tm_year - 1) / 100 + 1;
|
|
|
|
else
|
|
|
|
/* Century 6BC == 600BC - 501BC */
|
|
|
|
i = tm->tm_year / 100 - 1;
|
|
|
|
}
|
2008-03-22 23:32:19 +01:00
|
|
|
if (i <= 99 && i >= -99)
|
2015-10-06 02:51:46 +02:00
|
|
|
sprintf(s, "%0*d", S_FM(n->suffix) ? 0 : (i >= 0) ? 2 : 3, i);
|
2008-03-22 23:32:19 +01:00
|
|
|
else
|
|
|
|
sprintf(s, "%d", i);
|
|
|
|
if (S_THth(n->suffix))
|
|
|
|
str_numth(s, s, S_TH_TYPE(n->suffix));
|
|
|
|
s += strlen(s);
|
|
|
|
break;
|
|
|
|
case DCH_Y_YYY:
|
|
|
|
i = ADJUST_YEAR(tm->tm_year, is_interval) / 1000;
|
|
|
|
sprintf(s, "%d,%03d", i,
|
|
|
|
ADJUST_YEAR(tm->tm_year, is_interval) - (i * 1000));
|
|
|
|
if (S_THth(n->suffix))
|
|
|
|
str_numth(s, s, S_TH_TYPE(n->suffix));
|
|
|
|
s += strlen(s);
|
|
|
|
break;
|
|
|
|
case DCH_YYYY:
|
|
|
|
case DCH_IYYY:
|
2010-04-07 23:41:53 +02:00
|
|
|
sprintf(s, "%0*d",
|
2015-10-06 02:51:46 +02:00
|
|
|
S_FM(n->suffix) ? 0 :
|
|
|
|
(ADJUST_YEAR(tm->tm_year, is_interval) >= 0) ? 4 : 5,
|
2010-04-07 23:41:53 +02:00
|
|
|
(n->key->id == DCH_YYYY ?
|
|
|
|
ADJUST_YEAR(tm->tm_year, is_interval) :
|
|
|
|
ADJUST_YEAR(date2isoyear(tm->tm_year,
|
|
|
|
tm->tm_mon,
|
|
|
|
tm->tm_mday),
|
|
|
|
is_interval)));
|
2008-03-22 23:32:19 +01:00
|
|
|
if (S_THth(n->suffix))
|
|
|
|
str_numth(s, s, S_TH_TYPE(n->suffix));
|
|
|
|
s += strlen(s);
|
|
|
|
break;
|
|
|
|
case DCH_YYY:
|
|
|
|
case DCH_IYY:
|
2010-04-07 23:41:53 +02:00
|
|
|
sprintf(s, "%0*d",
|
2015-10-06 02:51:46 +02:00
|
|
|
S_FM(n->suffix) ? 0 :
|
|
|
|
(ADJUST_YEAR(tm->tm_year, is_interval) >= 0) ? 3 : 4,
|
2010-04-07 23:41:53 +02:00
|
|
|
(n->key->id == DCH_YYY ?
|
2008-03-22 23:32:19 +01:00
|
|
|
ADJUST_YEAR(tm->tm_year, is_interval) :
|
|
|
|
ADJUST_YEAR(date2isoyear(tm->tm_year,
|
2010-04-07 23:41:53 +02:00
|
|
|
tm->tm_mon,
|
|
|
|
tm->tm_mday),
|
|
|
|
is_interval)) % 1000);
|
2008-03-22 23:32:19 +01:00
|
|
|
if (S_THth(n->suffix))
|
|
|
|
str_numth(s, s, S_TH_TYPE(n->suffix));
|
|
|
|
s += strlen(s);
|
|
|
|
break;
|
|
|
|
case DCH_YY:
|
|
|
|
case DCH_IY:
|
2010-04-07 23:41:53 +02:00
|
|
|
sprintf(s, "%0*d",
|
2015-10-06 02:51:46 +02:00
|
|
|
S_FM(n->suffix) ? 0 :
|
|
|
|
(ADJUST_YEAR(tm->tm_year, is_interval) >= 0) ? 2 : 3,
|
2010-04-07 23:41:53 +02:00
|
|
|
(n->key->id == DCH_YY ?
|
2008-03-22 23:32:19 +01:00
|
|
|
ADJUST_YEAR(tm->tm_year, is_interval) :
|
|
|
|
ADJUST_YEAR(date2isoyear(tm->tm_year,
|
2010-04-07 23:41:53 +02:00
|
|
|
tm->tm_mon,
|
|
|
|
tm->tm_mday),
|
|
|
|
is_interval)) % 100);
|
2008-03-22 23:32:19 +01:00
|
|
|
if (S_THth(n->suffix))
|
|
|
|
str_numth(s, s, S_TH_TYPE(n->suffix));
|
|
|
|
s += strlen(s);
|
|
|
|
break;
|
|
|
|
case DCH_Y:
|
|
|
|
case DCH_I:
|
2010-04-07 23:41:53 +02:00
|
|
|
sprintf(s, "%1d",
|
|
|
|
(n->key->id == DCH_Y ?
|
2008-03-22 23:32:19 +01:00
|
|
|
ADJUST_YEAR(tm->tm_year, is_interval) :
|
|
|
|
ADJUST_YEAR(date2isoyear(tm->tm_year,
|
2010-04-07 23:41:53 +02:00
|
|
|
tm->tm_mon,
|
|
|
|
tm->tm_mday),
|
|
|
|
is_interval)) % 10);
|
2008-03-22 23:32:19 +01:00
|
|
|
if (S_THth(n->suffix))
|
|
|
|
str_numth(s, s, S_TH_TYPE(n->suffix));
|
|
|
|
s += strlen(s);
|
|
|
|
break;
|
|
|
|
case DCH_RM:
|
|
|
|
if (!tm->tm_mon)
|
|
|
|
break;
|
|
|
|
sprintf(s, "%*s", S_FM(n->suffix) ? 0 : -4,
|
2011-03-12 15:31:18 +01:00
|
|
|
rm_months_upper[MONTHS_PER_YEAR - tm->tm_mon]);
|
2008-03-22 23:32:19 +01:00
|
|
|
s += strlen(s);
|
|
|
|
break;
|
|
|
|
case DCH_rm:
|
|
|
|
if (!tm->tm_mon)
|
|
|
|
break;
|
|
|
|
sprintf(s, "%*s", S_FM(n->suffix) ? 0 : -4,
|
2011-03-12 15:31:18 +01:00
|
|
|
rm_months_lower[MONTHS_PER_YEAR - tm->tm_mon]);
|
2008-03-22 23:32:19 +01:00
|
|
|
s += strlen(s);
|
|
|
|
break;
|
|
|
|
case DCH_W:
|
|
|
|
sprintf(s, "%d", (tm->tm_mday - 1) / 7 + 1);
|
|
|
|
if (S_THth(n->suffix))
|
|
|
|
str_numth(s, s, S_TH_TYPE(n->suffix));
|
|
|
|
s += strlen(s);
|
|
|
|
break;
|
|
|
|
case DCH_J:
|
|
|
|
sprintf(s, "%d", date2j(tm->tm_year, tm->tm_mon, tm->tm_mday));
|
|
|
|
if (S_THth(n->suffix))
|
|
|
|
str_numth(s, s, S_TH_TYPE(n->suffix));
|
|
|
|
s += strlen(s);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2000-07-03 18:01:33 +02:00
|
|
|
|
2008-03-22 23:32:19 +01:00
|
|
|
*s = '\0';
|
|
|
|
}
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
|
|
|
/* ----------
|
2008-03-22 23:32:19 +01:00
|
|
|
* Process a string as denoted by a list of FormatNodes.
|
|
|
|
* The TmFromChar struct pointed to by 'out' is populated with the results.
|
|
|
|
*
|
|
|
|
* Note: we currently don't have any to_interval() function, so there
|
|
|
|
* is no need here for INVALID_FOR_INTERVAL checks.
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* ----------
|
|
|
|
*/
|
2008-03-22 23:32:19 +01:00
|
|
|
static void
|
|
|
|
DCH_from_char(FormatNode *node, char *in, TmFromChar *out)
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
{
|
2008-03-22 23:32:19 +01:00
|
|
|
FormatNode *n;
|
|
|
|
char *s;
|
2009-02-07 15:16:46 +01:00
|
|
|
int len,
|
|
|
|
value;
|
2008-03-22 23:32:19 +01:00
|
|
|
bool fx_mode = false;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
2008-03-22 23:32:19 +01:00
|
|
|
for (n = node, s = in; n->type != NODE_TYPE_END && *s != '\0'; n++)
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2008-03-22 23:32:19 +01:00
|
|
|
if (n->type != NODE_TYPE_ACTION)
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2014-01-20 19:45:51 +01:00
|
|
|
/*
|
|
|
|
* Separator, so consume one character from input string. Notice
|
|
|
|
* we don't insist that the consumed character match the format's
|
|
|
|
* character.
|
|
|
|
*/
|
2008-03-22 23:32:19 +01:00
|
|
|
s++;
|
|
|
|
continue;
|
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2014-01-20 19:45:51 +01:00
|
|
|
/* Ignore spaces before fields when not in FX (fixed width) mode */
|
|
|
|
if (!fx_mode && n->key->id != DCH_FX)
|
|
|
|
{
|
|
|
|
while (*s != '\0' && isspace((unsigned char) *s))
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
|
2008-09-11 19:32:34 +02:00
|
|
|
from_char_set_mode(out, n->key->date_mode);
|
|
|
|
|
2008-03-22 23:32:19 +01:00
|
|
|
switch (n->key->id)
|
|
|
|
{
|
|
|
|
case DCH_FX:
|
|
|
|
fx_mode = true;
|
|
|
|
break;
|
|
|
|
case DCH_A_M:
|
|
|
|
case DCH_P_M:
|
|
|
|
case DCH_a_m:
|
|
|
|
case DCH_p_m:
|
2009-02-07 15:16:46 +01:00
|
|
|
from_char_seq_search(&value, &s, ampm_strings_long,
|
|
|
|
ALL_UPPER, n->key->len, n);
|
|
|
|
from_char_set_int(&out->pm, value % 2, n);
|
|
|
|
out->clock = CLOCK_12_HOUR;
|
2008-03-22 23:32:19 +01:00
|
|
|
break;
|
2009-02-07 15:16:46 +01:00
|
|
|
case DCH_AM:
|
|
|
|
case DCH_PM:
|
2008-03-22 23:32:19 +01:00
|
|
|
case DCH_am:
|
|
|
|
case DCH_pm:
|
2009-02-07 15:16:46 +01:00
|
|
|
from_char_seq_search(&value, &s, ampm_strings,
|
|
|
|
ALL_UPPER, n->key->len, n);
|
|
|
|
from_char_set_int(&out->pm, value % 2, n);
|
|
|
|
out->clock = CLOCK_12_HOUR;
|
2008-03-22 23:32:19 +01:00
|
|
|
break;
|
|
|
|
case DCH_HH:
|
|
|
|
case DCH_HH12:
|
2009-02-07 15:16:46 +01:00
|
|
|
from_char_parse_int_len(&out->hh, &s, 2, n);
|
|
|
|
out->clock = CLOCK_12_HOUR;
|
|
|
|
s += SKIP_THth(n->suffix);
|
|
|
|
break;
|
2008-03-22 23:32:19 +01:00
|
|
|
case DCH_HH24:
|
2008-09-11 19:32:34 +02:00
|
|
|
from_char_parse_int_len(&out->hh, &s, 2, n);
|
|
|
|
s += SKIP_THth(n->suffix);
|
2008-03-22 23:32:19 +01:00
|
|
|
break;
|
|
|
|
case DCH_MI:
|
2008-09-11 19:32:34 +02:00
|
|
|
from_char_parse_int(&out->mi, &s, n);
|
|
|
|
s += SKIP_THth(n->suffix);
|
2008-03-22 23:32:19 +01:00
|
|
|
break;
|
|
|
|
case DCH_SS:
|
2008-09-11 19:32:34 +02:00
|
|
|
from_char_parse_int(&out->ss, &s, n);
|
|
|
|
s += SKIP_THth(n->suffix);
|
2008-03-22 23:32:19 +01:00
|
|
|
break;
|
2009-06-11 16:49:15 +02:00
|
|
|
case DCH_MS: /* millisecond */
|
2008-09-11 19:32:34 +02:00
|
|
|
len = from_char_parse_int_len(&out->ms, &s, 3, n);
|
2007-11-15 22:14:46 +01:00
|
|
|
|
2008-03-22 23:32:19 +01:00
|
|
|
/*
|
|
|
|
* 25 is 0.25 and 250 is 0.25 too; 025 is 0.025 and not 0.25
|
|
|
|
*/
|
2008-09-11 19:32:34 +02:00
|
|
|
out->ms *= len == 1 ? 100 :
|
|
|
|
len == 2 ? 10 : 1;
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2008-09-26 17:35:28 +02:00
|
|
|
s += SKIP_THth(n->suffix);
|
2008-03-22 23:32:19 +01:00
|
|
|
break;
|
2009-06-11 16:49:15 +02:00
|
|
|
case DCH_US: /* microsecond */
|
2008-09-11 19:32:34 +02:00
|
|
|
len = from_char_parse_int_len(&out->us, &s, 6, n);
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2008-09-11 19:32:34 +02:00
|
|
|
out->us *= len == 1 ? 100000 :
|
|
|
|
len == 2 ? 10000 :
|
|
|
|
len == 3 ? 1000 :
|
|
|
|
len == 4 ? 100 :
|
|
|
|
len == 5 ? 10 : 1;
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2008-09-26 17:35:28 +02:00
|
|
|
s += SKIP_THth(n->suffix);
|
2008-03-22 23:32:19 +01:00
|
|
|
break;
|
|
|
|
case DCH_SSSS:
|
2008-09-11 19:32:34 +02:00
|
|
|
from_char_parse_int(&out->ssss, &s, n);
|
|
|
|
s += SKIP_THth(n->suffix);
|
2008-03-22 23:32:19 +01:00
|
|
|
break;
|
|
|
|
case DCH_tz:
|
|
|
|
case DCH_TZ:
|
2013-07-01 19:40:18 +02:00
|
|
|
case DCH_OF:
|
2008-03-22 23:32:19 +01:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
2013-07-01 19:40:18 +02:00
|
|
|
errmsg("\"TZ\"/\"tz\"/\"OF\" format patterns are not supported in to_date")));
|
2008-03-22 23:32:19 +01:00
|
|
|
case DCH_A_D:
|
|
|
|
case DCH_B_C:
|
|
|
|
case DCH_a_d:
|
|
|
|
case DCH_b_c:
|
2009-02-07 15:16:46 +01:00
|
|
|
from_char_seq_search(&value, &s, adbc_strings_long,
|
|
|
|
ALL_UPPER, n->key->len, n);
|
|
|
|
from_char_set_int(&out->bc, value % 2, n);
|
2008-03-22 23:32:19 +01:00
|
|
|
break;
|
2009-02-07 15:16:46 +01:00
|
|
|
case DCH_AD:
|
|
|
|
case DCH_BC:
|
2008-03-22 23:32:19 +01:00
|
|
|
case DCH_ad:
|
|
|
|
case DCH_bc:
|
2009-02-07 15:16:46 +01:00
|
|
|
from_char_seq_search(&value, &s, adbc_strings,
|
|
|
|
ALL_UPPER, n->key->len, n);
|
|
|
|
from_char_set_int(&out->bc, value % 2, n);
|
2008-03-22 23:32:19 +01:00
|
|
|
break;
|
|
|
|
case DCH_MONTH:
|
|
|
|
case DCH_Month:
|
|
|
|
case DCH_month:
|
2009-02-07 15:16:46 +01:00
|
|
|
from_char_seq_search(&value, &s, months_full, ONE_UPPER,
|
|
|
|
MAX_MONTH_LEN, n);
|
|
|
|
from_char_set_int(&out->mm, value + 1, n);
|
2008-03-22 23:32:19 +01:00
|
|
|
break;
|
|
|
|
case DCH_MON:
|
|
|
|
case DCH_Mon:
|
|
|
|
case DCH_mon:
|
2009-02-07 15:16:46 +01:00
|
|
|
from_char_seq_search(&value, &s, months, ONE_UPPER,
|
2008-09-11 19:32:34 +02:00
|
|
|
MAX_MON_LEN, n);
|
2009-02-07 15:16:46 +01:00
|
|
|
from_char_set_int(&out->mm, value + 1, n);
|
2008-03-22 23:32:19 +01:00
|
|
|
break;
|
|
|
|
case DCH_MM:
|
2008-09-11 19:32:34 +02:00
|
|
|
from_char_parse_int(&out->mm, &s, n);
|
|
|
|
s += SKIP_THth(n->suffix);
|
2008-03-22 23:32:19 +01:00
|
|
|
break;
|
|
|
|
case DCH_DAY:
|
|
|
|
case DCH_Day:
|
|
|
|
case DCH_day:
|
2009-02-07 15:16:46 +01:00
|
|
|
from_char_seq_search(&value, &s, days, ONE_UPPER,
|
|
|
|
MAX_DAY_LEN, n);
|
|
|
|
from_char_set_int(&out->d, value, n);
|
2012-09-04 04:52:34 +02:00
|
|
|
out->d++;
|
2008-03-22 23:32:19 +01:00
|
|
|
break;
|
|
|
|
case DCH_DY:
|
|
|
|
case DCH_Dy:
|
|
|
|
case DCH_dy:
|
2009-02-07 15:16:46 +01:00
|
|
|
from_char_seq_search(&value, &s, days, ONE_UPPER,
|
2008-09-11 19:32:34 +02:00
|
|
|
MAX_DY_LEN, n);
|
2009-02-07 15:16:46 +01:00
|
|
|
from_char_set_int(&out->d, value, n);
|
2012-09-04 04:52:34 +02:00
|
|
|
out->d++;
|
2008-03-22 23:32:19 +01:00
|
|
|
break;
|
|
|
|
case DCH_DDD:
|
2008-09-11 19:32:34 +02:00
|
|
|
from_char_parse_int(&out->ddd, &s, n);
|
|
|
|
s += SKIP_THth(n->suffix);
|
|
|
|
break;
|
2008-03-22 23:32:19 +01:00
|
|
|
case DCH_IDDD:
|
2008-09-11 19:32:34 +02:00
|
|
|
from_char_parse_int_len(&out->ddd, &s, 3, n);
|
|
|
|
s += SKIP_THth(n->suffix);
|
2008-03-22 23:32:19 +01:00
|
|
|
break;
|
|
|
|
case DCH_DD:
|
2008-09-11 19:32:34 +02:00
|
|
|
from_char_parse_int(&out->dd, &s, n);
|
|
|
|
s += SKIP_THth(n->suffix);
|
2008-03-22 23:32:19 +01:00
|
|
|
break;
|
|
|
|
case DCH_D:
|
2008-09-11 19:32:34 +02:00
|
|
|
from_char_parse_int(&out->d, &s, n);
|
|
|
|
s += SKIP_THth(n->suffix);
|
|
|
|
break;
|
2008-03-22 23:32:19 +01:00
|
|
|
case DCH_ID:
|
2008-09-11 19:32:34 +02:00
|
|
|
from_char_parse_int_len(&out->d, &s, 1, n);
|
2012-09-04 04:52:34 +02:00
|
|
|
/* Shift numbering to match Gregorian where Sunday = 1 */
|
|
|
|
if (++out->d > 7)
|
|
|
|
out->d = 1;
|
2008-09-11 19:32:34 +02:00
|
|
|
s += SKIP_THth(n->suffix);
|
2008-03-22 23:32:19 +01:00
|
|
|
break;
|
|
|
|
case DCH_WW:
|
|
|
|
case DCH_IW:
|
2008-09-11 19:32:34 +02:00
|
|
|
from_char_parse_int(&out->ww, &s, n);
|
|
|
|
s += SKIP_THth(n->suffix);
|
2008-03-22 23:32:19 +01:00
|
|
|
break;
|
|
|
|
case DCH_Q:
|
2010-07-06 21:19:02 +02:00
|
|
|
|
2008-03-22 23:32:19 +01:00
|
|
|
/*
|
2010-07-06 21:19:02 +02:00
|
|
|
* We ignore 'Q' when converting to date because it is unclear
|
|
|
|
* which date in the quarter to use, and some people specify
|
|
|
|
* both quarter and month, so if it was honored it might
|
|
|
|
* conflict with the supplied month. That is also why we don't
|
|
|
|
* throw an error.
|
2008-09-11 19:32:34 +02:00
|
|
|
*
|
|
|
|
* We still parse the source string for an integer, but it
|
|
|
|
* isn't stored anywhere in 'out'.
|
2008-03-22 23:32:19 +01:00
|
|
|
*/
|
2008-09-11 19:32:34 +02:00
|
|
|
from_char_parse_int((int *) NULL, &s, n);
|
|
|
|
s += SKIP_THth(n->suffix);
|
2008-03-22 23:32:19 +01:00
|
|
|
break;
|
|
|
|
case DCH_CC:
|
2008-09-11 19:32:34 +02:00
|
|
|
from_char_parse_int(&out->cc, &s, n);
|
|
|
|
s += SKIP_THth(n->suffix);
|
2008-03-22 23:32:19 +01:00
|
|
|
break;
|
|
|
|
case DCH_Y_YYY:
|
2001-09-06 05:22:42 +02:00
|
|
|
{
|
2009-06-11 16:49:15 +02:00
|
|
|
int matched,
|
|
|
|
years,
|
|
|
|
millenia;
|
2008-09-11 19:32:34 +02:00
|
|
|
|
|
|
|
matched = sscanf(s, "%d,%03d", &millenia, &years);
|
|
|
|
if (matched != 2)
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
|
2009-06-11 16:49:15 +02:00
|
|
|
errmsg("invalid input string for \"Y,YYY\"")));
|
2008-09-11 19:32:34 +02:00
|
|
|
years += (millenia * 1000);
|
|
|
|
from_char_set_int(&out->year, years, n);
|
2008-03-22 23:32:19 +01:00
|
|
|
out->yysz = 4;
|
2008-09-11 19:32:34 +02:00
|
|
|
s += strdigits_len(s) + 4 + SKIP_THth(n->suffix);
|
2001-09-06 05:22:42 +02:00
|
|
|
}
|
2008-03-22 23:32:19 +01:00
|
|
|
break;
|
2008-09-11 19:32:34 +02:00
|
|
|
case DCH_YYYY:
|
|
|
|
case DCH_IYYY:
|
|
|
|
from_char_parse_int(&out->year, &s, n);
|
|
|
|
out->yysz = 4;
|
|
|
|
s += SKIP_THth(n->suffix);
|
|
|
|
break;
|
2008-03-22 23:32:19 +01:00
|
|
|
case DCH_YYY:
|
|
|
|
case DCH_IYY:
|
2011-09-07 15:47:51 +02:00
|
|
|
if (from_char_parse_int(&out->year, &s, n) < 4)
|
|
|
|
out->year = adjust_partial_year_to_2020(out->year);
|
2008-09-11 19:32:34 +02:00
|
|
|
out->yysz = 3;
|
|
|
|
s += SKIP_THth(n->suffix);
|
2008-03-22 23:32:19 +01:00
|
|
|
break;
|
|
|
|
case DCH_YY:
|
|
|
|
case DCH_IY:
|
2011-09-07 15:47:51 +02:00
|
|
|
if (from_char_parse_int(&out->year, &s, n) < 4)
|
|
|
|
out->year = adjust_partial_year_to_2020(out->year);
|
2008-09-11 19:32:34 +02:00
|
|
|
out->yysz = 2;
|
|
|
|
s += SKIP_THth(n->suffix);
|
2008-03-22 23:32:19 +01:00
|
|
|
break;
|
|
|
|
case DCH_Y:
|
|
|
|
case DCH_I:
|
2011-09-07 15:47:51 +02:00
|
|
|
if (from_char_parse_int(&out->year, &s, n) < 4)
|
|
|
|
out->year = adjust_partial_year_to_2020(out->year);
|
2008-09-11 19:32:34 +02:00
|
|
|
out->yysz = 1;
|
|
|
|
s += SKIP_THth(n->suffix);
|
2008-03-22 23:32:19 +01:00
|
|
|
break;
|
|
|
|
case DCH_RM:
|
2009-06-11 16:49:15 +02:00
|
|
|
from_char_seq_search(&value, &s, rm_months_upper,
|
2009-02-07 15:16:46 +01:00
|
|
|
ALL_UPPER, MAX_RM_LEN, n);
|
2011-03-12 15:31:18 +01:00
|
|
|
from_char_set_int(&out->mm, MONTHS_PER_YEAR - value, n);
|
2008-03-22 23:32:19 +01:00
|
|
|
break;
|
|
|
|
case DCH_rm:
|
2009-06-11 16:49:15 +02:00
|
|
|
from_char_seq_search(&value, &s, rm_months_lower,
|
2009-02-07 15:16:46 +01:00
|
|
|
ALL_LOWER, MAX_RM_LEN, n);
|
2011-03-12 15:31:18 +01:00
|
|
|
from_char_set_int(&out->mm, MONTHS_PER_YEAR - value, n);
|
2008-03-22 23:32:19 +01:00
|
|
|
break;
|
|
|
|
case DCH_W:
|
2008-09-11 19:32:34 +02:00
|
|
|
from_char_parse_int(&out->w, &s, n);
|
|
|
|
s += SKIP_THth(n->suffix);
|
2008-03-22 23:32:19 +01:00
|
|
|
break;
|
|
|
|
case DCH_J:
|
2008-09-11 19:32:34 +02:00
|
|
|
from_char_parse_int(&out->j, &s, n);
|
|
|
|
s += SKIP_THth(n->suffix);
|
2008-03-22 23:32:19 +01:00
|
|
|
break;
|
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
|
|
|
}
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
2000-03-16 02:35:41 +01:00
|
|
|
static DCHCacheEntry *
|
2000-04-12 19:17:23 +02:00
|
|
|
DCH_cache_getnew(char *str)
|
2000-03-16 02:35:41 +01:00
|
|
|
{
|
2009-03-12 01:53:25 +01:00
|
|
|
DCHCacheEntry *ent;
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2009-03-12 01:53:25 +01:00
|
|
|
/* counter overflow check - paranoia? */
|
|
|
|
if (DCHCounter >= (INT_MAX - DCH_CACHE_FIELDS - 1))
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2000-03-16 02:35:41 +01:00
|
|
|
DCHCounter = 0;
|
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
for (ent = DCHCache; ent <= (DCHCache + DCH_CACHE_FIELDS); ent++)
|
|
|
|
ent->age = (++DCHCounter);
|
2000-03-16 02:35:41 +01:00
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
2009-03-12 01:53:25 +01:00
|
|
|
* If cache is full, remove oldest entry
|
2000-03-16 02:35:41 +01:00
|
|
|
*/
|
2000-04-12 19:17:23 +02:00
|
|
|
if (n_DCHCache > DCH_CACHE_FIELDS)
|
|
|
|
{
|
|
|
|
DCHCacheEntry *old = DCHCache + 0;
|
2000-03-16 02:35:41 +01:00
|
|
|
|
|
|
|
#ifdef DEBUG_TO_FROM_CHAR
|
2003-07-27 06:53:12 +02:00
|
|
|
elog(DEBUG_elog_output, "cache is full (%d)", n_DCHCache);
|
2000-04-12 19:17:23 +02:00
|
|
|
#endif
|
2009-03-12 01:53:25 +01:00
|
|
|
for (ent = DCHCache + 1; ent <= (DCHCache + DCH_CACHE_FIELDS); ent++)
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2000-03-16 02:35:41 +01:00
|
|
|
if (ent->age < old->age)
|
|
|
|
old = ent;
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
2000-03-16 02:35:41 +01:00
|
|
|
#ifdef DEBUG_TO_FROM_CHAR
|
|
|
|
elog(DEBUG_elog_output, "OLD: '%s' AGE: %d", old->str, old->age);
|
2000-04-12 19:17:23 +02:00
|
|
|
#endif
|
2002-09-20 05:54:57 +02:00
|
|
|
StrNCpy(old->str, str, DCH_CACHE_SIZE + 1);
|
2000-03-16 02:35:41 +01:00
|
|
|
/* old->format fill parser */
|
|
|
|
old->age = (++DCHCounter);
|
|
|
|
return old;
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_TO_FROM_CHAR
|
2000-03-16 02:35:41 +01:00
|
|
|
elog(DEBUG_elog_output, "NEW (%d)", n_DCHCache);
|
2000-04-12 19:17:23 +02:00
|
|
|
#endif
|
2000-03-16 02:35:41 +01:00
|
|
|
ent = DCHCache + n_DCHCache;
|
2002-09-20 05:54:57 +02:00
|
|
|
StrNCpy(ent->str, str, DCH_CACHE_SIZE + 1);
|
2000-03-16 02:35:41 +01:00
|
|
|
/* ent->format fill parser */
|
|
|
|
ent->age = (++DCHCounter);
|
|
|
|
++n_DCHCache;
|
|
|
|
return ent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static DCHCacheEntry *
|
2000-04-12 19:17:23 +02:00
|
|
|
DCH_cache_search(char *str)
|
2000-03-16 02:35:41 +01:00
|
|
|
{
|
2009-03-12 01:53:25 +01:00
|
|
|
int i;
|
2000-04-12 19:17:23 +02:00
|
|
|
DCHCacheEntry *ent;
|
2000-03-16 02:35:41 +01:00
|
|
|
|
2009-03-12 01:53:25 +01:00
|
|
|
/* counter overflow check - paranoia? */
|
|
|
|
if (DCHCounter >= (INT_MAX - DCH_CACHE_FIELDS - 1))
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2000-03-16 02:35:41 +01:00
|
|
|
DCHCounter = 0;
|
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
for (ent = DCHCache; ent <= (DCHCache + DCH_CACHE_FIELDS); ent++)
|
|
|
|
ent->age = (++DCHCounter);
|
2000-03-16 02:35:41 +01:00
|
|
|
}
|
|
|
|
|
2009-03-12 01:53:25 +01:00
|
|
|
for (i = 0, ent = DCHCache; i < n_DCHCache; i++, ent++)
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
|
|
|
if (strcmp(ent->str, str) == 0)
|
|
|
|
{
|
2000-03-16 02:35:41 +01:00
|
|
|
ent->age = (++DCHCounter);
|
|
|
|
return ent;
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
2000-03-16 02:35:41 +01:00
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2004-01-07 19:56:30 +01:00
|
|
|
return NULL;
|
2000-03-16 02:35:41 +01:00
|
|
|
}
|
|
|
|
|
2008-03-22 23:32:19 +01:00
|
|
|
/*
|
|
|
|
* Format a date/time or interval into a string according to fmt.
|
|
|
|
* We parse fmt into a list of FormatNodes. This is then passed to DCH_to_char
|
|
|
|
* for formatting.
|
|
|
|
*/
|
2001-09-06 05:22:42 +02:00
|
|
|
static text *
|
2011-02-08 22:04:18 +01:00
|
|
|
datetime_to_char_body(TmToChar *tmtc, text *fmt, bool is_interval, Oid collid)
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
FormatNode *format;
|
2003-09-03 16:59:41 +02:00
|
|
|
char *fmt_str,
|
2004-08-29 07:07:03 +02:00
|
|
|
*result;
|
|
|
|
bool incache;
|
2008-03-25 23:42:46 +01:00
|
|
|
int fmt_len;
|
2005-10-20 17:59:46 +02:00
|
|
|
text *res;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
2000-12-01 06:17:19 +01:00
|
|
|
* Convert fmt to C string
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
*/
|
2008-03-25 23:42:46 +01:00
|
|
|
fmt_str = text_to_cstring(fmt);
|
|
|
|
fmt_len = strlen(fmt_str);
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
2005-10-20 17:59:46 +02:00
|
|
|
* Allocate workspace for result as C string
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
*/
|
2003-09-03 16:59:41 +02:00
|
|
|
result = palloc((fmt_len * DCH_MAX_ITEM_SIZ) + 1);
|
2005-10-20 17:59:46 +02:00
|
|
|
*result = '\0';
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
2005-10-15 04:49:52 +02:00
|
|
|
* Allocate new memory if format picture is bigger than static cache and
|
|
|
|
* not use cache (call parser always)
|
2000-07-03 18:01:33 +02:00
|
|
|
*/
|
2003-09-03 16:59:41 +02:00
|
|
|
if (fmt_len > DCH_CACHE_SIZE)
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2003-09-03 16:59:41 +02:00
|
|
|
format = (FormatNode *) palloc((fmt_len + 1) * sizeof(FormatNode));
|
2001-09-06 05:22:42 +02:00
|
|
|
incache = FALSE;
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2003-09-03 16:59:41 +02:00
|
|
|
parse_format(format, fmt_str, DCH_keywords,
|
2000-04-12 19:17:23 +02:00
|
|
|
DCH_suff, DCH_index, DCH_TYPE, NULL);
|
|
|
|
|
2004-08-29 07:07:03 +02:00
|
|
|
(format + fmt_len)->type = NODE_TYPE_END; /* Paranoia? */
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* Use cache buffers
|
|
|
|
*/
|
2000-04-12 19:17:23 +02:00
|
|
|
DCHCacheEntry *ent;
|
2004-08-29 07:07:03 +02:00
|
|
|
|
2001-09-06 05:22:42 +02:00
|
|
|
incache = TRUE;
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2003-09-03 16:59:41 +02:00
|
|
|
if ((ent = DCH_cache_search(fmt_str)) == NULL)
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2003-09-03 16:59:41 +02:00
|
|
|
ent = DCH_cache_getnew(fmt_str);
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
2005-10-15 04:49:52 +02:00
|
|
|
* Not in the cache, must run parser and save a new format-picture
|
|
|
|
* to the cache.
|
2000-07-03 18:01:33 +02:00
|
|
|
*/
|
2003-09-03 16:59:41 +02:00
|
|
|
parse_format(ent->format, fmt_str, DCH_keywords,
|
2001-03-22 05:01:46 +01:00
|
|
|
DCH_suff, DCH_index, DCH_TYPE, NULL);
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2004-08-29 07:07:03 +02:00
|
|
|
(ent->format + fmt_len)->type = NODE_TYPE_END; /* Paranoia? */
|
2000-04-12 19:17:23 +02:00
|
|
|
|
|
|
|
#ifdef DEBUG_TO_FROM_CHAR
|
2003-09-03 16:59:41 +02:00
|
|
|
/* dump_node(ent->format, fmt_len); */
|
2000-04-07 21:17:51 +02:00
|
|
|
/* dump_index(DCH_keywords, DCH_index); */
|
2000-04-12 19:17:23 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
format = ent->format;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2005-10-20 17:59:46 +02:00
|
|
|
/* The real work is here */
|
2011-02-08 22:04:18 +01:00
|
|
|
DCH_to_char(format, is_interval, tmtc, result, collid);
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
2001-09-06 05:22:42 +02:00
|
|
|
if (!incache)
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
pfree(format);
|
|
|
|
|
2003-09-03 16:59:41 +02:00
|
|
|
pfree(fmt_str);
|
2000-03-16 02:35:41 +01:00
|
|
|
|
2005-10-20 17:59:46 +02:00
|
|
|
/* convert C-string result to TEXT format */
|
2008-03-25 23:42:46 +01:00
|
|
|
res = cstring_to_text(result);
|
2001-09-06 05:22:42 +02:00
|
|
|
|
2003-09-03 16:59:41 +02:00
|
|
|
pfree(result);
|
2005-10-20 17:59:46 +02:00
|
|
|
return res;
|
2001-09-06 05:22:42 +02:00
|
|
|
}
|
2001-03-22 05:01:46 +01:00
|
|
|
|
2001-09-06 05:22:42 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Public routines
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
/* -------------------
|
|
|
|
* TIMESTAMP to_char()
|
|
|
|
* -------------------
|
|
|
|
*/
|
|
|
|
Datum
|
|
|
|
timestamp_to_char(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2001-10-25 07:50:21 +02:00
|
|
|
Timestamp dt = PG_GETARG_TIMESTAMP(0);
|
|
|
|
text *fmt = PG_GETARG_TEXT_P(1),
|
|
|
|
*res;
|
|
|
|
TmToChar tmtc;
|
2005-10-20 17:59:46 +02:00
|
|
|
struct pg_tm *tm;
|
|
|
|
int thisdate;
|
2001-09-28 10:09:14 +02:00
|
|
|
|
2001-10-25 07:50:21 +02:00
|
|
|
if ((VARSIZE(fmt) - VARHDRSZ) <= 0 || TIMESTAMP_NOT_FINITE(dt))
|
2001-09-28 10:09:14 +02:00
|
|
|
PG_RETURN_NULL();
|
|
|
|
|
|
|
|
ZERO_tmtc(&tmtc);
|
2005-10-20 17:59:46 +02:00
|
|
|
tm = tmtcTm(&tmtc);
|
2001-09-28 10:09:14 +02:00
|
|
|
|
2005-10-20 17:59:46 +02:00
|
|
|
if (timestamp2tm(dt, NULL, tm, &tmtcFsec(&tmtc), NULL, NULL) != 0)
|
2003-07-27 06:53:12 +02:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
|
|
|
|
errmsg("timestamp out of range")));
|
2001-09-28 10:09:14 +02:00
|
|
|
|
2005-10-20 17:59:46 +02:00
|
|
|
thisdate = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday);
|
|
|
|
tm->tm_wday = (thisdate + 1) % 7;
|
|
|
|
tm->tm_yday = thisdate - date2j(tm->tm_year, 1, 1) + 1;
|
|
|
|
|
2011-02-08 22:04:18 +01:00
|
|
|
if (!(res = datetime_to_char_body(&tmtc, fmt, false, PG_GET_COLLATION())))
|
2001-09-28 10:09:14 +02:00
|
|
|
PG_RETURN_NULL();
|
|
|
|
|
|
|
|
PG_RETURN_TEXT_P(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
|
|
|
timestamptz_to_char(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
TimestampTz dt = PG_GETARG_TIMESTAMP(0);
|
2001-10-25 07:50:21 +02:00
|
|
|
text *fmt = PG_GETARG_TEXT_P(1),
|
|
|
|
*res;
|
|
|
|
TmToChar tmtc;
|
2003-07-27 06:53:12 +02:00
|
|
|
int tz;
|
2005-10-20 17:59:46 +02:00
|
|
|
struct pg_tm *tm;
|
|
|
|
int thisdate;
|
2001-09-06 05:22:42 +02:00
|
|
|
|
2001-10-25 07:50:21 +02:00
|
|
|
if ((VARSIZE(fmt) - VARHDRSZ) <= 0 || TIMESTAMP_NOT_FINITE(dt))
|
2001-09-06 05:22:42 +02:00
|
|
|
PG_RETURN_NULL();
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2001-09-06 05:22:42 +02:00
|
|
|
ZERO_tmtc(&tmtc);
|
2005-10-20 17:59:46 +02:00
|
|
|
tm = tmtcTm(&tmtc);
|
2000-03-16 02:35:41 +01:00
|
|
|
|
2005-10-20 17:59:46 +02:00
|
|
|
if (timestamp2tm(dt, &tz, tm, &tmtcFsec(&tmtc), &tmtcTzn(&tmtc), NULL) != 0)
|
2003-07-27 06:53:12 +02:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
|
|
|
|
errmsg("timestamp out of range")));
|
2001-09-06 05:22:42 +02:00
|
|
|
|
2005-10-20 17:59:46 +02:00
|
|
|
thisdate = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday);
|
|
|
|
tm->tm_wday = (thisdate + 1) % 7;
|
|
|
|
tm->tm_yday = thisdate - date2j(tm->tm_year, 1, 1) + 1;
|
|
|
|
|
2011-02-08 22:04:18 +01:00
|
|
|
if (!(res = datetime_to_char_body(&tmtc, fmt, false, PG_GET_COLLATION())))
|
2001-09-06 05:22:42 +02:00
|
|
|
PG_RETURN_NULL();
|
|
|
|
|
|
|
|
PG_RETURN_TEXT_P(res);
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-06 05:22:42 +02:00
|
|
|
/* -------------------
|
|
|
|
* INTERVAL to_char()
|
|
|
|
* -------------------
|
|
|
|
*/
|
|
|
|
Datum
|
|
|
|
interval_to_char(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2001-10-25 07:50:21 +02:00
|
|
|
Interval *it = PG_GETARG_INTERVAL_P(0);
|
|
|
|
text *fmt = PG_GETARG_TEXT_P(1),
|
|
|
|
*res;
|
|
|
|
TmToChar tmtc;
|
2005-10-20 17:59:46 +02:00
|
|
|
struct pg_tm *tm;
|
2001-09-06 05:22:42 +02:00
|
|
|
|
|
|
|
if ((VARSIZE(fmt) - VARHDRSZ) <= 0)
|
|
|
|
PG_RETURN_NULL();
|
|
|
|
|
|
|
|
ZERO_tmtc(&tmtc);
|
2005-10-20 17:59:46 +02:00
|
|
|
tm = tmtcTm(&tmtc);
|
2001-09-06 05:22:42 +02:00
|
|
|
|
2005-10-20 17:59:46 +02:00
|
|
|
if (interval2tm(*it, tm, &tmtcFsec(&tmtc)) != 0)
|
2001-09-06 05:22:42 +02:00
|
|
|
PG_RETURN_NULL();
|
|
|
|
|
2005-10-20 17:59:46 +02:00
|
|
|
/* wday is meaningless, yday approximates the total span in days */
|
|
|
|
tm->tm_yday = (tm->tm_year * MONTHS_PER_YEAR + tm->tm_mon) * DAYS_PER_MONTH + tm->tm_mday;
|
|
|
|
|
2011-02-08 22:04:18 +01:00
|
|
|
if (!(res = datetime_to_char_body(&tmtc, fmt, true, PG_GET_COLLATION())))
|
2001-09-06 05:22:42 +02:00
|
|
|
PG_RETURN_NULL();
|
|
|
|
|
|
|
|
PG_RETURN_TEXT_P(res);
|
|
|
|
}
|
|
|
|
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
/* ---------------------
|
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:26:26 +01:00
|
|
|
* TO_TIMESTAMP()
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
*
|
2001-09-28 10:09:14 +02:00
|
|
|
* Make Timestamp from date_str which is formatted at argument 'fmt'
|
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:26:26 +01:00
|
|
|
* ( to_timestamp is reverse to_char() )
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* ---------------------
|
|
|
|
*/
|
2000-07-01 23:27:14 +02:00
|
|
|
Datum
|
|
|
|
to_timestamp(PG_FUNCTION_ARGS)
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
{
|
2001-10-25 07:50:21 +02:00
|
|
|
text *date_txt = PG_GETARG_TEXT_P(0);
|
|
|
|
text *fmt = PG_GETARG_TEXT_P(1);
|
|
|
|
Timestamp result;
|
2003-08-25 18:13:27 +02:00
|
|
|
int tz;
|
2004-08-29 07:07:03 +02:00
|
|
|
struct pg_tm tm;
|
2003-08-25 18:13:27 +02:00
|
|
|
fsec_t fsec;
|
|
|
|
|
|
|
|
do_to_timestamp(date_txt, fmt, &tm, &fsec);
|
|
|
|
|
2007-08-04 03:26:54 +02:00
|
|
|
tz = DetermineTimeZoneOffset(&tm, session_timezone);
|
2003-08-25 18:13:27 +02:00
|
|
|
|
|
|
|
if (tm2timestamp(&tm, fsec, &tz, &result) != 0)
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
|
|
|
|
errmsg("timestamp out of range")));
|
|
|
|
|
|
|
|
PG_RETURN_TIMESTAMP(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------
|
|
|
|
* TO_DATE
|
|
|
|
* Make Date from date_str which is formated at argument 'fmt'
|
|
|
|
* ----------
|
|
|
|
*/
|
|
|
|
Datum
|
|
|
|
to_date(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
text *date_txt = PG_GETARG_TEXT_P(0);
|
|
|
|
text *fmt = PG_GETARG_TEXT_P(1);
|
|
|
|
DateADT result;
|
2004-08-29 07:07:03 +02:00
|
|
|
struct pg_tm tm;
|
2003-08-25 18:13:27 +02:00
|
|
|
fsec_t fsec;
|
|
|
|
|
|
|
|
do_to_timestamp(date_txt, fmt, &tm, &fsec);
|
|
|
|
|
2016-03-17 00:09:04 +01:00
|
|
|
/* Prevent overflow in Julian-day routines */
|
2013-01-14 21:19:48 +01:00
|
|
|
if (!IS_VALID_JULIAN(tm.tm_year, tm.tm_mon, tm.tm_mday))
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
|
|
|
|
errmsg("date out of range: \"%s\"",
|
|
|
|
text_to_cstring(date_txt))));
|
|
|
|
|
2003-08-25 18:13:27 +02:00
|
|
|
result = date2j(tm.tm_year, tm.tm_mon, tm.tm_mday) - POSTGRES_EPOCH_JDATE;
|
|
|
|
|
2016-03-17 00:09:04 +01:00
|
|
|
/* Now check for just-out-of-range dates */
|
|
|
|
if (!IS_VALID_DATE(result))
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
|
|
|
|
errmsg("date out of range: \"%s\"",
|
|
|
|
text_to_cstring(date_txt))));
|
|
|
|
|
2003-08-25 18:13:27 +02:00
|
|
|
PG_RETURN_DATEADT(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* do_to_timestamp: shared code for to_timestamp and to_date
|
|
|
|
*
|
2004-05-21 07:08:06 +02:00
|
|
|
* Parse the 'date_txt' according to 'fmt', return results as a struct pg_tm
|
2003-08-25 18:13:27 +02:00
|
|
|
* and fractional seconds.
|
2008-03-22 23:32:19 +01:00
|
|
|
*
|
|
|
|
* We parse 'fmt' into a list of FormatNodes, which is then passed to
|
|
|
|
* DCH_from_char to populate a TmFromChar with the parsed contents of
|
|
|
|
* 'date_txt'.
|
|
|
|
*
|
|
|
|
* The TmFromChar is then analysed and converted into the final results in
|
|
|
|
* struct 'tm' and 'fsec'.
|
2010-02-25 19:36:14 +01:00
|
|
|
*
|
|
|
|
* This function does very little error checking, e.g.
|
|
|
|
* to_timestamp('20096040','YYYYMMDD') works
|
2003-08-25 18:13:27 +02:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
do_to_timestamp(text *date_txt, text *fmt,
|
2005-10-15 04:49:52 +02:00
|
|
|
struct pg_tm * tm, fsec_t *fsec)
|
2003-08-25 18:13:27 +02:00
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
FormatNode *format;
|
2001-10-25 07:50:21 +02:00
|
|
|
TmFromChar tmfc;
|
2008-09-11 19:32:34 +02:00
|
|
|
int fmt_len;
|
2003-08-25 18:13:27 +02:00
|
|
|
|
2008-03-22 23:32:19 +01:00
|
|
|
ZERO_tmfc(&tmfc);
|
2003-08-25 18:13:27 +02:00
|
|
|
ZERO_tm(tm);
|
|
|
|
*fsec = 0;
|
2001-09-06 05:22:42 +02:00
|
|
|
|
2008-03-25 23:42:46 +01:00
|
|
|
fmt_len = VARSIZE_ANY_EXHDR(fmt);
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2003-09-03 16:59:41 +02:00
|
|
|
if (fmt_len)
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2004-08-29 07:07:03 +02:00
|
|
|
char *fmt_str;
|
|
|
|
char *date_str;
|
|
|
|
bool incache;
|
|
|
|
|
2008-03-25 23:42:46 +01:00
|
|
|
fmt_str = text_to_cstring(fmt);
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
2005-10-15 04:49:52 +02:00
|
|
|
* Allocate new memory if format picture is bigger than static cache
|
|
|
|
* and not use cache (call parser always)
|
2000-07-03 18:01:33 +02:00
|
|
|
*/
|
2003-09-03 16:59:41 +02:00
|
|
|
if (fmt_len > DCH_CACHE_SIZE)
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2003-09-03 16:59:41 +02:00
|
|
|
format = (FormatNode *) palloc((fmt_len + 1) * sizeof(FormatNode));
|
2001-09-06 05:22:42 +02:00
|
|
|
incache = FALSE;
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2003-09-03 16:59:41 +02:00
|
|
|
parse_format(format, fmt_str, DCH_keywords,
|
2000-04-12 19:17:23 +02:00
|
|
|
DCH_suff, DCH_index, DCH_TYPE, NULL);
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
2004-08-29 07:07:03 +02:00
|
|
|
(format + fmt_len)->type = NODE_TYPE_END; /* Paranoia? */
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* Use cache buffers
|
|
|
|
*/
|
2000-04-12 19:17:23 +02:00
|
|
|
DCHCacheEntry *ent;
|
2004-08-29 07:07:03 +02:00
|
|
|
|
2003-09-03 16:59:41 +02:00
|
|
|
incache = TRUE;
|
2001-10-25 07:50:21 +02:00
|
|
|
|
2003-09-03 16:59:41 +02:00
|
|
|
if ((ent = DCH_cache_search(fmt_str)) == NULL)
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2003-09-03 16:59:41 +02:00
|
|
|
ent = DCH_cache_getnew(fmt_str);
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
2000-03-16 02:35:41 +01:00
|
|
|
* Not in the cache, must run parser and save a new
|
2000-04-12 19:17:23 +02:00
|
|
|
* format-picture to the cache.
|
2001-03-22 07:16:21 +01:00
|
|
|
*/
|
2003-09-03 16:59:41 +02:00
|
|
|
parse_format(ent->format, fmt_str, DCH_keywords,
|
2000-04-12 19:17:23 +02:00
|
|
|
DCH_suff, DCH_index, DCH_TYPE, NULL);
|
|
|
|
|
2004-08-29 07:07:03 +02:00
|
|
|
(ent->format + fmt_len)->type = NODE_TYPE_END; /* Paranoia? */
|
2000-04-12 19:17:23 +02:00
|
|
|
#ifdef DEBUG_TO_FROM_CHAR
|
2003-09-03 16:59:41 +02:00
|
|
|
/* dump_node(ent->format, fmt_len); */
|
2000-03-16 02:35:41 +01:00
|
|
|
/* dump_index(DCH_keywords, DCH_index); */
|
2000-04-12 19:17:23 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
format = ent->format;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG_TO_FROM_CHAR
|
2003-09-03 16:59:41 +02:00
|
|
|
/* dump_node(format, fmt_len); */
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
#endif
|
|
|
|
|
2008-03-25 23:42:46 +01:00
|
|
|
date_str = text_to_cstring(date_txt);
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2008-03-22 23:32:19 +01:00
|
|
|
DCH_from_char(format, date_str, &tmfc);
|
2000-12-01 06:17:19 +01:00
|
|
|
|
|
|
|
pfree(date_str);
|
2003-09-03 16:59:41 +02:00
|
|
|
pfree(fmt_str);
|
|
|
|
if (!incache)
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
pfree(format);
|
|
|
|
}
|
|
|
|
|
2001-10-25 07:50:21 +02:00
|
|
|
DEBUG_TMFC(&tmfc);
|
2001-09-06 05:22:42 +02:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
2005-10-15 04:49:52 +02:00
|
|
|
* Convert values that user define for FROM_CHAR (to_date/to_timestamp) to
|
|
|
|
* standard 'tm'
|
2001-03-22 05:01:46 +01:00
|
|
|
*/
|
2001-09-06 05:22:42 +02:00
|
|
|
if (tmfc.ssss)
|
2000-07-03 18:01:33 +02:00
|
|
|
{
|
2001-10-25 07:50:21 +02:00
|
|
|
int x = tmfc.ssss;
|
2000-12-23 05:05:31 +01:00
|
|
|
|
2005-07-21 05:56:25 +02:00
|
|
|
tm->tm_hour = x / SECS_PER_HOUR;
|
|
|
|
x %= SECS_PER_HOUR;
|
|
|
|
tm->tm_min = x / SECS_PER_MINUTE;
|
|
|
|
x %= SECS_PER_MINUTE;
|
2003-08-25 18:13:27 +02:00
|
|
|
tm->tm_sec = x;
|
2000-12-23 05:05:31 +01:00
|
|
|
}
|
2000-07-03 18:01:33 +02:00
|
|
|
|
2001-09-06 05:22:42 +02:00
|
|
|
if (tmfc.ss)
|
2003-08-25 18:13:27 +02:00
|
|
|
tm->tm_sec = tmfc.ss;
|
2001-09-06 05:22:42 +02:00
|
|
|
if (tmfc.mi)
|
2003-08-25 18:13:27 +02:00
|
|
|
tm->tm_min = tmfc.mi;
|
2001-09-06 05:22:42 +02:00
|
|
|
if (tmfc.hh)
|
2003-08-25 18:13:27 +02:00
|
|
|
tm->tm_hour = tmfc.hh;
|
2001-03-22 05:01:46 +01:00
|
|
|
|
2009-02-07 15:16:46 +01:00
|
|
|
if (tmfc.clock == CLOCK_12_HOUR)
|
2001-03-22 05:01:46 +01:00
|
|
|
{
|
2011-03-12 15:31:18 +01:00
|
|
|
if (tm->tm_hour < 1 || tm->tm_hour > HOURS_PER_DAY / 2)
|
2003-07-27 06:53:12 +02:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
|
2009-02-07 15:16:46 +01:00
|
|
|
errmsg("hour \"%d\" is invalid for the 12-hour clock",
|
|
|
|
tm->tm_hour),
|
|
|
|
errhint("Use the 24-hour clock, or give an hour between 1 and 12.")));
|
2001-03-22 05:01:46 +01:00
|
|
|
|
2011-03-12 15:31:18 +01:00
|
|
|
if (tmfc.pm && tm->tm_hour < HOURS_PER_DAY / 2)
|
|
|
|
tm->tm_hour += HOURS_PER_DAY / 2;
|
|
|
|
else if (!tmfc.pm && tm->tm_hour == HOURS_PER_DAY / 2)
|
2003-08-25 18:13:27 +02:00
|
|
|
tm->tm_hour = 0;
|
2001-03-22 05:01:46 +01:00
|
|
|
}
|
2000-07-03 18:01:33 +02:00
|
|
|
|
2008-09-11 19:32:34 +02:00
|
|
|
if (tmfc.year)
|
2005-03-25 17:08:40 +01:00
|
|
|
{
|
2007-01-13 00:34:55 +01:00
|
|
|
/*
|
2007-11-15 22:14:46 +01:00
|
|
|
* If CC and YY (or Y) are provided, use YY as 2 low-order digits for
|
|
|
|
* the year in the given century. Keep in mind that the 21st century
|
2012-08-07 19:34:44 +02:00
|
|
|
* AD runs from 2001-2100, not 2000-2099; 6th century BC runs from
|
|
|
|
* 600BC to 501BC.
|
2007-01-13 00:34:55 +01:00
|
|
|
*/
|
|
|
|
if (tmfc.cc && tmfc.yysz <= 2)
|
2005-03-25 17:08:40 +01:00
|
|
|
{
|
2012-08-07 19:34:44 +02:00
|
|
|
if (tmfc.bc)
|
|
|
|
tmfc.cc = -tmfc.cc;
|
2008-09-11 19:32:34 +02:00
|
|
|
tm->tm_year = tmfc.year % 100;
|
2007-01-13 00:34:55 +01:00
|
|
|
if (tm->tm_year)
|
2012-08-07 19:34:44 +02:00
|
|
|
{
|
|
|
|
if (tmfc.cc >= 0)
|
|
|
|
tm->tm_year += (tmfc.cc - 1) * 100;
|
|
|
|
else
|
|
|
|
tm->tm_year = (tmfc.cc + 1) * 100 - tm->tm_year + 1;
|
|
|
|
}
|
2007-01-13 00:34:55 +01:00
|
|
|
else
|
2012-08-07 19:34:44 +02:00
|
|
|
/* find century year for dates ending in "00" */
|
2013-05-29 22:58:43 +02:00
|
|
|
tm->tm_year = tmfc.cc * 100 + ((tmfc.cc >= 0) ? 0 : 1);
|
2005-03-25 17:08:40 +01:00
|
|
|
}
|
|
|
|
else
|
2013-05-29 22:58:43 +02:00
|
|
|
/* If a 4-digit year is provided, we use that and ignore CC. */
|
2012-08-07 19:34:44 +02:00
|
|
|
{
|
2008-09-11 19:32:34 +02:00
|
|
|
tm->tm_year = tmfc.year;
|
2012-08-07 19:34:44 +02:00
|
|
|
if (tmfc.bc && tm->tm_year > 0)
|
|
|
|
tm->tm_year = -(tm->tm_year - 1);
|
|
|
|
}
|
2005-03-25 17:08:40 +01:00
|
|
|
}
|
2013-05-29 22:58:43 +02:00
|
|
|
else if (tmfc.cc) /* use first year of century */
|
2000-11-25 06:00:33 +01:00
|
|
|
{
|
2012-08-07 19:34:44 +02:00
|
|
|
if (tmfc.bc)
|
|
|
|
tmfc.cc = -tmfc.cc;
|
|
|
|
if (tmfc.cc >= 0)
|
2014-05-22 05:18:38 +02:00
|
|
|
/* +1 because 21st century started in 2001 */
|
2012-08-07 19:34:44 +02:00
|
|
|
tm->tm_year = (tmfc.cc - 1) * 100 + 1;
|
2000-11-25 06:00:33 +01:00
|
|
|
else
|
2012-08-08 19:26:39 +02:00
|
|
|
/* +1 because year == 599 is 600 BC */
|
2012-08-07 19:34:44 +02:00
|
|
|
tm->tm_year = tmfc.cc * 100 + 1;
|
2001-03-22 05:01:46 +01:00
|
|
|
}
|
|
|
|
|
2001-09-06 05:22:42 +02:00
|
|
|
if (tmfc.j)
|
2003-08-25 18:13:27 +02:00
|
|
|
j2date(tmfc.j, &tm->tm_year, &tm->tm_mon, &tm->tm_mday);
|
2001-03-22 05:01:46 +01:00
|
|
|
|
2008-09-11 19:32:34 +02:00
|
|
|
if (tmfc.ww)
|
2007-02-16 04:39:46 +01:00
|
|
|
{
|
2008-09-11 19:32:34 +02:00
|
|
|
if (tmfc.mode == FROM_CHAR_DATE_ISOWEEK)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* If tmfc.d is not set, then the date is left at the beginning of
|
|
|
|
* the ISO week (Monday).
|
|
|
|
*/
|
|
|
|
if (tmfc.d)
|
|
|
|
isoweekdate2date(tmfc.ww, tmfc.d, &tm->tm_year, &tm->tm_mon, &tm->tm_mday);
|
|
|
|
else
|
|
|
|
isoweek2date(tmfc.ww, &tm->tm_year, &tm->tm_mon, &tm->tm_mday);
|
|
|
|
}
|
2007-02-16 04:39:46 +01:00
|
|
|
else
|
2008-09-11 19:32:34 +02:00
|
|
|
tmfc.ddd = (tmfc.ww - 1) * 7 + 1;
|
2007-02-16 04:39:46 +01:00
|
|
|
}
|
|
|
|
|
2008-09-11 19:32:34 +02:00
|
|
|
if (tmfc.w)
|
|
|
|
tmfc.dd = (tmfc.w - 1) * 7 + 1;
|
2001-09-06 05:22:42 +02:00
|
|
|
if (tmfc.d)
|
2013-05-29 22:58:43 +02:00
|
|
|
tm->tm_wday = tmfc.d - 1; /* convert to native numbering */
|
2001-09-06 05:22:42 +02:00
|
|
|
if (tmfc.dd)
|
2003-08-25 18:13:27 +02:00
|
|
|
tm->tm_mday = tmfc.dd;
|
2008-09-11 19:32:34 +02:00
|
|
|
if (tmfc.ddd)
|
2003-08-25 18:13:27 +02:00
|
|
|
tm->tm_yday = tmfc.ddd;
|
2001-09-06 05:22:42 +02:00
|
|
|
if (tmfc.mm)
|
2003-08-25 18:13:27 +02:00
|
|
|
tm->tm_mon = tmfc.mm;
|
2000-07-03 18:01:33 +02:00
|
|
|
|
2003-08-25 18:13:27 +02:00
|
|
|
if (tmfc.ddd && (tm->tm_mon <= 1 || tm->tm_mday <= 1))
|
2000-07-03 18:01:33 +02:00
|
|
|
{
|
2007-02-16 04:39:46 +01:00
|
|
|
/*
|
2009-06-11 16:49:15 +02:00
|
|
|
* The month and day field have not been set, so we use the
|
2014-05-06 18:12:18 +02:00
|
|
|
* day-of-year field to populate them. Depending on the date mode,
|
2009-06-11 16:49:15 +02:00
|
|
|
* this field may be interpreted as a Gregorian day-of-year, or an ISO
|
|
|
|
* week date day-of-year.
|
2007-02-16 04:39:46 +01:00
|
|
|
*/
|
2009-03-15 21:31:19 +01:00
|
|
|
|
|
|
|
if (!tm->tm_year && !tmfc.bc)
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
|
2009-06-11 16:49:15 +02:00
|
|
|
errmsg("cannot calculate day of year without year information")));
|
2009-03-15 21:31:19 +01:00
|
|
|
|
2008-09-11 19:32:34 +02:00
|
|
|
if (tmfc.mode == FROM_CHAR_DATE_ISOWEEK)
|
2007-02-16 04:39:46 +01:00
|
|
|
{
|
2007-11-15 22:14:46 +01:00
|
|
|
int j0; /* zeroth day of the ISO year, in Julian */
|
|
|
|
|
2009-03-15 21:31:19 +01:00
|
|
|
j0 = isoweek2j(tm->tm_year, 1) - 1;
|
2001-03-22 05:01:46 +01:00
|
|
|
|
2007-02-16 04:39:46 +01:00
|
|
|
j2date(j0 + tmfc.ddd, &tm->tm_year, &tm->tm_mon, &tm->tm_mday);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-03-15 21:31:19 +01:00
|
|
|
const int *y;
|
|
|
|
int i;
|
2001-03-22 05:01:46 +01:00
|
|
|
|
2009-03-15 21:31:19 +01:00
|
|
|
static const int ysum[2][13] = {
|
|
|
|
{0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365},
|
2009-06-11 16:49:15 +02:00
|
|
|
{0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366}};
|
2001-03-22 05:01:46 +01:00
|
|
|
|
2007-02-16 04:39:46 +01:00
|
|
|
y = ysum[isleap(tm->tm_year)];
|
2001-03-22 05:01:46 +01:00
|
|
|
|
2011-03-12 15:31:18 +01:00
|
|
|
for (i = 1; i <= MONTHS_PER_YEAR; i++)
|
2007-02-16 04:39:46 +01:00
|
|
|
{
|
2009-03-15 21:31:19 +01:00
|
|
|
if (tmfc.ddd < y[i])
|
2007-02-16 04:39:46 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (tm->tm_mon <= 1)
|
2009-03-15 21:31:19 +01:00
|
|
|
tm->tm_mon = i;
|
2007-02-16 04:39:46 +01:00
|
|
|
|
|
|
|
if (tm->tm_mday <= 1)
|
2009-03-15 21:31:19 +01:00
|
|
|
tm->tm_mday = tmfc.ddd - y[i - 1];
|
2007-02-16 04:39:46 +01:00
|
|
|
}
|
2000-07-03 18:01:33 +02:00
|
|
|
}
|
2001-03-22 05:01:46 +01:00
|
|
|
|
2002-04-21 21:52:18 +02:00
|
|
|
#ifdef HAVE_INT64_TIMESTAMP
|
|
|
|
if (tmfc.ms)
|
2003-08-25 18:13:27 +02:00
|
|
|
*fsec += tmfc.ms * 1000;
|
2002-04-21 21:52:18 +02:00
|
|
|
if (tmfc.us)
|
2003-08-25 18:13:27 +02:00
|
|
|
*fsec += tmfc.us;
|
2002-04-21 21:52:18 +02:00
|
|
|
#else
|
2001-09-06 05:22:42 +02:00
|
|
|
if (tmfc.ms)
|
2003-08-25 18:13:27 +02:00
|
|
|
*fsec += (double) tmfc.ms / 1000;
|
2001-09-06 05:22:42 +02:00
|
|
|
if (tmfc.us)
|
2003-08-25 18:13:27 +02:00
|
|
|
*fsec += (double) tmfc.us / 1000000;
|
2002-04-21 21:52:18 +02:00
|
|
|
#endif
|
2001-09-06 05:22:42 +02:00
|
|
|
|
2003-08-25 18:13:27 +02:00
|
|
|
DEBUG_TM(tm);
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
2000-04-12 19:17:23 +02:00
|
|
|
* the NUMBER version part
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
static char *
|
|
|
|
fill_str(char *str, int c, int max)
|
|
|
|
{
|
|
|
|
memset(str, c, max);
|
2007-06-29 03:51:35 +02:00
|
|
|
*(str + max) = '\0';
|
2000-04-12 19:17:23 +02:00
|
|
|
return str;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
}
|
|
|
|
|
2000-07-03 18:01:33 +02:00
|
|
|
#define zeroize_NUM(_n) \
|
|
|
|
do { \
|
2000-04-12 19:17:23 +02:00
|
|
|
(_n)->flag = 0; \
|
2000-03-16 02:35:41 +01:00
|
|
|
(_n)->lsign = 0; \
|
|
|
|
(_n)->pre = 0; \
|
|
|
|
(_n)->post = 0; \
|
2001-03-22 05:01:46 +01:00
|
|
|
(_n)->pre_lsign_num = 0; \
|
2000-03-16 02:35:41 +01:00
|
|
|
(_n)->need_locale = 0; \
|
|
|
|
(_n)->multi = 0; \
|
|
|
|
(_n)->zero_start = 0; \
|
|
|
|
(_n)->zero_end = 0; \
|
2000-07-03 18:01:33 +02:00
|
|
|
} while(0)
|
2000-03-16 02:35:41 +01:00
|
|
|
|
|
|
|
static NUMCacheEntry *
|
2000-04-12 19:17:23 +02:00
|
|
|
NUM_cache_getnew(char *str)
|
2000-03-16 02:35:41 +01:00
|
|
|
{
|
2009-03-12 01:53:25 +01:00
|
|
|
NUMCacheEntry *ent;
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2009-03-12 01:53:25 +01:00
|
|
|
/* counter overflow check - paranoia? */
|
|
|
|
if (NUMCounter >= (INT_MAX - NUM_CACHE_FIELDS - 1))
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2000-03-16 02:35:41 +01:00
|
|
|
NUMCounter = 0;
|
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
for (ent = NUMCache; ent <= (NUMCache + NUM_CACHE_FIELDS); ent++)
|
|
|
|
ent->age = (++NUMCounter);
|
2000-03-16 02:35:41 +01:00
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
2009-03-12 01:53:25 +01:00
|
|
|
* If cache is full, remove oldest entry
|
2000-03-16 02:35:41 +01:00
|
|
|
*/
|
2000-04-12 19:17:23 +02:00
|
|
|
if (n_NUMCache > NUM_CACHE_FIELDS)
|
|
|
|
{
|
|
|
|
NUMCacheEntry *old = NUMCache + 0;
|
2000-03-16 02:35:41 +01:00
|
|
|
|
|
|
|
#ifdef DEBUG_TO_FROM_CHAR
|
|
|
|
elog(DEBUG_elog_output, "Cache is full (%d)", n_NUMCache);
|
|
|
|
#endif
|
2000-04-12 19:17:23 +02:00
|
|
|
for (ent = NUMCache; ent <= (NUMCache + NUM_CACHE_FIELDS); ent++)
|
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
/*
|
2009-06-11 16:49:15 +02:00
|
|
|
* entry removed via NUM_cache_remove() can be used here, which is
|
|
|
|
* why it's worth scanning first entry again
|
2000-12-15 20:15:09 +01:00
|
|
|
*/
|
2009-03-12 01:53:25 +01:00
|
|
|
if (ent->str[0] == '\0')
|
2000-12-15 20:15:09 +01:00
|
|
|
{
|
|
|
|
old = ent;
|
|
|
|
break;
|
|
|
|
}
|
2000-03-16 02:35:41 +01:00
|
|
|
if (ent->age < old->age)
|
|
|
|
old = ent;
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
|
|
|
#ifdef DEBUG_TO_FROM_CHAR
|
2003-07-27 06:53:12 +02:00
|
|
|
elog(DEBUG_elog_output, "OLD: \"%s\" AGE: %d", old->str, old->age);
|
2000-04-12 19:17:23 +02:00
|
|
|
#endif
|
2002-09-20 05:54:57 +02:00
|
|
|
StrNCpy(old->str, str, NUM_CACHE_SIZE + 1);
|
2000-03-16 02:35:41 +01:00
|
|
|
/* old->format fill parser */
|
|
|
|
old->age = (++NUMCounter);
|
|
|
|
ent = old;
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_TO_FROM_CHAR
|
2000-03-16 02:35:41 +01:00
|
|
|
elog(DEBUG_elog_output, "NEW (%d)", n_NUMCache);
|
2000-04-12 19:17:23 +02:00
|
|
|
#endif
|
2000-03-16 02:35:41 +01:00
|
|
|
ent = NUMCache + n_NUMCache;
|
2002-09-20 05:54:57 +02:00
|
|
|
StrNCpy(ent->str, str, NUM_CACHE_SIZE + 1);
|
2000-03-16 02:35:41 +01:00
|
|
|
/* ent->format fill parser */
|
|
|
|
ent->age = (++NUMCounter);
|
|
|
|
++n_NUMCache;
|
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2014-09-13 02:42:19 +02:00
|
|
|
zeroize_NUM(&ent->Num);
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2000-12-15 20:15:09 +01:00
|
|
|
last_NUMCacheEntry = ent;
|
2009-03-12 01:53:25 +01:00
|
|
|
return ent;
|
2000-03-16 02:35:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static NUMCacheEntry *
|
2000-04-12 19:17:23 +02:00
|
|
|
NUM_cache_search(char *str)
|
2000-03-16 02:35:41 +01:00
|
|
|
{
|
2009-03-12 01:53:25 +01:00
|
|
|
int i;
|
2000-04-12 19:17:23 +02:00
|
|
|
NUMCacheEntry *ent;
|
2000-03-16 02:35:41 +01:00
|
|
|
|
2009-03-12 01:53:25 +01:00
|
|
|
/* counter overflow check - paranoia? */
|
|
|
|
if (NUMCounter >= (INT_MAX - NUM_CACHE_FIELDS - 1))
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2000-03-16 02:35:41 +01:00
|
|
|
NUMCounter = 0;
|
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
for (ent = NUMCache; ent <= (NUMCache + NUM_CACHE_FIELDS); ent++)
|
|
|
|
ent->age = (++NUMCounter);
|
2000-03-16 02:35:41 +01:00
|
|
|
}
|
|
|
|
|
2009-03-12 01:53:25 +01:00
|
|
|
for (i = 0, ent = NUMCache; i < n_NUMCache; i++, ent++)
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
|
|
|
if (strcmp(ent->str, str) == 0)
|
|
|
|
{
|
2000-03-16 02:35:41 +01:00
|
|
|
ent->age = (++NUMCounter);
|
2000-12-15 20:15:09 +01:00
|
|
|
last_NUMCacheEntry = ent;
|
2000-03-16 02:35:41 +01:00
|
|
|
return ent;
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
2000-03-16 02:35:41 +01:00
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2004-01-07 19:56:30 +01:00
|
|
|
return NULL;
|
2000-03-16 02:35:41 +01:00
|
|
|
}
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
2000-12-15 20:15:09 +01:00
|
|
|
static void
|
|
|
|
NUM_cache_remove(NUMCacheEntry *ent)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_TO_FROM_CHAR
|
|
|
|
elog(DEBUG_elog_output, "REMOVING ENTRY (%s)", ent->str);
|
|
|
|
#endif
|
2009-03-12 01:53:25 +01:00
|
|
|
ent->str[0] = '\0';
|
2000-12-15 20:15:09 +01:00
|
|
|
ent->age = 0;
|
|
|
|
}
|
|
|
|
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
/* ----------
|
|
|
|
* Cache routine for NUM to_char version
|
|
|
|
* ----------
|
|
|
|
*/
|
|
|
|
static FormatNode *
|
2014-09-13 02:42:19 +02:00
|
|
|
NUM_cache(int len, NUMDesc *Num, text *pars_str, bool *shouldFree)
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
|
|
|
FormatNode *format = NULL;
|
|
|
|
char *str;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
2008-03-25 23:42:46 +01:00
|
|
|
str = text_to_cstring(pars_str);
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
2005-10-15 04:49:52 +02:00
|
|
|
* Allocate new memory if format picture is bigger than static cache and
|
|
|
|
* not use cache (call parser always). This branches sets shouldFree to
|
|
|
|
* true, accordingly.
|
2000-12-15 20:15:09 +01:00
|
|
|
*/
|
2000-04-12 19:17:23 +02:00
|
|
|
if (len > NUM_CACHE_SIZE)
|
|
|
|
{
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
format = (FormatNode *) palloc((len + 1) * sizeof(FormatNode));
|
2002-09-20 05:54:57 +02:00
|
|
|
|
|
|
|
*shouldFree = true;
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2014-09-13 02:42:19 +02:00
|
|
|
zeroize_NUM(Num);
|
2000-04-12 19:17:23 +02:00
|
|
|
|
|
|
|
parse_format(format, str, NUM_keywords,
|
2014-09-13 02:42:19 +02:00
|
|
|
NULL, NUM_index, NUM_TYPE, Num);
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2002-09-20 05:54:57 +02:00
|
|
|
(format + len)->type = NODE_TYPE_END; /* Paranoia? */
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
2000-03-16 02:35:41 +01:00
|
|
|
* Use cache buffers
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
*/
|
2000-04-12 19:17:23 +02:00
|
|
|
NUMCacheEntry *ent;
|
|
|
|
|
2002-09-20 05:54:57 +02:00
|
|
|
*shouldFree = false;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
if ((ent = NUM_cache_search(str)) == NULL)
|
|
|
|
{
|
2000-03-16 02:35:41 +01:00
|
|
|
ent = NUM_cache_getnew(str);
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
2005-10-15 04:49:52 +02:00
|
|
|
* Not in the cache, must run parser and save a new format-picture
|
|
|
|
* to the cache.
|
2001-03-22 07:16:21 +01:00
|
|
|
*/
|
2000-04-12 19:17:23 +02:00
|
|
|
parse_format(ent->format, str, NUM_keywords,
|
2014-09-13 02:42:19 +02:00
|
|
|
NULL, NUM_index, NUM_TYPE, &ent->Num);
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2002-09-20 05:54:57 +02:00
|
|
|
(ent->format + len)->type = NODE_TYPE_END; /* Paranoia? */
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
format = ent->format;
|
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* Copy cache to used struct
|
|
|
|
*/
|
2014-09-13 02:42:19 +02:00
|
|
|
Num->flag = ent->Num.flag;
|
|
|
|
Num->lsign = ent->Num.lsign;
|
|
|
|
Num->pre = ent->Num.pre;
|
|
|
|
Num->post = ent->Num.post;
|
|
|
|
Num->pre_lsign_num = ent->Num.pre_lsign_num;
|
|
|
|
Num->need_locale = ent->Num.need_locale;
|
|
|
|
Num->multi = ent->Num.multi;
|
|
|
|
Num->zero_start = ent->Num.zero_start;
|
|
|
|
Num->zero_end = ent->Num.zero_end;
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG_TO_FROM_CHAR
|
2000-04-07 21:17:51 +02:00
|
|
|
/* dump_node(format, len); */
|
2000-04-12 19:17:23 +02:00
|
|
|
dump_index(NUM_keywords, NUM_index);
|
|
|
|
#endif
|
2000-04-07 21:17:51 +02:00
|
|
|
|
2000-03-16 02:35:41 +01:00
|
|
|
pfree(str);
|
|
|
|
return format;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static char *
|
|
|
|
int_to_roman(int number)
|
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
int len = 0,
|
2005-06-22 03:43:05 +02:00
|
|
|
num = 0;
|
2001-03-22 05:01:46 +01:00
|
|
|
char *p = NULL,
|
|
|
|
*result,
|
|
|
|
numstr[5];
|
2000-04-12 19:17:23 +02:00
|
|
|
|
|
|
|
result = (char *) palloc(16);
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
*result = '\0';
|
2000-04-12 19:17:23 +02:00
|
|
|
|
|
|
|
if (number > 3999 || number < 1)
|
|
|
|
{
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
fill_str(result, '#', 15);
|
|
|
|
return result;
|
|
|
|
}
|
2001-02-27 09:13:31 +01:00
|
|
|
len = snprintf(numstr, sizeof(numstr), "%d", number);
|
2000-04-12 19:17:23 +02:00
|
|
|
|
|
|
|
for (p = numstr; *p != '\0'; p++, --len)
|
|
|
|
{
|
|
|
|
num = *p - 49; /* 48 ascii + 1 */
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
if (num < 0)
|
|
|
|
continue;
|
2000-04-12 19:17:23 +02:00
|
|
|
|
|
|
|
if (len > 3)
|
|
|
|
{
|
|
|
|
while (num-- != -1)
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
strcat(result, "M");
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (len == 3)
|
|
|
|
strcat(result, rm100[num]);
|
|
|
|
else if (len == 2)
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
strcat(result, rm10[num]);
|
2000-04-12 19:17:23 +02:00
|
|
|
else if (len == 1)
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
strcat(result, rm1[num]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* ----------
|
|
|
|
* Locale
|
|
|
|
* ----------
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
NUM_prepare_locale(NUMProc *Np)
|
|
|
|
{
|
2014-09-13 02:42:19 +02:00
|
|
|
if (Np->Num->need_locale)
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
|
|
|
struct lconv *lconv;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* Get locales
|
|
|
|
*/
|
|
|
|
lconv = PGLC_localeconv();
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* Positive / Negative number sign
|
|
|
|
*/
|
|
|
|
if (lconv->negative_sign && *lconv->negative_sign)
|
|
|
|
Np->L_negative_sign = lconv->negative_sign;
|
|
|
|
else
|
|
|
|
Np->L_negative_sign = "-";
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2006-02-13 00:48:23 +01:00
|
|
|
if (lconv->positive_sign && *lconv->positive_sign)
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
Np->L_positive_sign = lconv->positive_sign;
|
2000-04-12 19:17:23 +02:00
|
|
|
else
|
|
|
|
Np->L_positive_sign = "+";
|
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* Number decimal point
|
|
|
|
*/
|
|
|
|
if (lconv->decimal_point && *lconv->decimal_point)
|
|
|
|
Np->decimal = lconv->decimal_point;
|
2009-06-11 16:49:15 +02:00
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
else
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
Np->decimal = ".";
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2014-09-13 02:42:19 +02:00
|
|
|
if (!IS_LDECIMAL(Np->Num))
|
2007-02-13 03:00:55 +01:00
|
|
|
Np->decimal = ".";
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Number thousands separator
|
2007-11-15 22:14:46 +01:00
|
|
|
*
|
|
|
|
* Some locales (e.g. broken glibc pt_BR), have a comma for decimal,
|
2007-11-22 16:10:05 +01:00
|
|
|
* but "" for thousands_sep, so we set the thousands_sep too.
|
2007-11-22 18:51:39 +01:00
|
|
|
* http://archives.postgresql.org/pgsql-hackers/2007-11/msg00772.php
|
2007-02-13 03:00:55 +01:00
|
|
|
*/
|
|
|
|
if (lconv->thousands_sep && *lconv->thousands_sep)
|
|
|
|
Np->L_thousands_sep = lconv->thousands_sep;
|
2007-11-22 16:10:05 +01:00
|
|
|
/* Make sure thousands separator doesn't match decimal point symbol. */
|
2009-06-11 16:49:15 +02:00
|
|
|
else if (strcmp(Np->decimal, ",") !=0)
|
2007-02-13 03:00:55 +01:00
|
|
|
Np->L_thousands_sep = ",";
|
2007-11-21 23:28:18 +01:00
|
|
|
else
|
|
|
|
Np->L_thousands_sep = ".";
|
2007-02-13 03:00:55 +01:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* Currency symbol
|
|
|
|
*/
|
2000-04-12 19:17:23 +02:00
|
|
|
if (lconv->currency_symbol && *lconv->currency_symbol)
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
Np->L_currency_symbol = lconv->currency_symbol;
|
2000-04-12 19:17:23 +02:00
|
|
|
else
|
|
|
|
Np->L_currency_symbol = " ";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* Default values
|
|
|
|
*/
|
2000-04-12 19:17:23 +02:00
|
|
|
Np->L_negative_sign = "-";
|
|
|
|
Np->L_positive_sign = "+";
|
|
|
|
Np->decimal = ".";
|
2007-11-15 22:14:46 +01:00
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
Np->L_thousands_sep = ",";
|
|
|
|
Np->L_currency_symbol = " ";
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------
|
2000-02-08 16:57:01 +01:00
|
|
|
* Return pointer of last relevant number after decimal point
|
2000-04-12 19:17:23 +02:00
|
|
|
* 12.0500 --> last relevant is '5'
|
2011-09-07 23:06:10 +02:00
|
|
|
* 12.0000 --> last relevant is '.'
|
|
|
|
* If there is no decimal point, return NULL (which will result in same
|
|
|
|
* behavior as if FM hadn't been specified).
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* ----------
|
2000-04-12 19:17:23 +02:00
|
|
|
*/
|
2000-02-08 16:57:01 +01:00
|
|
|
static char *
|
|
|
|
get_last_relevant_decnum(char *num)
|
|
|
|
{
|
2000-04-12 19:17:23 +02:00
|
|
|
char *result,
|
2001-03-22 05:01:46 +01:00
|
|
|
*p = strchr(num, '.');
|
2000-04-12 19:17:23 +02:00
|
|
|
|
|
|
|
#ifdef DEBUG_TO_FROM_CHAR
|
2003-07-27 06:53:12 +02:00
|
|
|
elog(DEBUG_elog_output, "get_last_relevant_decnum()");
|
2000-03-16 02:35:41 +01:00
|
|
|
#endif
|
2000-04-12 19:17:23 +02:00
|
|
|
|
|
|
|
if (!p)
|
2011-09-07 23:06:10 +02:00
|
|
|
return NULL;
|
|
|
|
|
2000-02-08 16:57:01 +01:00
|
|
|
result = p;
|
2000-04-12 19:17:23 +02:00
|
|
|
|
|
|
|
while (*(++p))
|
|
|
|
{
|
|
|
|
if (*p != '0')
|
2000-02-08 16:57:01 +01:00
|
|
|
result = p;
|
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2000-02-08 16:57:01 +01:00
|
|
|
return result;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------
|
2000-02-08 16:57:01 +01:00
|
|
|
* Number extraction for TO_NUMBER()
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* ----------
|
|
|
|
*/
|
2000-02-08 16:57:01 +01:00
|
|
|
static void
|
2014-09-05 15:52:31 +02:00
|
|
|
NUM_numpart_from_char(NUMProc *Np, int id, int input_len)
|
2000-02-08 16:57:01 +01:00
|
|
|
{
|
2005-10-15 04:49:52 +02:00
|
|
|
bool isread = FALSE;
|
|
|
|
|
2000-02-08 16:57:01 +01:00
|
|
|
#ifdef DEBUG_TO_FROM_CHAR
|
2004-10-28 20:55:08 +02:00
|
|
|
elog(DEBUG_elog_output, " --- scan start --- id=%s",
|
2005-10-15 04:49:52 +02:00
|
|
|
(id == NUM_0 || id == NUM_9) ? "NUM_0/9" : id == NUM_DEC ? "NUM_DEC" : "???");
|
2000-02-08 16:57:01 +01:00
|
|
|
#endif
|
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
if (*Np->inout_p == ' ')
|
|
|
|
Np->inout_p++;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
2014-09-05 15:52:31 +02:00
|
|
|
#define OVERLOAD_TEST (Np->inout_p >= Np->inout + input_len)
|
|
|
|
#define AMOUNT_TEST(_s) (input_len-(Np->inout_p-Np->inout) >= _s)
|
2000-03-16 02:35:41 +01:00
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
if (*Np->inout_p == ' ')
|
|
|
|
Np->inout_p++;
|
|
|
|
|
2000-03-08 02:34:41 +01:00
|
|
|
if (OVERLOAD_TEST)
|
|
|
|
return;
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
2004-10-28 20:55:08 +02:00
|
|
|
* read sign before number
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
*/
|
2014-09-13 02:42:19 +02:00
|
|
|
if (*Np->number == ' ' && (id == NUM_0 || id == NUM_9) &&
|
2005-10-15 04:49:52 +02:00
|
|
|
(Np->read_pre + Np->read_post) == 0)
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2000-02-08 16:57:01 +01:00
|
|
|
#ifdef DEBUG_TO_FROM_CHAR
|
2005-10-15 04:49:52 +02:00
|
|
|
elog(DEBUG_elog_output, "Try read sign (%c), locale positive: %s, negative: %s",
|
|
|
|
*Np->inout_p, Np->L_positive_sign, Np->L_negative_sign);
|
2000-04-12 19:17:23 +02:00
|
|
|
#endif
|
2001-03-22 07:16:21 +01:00
|
|
|
|
|
|
|
/*
|
2000-02-08 16:57:01 +01:00
|
|
|
* locale sign
|
|
|
|
*/
|
2014-09-13 02:42:19 +02:00
|
|
|
if (IS_LSIGN(Np->Num) && Np->Num->lsign == NUM_LSIGN_PRE)
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2005-10-15 04:49:52 +02:00
|
|
|
int x = 0;
|
|
|
|
|
2000-02-08 16:57:01 +01:00
|
|
|
#ifdef DEBUG_TO_FROM_CHAR
|
2004-10-28 20:55:08 +02:00
|
|
|
elog(DEBUG_elog_output, "Try read locale pre-sign (%c)", *Np->inout_p);
|
2000-04-12 19:17:23 +02:00
|
|
|
#endif
|
2005-10-15 04:49:52 +02:00
|
|
|
if ((x = strlen(Np->L_negative_sign)) &&
|
2004-10-28 20:55:08 +02:00
|
|
|
AMOUNT_TEST(x) &&
|
2005-10-15 04:49:52 +02:00
|
|
|
strncmp(Np->inout_p, Np->L_negative_sign, x) == 0)
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2004-10-28 20:55:08 +02:00
|
|
|
Np->inout_p += x;
|
2014-09-13 02:42:19 +02:00
|
|
|
*Np->number = '-';
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
}
|
2005-10-15 04:49:52 +02:00
|
|
|
else if ((x = strlen(Np->L_positive_sign)) &&
|
|
|
|
AMOUNT_TEST(x) &&
|
|
|
|
strncmp(Np->inout_p, Np->L_positive_sign, x) == 0)
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2004-10-28 20:55:08 +02:00
|
|
|
Np->inout_p += x;
|
2014-09-13 02:42:19 +02:00
|
|
|
*Np->number = '+';
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
}
|
2000-02-08 16:57:01 +01:00
|
|
|
}
|
2004-10-28 20:55:08 +02:00
|
|
|
else
|
|
|
|
{
|
2000-02-08 16:57:01 +01:00
|
|
|
#ifdef DEBUG_TO_FROM_CHAR
|
2004-10-28 20:55:08 +02:00
|
|
|
elog(DEBUG_elog_output, "Try read simple sign (%c)", *Np->inout_p);
|
2000-04-12 19:17:23 +02:00
|
|
|
#endif
|
2005-10-15 04:49:52 +02:00
|
|
|
|
2004-10-28 20:55:08 +02:00
|
|
|
/*
|
|
|
|
* simple + - < >
|
|
|
|
*/
|
2014-09-13 02:42:19 +02:00
|
|
|
if (*Np->inout_p == '-' || (IS_BRACKET(Np->Num) &&
|
2004-10-28 20:55:08 +02:00
|
|
|
*Np->inout_p == '<'))
|
|
|
|
{
|
2014-09-13 02:42:19 +02:00
|
|
|
*Np->number = '-'; /* set - */
|
2004-10-28 20:55:08 +02:00
|
|
|
Np->inout_p++;
|
|
|
|
}
|
|
|
|
else if (*Np->inout_p == '+')
|
|
|
|
{
|
2014-09-13 02:42:19 +02:00
|
|
|
*Np->number = '+'; /* set + */
|
2004-10-28 20:55:08 +02:00
|
|
|
Np->inout_p++;
|
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
2000-02-08 16:57:01 +01:00
|
|
|
}
|
2000-03-16 02:35:41 +01:00
|
|
|
|
2000-03-08 02:34:41 +01:00
|
|
|
if (OVERLOAD_TEST)
|
|
|
|
return;
|
2005-10-15 04:49:52 +02:00
|
|
|
|
2004-10-28 20:55:08 +02:00
|
|
|
#ifdef DEBUG_TO_FROM_CHAR
|
2014-09-13 02:42:19 +02:00
|
|
|
elog(DEBUG_elog_output, "Scan for numbers (%c), current number: '%s'", *Np->inout_p, Np->number);
|
2004-10-28 20:55:08 +02:00
|
|
|
#endif
|
2005-10-15 04:49:52 +02:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
2013-05-11 22:35:03 +02:00
|
|
|
* read digit or decimal point
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
*/
|
2000-04-12 19:17:23 +02:00
|
|
|
if (isdigit((unsigned char) *Np->inout_p))
|
|
|
|
{
|
2014-09-13 02:42:19 +02:00
|
|
|
if (Np->read_dec && Np->read_post == Np->Num->post)
|
2000-02-08 16:57:01 +01:00
|
|
|
return;
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2014-09-13 02:42:19 +02:00
|
|
|
*Np->number_p = *Np->inout_p;
|
|
|
|
Np->number_p++;
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2000-02-08 16:57:01 +01:00
|
|
|
if (Np->read_dec)
|
|
|
|
Np->read_post++;
|
2004-10-28 20:55:08 +02:00
|
|
|
else
|
|
|
|
Np->read_pre++;
|
2000-02-08 16:57:01 +01:00
|
|
|
|
2004-10-28 20:55:08 +02:00
|
|
|
isread = TRUE;
|
2005-10-15 04:49:52 +02:00
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
#ifdef DEBUG_TO_FROM_CHAR
|
2003-07-27 06:53:12 +02:00
|
|
|
elog(DEBUG_elog_output, "Read digit (%c)", *Np->inout_p);
|
2000-04-12 19:17:23 +02:00
|
|
|
#endif
|
|
|
|
}
|
2014-09-13 02:42:19 +02:00
|
|
|
else if (IS_DECIMAL(Np->Num) && Np->read_dec == FALSE)
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2013-05-11 22:35:03 +02:00
|
|
|
/*
|
2014-09-13 02:42:19 +02:00
|
|
|
* We need not test IS_LDECIMAL(Np->Num) explicitly here, because
|
2013-05-11 22:35:03 +02:00
|
|
|
* Np->decimal is always just "." if we don't have a D format token.
|
|
|
|
* So we just unconditionally match to Np->decimal.
|
|
|
|
*/
|
|
|
|
int x = strlen(Np->decimal);
|
|
|
|
|
2000-02-08 16:57:01 +01:00
|
|
|
#ifdef DEBUG_TO_FROM_CHAR
|
2013-05-11 22:35:03 +02:00
|
|
|
elog(DEBUG_elog_output, "Try read decimal point (%c)",
|
|
|
|
*Np->inout_p);
|
2000-04-12 19:17:23 +02:00
|
|
|
#endif
|
2013-05-11 22:35:03 +02:00
|
|
|
if (x && AMOUNT_TEST(x) && strncmp(Np->inout_p, Np->decimal, x) == 0)
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2013-05-11 22:35:03 +02:00
|
|
|
Np->inout_p += x - 1;
|
2014-09-13 02:42:19 +02:00
|
|
|
*Np->number_p = '.';
|
|
|
|
Np->number_p++;
|
2000-02-08 16:57:01 +01:00
|
|
|
Np->read_dec = TRUE;
|
2004-10-28 20:55:08 +02:00
|
|
|
isread = TRUE;
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
|
|
|
}
|
2004-10-28 20:55:08 +02:00
|
|
|
|
|
|
|
if (OVERLOAD_TEST)
|
|
|
|
return;
|
2005-10-15 04:49:52 +02:00
|
|
|
|
2004-10-28 20:55:08 +02:00
|
|
|
/*
|
|
|
|
* Read sign behind "last" number
|
|
|
|
*
|
2005-10-15 04:49:52 +02:00
|
|
|
* We need sign detection because determine exact position of post-sign is
|
|
|
|
* difficult:
|
2004-10-28 20:55:08 +02:00
|
|
|
*
|
2005-11-22 19:17:34 +01:00
|
|
|
* FM9999.9999999S -> 123.001- 9.9S -> .5- FM9.999999MI ->
|
|
|
|
* 5.01-
|
2004-10-28 20:55:08 +02:00
|
|
|
*/
|
2014-09-13 02:42:19 +02:00
|
|
|
if (*Np->number == ' ' && Np->read_pre + Np->read_post > 0)
|
2004-10-28 20:55:08 +02:00
|
|
|
{
|
|
|
|
/*
|
2005-10-15 04:49:52 +02:00
|
|
|
* locale sign (NUM_S) is always anchored behind a last number, if: -
|
|
|
|
* locale sign expected - last read char was NUM_0/9 or NUM_DEC - and
|
|
|
|
* next char is not digit
|
|
|
|
*/
|
2014-09-13 02:42:19 +02:00
|
|
|
if (IS_LSIGN(Np->Num) && isread &&
|
2014-09-05 15:52:31 +02:00
|
|
|
(Np->inout_p + 1) <= Np->inout + input_len &&
|
2005-10-15 04:49:52 +02:00
|
|
|
!isdigit((unsigned char) *(Np->inout_p + 1)))
|
2004-10-28 20:55:08 +02:00
|
|
|
{
|
2005-10-15 04:49:52 +02:00
|
|
|
int x;
|
|
|
|
char *tmp = Np->inout_p++;
|
|
|
|
|
2004-10-28 20:55:08 +02:00
|
|
|
#ifdef DEBUG_TO_FROM_CHAR
|
|
|
|
elog(DEBUG_elog_output, "Try read locale post-sign (%c)", *Np->inout_p);
|
|
|
|
#endif
|
2005-10-15 04:49:52 +02:00
|
|
|
if ((x = strlen(Np->L_negative_sign)) &&
|
2004-10-28 20:55:08 +02:00
|
|
|
AMOUNT_TEST(x) &&
|
2005-10-15 04:49:52 +02:00
|
|
|
strncmp(Np->inout_p, Np->L_negative_sign, x) == 0)
|
2004-10-28 20:55:08 +02:00
|
|
|
{
|
2005-10-15 04:49:52 +02:00
|
|
|
Np->inout_p += x - 1; /* -1 .. NUM_processor() do inout_p++ */
|
2014-09-13 02:42:19 +02:00
|
|
|
*Np->number = '-';
|
2004-10-28 20:55:08 +02:00
|
|
|
}
|
2005-10-15 04:49:52 +02:00
|
|
|
else if ((x = strlen(Np->L_positive_sign)) &&
|
|
|
|
AMOUNT_TEST(x) &&
|
|
|
|
strncmp(Np->inout_p, Np->L_positive_sign, x) == 0)
|
2004-10-28 20:55:08 +02:00
|
|
|
{
|
2005-10-15 04:49:52 +02:00
|
|
|
Np->inout_p += x - 1; /* -1 .. NUM_processor() do inout_p++ */
|
2014-09-13 02:42:19 +02:00
|
|
|
*Np->number = '+';
|
2004-10-28 20:55:08 +02:00
|
|
|
}
|
2014-09-13 02:42:19 +02:00
|
|
|
if (*Np->number == ' ')
|
2004-10-28 20:55:08 +02:00
|
|
|
/* no sign read */
|
|
|
|
Np->inout_p = tmp;
|
|
|
|
}
|
2005-10-15 04:49:52 +02:00
|
|
|
|
2004-10-28 20:55:08 +02:00
|
|
|
/*
|
|
|
|
* try read non-locale sign, it's happen only if format is not exact
|
|
|
|
* and we cannot determine sign position of MI/PL/SG, an example:
|
|
|
|
*
|
2005-10-15 04:49:52 +02:00
|
|
|
* FM9.999999MI -> 5.01-
|
2004-10-28 20:55:08 +02:00
|
|
|
*
|
2014-09-13 02:42:19 +02:00
|
|
|
* if (.... && IS_LSIGN(Np->Num)==FALSE) prevents read wrong formats
|
2005-11-22 19:17:34 +01:00
|
|
|
* like to_number('1 -', '9S') where sign is not anchored to last
|
|
|
|
* number.
|
2004-10-28 20:55:08 +02:00
|
|
|
*/
|
2014-09-13 02:42:19 +02:00
|
|
|
else if (isread == FALSE && IS_LSIGN(Np->Num) == FALSE &&
|
|
|
|
(IS_PLUS(Np->Num) || IS_MINUS(Np->Num)))
|
2004-10-28 20:55:08 +02:00
|
|
|
{
|
|
|
|
#ifdef DEBUG_TO_FROM_CHAR
|
|
|
|
elog(DEBUG_elog_output, "Try read simple post-sign (%c)", *Np->inout_p);
|
|
|
|
#endif
|
2005-10-15 04:49:52 +02:00
|
|
|
|
2004-10-28 20:55:08 +02:00
|
|
|
/*
|
|
|
|
* simple + -
|
|
|
|
*/
|
|
|
|
if (*Np->inout_p == '-' || *Np->inout_p == '+')
|
|
|
|
/* NUM_processor() do inout_p++ */
|
2014-09-13 02:42:19 +02:00
|
|
|
*Np->number = *Np->inout_p;
|
2004-10-28 20:55:08 +02:00
|
|
|
}
|
|
|
|
}
|
2000-02-08 16:57:01 +01:00
|
|
|
}
|
|
|
|
|
2003-03-27 17:35:31 +01:00
|
|
|
#define IS_PREDEC_SPACE(_n) \
|
2014-09-13 02:42:19 +02:00
|
|
|
(IS_ZERO((_n)->Num)==FALSE && \
|
|
|
|
(_n)->number == (_n)->number_p && \
|
|
|
|
*(_n)->number == '0' && \
|
|
|
|
(_n)->Num->post != 0)
|
2003-03-27 17:35:31 +01:00
|
|
|
|
2000-02-08 16:57:01 +01:00
|
|
|
/* ----------
|
|
|
|
* Add digit or sign to number-string
|
|
|
|
* ----------
|
|
|
|
*/
|
|
|
|
static void
|
2000-04-12 19:17:23 +02:00
|
|
|
NUM_numpart_to_char(NUMProc *Np, int id)
|
|
|
|
{
|
2003-08-04 02:43:34 +02:00
|
|
|
int end;
|
|
|
|
|
2014-09-13 02:42:19 +02:00
|
|
|
if (IS_ROMAN(Np->Num))
|
2000-02-08 16:57:01 +01:00
|
|
|
return;
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2000-02-08 16:57:01 +01:00
|
|
|
/* Note: in this elog() output not set '\0' in 'inout' */
|
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
#ifdef DEBUG_TO_FROM_CHAR
|
|
|
|
|
2000-02-08 16:57:01 +01:00
|
|
|
/*
|
2000-04-12 19:17:23 +02:00
|
|
|
* Np->num_curr is number of current item in format-picture, it is not
|
|
|
|
* current position in inout!
|
|
|
|
*/
|
|
|
|
elog(DEBUG_elog_output,
|
2003-07-27 06:53:12 +02:00
|
|
|
"SIGN_WROTE: %d, CURRENT: %d, NUMBER_P: \"%s\", INOUT: \"%s\"",
|
2000-04-12 19:17:23 +02:00
|
|
|
Np->sign_wrote,
|
|
|
|
Np->num_curr,
|
2014-09-13 02:42:19 +02:00
|
|
|
Np->number_p,
|
2000-04-12 19:17:23 +02:00
|
|
|
Np->inout);
|
|
|
|
#endif
|
2000-02-08 16:57:01 +01:00
|
|
|
Np->num_in = FALSE;
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
2005-10-15 04:49:52 +02:00
|
|
|
* Write sign if real number will write to output Note: IS_PREDEC_SPACE()
|
|
|
|
* handle "9.9" --> " .1"
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
*/
|
2003-08-04 02:43:34 +02:00
|
|
|
if (Np->sign_wrote == FALSE &&
|
2014-09-13 02:42:19 +02:00
|
|
|
(Np->num_curr >= Np->out_pre_spaces || (IS_ZERO(Np->Num) && Np->Num->zero_start == Np->num_curr)) &&
|
2003-08-04 02:43:34 +02:00
|
|
|
(IS_PREDEC_SPACE(Np) == FALSE || (Np->last_relevant && *Np->last_relevant == '.')))
|
|
|
|
{
|
2014-09-13 02:42:19 +02:00
|
|
|
if (IS_LSIGN(Np->Num))
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2014-09-13 02:42:19 +02:00
|
|
|
if (Np->Num->lsign == NUM_LSIGN_PRE)
|
2003-03-27 17:35:31 +01:00
|
|
|
{
|
|
|
|
if (Np->sign == '-')
|
|
|
|
strcpy(Np->inout_p, Np->L_negative_sign);
|
|
|
|
else
|
|
|
|
strcpy(Np->inout_p, Np->L_positive_sign);
|
|
|
|
Np->inout_p += strlen(Np->inout_p);
|
|
|
|
Np->sign_wrote = TRUE;
|
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
2014-09-13 02:42:19 +02:00
|
|
|
else if (IS_BRACKET(Np->Num))
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2003-03-27 17:35:31 +01:00
|
|
|
*Np->inout_p = Np->sign == '+' ? ' ' : '<';
|
2000-02-08 16:57:01 +01:00
|
|
|
++Np->inout_p;
|
2003-03-27 17:35:31 +01:00
|
|
|
Np->sign_wrote = TRUE;
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
|
|
|
else if (Np->sign == '+')
|
|
|
|
{
|
2014-09-13 02:42:19 +02:00
|
|
|
if (!IS_FILLMODE(Np->Num))
|
2003-03-27 17:35:31 +01:00
|
|
|
{
|
2003-08-04 02:43:34 +02:00
|
|
|
*Np->inout_p = ' '; /* Write + */
|
2003-03-27 17:35:31 +01:00
|
|
|
++Np->inout_p;
|
|
|
|
}
|
|
|
|
Np->sign_wrote = TRUE;
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
|
|
|
else if (Np->sign == '-')
|
|
|
|
{ /* Write - */
|
2000-02-08 16:57:01 +01:00
|
|
|
*Np->inout_p = '-';
|
2000-04-12 19:17:23 +02:00
|
|
|
++Np->inout_p;
|
2003-03-27 17:35:31 +01:00
|
|
|
Np->sign_wrote = TRUE;
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
|
|
|
}
|
2003-08-04 02:43:34 +02:00
|
|
|
|
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
2000-02-08 16:57:01 +01:00
|
|
|
* digits / FM / Zero / Dec. point
|
|
|
|
*/
|
2003-03-27 17:35:31 +01:00
|
|
|
if (id == NUM_9 || id == NUM_0 || id == NUM_D || id == NUM_DEC)
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2014-09-05 15:52:31 +02:00
|
|
|
if (Np->num_curr < Np->out_pre_spaces &&
|
2014-09-13 02:42:19 +02:00
|
|
|
(Np->Num->zero_start > Np->num_curr || !IS_ZERO(Np->Num)))
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
2000-04-12 19:17:23 +02:00
|
|
|
* Write blank space
|
|
|
|
*/
|
2014-09-13 02:42:19 +02:00
|
|
|
if (!IS_FILLMODE(Np->Num))
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
|
|
|
*Np->inout_p = ' '; /* Write ' ' */
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
++Np->inout_p;
|
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
2014-09-13 02:42:19 +02:00
|
|
|
else if (IS_ZERO(Np->Num) &&
|
2014-09-05 15:52:31 +02:00
|
|
|
Np->num_curr < Np->out_pre_spaces &&
|
2014-09-13 02:42:19 +02:00
|
|
|
Np->Num->zero_start <= Np->num_curr)
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
2000-02-08 16:57:01 +01:00
|
|
|
* Write ZERO
|
|
|
|
*/
|
2000-04-12 19:17:23 +02:00
|
|
|
*Np->inout_p = '0'; /* Write '0' */
|
2000-02-08 16:57:01 +01:00
|
|
|
++Np->inout_p;
|
|
|
|
Np->num_in = TRUE;
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
2003-03-10 23:28:22 +01:00
|
|
|
* Write Decimal point
|
2001-03-22 07:16:21 +01:00
|
|
|
*/
|
2014-09-13 02:42:19 +02:00
|
|
|
if (*Np->number_p == '.')
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
|
|
|
if (!Np->last_relevant || *Np->last_relevant != '.')
|
|
|
|
{
|
2000-02-08 16:57:01 +01:00
|
|
|
strcpy(Np->inout_p, Np->decimal); /* Write DEC/D */
|
|
|
|
Np->inout_p += strlen(Np->inout_p);
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
2003-08-04 02:43:34 +02:00
|
|
|
|
2002-09-20 05:57:09 +02:00
|
|
|
/*
|
|
|
|
* Ora 'n' -- FM9.9 --> 'n.'
|
|
|
|
*/
|
2014-09-13 02:42:19 +02:00
|
|
|
else if (IS_FILLMODE(Np->Num) &&
|
2000-04-12 19:17:23 +02:00
|
|
|
Np->last_relevant && *Np->last_relevant == '.')
|
|
|
|
{
|
2000-02-08 16:57:01 +01:00
|
|
|
strcpy(Np->inout_p, Np->decimal); /* Write DEC/D */
|
|
|
|
Np->inout_p += strlen(Np->inout_p);
|
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
2000-02-08 16:57:01 +01:00
|
|
|
* Write Digits
|
|
|
|
*/
|
2014-09-13 02:42:19 +02:00
|
|
|
if (Np->last_relevant && Np->number_p > Np->last_relevant &&
|
2000-04-12 19:17:23 +02:00
|
|
|
id != NUM_0)
|
2000-02-08 16:57:01 +01:00
|
|
|
;
|
2003-08-04 02:43:34 +02:00
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
/*
|
2003-03-27 17:35:31 +01:00
|
|
|
* '0.1' -- 9.9 --> ' .1'
|
2000-02-08 16:57:01 +01:00
|
|
|
*/
|
2003-03-27 17:35:31 +01:00
|
|
|
else if (IS_PREDEC_SPACE(Np))
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2014-09-13 02:42:19 +02:00
|
|
|
if (!IS_FILLMODE(Np->Num))
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2000-02-08 16:57:01 +01:00
|
|
|
*Np->inout_p = ' ';
|
|
|
|
++Np->inout_p;
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
2003-08-04 02:43:34 +02:00
|
|
|
|
2002-09-20 05:57:09 +02:00
|
|
|
/*
|
2003-03-27 17:35:31 +01:00
|
|
|
* '0' -- FM9.9 --> '0.'
|
2002-09-20 05:57:09 +02:00
|
|
|
*/
|
2000-04-12 19:17:23 +02:00
|
|
|
else if (Np->last_relevant && *Np->last_relevant == '.')
|
|
|
|
{
|
2000-02-08 16:57:01 +01:00
|
|
|
*Np->inout_p = '0';
|
|
|
|
++Np->inout_p;
|
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-09-13 02:42:19 +02:00
|
|
|
*Np->inout_p = *Np->number_p; /* Write DIGIT */
|
2000-02-08 16:57:01 +01:00
|
|
|
++Np->inout_p;
|
|
|
|
Np->num_in = TRUE;
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
}
|
2015-02-02 16:00:44 +01:00
|
|
|
/* do no exceed string length */
|
|
|
|
if (*Np->number_p)
|
|
|
|
++Np->number_p;
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
2003-03-27 17:35:31 +01:00
|
|
|
|
2014-09-13 02:42:19 +02:00
|
|
|
end = Np->num_count + (Np->out_pre_spaces ? 1 : 0) + (IS_DECIMAL(Np->Num) ? 1 : 0);
|
2003-08-04 02:43:34 +02:00
|
|
|
|
2014-09-13 02:42:19 +02:00
|
|
|
if (Np->last_relevant && Np->last_relevant == Np->number_p)
|
2003-03-27 17:35:31 +01:00
|
|
|
end = Np->num_curr;
|
2003-08-04 02:43:34 +02:00
|
|
|
|
|
|
|
if (Np->num_curr + 1 == end)
|
2003-03-27 17:35:31 +01:00
|
|
|
{
|
2014-09-13 02:42:19 +02:00
|
|
|
if (Np->sign_wrote == TRUE && IS_BRACKET(Np->Num))
|
2003-03-27 17:35:31 +01:00
|
|
|
{
|
|
|
|
*Np->inout_p = Np->sign == '+' ? ' ' : '>';
|
|
|
|
++Np->inout_p;
|
|
|
|
}
|
2014-09-13 02:42:19 +02:00
|
|
|
else if (IS_LSIGN(Np->Num) && Np->Num->lsign == NUM_LSIGN_POST)
|
2003-03-27 17:35:31 +01:00
|
|
|
{
|
|
|
|
if (Np->sign == '-')
|
|
|
|
strcpy(Np->inout_p, Np->L_negative_sign);
|
|
|
|
else
|
|
|
|
strcpy(Np->inout_p, Np->L_positive_sign);
|
|
|
|
Np->inout_p += strlen(Np->inout_p);
|
|
|
|
}
|
|
|
|
}
|
2000-02-08 16:57:01 +01:00
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2000-02-08 16:57:01 +01:00
|
|
|
++Np->num_curr;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
static char *
|
2014-09-13 02:42:19 +02:00
|
|
|
NUM_processor(FormatNode *node, NUMDesc *Num, char *inout,
|
2015-05-24 03:35:49 +02:00
|
|
|
char *number, int from_char_input_len, int to_char_out_pre_spaces,
|
2014-09-05 15:52:31 +02:00
|
|
|
int sign, bool is_to_char, Oid collid)
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
{
|
2000-04-12 19:17:23 +02:00
|
|
|
FormatNode *n;
|
2001-03-22 05:01:46 +01:00
|
|
|
NUMProc _Np,
|
|
|
|
*Np = &_Np;
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2003-04-02 04:33:52 +02:00
|
|
|
MemSet(Np, 0, sizeof(NUMProc));
|
|
|
|
|
2014-09-13 02:42:19 +02:00
|
|
|
Np->Num = Num;
|
2005-08-17 23:47:55 +02:00
|
|
|
Np->is_to_char = is_to_char;
|
2014-09-13 02:42:19 +02:00
|
|
|
Np->number = number;
|
2000-04-12 19:17:23 +02:00
|
|
|
Np->inout = inout;
|
2000-02-08 16:57:01 +01:00
|
|
|
Np->last_relevant = NULL;
|
2000-04-12 19:17:23 +02:00
|
|
|
Np->read_post = 0;
|
2005-10-15 04:49:52 +02:00
|
|
|
Np->read_pre = 0;
|
2000-04-12 19:17:23 +02:00
|
|
|
Np->read_dec = FALSE;
|
2000-02-08 16:57:01 +01:00
|
|
|
|
2014-09-13 02:42:19 +02:00
|
|
|
if (Np->Num->zero_start)
|
|
|
|
--Np->Num->zero_start;
|
2003-08-04 02:43:34 +02:00
|
|
|
|
2014-09-13 02:42:19 +02:00
|
|
|
if (IS_EEEE(Np->Num))
|
2009-08-10 20:29:27 +02:00
|
|
|
{
|
|
|
|
if (!Np->is_to_char)
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
|
|
|
errmsg("\"EEEE\" not supported for input")));
|
2014-09-13 02:42:19 +02:00
|
|
|
return strcpy(inout, number);
|
2009-08-10 20:29:27 +02:00
|
|
|
}
|
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
2000-04-12 19:17:23 +02:00
|
|
|
* Roman correction
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
*/
|
2014-09-13 02:42:19 +02:00
|
|
|
if (IS_ROMAN(Np->Num))
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2005-08-17 23:47:55 +02:00
|
|
|
if (!Np->is_to_char)
|
2003-07-27 06:53:12 +02:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
2009-08-10 20:29:27 +02:00
|
|
|
errmsg("\"RN\" not supported for input")));
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2014-09-13 02:42:19 +02:00
|
|
|
Np->Num->lsign = Np->Num->pre_lsign_num = Np->Num->post =
|
|
|
|
Np->Num->pre = Np->out_pre_spaces = Np->sign = 0;
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2014-09-13 02:42:19 +02:00
|
|
|
if (IS_FILLMODE(Np->Num))
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2014-09-13 02:42:19 +02:00
|
|
|
Np->Num->flag = 0;
|
|
|
|
Np->Num->flag |= NUM_F_FILLMODE;
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
|
|
|
else
|
2014-09-13 02:42:19 +02:00
|
|
|
Np->Num->flag = 0;
|
|
|
|
Np->Num->flag |= NUM_F_ROMAN;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
2000-02-08 16:57:01 +01:00
|
|
|
* Sign
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
*/
|
2005-08-17 23:47:55 +02:00
|
|
|
if (is_to_char)
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
|
|
|
Np->sign = sign;
|
2003-08-04 02:43:34 +02:00
|
|
|
|
2003-03-27 17:35:31 +01:00
|
|
|
/* MI/PL/SG - write sign itself and not in number */
|
2014-09-13 02:42:19 +02:00
|
|
|
if (IS_PLUS(Np->Num) || IS_MINUS(Np->Num))
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2014-09-13 02:42:19 +02:00
|
|
|
if (IS_PLUS(Np->Num) && IS_MINUS(Np->Num) == FALSE)
|
2003-08-04 02:43:34 +02:00
|
|
|
Np->sign_wrote = FALSE; /* need sign */
|
2003-04-02 04:33:52 +02:00
|
|
|
else
|
2003-08-04 02:43:34 +02:00
|
|
|
Np->sign_wrote = TRUE; /* needn't sign */
|
2000-02-08 16:57:01 +01:00
|
|
|
}
|
|
|
|
else
|
2003-03-27 17:35:31 +01:00
|
|
|
{
|
|
|
|
if (Np->sign != '-')
|
|
|
|
{
|
2014-09-13 02:42:19 +02:00
|
|
|
if (IS_BRACKET(Np->Num) && IS_FILLMODE(Np->Num))
|
|
|
|
Np->Num->flag &= ~NUM_F_BRACKET;
|
|
|
|
if (IS_MINUS(Np->Num))
|
|
|
|
Np->Num->flag &= ~NUM_F_MINUS;
|
2003-03-27 17:35:31 +01:00
|
|
|
}
|
2014-09-13 02:42:19 +02:00
|
|
|
else if (Np->sign != '+' && IS_PLUS(Np->Num))
|
|
|
|
Np->Num->flag &= ~NUM_F_PLUS;
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2014-09-13 02:42:19 +02:00
|
|
|
if (Np->sign == '+' && IS_FILLMODE(Np->Num) && IS_LSIGN(Np->Num) == FALSE)
|
2003-08-04 02:43:34 +02:00
|
|
|
Np->sign_wrote = TRUE; /* needn't sign */
|
2003-03-27 17:35:31 +01:00
|
|
|
else
|
2003-08-04 02:43:34 +02:00
|
|
|
Np->sign_wrote = FALSE; /* need sign */
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2014-09-13 02:42:19 +02:00
|
|
|
if (Np->Num->lsign == NUM_LSIGN_PRE && Np->Num->pre == Np->Num->pre_lsign_num)
|
|
|
|
Np->Num->lsign = NUM_LSIGN_POST;
|
2003-03-27 17:35:31 +01:00
|
|
|
}
|
2000-02-08 16:57:01 +01:00
|
|
|
}
|
2005-08-17 23:47:55 +02:00
|
|
|
else
|
|
|
|
Np->sign = FALSE;
|
2000-02-08 16:57:01 +01:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
2000-02-08 16:57:01 +01:00
|
|
|
* Count
|
|
|
|
*/
|
2014-09-13 02:42:19 +02:00
|
|
|
Np->num_count = Np->Num->post + Np->Num->pre - 1;
|
2000-02-08 16:57:01 +01:00
|
|
|
|
2005-08-17 23:47:55 +02:00
|
|
|
if (is_to_char)
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2014-09-05 15:52:31 +02:00
|
|
|
Np->out_pre_spaces = to_char_out_pre_spaces;
|
2000-02-08 16:57:01 +01:00
|
|
|
|
2014-09-13 02:42:19 +02:00
|
|
|
if (IS_FILLMODE(Np->Num) && IS_DECIMAL(Np->Num))
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2014-09-13 02:42:19 +02:00
|
|
|
Np->last_relevant = get_last_relevant_decnum(Np->number);
|
2011-09-07 23:06:10 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If any '0' specifiers are present, make sure we don't strip
|
|
|
|
* those digits.
|
|
|
|
*/
|
2014-09-13 02:42:19 +02:00
|
|
|
if (Np->last_relevant && Np->Num->zero_end > Np->out_pre_spaces)
|
2011-09-07 23:06:10 +02:00
|
|
|
{
|
2012-06-10 21:20:04 +02:00
|
|
|
char *last_zero;
|
2011-09-07 23:06:10 +02:00
|
|
|
|
2014-09-13 02:42:19 +02:00
|
|
|
last_zero = Np->number + (Np->Num->zero_end - Np->out_pre_spaces);
|
2011-09-07 23:06:10 +02:00
|
|
|
if (Np->last_relevant < last_zero)
|
|
|
|
Np->last_relevant = last_zero;
|
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
|
|
|
|
2014-09-05 15:52:31 +02:00
|
|
|
if (Np->sign_wrote == FALSE && Np->out_pre_spaces == 0)
|
2000-02-08 16:57:01 +01:00
|
|
|
++Np->num_count;
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-09-05 15:52:31 +02:00
|
|
|
Np->out_pre_spaces = 0;
|
2014-09-13 02:42:19 +02:00
|
|
|
*Np->number = ' '; /* sign space */
|
|
|
|
*(Np->number + 1) = '\0';
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Np->num_in = 0;
|
|
|
|
Np->num_curr = 0;
|
|
|
|
|
|
|
|
#ifdef DEBUG_TO_FROM_CHAR
|
|
|
|
elog(DEBUG_elog_output,
|
2009-08-10 20:29:27 +02:00
|
|
|
"\n\tSIGN: '%c'\n\tNUM: '%s'\n\tPRE: %d\n\tPOST: %d\n\tNUM_COUNT: %d\n\tNUM_PRE: %d\n\tSIGN_WROTE: %s\n\tZERO: %s\n\tZERO_START: %d\n\tZERO_END: %d\n\tLAST_RELEVANT: %s\n\tBRACKET: %s\n\tPLUS: %s\n\tMINUS: %s\n\tFILLMODE: %s\n\tROMAN: %s\n\tEEEE: %s",
|
2003-03-27 17:35:31 +01:00
|
|
|
Np->sign,
|
2014-09-13 02:42:19 +02:00
|
|
|
Np->number,
|
|
|
|
Np->Num->pre,
|
|
|
|
Np->Num->post,
|
2000-04-12 19:17:23 +02:00
|
|
|
Np->num_count,
|
2014-09-05 15:52:31 +02:00
|
|
|
Np->out_pre_spaces,
|
2000-04-12 19:17:23 +02:00
|
|
|
Np->sign_wrote ? "Yes" : "No",
|
2014-09-13 02:42:19 +02:00
|
|
|
IS_ZERO(Np->Num) ? "Yes" : "No",
|
|
|
|
Np->Num->zero_start,
|
|
|
|
Np->Num->zero_end,
|
2003-03-27 17:35:31 +01:00
|
|
|
Np->last_relevant ? Np->last_relevant : "<not set>",
|
2014-09-13 02:42:19 +02:00
|
|
|
IS_BRACKET(Np->Num) ? "Yes" : "No",
|
|
|
|
IS_PLUS(Np->Num) ? "Yes" : "No",
|
|
|
|
IS_MINUS(Np->Num) ? "Yes" : "No",
|
|
|
|
IS_FILLMODE(Np->Num) ? "Yes" : "No",
|
|
|
|
IS_ROMAN(Np->Num) ? "Yes" : "No",
|
|
|
|
IS_EEEE(Np->Num) ? "Yes" : "No"
|
2003-08-04 02:43:34 +02:00
|
|
|
);
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
#endif
|
2000-02-08 16:57:01 +01:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* Locale
|
|
|
|
*/
|
|
|
|
NUM_prepare_locale(Np);
|
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* Processor direct cycle
|
|
|
|
*/
|
2005-08-17 23:47:55 +02:00
|
|
|
if (Np->is_to_char)
|
2014-09-13 02:42:19 +02:00
|
|
|
Np->number_p = Np->number;
|
2005-08-17 23:47:55 +02:00
|
|
|
else
|
2014-09-13 02:42:19 +02:00
|
|
|
Np->number_p = Np->number + 1; /* first char is space for sign */
|
2000-04-12 19:17:23 +02:00
|
|
|
|
|
|
|
for (n = node, Np->inout_p = Np->inout; n->type != NODE_TYPE_END; n++)
|
|
|
|
{
|
2005-08-17 23:47:55 +02:00
|
|
|
if (!Np->is_to_char)
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* Check non-string inout end
|
|
|
|
*/
|
2014-09-05 15:52:31 +02:00
|
|
|
if (Np->inout_p >= Np->inout + from_char_input_len)
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
break;
|
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* Format pictures actions
|
|
|
|
*/
|
2000-04-12 19:17:23 +02:00
|
|
|
if (n->type == NODE_TYPE_ACTION)
|
|
|
|
{
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
2000-04-12 19:17:23 +02:00
|
|
|
* Create/reading digit/zero/blank/sing
|
2004-10-28 20:55:08 +02:00
|
|
|
*
|
2005-10-15 04:49:52 +02:00
|
|
|
* 'NUM_S' note: The locale sign is anchored to number and we
|
|
|
|
* read/write it when we work with first or last number
|
|
|
|
* (NUM_0/NUM_9). This is reason why NUM_S missing in follow
|
|
|
|
* switch().
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
*/
|
2000-04-12 19:17:23 +02:00
|
|
|
switch (n->key->id)
|
|
|
|
{
|
|
|
|
case NUM_9:
|
|
|
|
case NUM_0:
|
|
|
|
case NUM_DEC:
|
|
|
|
case NUM_D:
|
2005-08-17 23:47:55 +02:00
|
|
|
if (Np->is_to_char)
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
|
|
|
NUM_numpart_to_char(Np, n->key->id);
|
|
|
|
continue; /* for() */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-09-05 15:52:31 +02:00
|
|
|
NUM_numpart_from_char(Np, n->key->id, from_char_input_len);
|
2000-04-12 19:17:23 +02:00
|
|
|
break; /* switch() case: */
|
|
|
|
}
|
|
|
|
|
|
|
|
case NUM_COMMA:
|
2005-08-17 23:47:55 +02:00
|
|
|
if (Np->is_to_char)
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
|
|
|
if (!Np->num_in)
|
|
|
|
{
|
2014-09-13 02:42:19 +02:00
|
|
|
if (IS_FILLMODE(Np->Num))
|
2000-04-12 19:17:23 +02:00
|
|
|
continue;
|
|
|
|
else
|
|
|
|
*Np->inout_p = ' ';
|
|
|
|
}
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
else
|
2000-04-12 19:17:23 +02:00
|
|
|
*Np->inout_p = ',';
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
}
|
2005-08-17 23:47:55 +02:00
|
|
|
else
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
|
|
|
if (!Np->num_in)
|
|
|
|
{
|
2014-09-13 02:42:19 +02:00
|
|
|
if (IS_FILLMODE(Np->Num))
|
2000-04-12 19:17:23 +02:00
|
|
|
continue;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
}
|
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NUM_G:
|
2005-08-17 23:47:55 +02:00
|
|
|
if (Np->is_to_char)
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
|
|
|
if (!Np->num_in)
|
|
|
|
{
|
2014-09-13 02:42:19 +02:00
|
|
|
if (IS_FILLMODE(Np->Num))
|
2000-04-12 19:17:23 +02:00
|
|
|
continue;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int x = strlen(Np->L_thousands_sep);
|
|
|
|
|
|
|
|
memset(Np->inout_p, ' ', x);
|
|
|
|
Np->inout_p += x - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
strcpy(Np->inout_p, Np->L_thousands_sep);
|
|
|
|
Np->inout_p += strlen(Np->inout_p) - 1;
|
|
|
|
}
|
|
|
|
}
|
2005-08-17 23:47:55 +02:00
|
|
|
else
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
|
|
|
if (!Np->num_in)
|
|
|
|
{
|
2014-09-13 02:42:19 +02:00
|
|
|
if (IS_FILLMODE(Np->Num))
|
2000-04-12 19:17:23 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
Np->inout_p += strlen(Np->L_thousands_sep) - 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NUM_L:
|
2005-08-17 23:47:55 +02:00
|
|
|
if (Np->is_to_char)
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
|
|
|
strcpy(Np->inout_p, Np->L_currency_symbol);
|
|
|
|
Np->inout_p += strlen(Np->inout_p) - 1;
|
|
|
|
}
|
2005-08-17 23:47:55 +02:00
|
|
|
else
|
2000-04-12 19:17:23 +02:00
|
|
|
Np->inout_p += strlen(Np->L_currency_symbol) - 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NUM_RN:
|
2014-09-13 02:42:19 +02:00
|
|
|
if (IS_FILLMODE(Np->Num))
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2014-09-13 02:42:19 +02:00
|
|
|
strcpy(Np->inout_p, Np->number_p);
|
2000-04-12 19:17:23 +02:00
|
|
|
Np->inout_p += strlen(Np->inout_p) - 1;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
}
|
2000-02-08 16:57:01 +01:00
|
|
|
else
|
2001-12-05 03:06:19 +01:00
|
|
|
{
|
2014-09-13 02:42:19 +02:00
|
|
|
sprintf(Np->inout_p, "%15s", Np->number_p);
|
2001-12-05 03:06:19 +01:00
|
|
|
Np->inout_p += strlen(Np->inout_p) - 1;
|
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
break;
|
2001-10-25 07:50:21 +02:00
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
case NUM_rn:
|
2014-09-13 02:42:19 +02:00
|
|
|
if (IS_FILLMODE(Np->Num))
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2014-09-13 02:42:19 +02:00
|
|
|
strcpy(Np->inout_p, asc_tolower_z(Np->number_p));
|
2000-04-12 19:17:23 +02:00
|
|
|
Np->inout_p += strlen(Np->inout_p) - 1;
|
|
|
|
}
|
|
|
|
else
|
2001-12-05 03:06:19 +01:00
|
|
|
{
|
2014-09-13 02:42:19 +02:00
|
|
|
sprintf(Np->inout_p, "%15s", asc_tolower_z(Np->number_p));
|
2001-12-05 03:06:19 +01:00
|
|
|
Np->inout_p += strlen(Np->inout_p) - 1;
|
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NUM_th:
|
2014-09-13 02:42:19 +02:00
|
|
|
if (IS_ROMAN(Np->Num) || *Np->number == '#' ||
|
|
|
|
Np->sign == '-' || IS_DECIMAL(Np->Num))
|
2000-04-12 19:17:23 +02:00
|
|
|
continue;
|
|
|
|
|
2005-08-17 23:47:55 +02:00
|
|
|
if (Np->is_to_char)
|
2014-09-13 02:42:19 +02:00
|
|
|
strcpy(Np->inout_p, get_th(Np->number, TH_LOWER));
|
2000-04-12 19:17:23 +02:00
|
|
|
Np->inout_p += 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NUM_TH:
|
2014-09-13 02:42:19 +02:00
|
|
|
if (IS_ROMAN(Np->Num) || *Np->number == '#' ||
|
|
|
|
Np->sign == '-' || IS_DECIMAL(Np->Num))
|
2000-04-12 19:17:23 +02:00
|
|
|
continue;
|
|
|
|
|
2005-08-17 23:47:55 +02:00
|
|
|
if (Np->is_to_char)
|
2014-09-13 02:42:19 +02:00
|
|
|
strcpy(Np->inout_p, get_th(Np->number, TH_UPPER));
|
2000-04-12 19:17:23 +02:00
|
|
|
Np->inout_p += 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NUM_MI:
|
2005-08-17 23:47:55 +02:00
|
|
|
if (Np->is_to_char)
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
|
|
|
if (Np->sign == '-')
|
|
|
|
*Np->inout_p = '-';
|
2014-09-13 02:42:19 +02:00
|
|
|
else if (IS_FILLMODE(Np->Num))
|
2003-03-27 17:35:31 +01:00
|
|
|
continue;
|
2000-04-12 19:17:23 +02:00
|
|
|
else
|
|
|
|
*Np->inout_p = ' ';
|
|
|
|
}
|
2005-08-17 23:47:55 +02:00
|
|
|
else
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
|
|
|
if (*Np->inout_p == '-')
|
2014-09-13 02:42:19 +02:00
|
|
|
*Np->number = '-';
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NUM_PL:
|
2005-08-17 23:47:55 +02:00
|
|
|
if (Np->is_to_char)
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
|
|
|
if (Np->sign == '+')
|
|
|
|
*Np->inout_p = '+';
|
2014-09-13 02:42:19 +02:00
|
|
|
else if (IS_FILLMODE(Np->Num))
|
2003-03-27 17:35:31 +01:00
|
|
|
continue;
|
2000-04-12 19:17:23 +02:00
|
|
|
else
|
|
|
|
*Np->inout_p = ' ';
|
|
|
|
}
|
2005-08-17 23:47:55 +02:00
|
|
|
else
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
|
|
|
if (*Np->inout_p == '+')
|
2014-09-13 02:42:19 +02:00
|
|
|
*Np->number = '+';
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NUM_SG:
|
2005-08-17 23:47:55 +02:00
|
|
|
if (Np->is_to_char)
|
2000-04-12 19:17:23 +02:00
|
|
|
*Np->inout_p = Np->sign;
|
|
|
|
|
2005-08-17 23:47:55 +02:00
|
|
|
else
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
|
|
|
if (*Np->inout_p == '-')
|
2014-09-13 02:42:19 +02:00
|
|
|
*Np->number = '-';
|
2000-04-12 19:17:23 +02:00
|
|
|
else if (*Np->inout_p == '+')
|
2014-09-13 02:42:19 +02:00
|
|
|
*Np->number = '+';
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
continue;
|
|
|
|
break;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* Remove to output char from input in TO_CHAR
|
|
|
|
*/
|
2005-08-17 23:47:55 +02:00
|
|
|
if (Np->is_to_char)
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
*Np->inout_p = n->character;
|
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
Np->inout_p++;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2005-08-17 23:47:55 +02:00
|
|
|
if (Np->is_to_char)
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
*Np->inout_p = '\0';
|
2000-04-12 19:17:23 +02:00
|
|
|
return Np->inout;
|
|
|
|
}
|
2005-08-17 23:47:55 +02:00
|
|
|
else
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2014-09-13 02:42:19 +02:00
|
|
|
if (*(Np->number_p - 1) == '.')
|
|
|
|
*(Np->number_p - 1) = '\0';
|
2000-02-08 16:57:01 +01:00
|
|
|
else
|
2014-09-13 02:42:19 +02:00
|
|
|
*Np->number_p = '\0';
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
2000-02-08 16:57:01 +01:00
|
|
|
* Correction - precision of dec. number
|
|
|
|
*/
|
2014-09-13 02:42:19 +02:00
|
|
|
Np->Num->post = Np->read_post;
|
2000-02-08 16:57:01 +01:00
|
|
|
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
#ifdef DEBUG_TO_FROM_CHAR
|
2014-09-13 02:42:19 +02:00
|
|
|
elog(DEBUG_elog_output, "TO_NUMBER (number): '%s'", Np->number);
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
#endif
|
2014-09-13 02:42:19 +02:00
|
|
|
return Np->number;
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------
|
|
|
|
* MACRO: Start part of NUM - for all NUM's to_char variants
|
|
|
|
* (sorry, but I hate copy same code - macro is better..)
|
|
|
|
* ----------
|
|
|
|
*/
|
2000-07-03 18:01:33 +02:00
|
|
|
#define NUM_TOCHAR_prepare \
|
|
|
|
do { \
|
2013-12-02 16:51:06 +01:00
|
|
|
int len = VARSIZE_ANY_EXHDR(fmt); \
|
2007-06-29 03:51:35 +02:00
|
|
|
if (len <= 0 || len >= (INT_MAX-VARHDRSZ)/NUM_MAX_ITEM_SIZ) \
|
2008-03-25 23:42:46 +01:00
|
|
|
PG_RETURN_TEXT_P(cstring_to_text("")); \
|
2007-06-29 03:51:35 +02:00
|
|
|
result = (text *) palloc0((len * NUM_MAX_ITEM_SIZ) + 1 + VARHDRSZ); \
|
2014-09-13 02:42:19 +02:00
|
|
|
format = NUM_cache(len, &Num, fmt, &shouldFree); \
|
2000-07-06 01:12:09 +02:00
|
|
|
} while (0)
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
|
|
|
/* ----------
|
|
|
|
* MACRO: Finish part of NUM
|
|
|
|
* ----------
|
|
|
|
*/
|
2000-07-03 18:01:33 +02:00
|
|
|
#define NUM_TOCHAR_finish \
|
|
|
|
do { \
|
2013-12-02 16:51:06 +01:00
|
|
|
int len; \
|
|
|
|
\
|
2014-09-13 02:42:19 +02:00
|
|
|
NUM_processor(format, &Num, VARDATA(result), numstr, 0, out_pre_spaces, sign, true, PG_GET_COLLATION()); \
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
\
|
2007-06-29 03:51:35 +02:00
|
|
|
if (shouldFree) \
|
|
|
|
pfree(format); \
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
\
|
2007-06-29 03:51:35 +02:00
|
|
|
/* \
|
|
|
|
* Convert null-terminated representation of result to standard text. \
|
|
|
|
* The result is usually much bigger than it needs to be, but there \
|
|
|
|
* seems little point in realloc'ing it smaller. \
|
2000-03-16 02:35:41 +01:00
|
|
|
*/ \
|
2007-06-29 03:51:35 +02:00
|
|
|
len = strlen(VARDATA(result)); \
|
|
|
|
SET_VARSIZE(result, len + VARHDRSZ); \
|
|
|
|
} while (0)
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
|
|
|
/* -------------------
|
2000-04-12 19:17:23 +02:00
|
|
|
* NUMERIC to_number() (convert string to numeric)
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* -------------------
|
|
|
|
*/
|
2000-07-01 23:27:14 +02:00
|
|
|
Datum
|
|
|
|
numeric_to_number(PG_FUNCTION_ARGS)
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
text *value = PG_GETARG_TEXT_P(0);
|
|
|
|
text *fmt = PG_GETARG_TEXT_P(1);
|
2014-09-13 02:42:19 +02:00
|
|
|
NUMDesc Num;
|
2001-03-22 05:01:46 +01:00
|
|
|
Datum result;
|
2000-04-12 19:17:23 +02:00
|
|
|
FormatNode *format;
|
2001-03-22 05:01:46 +01:00
|
|
|
char *numstr;
|
2002-09-20 05:54:57 +02:00
|
|
|
bool shouldFree;
|
2001-03-22 05:01:46 +01:00
|
|
|
int len = 0;
|
|
|
|
int scale,
|
|
|
|
precision;
|
2000-04-12 19:17:23 +02:00
|
|
|
|
|
|
|
len = VARSIZE(fmt) - VARHDRSZ;
|
|
|
|
|
2007-11-15 22:14:46 +01:00
|
|
|
if (len <= 0 || len >= INT_MAX / NUM_MAX_ITEM_SIZ)
|
2000-07-01 23:27:14 +02:00
|
|
|
PG_RETURN_NULL();
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
2014-09-13 02:42:19 +02:00
|
|
|
format = NUM_cache(len, &Num, fmt, &shouldFree);
|
2000-04-12 19:17:23 +02:00
|
|
|
|
|
|
|
numstr = (char *) palloc((len * NUM_MAX_ITEM_SIZ) + 1);
|
|
|
|
|
2014-09-13 02:42:19 +02:00
|
|
|
NUM_processor(format, &Num, VARDATA(value), numstr,
|
2014-09-05 15:52:31 +02:00
|
|
|
VARSIZE(value) - VARHDRSZ, 0, 0, false, PG_GET_COLLATION());
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2014-09-13 02:42:19 +02:00
|
|
|
scale = Num.post;
|
2015-10-06 03:03:38 +02:00
|
|
|
precision = Num.pre + Num.multi + scale;
|
2000-03-16 02:35:41 +01:00
|
|
|
|
2002-09-20 05:54:57 +02:00
|
|
|
if (shouldFree)
|
2000-03-16 02:35:41 +01:00
|
|
|
pfree(format);
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2000-07-01 23:27:14 +02:00
|
|
|
result = DirectFunctionCall3(numeric_in,
|
2001-03-22 05:01:46 +01:00
|
|
|
CStringGetDatum(numstr),
|
|
|
|
ObjectIdGetDatum(InvalidOid),
|
2005-10-15 04:49:52 +02:00
|
|
|
Int32GetDatum(((precision << 16) | scale) + VARHDRSZ));
|
2015-10-06 03:03:38 +02:00
|
|
|
|
|
|
|
if (IS_MULTI(&Num))
|
|
|
|
{
|
|
|
|
Numeric x;
|
|
|
|
Numeric a = DatumGetNumeric(DirectFunctionCall1(int4_numeric,
|
|
|
|
Int32GetDatum(10)));
|
|
|
|
Numeric b = DatumGetNumeric(DirectFunctionCall1(int4_numeric,
|
|
|
|
Int32GetDatum(-Num.multi)));
|
|
|
|
|
|
|
|
x = DatumGetNumeric(DirectFunctionCall2(numeric_power,
|
|
|
|
NumericGetDatum(a),
|
|
|
|
NumericGetDatum(b)));
|
|
|
|
result = DirectFunctionCall2(numeric_mul,
|
|
|
|
result,
|
|
|
|
NumericGetDatum(x));
|
|
|
|
}
|
|
|
|
|
2000-03-16 02:35:41 +01:00
|
|
|
pfree(numstr);
|
|
|
|
return result;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------
|
|
|
|
* NUMERIC to_char()
|
|
|
|
* ------------------
|
2000-04-12 19:17:23 +02:00
|
|
|
*/
|
2000-07-01 23:27:14 +02:00
|
|
|
Datum
|
|
|
|
numeric_to_char(PG_FUNCTION_ARGS)
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
Numeric value = PG_GETARG_NUMERIC(0);
|
|
|
|
text *fmt = PG_GETARG_TEXT_P(1);
|
2014-09-13 02:42:19 +02:00
|
|
|
NUMDesc Num;
|
2000-04-12 19:17:23 +02:00
|
|
|
FormatNode *format;
|
2007-06-29 03:51:35 +02:00
|
|
|
text *result;
|
2002-09-20 05:54:57 +02:00
|
|
|
bool shouldFree;
|
2014-09-05 15:52:31 +02:00
|
|
|
int out_pre_spaces = 0,
|
2001-03-22 05:01:46 +01:00
|
|
|
sign = 0;
|
|
|
|
char *numstr,
|
|
|
|
*orgnum,
|
|
|
|
*p;
|
|
|
|
Numeric x;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
|
|
|
NUM_TOCHAR_prepare;
|
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* On DateType depend part (numeric)
|
|
|
|
*/
|
2014-09-13 02:42:19 +02:00
|
|
|
if (IS_ROMAN(&Num))
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2000-07-01 23:27:14 +02:00
|
|
|
x = DatumGetNumeric(DirectFunctionCall2(numeric_round,
|
2001-03-22 05:01:46 +01:00
|
|
|
NumericGetDatum(value),
|
|
|
|
Int32GetDatum(0)));
|
2000-07-29 05:26:51 +02:00
|
|
|
numstr = orgnum =
|
|
|
|
int_to_roman(DatumGetInt32(DirectFunctionCall1(numeric_int4,
|
2005-10-15 04:49:52 +02:00
|
|
|
NumericGetDatum(x))));
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
2014-09-13 02:42:19 +02:00
|
|
|
else if (IS_EEEE(&Num))
|
2009-08-10 20:29:27 +02:00
|
|
|
{
|
2014-09-13 02:42:19 +02:00
|
|
|
orgnum = numeric_out_sci(value, Num.post);
|
2009-08-10 20:29:27 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* numeric_out_sci() does not emit a sign for positive numbers. We
|
|
|
|
* need to add a space in this case so that positive and negative
|
|
|
|
* numbers are aligned. We also have to do the right thing for NaN.
|
|
|
|
*/
|
|
|
|
if (strcmp(orgnum, "NaN") == 0)
|
|
|
|
{
|
|
|
|
/*
|
2010-02-26 03:01:40 +01:00
|
|
|
* Allow 6 characters for the leading sign, the decimal point,
|
|
|
|
* "e", the exponent's sign and two exponent digits.
|
2009-08-10 20:29:27 +02:00
|
|
|
*/
|
2014-09-13 02:42:19 +02:00
|
|
|
numstr = (char *) palloc(Num.pre + Num.post + 7);
|
|
|
|
fill_str(numstr, '#', Num.pre + Num.post + 6);
|
2009-08-10 20:29:27 +02:00
|
|
|
*numstr = ' ';
|
2014-09-13 02:42:19 +02:00
|
|
|
*(numstr + Num.pre + 1) = '.';
|
2009-08-10 20:29:27 +02:00
|
|
|
}
|
|
|
|
else if (*orgnum != '-')
|
|
|
|
{
|
|
|
|
numstr = (char *) palloc(strlen(orgnum) + 2);
|
|
|
|
*numstr = ' ';
|
|
|
|
strcpy(numstr + 1, orgnum);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
numstr = orgnum;
|
|
|
|
}
|
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
else
|
|
|
|
{
|
2014-09-05 15:52:31 +02:00
|
|
|
int numstr_pre_len;
|
2000-04-12 19:17:23 +02:00
|
|
|
Numeric val = value;
|
|
|
|
|
2014-09-13 02:42:19 +02:00
|
|
|
if (IS_MULTI(&Num))
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2000-07-01 23:27:14 +02:00
|
|
|
Numeric a = DatumGetNumeric(DirectFunctionCall1(int4_numeric,
|
2005-10-15 04:49:52 +02:00
|
|
|
Int32GetDatum(10)));
|
2000-07-01 23:27:14 +02:00
|
|
|
Numeric b = DatumGetNumeric(DirectFunctionCall1(int4_numeric,
|
2014-09-13 02:42:19 +02:00
|
|
|
Int32GetDatum(Num.multi)));
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2000-07-29 05:26:51 +02:00
|
|
|
x = DatumGetNumeric(DirectFunctionCall2(numeric_power,
|
|
|
|
NumericGetDatum(a),
|
|
|
|
NumericGetDatum(b)));
|
|
|
|
val = DatumGetNumeric(DirectFunctionCall2(numeric_mul,
|
2005-10-15 04:49:52 +02:00
|
|
|
NumericGetDatum(value),
|
|
|
|
NumericGetDatum(x)));
|
2014-09-13 02:42:19 +02:00
|
|
|
Num.pre += Num.multi;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2000-07-01 23:27:14 +02:00
|
|
|
x = DatumGetNumeric(DirectFunctionCall2(numeric_round,
|
2001-03-22 05:01:46 +01:00
|
|
|
NumericGetDatum(val),
|
2014-09-13 02:42:19 +02:00
|
|
|
Int32GetDatum(Num.post)));
|
2000-07-01 23:27:14 +02:00
|
|
|
orgnum = DatumGetCString(DirectFunctionCall1(numeric_out,
|
2001-03-22 05:01:46 +01:00
|
|
|
NumericGetDatum(x)));
|
2000-04-12 19:17:23 +02:00
|
|
|
|
|
|
|
if (*orgnum == '-')
|
2007-06-29 03:51:35 +02:00
|
|
|
{
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
sign = '-';
|
2000-04-12 19:17:23 +02:00
|
|
|
numstr = orgnum + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
sign = '+';
|
|
|
|
numstr = orgnum;
|
|
|
|
}
|
2014-09-05 15:52:31 +02:00
|
|
|
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
if ((p = strchr(numstr, '.')))
|
2014-09-05 15:52:31 +02:00
|
|
|
numstr_pre_len = p - numstr;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
else
|
2014-09-05 15:52:31 +02:00
|
|
|
numstr_pre_len = strlen(numstr);
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2014-09-05 15:52:31 +02:00
|
|
|
/* needs padding? */
|
2014-09-13 02:42:19 +02:00
|
|
|
if (numstr_pre_len < Num.pre)
|
|
|
|
out_pre_spaces = Num.pre - numstr_pre_len;
|
2014-09-05 15:52:31 +02:00
|
|
|
/* overflowed prefix digit format? */
|
2014-09-13 02:42:19 +02:00
|
|
|
else if (numstr_pre_len > Num.pre)
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2014-09-13 02:42:19 +02:00
|
|
|
numstr = (char *) palloc(Num.pre + Num.post + 2);
|
|
|
|
fill_str(numstr, '#', Num.pre + Num.post + 1);
|
|
|
|
*(numstr + Num.pre) = '.';
|
2000-03-16 02:35:41 +01:00
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
2000-02-08 16:57:01 +01:00
|
|
|
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
NUM_TOCHAR_finish;
|
2000-07-01 23:27:14 +02:00
|
|
|
PG_RETURN_TEXT_P(result);
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------
|
|
|
|
* INT4 to_char()
|
|
|
|
* ---------------
|
2000-04-12 19:17:23 +02:00
|
|
|
*/
|
2000-07-01 23:27:14 +02:00
|
|
|
Datum
|
|
|
|
int4_to_char(PG_FUNCTION_ARGS)
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
int32 value = PG_GETARG_INT32(0);
|
|
|
|
text *fmt = PG_GETARG_TEXT_P(1);
|
2014-09-13 02:42:19 +02:00
|
|
|
NUMDesc Num;
|
2000-04-12 19:17:23 +02:00
|
|
|
FormatNode *format;
|
2007-06-29 03:51:35 +02:00
|
|
|
text *result;
|
2002-09-20 05:54:57 +02:00
|
|
|
bool shouldFree;
|
2014-09-05 15:52:31 +02:00
|
|
|
int out_pre_spaces = 0,
|
2001-03-22 05:01:46 +01:00
|
|
|
sign = 0;
|
|
|
|
char *numstr,
|
|
|
|
*orgnum;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
|
|
|
NUM_TOCHAR_prepare;
|
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* On DateType depend part (int32)
|
|
|
|
*/
|
2014-09-13 02:42:19 +02:00
|
|
|
if (IS_ROMAN(&Num))
|
2000-04-12 19:17:23 +02:00
|
|
|
numstr = orgnum = int_to_roman(value);
|
2014-09-13 02:42:19 +02:00
|
|
|
else if (IS_EEEE(&Num))
|
2009-08-10 20:29:27 +02:00
|
|
|
{
|
|
|
|
/* we can do it easily because float8 won't lose any precision */
|
2010-02-26 03:01:40 +01:00
|
|
|
float8 val = (float8) value;
|
2009-08-10 20:29:27 +02:00
|
|
|
|
2015-03-23 03:56:52 +01:00
|
|
|
orgnum = (char *) palloc(MAXDOUBLEWIDTH + 1);
|
|
|
|
snprintf(orgnum, MAXDOUBLEWIDTH + 1, "%+.*e", Num.post, val);
|
2009-08-10 20:29:27 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Swap a leading positive sign for a space.
|
|
|
|
*/
|
|
|
|
if (*orgnum == '+')
|
|
|
|
*orgnum = ' ';
|
|
|
|
|
|
|
|
numstr = orgnum;
|
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
else
|
|
|
|
{
|
2014-09-05 15:52:31 +02:00
|
|
|
int numstr_pre_len;
|
2013-12-02 16:51:06 +01:00
|
|
|
|
2014-09-13 02:42:19 +02:00
|
|
|
if (IS_MULTI(&Num))
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2000-06-05 09:29:25 +02:00
|
|
|
orgnum = DatumGetCString(DirectFunctionCall1(int4out,
|
2014-09-13 02:42:19 +02:00
|
|
|
Int32GetDatum(value * ((int32) pow((double) 10, (double) Num.multi)))));
|
|
|
|
Num.pre += Num.multi;
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
|
|
|
else
|
2000-06-05 09:29:25 +02:00
|
|
|
{
|
|
|
|
orgnum = DatumGetCString(DirectFunctionCall1(int4out,
|
2005-10-15 04:49:52 +02:00
|
|
|
Int32GetDatum(value)));
|
2000-06-05 09:29:25 +02:00
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
|
|
|
|
if (*orgnum == '-')
|
2007-06-29 03:51:35 +02:00
|
|
|
{
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
sign = '-';
|
2007-06-29 03:51:35 +02:00
|
|
|
orgnum++;
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
|
|
|
else
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
sign = '+';
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2014-09-05 15:52:31 +02:00
|
|
|
numstr_pre_len = strlen(orgnum);
|
|
|
|
|
|
|
|
/* post-decimal digits? Pad out with zeros. */
|
2014-09-13 02:42:19 +02:00
|
|
|
if (Num.post)
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2014-09-13 02:42:19 +02:00
|
|
|
numstr = (char *) palloc(numstr_pre_len + Num.post + 2);
|
2007-06-29 03:51:35 +02:00
|
|
|
strcpy(numstr, orgnum);
|
2014-09-05 15:52:31 +02:00
|
|
|
*(numstr + numstr_pre_len) = '.';
|
2014-09-13 02:42:19 +02:00
|
|
|
memset(numstr + numstr_pre_len + 1, '0', Num.post);
|
|
|
|
*(numstr + numstr_pre_len + Num.post + 1) = '\0';
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
|
|
|
else
|
2007-06-29 03:51:35 +02:00
|
|
|
numstr = orgnum;
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2014-09-05 15:52:31 +02:00
|
|
|
/* needs padding? */
|
2014-09-13 02:42:19 +02:00
|
|
|
if (numstr_pre_len < Num.pre)
|
|
|
|
out_pre_spaces = Num.pre - numstr_pre_len;
|
2014-09-05 15:52:31 +02:00
|
|
|
/* overflowed prefix digit format? */
|
2014-09-13 02:42:19 +02:00
|
|
|
else if (numstr_pre_len > Num.pre)
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2014-09-13 02:42:19 +02:00
|
|
|
numstr = (char *) palloc(Num.pre + Num.post + 2);
|
|
|
|
fill_str(numstr, '#', Num.pre + Num.post + 1);
|
|
|
|
*(numstr + Num.pre) = '.';
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NUM_TOCHAR_finish;
|
2000-07-01 23:27:14 +02:00
|
|
|
PG_RETURN_TEXT_P(result);
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------
|
|
|
|
* INT8 to_char()
|
|
|
|
* ---------------
|
2000-04-12 19:17:23 +02:00
|
|
|
*/
|
2000-07-01 23:27:14 +02:00
|
|
|
Datum
|
|
|
|
int8_to_char(PG_FUNCTION_ARGS)
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
int64 value = PG_GETARG_INT64(0);
|
|
|
|
text *fmt = PG_GETARG_TEXT_P(1);
|
2014-09-13 02:42:19 +02:00
|
|
|
NUMDesc Num;
|
2000-04-12 19:17:23 +02:00
|
|
|
FormatNode *format;
|
2007-06-29 03:51:35 +02:00
|
|
|
text *result;
|
2002-09-20 05:54:57 +02:00
|
|
|
bool shouldFree;
|
2014-09-05 15:52:31 +02:00
|
|
|
int out_pre_spaces = 0,
|
2001-03-22 05:01:46 +01:00
|
|
|
sign = 0;
|
|
|
|
char *numstr,
|
|
|
|
*orgnum;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
|
|
|
NUM_TOCHAR_prepare;
|
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
* On DateType depend part (int32)
|
|
|
|
*/
|
2014-09-13 02:42:19 +02:00
|
|
|
if (IS_ROMAN(&Num))
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2000-07-01 23:27:14 +02:00
|
|
|
/* Currently don't support int8 conversion to roman... */
|
|
|
|
numstr = orgnum = int_to_roman(DatumGetInt32(
|
2005-10-15 04:49:52 +02:00
|
|
|
DirectFunctionCall1(int84, Int64GetDatum(value))));
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
2014-09-13 02:42:19 +02:00
|
|
|
else if (IS_EEEE(&Num))
|
2009-08-10 20:29:27 +02:00
|
|
|
{
|
|
|
|
/* to avoid loss of precision, must go via numeric not float8 */
|
2010-02-26 03:01:40 +01:00
|
|
|
Numeric val;
|
2009-08-10 20:29:27 +02:00
|
|
|
|
|
|
|
val = DatumGetNumeric(DirectFunctionCall1(int8_numeric,
|
|
|
|
Int64GetDatum(value)));
|
2014-09-13 02:42:19 +02:00
|
|
|
orgnum = numeric_out_sci(val, Num.post);
|
2009-08-10 20:29:27 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* numeric_out_sci() does not emit a sign for positive numbers. We
|
|
|
|
* need to add a space in this case so that positive and negative
|
|
|
|
* numbers are aligned. We don't have to worry about NaN here.
|
|
|
|
*/
|
|
|
|
if (*orgnum != '-')
|
|
|
|
{
|
|
|
|
numstr = (char *) palloc(strlen(orgnum) + 2);
|
|
|
|
*numstr = ' ';
|
|
|
|
strcpy(numstr + 1, orgnum);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
numstr = orgnum;
|
|
|
|
}
|
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
else
|
|
|
|
{
|
2014-09-05 15:52:31 +02:00
|
|
|
int numstr_pre_len;
|
2013-12-02 16:51:06 +01:00
|
|
|
|
2014-09-13 02:42:19 +02:00
|
|
|
if (IS_MULTI(&Num))
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2014-09-13 02:42:19 +02:00
|
|
|
double multi = pow((double) 10, (double) Num.multi);
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2000-07-01 23:27:14 +02:00
|
|
|
value = DatumGetInt64(DirectFunctionCall2(int8mul,
|
2005-10-15 04:49:52 +02:00
|
|
|
Int64GetDatum(value),
|
|
|
|
DirectFunctionCall1(dtoi8,
|
|
|
|
Float8GetDatum(multi))));
|
2014-09-13 02:42:19 +02:00
|
|
|
Num.pre += Num.multi;
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
2000-07-01 23:27:14 +02:00
|
|
|
|
|
|
|
orgnum = DatumGetCString(DirectFunctionCall1(int8out,
|
2005-10-15 04:49:52 +02:00
|
|
|
Int64GetDatum(value)));
|
2000-04-12 19:17:23 +02:00
|
|
|
|
|
|
|
if (*orgnum == '-')
|
2007-06-29 03:51:35 +02:00
|
|
|
{
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
sign = '-';
|
2007-06-29 03:51:35 +02:00
|
|
|
orgnum++;
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
|
|
|
else
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
sign = '+';
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2014-09-05 15:52:31 +02:00
|
|
|
numstr_pre_len = strlen(orgnum);
|
|
|
|
|
|
|
|
/* post-decimal digits? Pad out with zeros. */
|
2014-09-13 02:42:19 +02:00
|
|
|
if (Num.post)
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2014-09-13 02:42:19 +02:00
|
|
|
numstr = (char *) palloc(numstr_pre_len + Num.post + 2);
|
2007-06-29 03:51:35 +02:00
|
|
|
strcpy(numstr, orgnum);
|
2014-09-05 15:52:31 +02:00
|
|
|
*(numstr + numstr_pre_len) = '.';
|
2014-09-13 02:42:19 +02:00
|
|
|
memset(numstr + numstr_pre_len + 1, '0', Num.post);
|
|
|
|
*(numstr + numstr_pre_len + Num.post + 1) = '\0';
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
|
|
|
else
|
2007-06-29 03:51:35 +02:00
|
|
|
numstr = orgnum;
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2014-09-05 15:52:31 +02:00
|
|
|
/* needs padding? */
|
2014-09-13 02:42:19 +02:00
|
|
|
if (numstr_pre_len < Num.pre)
|
|
|
|
out_pre_spaces = Num.pre - numstr_pre_len;
|
2014-09-05 15:52:31 +02:00
|
|
|
/* overflowed prefix digit format? */
|
2014-09-13 02:42:19 +02:00
|
|
|
else if (numstr_pre_len > Num.pre)
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2014-09-13 02:42:19 +02:00
|
|
|
numstr = (char *) palloc(Num.pre + Num.post + 2);
|
|
|
|
fill_str(numstr, '#', Num.pre + Num.post + 1);
|
|
|
|
*(numstr + Num.pre) = '.';
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
NUM_TOCHAR_finish;
|
2000-07-01 23:27:14 +02:00
|
|
|
PG_RETURN_TEXT_P(result);
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -----------------
|
|
|
|
* FLOAT4 to_char()
|
|
|
|
* -----------------
|
2000-04-12 19:17:23 +02:00
|
|
|
*/
|
2000-07-01 23:27:14 +02:00
|
|
|
Datum
|
|
|
|
float4_to_char(PG_FUNCTION_ARGS)
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
float4 value = PG_GETARG_FLOAT4(0);
|
|
|
|
text *fmt = PG_GETARG_TEXT_P(1);
|
2014-09-13 02:42:19 +02:00
|
|
|
NUMDesc Num;
|
2000-04-12 19:17:23 +02:00
|
|
|
FormatNode *format;
|
2007-06-29 03:51:35 +02:00
|
|
|
text *result;
|
2002-09-20 05:54:57 +02:00
|
|
|
bool shouldFree;
|
2014-09-05 15:52:31 +02:00
|
|
|
int out_pre_spaces = 0,
|
2001-03-22 05:01:46 +01:00
|
|
|
sign = 0;
|
|
|
|
char *numstr,
|
|
|
|
*orgnum,
|
|
|
|
*p;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
|
|
|
NUM_TOCHAR_prepare;
|
|
|
|
|
2014-09-13 02:42:19 +02:00
|
|
|
if (IS_ROMAN(&Num))
|
2000-07-01 23:27:14 +02:00
|
|
|
numstr = orgnum = int_to_roman((int) rint(value));
|
2014-09-13 02:42:19 +02:00
|
|
|
else if (IS_EEEE(&Num))
|
2009-08-10 20:29:27 +02:00
|
|
|
{
|
2015-03-23 03:56:52 +01:00
|
|
|
numstr = orgnum = (char *) palloc(MAXDOUBLEWIDTH + 1);
|
2009-08-10 20:29:27 +02:00
|
|
|
if (isnan(value) || is_infinite(value))
|
|
|
|
{
|
|
|
|
/*
|
2010-02-26 03:01:40 +01:00
|
|
|
* Allow 6 characters for the leading sign, the decimal point,
|
|
|
|
* "e", the exponent's sign and two exponent digits.
|
2009-08-10 20:29:27 +02:00
|
|
|
*/
|
2014-09-13 02:42:19 +02:00
|
|
|
numstr = (char *) palloc(Num.pre + Num.post + 7);
|
|
|
|
fill_str(numstr, '#', Num.pre + Num.post + 6);
|
2009-08-10 20:29:27 +02:00
|
|
|
*numstr = ' ';
|
2014-09-13 02:42:19 +02:00
|
|
|
*(numstr + Num.pre + 1) = '.';
|
2009-08-10 20:29:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-03-23 03:56:52 +01:00
|
|
|
snprintf(orgnum, MAXDOUBLEWIDTH + 1, "%+.*e", Num.post, value);
|
2009-08-10 20:29:27 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Swap a leading positive sign for a space.
|
|
|
|
*/
|
2015-03-23 03:56:52 +01:00
|
|
|
if (*orgnum == '+')
|
|
|
|
*orgnum = ' ';
|
|
|
|
|
|
|
|
numstr = orgnum;
|
2009-08-10 20:29:27 +02:00
|
|
|
}
|
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
else
|
|
|
|
{
|
2000-07-01 23:27:14 +02:00
|
|
|
float4 val = value;
|
2014-09-05 15:52:31 +02:00
|
|
|
int numstr_pre_len;
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2014-09-13 02:42:19 +02:00
|
|
|
if (IS_MULTI(&Num))
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2014-09-13 02:42:19 +02:00
|
|
|
float multi = pow((double) 10, (double) Num.multi);
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2000-07-01 23:27:14 +02:00
|
|
|
val = value * multi;
|
2014-09-13 02:42:19 +02:00
|
|
|
Num.pre += Num.multi;
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
|
|
|
|
2015-03-23 03:56:52 +01:00
|
|
|
orgnum = (char *) palloc(MAXFLOATWIDTH + 1);
|
|
|
|
snprintf(orgnum, MAXFLOATWIDTH + 1, "%.0f", fabs(val));
|
|
|
|
numstr_pre_len = strlen(orgnum);
|
2014-09-05 15:52:31 +02:00
|
|
|
|
2015-03-23 03:56:52 +01:00
|
|
|
/* adjust post digits to fit max float digits */
|
|
|
|
if (numstr_pre_len >= FLT_DIG)
|
|
|
|
Num.post = 0;
|
|
|
|
else if (numstr_pre_len + Num.post > FLT_DIG)
|
|
|
|
Num.post = FLT_DIG - numstr_pre_len;
|
|
|
|
snprintf(orgnum, MAXFLOATWIDTH + 1, "%.*f", Num.post, val);
|
2000-04-12 19:17:23 +02:00
|
|
|
|
|
|
|
if (*orgnum == '-')
|
|
|
|
{ /* < 0 */
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
sign = '-';
|
2000-04-12 19:17:23 +02:00
|
|
|
numstr = orgnum + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
sign = '+';
|
|
|
|
numstr = orgnum;
|
|
|
|
}
|
2014-09-05 15:52:31 +02:00
|
|
|
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
if ((p = strchr(numstr, '.')))
|
2014-09-05 15:52:31 +02:00
|
|
|
numstr_pre_len = p - numstr;
|
2000-04-12 19:17:23 +02:00
|
|
|
else
|
2014-09-05 15:52:31 +02:00
|
|
|
numstr_pre_len = strlen(numstr);
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2014-09-05 15:52:31 +02:00
|
|
|
/* needs padding? */
|
2014-09-13 02:42:19 +02:00
|
|
|
if (numstr_pre_len < Num.pre)
|
|
|
|
out_pre_spaces = Num.pre - numstr_pre_len;
|
2014-09-05 15:52:31 +02:00
|
|
|
/* overflowed prefix digit format? */
|
2014-09-13 02:42:19 +02:00
|
|
|
else if (numstr_pre_len > Num.pre)
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2014-09-13 02:42:19 +02:00
|
|
|
numstr = (char *) palloc(Num.pre + Num.post + 2);
|
|
|
|
fill_str(numstr, '#', Num.pre + Num.post + 1);
|
|
|
|
*(numstr + Num.pre) = '.';
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
NUM_TOCHAR_finish;
|
2000-07-01 23:27:14 +02:00
|
|
|
PG_RETURN_TEXT_P(result);
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -----------------
|
|
|
|
* FLOAT8 to_char()
|
|
|
|
* -----------------
|
2000-04-12 19:17:23 +02:00
|
|
|
*/
|
2000-07-01 23:27:14 +02:00
|
|
|
Datum
|
|
|
|
float8_to_char(PG_FUNCTION_ARGS)
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
float8 value = PG_GETARG_FLOAT8(0);
|
|
|
|
text *fmt = PG_GETARG_TEXT_P(1);
|
2014-09-13 02:42:19 +02:00
|
|
|
NUMDesc Num;
|
2000-04-12 19:17:23 +02:00
|
|
|
FormatNode *format;
|
2007-06-29 03:51:35 +02:00
|
|
|
text *result;
|
2002-09-20 05:54:57 +02:00
|
|
|
bool shouldFree;
|
2014-09-05 15:52:31 +02:00
|
|
|
int out_pre_spaces = 0,
|
2001-03-22 05:01:46 +01:00
|
|
|
sign = 0;
|
|
|
|
char *numstr,
|
|
|
|
*orgnum,
|
|
|
|
*p;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
|
|
|
|
NUM_TOCHAR_prepare;
|
|
|
|
|
2014-09-13 02:42:19 +02:00
|
|
|
if (IS_ROMAN(&Num))
|
2000-07-01 23:27:14 +02:00
|
|
|
numstr = orgnum = int_to_roman((int) rint(value));
|
2014-09-13 02:42:19 +02:00
|
|
|
else if (IS_EEEE(&Num))
|
2009-08-10 20:29:27 +02:00
|
|
|
{
|
2015-03-23 03:56:52 +01:00
|
|
|
numstr = orgnum = (char *) palloc(MAXDOUBLEWIDTH + 1);
|
2009-08-10 20:29:27 +02:00
|
|
|
if (isnan(value) || is_infinite(value))
|
|
|
|
{
|
|
|
|
/*
|
2010-02-26 03:01:40 +01:00
|
|
|
* Allow 6 characters for the leading sign, the decimal point,
|
|
|
|
* "e", the exponent's sign and two exponent digits.
|
2009-08-10 20:29:27 +02:00
|
|
|
*/
|
2014-09-13 02:42:19 +02:00
|
|
|
numstr = (char *) palloc(Num.pre + Num.post + 7);
|
|
|
|
fill_str(numstr, '#', Num.pre + Num.post + 6);
|
2009-08-10 20:29:27 +02:00
|
|
|
*numstr = ' ';
|
2014-09-13 02:42:19 +02:00
|
|
|
*(numstr + Num.pre + 1) = '.';
|
2009-08-10 20:29:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-03-23 03:56:52 +01:00
|
|
|
snprintf(orgnum, MAXDOUBLEWIDTH + 1, "%+.*e", Num.post, value);
|
2009-08-10 20:29:27 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Swap a leading positive sign for a space.
|
|
|
|
*/
|
2015-03-23 03:56:52 +01:00
|
|
|
if (*orgnum == '+')
|
|
|
|
*orgnum = ' ';
|
|
|
|
|
|
|
|
numstr = orgnum;
|
2009-08-10 20:29:27 +02:00
|
|
|
}
|
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
else
|
|
|
|
{
|
2000-07-01 23:27:14 +02:00
|
|
|
float8 val = value;
|
2014-09-05 15:52:31 +02:00
|
|
|
int numstr_pre_len;
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2014-09-13 02:42:19 +02:00
|
|
|
if (IS_MULTI(&Num))
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2014-09-13 02:42:19 +02:00
|
|
|
double multi = pow((double) 10, (double) Num.multi);
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2000-07-01 23:27:14 +02:00
|
|
|
val = value * multi;
|
2014-09-13 02:42:19 +02:00
|
|
|
Num.pre += Num.multi;
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
2015-03-23 03:56:52 +01:00
|
|
|
orgnum = (char *) palloc(MAXDOUBLEWIDTH + 1);
|
|
|
|
numstr_pre_len = snprintf(orgnum, MAXDOUBLEWIDTH + 1, "%.0f", fabs(val));
|
|
|
|
|
|
|
|
/* adjust post digits to fit max double digits */
|
|
|
|
if (numstr_pre_len >= DBL_DIG)
|
|
|
|
Num.post = 0;
|
|
|
|
else if (numstr_pre_len + Num.post > DBL_DIG)
|
|
|
|
Num.post = DBL_DIG - numstr_pre_len;
|
|
|
|
snprintf(orgnum, MAXDOUBLEWIDTH + 1, "%.*f", Num.post, val);
|
2000-04-12 19:17:23 +02:00
|
|
|
|
|
|
|
if (*orgnum == '-')
|
|
|
|
{ /* < 0 */
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
sign = '-';
|
2000-04-12 19:17:23 +02:00
|
|
|
numstr = orgnum + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
sign = '+';
|
|
|
|
numstr = orgnum;
|
|
|
|
}
|
2014-09-05 15:52:31 +02:00
|
|
|
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
if ((p = strchr(numstr, '.')))
|
2014-09-05 15:52:31 +02:00
|
|
|
numstr_pre_len = p - numstr;
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
else
|
2014-09-05 15:52:31 +02:00
|
|
|
numstr_pre_len = strlen(numstr);
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2014-09-05 15:52:31 +02:00
|
|
|
/* needs padding? */
|
2014-09-13 02:42:19 +02:00
|
|
|
if (numstr_pre_len < Num.pre)
|
|
|
|
out_pre_spaces = Num.pre - numstr_pre_len;
|
2014-09-05 15:52:31 +02:00
|
|
|
/* overflowed prefix digit format? */
|
2014-09-13 02:42:19 +02:00
|
|
|
else if (numstr_pre_len > Num.pre)
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2014-09-13 02:42:19 +02:00
|
|
|
numstr = (char *) palloc(Num.pre + Num.post + 2);
|
|
|
|
fill_str(numstr, '#', Num.pre + Num.post + 1);
|
|
|
|
*(numstr + Num.pre) = '.';
|
2000-04-12 19:17:23 +02:00
|
|
|
}
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
NUM_TOCHAR_finish;
|
2000-07-01 23:27:14 +02:00
|
|
|
PG_RETURN_TEXT_P(result);
|
as attache of this mail is patch (to the main tree) with to_char's
family functions. Contain:
conversion from a datetype to formatted text:
to_char( datetime, text)
to_char( timestamp, text)
to_char( int4, text)
to_char( int8, text)
to_char( float4, text)
to_char( float8, text)
to_char( numeric, text)
vice versa:
to_date ( text, text)
to_datetime ( text, text)
to_timestamp ( text, text)
to_number ( text, text) (convert to numeric)
PostgreSQL to_char is very compatible with Oracle's to_char(), but not
total exactly (now). Small differentions are in number formating. It will
fix in next to_char() version.
! If will this patch aplly to the main tree, must be delete the current
to_char version in contrib (directory "dateformat" and note in contrib's
README), this patch not erase it (sorry Bruce).
The patch patching files:
doc/src/sgml/func.sgml
^^^^^^^^
Hmm, I'm not sure if my English... :( Check it anyone (volunteer)?
Thomas, it is right? SGML is not my primary lang and compile
the current PG docs tree is very happy job (hard variables setting in
docs/sgml/Makefile --> HSTYLE= /home/users/t/thomas/.... :-)
What add any definition to global configure.in and set Makefiles in docs
tree via ./configure?
src/backend/utils/adt/Makefile
src/backend/utils/adt/formatting.c
src/include/catalog/pg_proc.h
src/include/utils/formatting.h
Karel Zak <zakkr@zf.jcu.cz> http://home.zf.jcu.cz/~zakkr/
2000-01-26 00:53:56 +01:00
|
|
|
}
|