Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
ae526b40
Commit
ae526b40
authored
Jun 09, 2000
by
Tom Lane
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Another round of updates for new fmgr, mostly in the datetime code.
parent
20ad43b5
Changes
27
Hide whitespace changes
Inline
Side-by-side
Showing
27 changed files
with
2019 additions
and
1820 deletions
+2019
-1820
contrib/lo/lo.c
contrib/lo/lo.c
+7
-4
contrib/spi/moddatetime.c
contrib/spi/moddatetime.c
+2
-1
src/backend/access/nbtree/nbtcompare.c
src/backend/access/nbtree/nbtcompare.c
+6
-3
src/backend/commands/user.c
src/backend/commands/user.c
+7
-5
src/backend/libpq/be-fsstubs.c
src/backend/libpq/be-fsstubs.c
+82
-50
src/backend/libpq/crypt.c
src/backend/libpq/crypt.c
+3
-2
src/backend/utils/adt/arrayfuncs.c
src/backend/utils/adt/arrayfuncs.c
+51
-18
src/backend/utils/adt/chunk.c
src/backend/utils/adt/chunk.c
+41
-12
src/backend/utils/adt/date.c
src/backend/utils/adt/date.c
+381
-332
src/backend/utils/adt/formatting.c
src/backend/utils/adt/formatting.c
+27
-28
src/backend/utils/adt/nabstime.c
src/backend/utils/adt/nabstime.c
+428
-347
src/backend/utils/adt/not_in.c
src/backend/utils/adt/not_in.c
+27
-14
src/backend/utils/adt/ruleutils.c
src/backend/utils/adt/ruleutils.c
+5
-4
src/backend/utils/adt/selfuncs.c
src/backend/utils/adt/selfuncs.c
+10
-8
src/backend/utils/adt/sets.c
src/backend/utils/adt/sets.c
+8
-4
src/backend/utils/adt/tid.c
src/backend/utils/adt/tid.c
+28
-26
src/backend/utils/adt/timestamp.c
src/backend/utils/adt/timestamp.c
+450
-589
src/include/catalog/catversion.h
src/include/catalog/catversion.h
+2
-2
src/include/catalog/pg_proc.h
src/include/catalog/pg_proc.h
+164
-164
src/include/libpq/be-fsstubs.h
src/include/libpq/be-fsstubs.h
+22
-18
src/include/utils/builtins.h
src/include/utils/builtins.h
+7
-7
src/include/utils/date.h
src/include/utils/date.h
+73
-49
src/include/utils/formatting.h
src/include/utils/formatting.h
+7
-4
src/include/utils/nabstime.h
src/include/utils/nabstime.h
+79
-69
src/include/utils/sets.h
src/include/utils/sets.h
+5
-2
src/include/utils/timestamp.h
src/include/utils/timestamp.h
+77
-51
src/tutorial/beard.c
src/tutorial/beard.c
+20
-7
No files found.
contrib/lo/lo.c
View file @
ae526b40
/*
* PostgreSQL type definitions for managed LargeObjects.
*
* $Id: lo.c,v 1.
3 2000/05/29 01:59:02
tgl Exp $
* $Id: lo.c,v 1.
4 2000/06/09 01:10:58
tgl Exp $
*
*/
...
...
@@ -76,7 +76,8 @@ lo_in(char *str)
/*
* There is no Oid passed, so create a new one
*/
oid
=
lo_creat
(
INV_READ
|
INV_WRITE
);
oid
=
DatumGetObjectId
(
DirectFunctionCall1
(
lo_creat
,
Int32GetDatum
(
INV_READ
|
INV_WRITE
)));
if
(
oid
==
InvalidOid
)
{
elog
(
ERROR
,
"lo_in: InvalidOid returned from lo_creat"
);
...
...
@@ -186,7 +187,8 @@ lo_manage(PG_FUNCTION_ARGS)
char
*
newv
=
SPI_getvalue
(
newtuple
,
tupdesc
,
attnum
);
if
((
orig
!=
newv
&&
(
orig
==
NULL
||
newv
==
NULL
))
||
(
orig
!=
NULL
&&
newv
!=
NULL
&&
strcmp
(
orig
,
newv
)))
lo_unlink
(
atoi
(
orig
));
DirectFunctionCall1
(
lo_unlink
,
ObjectIdGetDatum
((
Oid
)
atoi
(
orig
)));
if
(
newv
)
pfree
(
newv
);
...
...
@@ -206,7 +208,8 @@ lo_manage(PG_FUNCTION_ARGS)
if
(
orig
!=
NULL
)
{
lo_unlink
(
atoi
(
orig
));
DirectFunctionCall1
(
lo_unlink
,
ObjectIdGetDatum
((
Oid
)
atoi
(
orig
)));
pfree
(
orig
);
}
...
...
contrib/spi/moddatetime.c
View file @
ae526b40
...
...
@@ -62,7 +62,8 @@ moddatetime(PG_FUNCTION_ARGS)
tupdesc
=
rel
->
rd_att
;
/* Get the current datetime. */
newdt
=
(
Datum
)
timestamp_in
(
"now"
);
newdt
=
DirectFunctionCall1
(
timestamp_in
,
CStringGetDatum
(
"now"
));
/*
* This gets the position in the turple of the field we want. args[0]
...
...
src/backend/access/nbtree/nbtcompare.c
View file @
ae526b40
...
...
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtcompare.c,v 1.3
5 2000/06/05 07:28:36
tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtcompare.c,v 1.3
6 2000/06/09 01:11:01
tgl Exp $
*
* NOTES
*
...
...
@@ -170,9 +170,12 @@ btoidvectorcmp(PG_FUNCTION_ARGS)
PG_RETURN_INT32
(
0
);
}
int32
btabstimecmp
(
AbsoluteTime
a
,
AbsoluteTime
b
)
Datum
btabstimecmp
(
PG_FUNCTION_ARGS
)
{
AbsoluteTime
a
=
PG_GETARG_ABSOLUTETIME
(
0
);
AbsoluteTime
b
=
PG_GETARG_ABSOLUTETIME
(
1
);
if
(
AbsoluteTimeIsBefore
(
a
,
b
))
PG_RETURN_INT32
(
-
1
);
else
if
(
AbsoluteTimeIsBefore
(
b
,
a
))
...
...
src/backend/commands/user.c
View file @
ae526b40
...
...
@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Header: /cvsroot/pgsql/src/backend/commands/user.c,v 1.5
7 2000/06/02 03:58:33
tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/user.c,v 1.5
8 2000/06/09 01:11:04
tgl Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -122,8 +122,8 @@ write_password_file(Relation rel)
"%s
\n
"
,
nameout
(
DatumGetName
(
datum_n
)),
null_p
?
""
:
textout
((
text
*
)
datum_p
),
null_v
?
"
\\
N"
:
nabstimeout
((
AbsoluteTime
)
datum_v
)
/* this is how the
* parser wants it */
null_v
?
"
\\
N"
:
DatumGetCString
(
DirectFunctionCall1
(
nabstimeout
,
datum_v
))
);
}
heap_endscan
(
scan
);
...
...
@@ -268,7 +268,8 @@ CreateUser(CreateUserStmt *stmt)
if
(
stmt
->
password
)
new_record
[
Anum_pg_shadow_passwd
-
1
]
=
PointerGetDatum
(
textin
(
stmt
->
password
));
if
(
stmt
->
validUntil
)
new_record
[
Anum_pg_shadow_valuntil
-
1
]
=
PointerGetDatum
(
nabstimein
(
stmt
->
validUntil
));
new_record
[
Anum_pg_shadow_valuntil
-
1
]
=
DirectFunctionCall1
(
nabstimein
,
CStringGetDatum
(
stmt
->
validUntil
));
new_record_nulls
[
Anum_pg_shadow_usename
-
1
]
=
' '
;
new_record_nulls
[
Anum_pg_shadow_usesysid
-
1
]
=
' '
;
...
...
@@ -445,7 +446,8 @@ AlterUser(AlterUserStmt *stmt)
/* valid until */
if
(
stmt
->
validUntil
)
{
new_record
[
Anum_pg_shadow_valuntil
-
1
]
=
PointerGetDatum
(
nabstimein
(
stmt
->
validUntil
));
new_record
[
Anum_pg_shadow_valuntil
-
1
]
=
DirectFunctionCall1
(
nabstimein
,
CStringGetDatum
(
stmt
->
validUntil
));
new_record_nulls
[
Anum_pg_shadow_valuntil
-
1
]
=
' '
;
}
else
...
...
src/backend/libpq/be-fsstubs.c
View file @
ae526b40
...
...
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/be-fsstubs.c,v 1.4
5 2000/06/02 15:57:20 momjian
Exp $
* $Header: /cvsroot/pgsql/src/backend/libpq/be-fsstubs.c,v 1.4
6 2000/06/09 01:11:06 tgl
Exp $
*
* NOTES
* This should be moved to a more appropriate place. It is here
...
...
@@ -49,6 +49,11 @@
#define BUFSIZE 1024
#define FNAME_BUFSIZE 8192
/*
* LO "FD"s are indexes into this array.
* A non-null entry is a pointer to a LargeObjectDesc allocated in the
* LO private memory context.
*/
static
LargeObjectDesc
*
cookies
[
MAX_LOBJ_FDS
];
static
GlobalMemory
fscxt
=
NULL
;
...
...
@@ -61,15 +66,17 @@ static void deleteLOfd(int fd);
* File Interfaces for Large Objects
*****************************************************************************/
int
lo_open
(
Oid
lobjId
,
int
mode
)
Datum
lo_open
(
PG_FUNCTION_ARGS
)
{
Oid
lobjId
=
PG_GETARG_OID
(
0
);
int32
mode
=
PG_GETARG_INT32
(
1
);
LargeObjectDesc
*
lobjDesc
;
int
fd
;
MemoryContext
currentContext
;
#if FSDB
elog
(
NOTICE
,
"
LO
open(%u,%d)"
,
lobjId
,
mode
);
elog
(
NOTICE
,
"
lo_
open(%u,%d)"
,
lobjId
,
mode
);
#endif
if
(
fscxt
==
NULL
)
...
...
@@ -84,7 +91,7 @@ lo_open(Oid lobjId, int mode)
#if FSDB
elog
(
NOTICE
,
"cannot open large object %u"
,
lobjId
);
#endif
return
-
1
;
PG_RETURN_INT32
(
-
1
)
;
}
fd
=
newLOfd
(
lobjDesc
);
...
...
@@ -97,26 +104,27 @@ lo_open(Oid lobjId, int mode)
elog
(
NOTICE
,
"Out of space for large object FDs"
);
#endif
return
fd
;
PG_RETURN_INT32
(
fd
)
;
}
int
lo_close
(
int
fd
)
Datum
lo_close
(
PG_FUNCTION_ARGS
)
{
int32
fd
=
PG_GETARG_INT32
(
0
);
MemoryContext
currentContext
;
if
(
fd
<
0
||
fd
>=
MAX_LOBJ_FDS
)
{
elog
(
ERROR
,
"lo_close: large obj descriptor (%d) out of range"
,
fd
);
return
-
2
;
PG_RETURN_INT32
(
-
2
)
;
}
if
(
cookies
[
fd
]
==
NULL
)
{
elog
(
ERROR
,
"lo_close: invalid large obj descriptor (%d)"
,
fd
);
return
-
3
;
PG_RETURN_INT32
(
-
3
)
;
}
#if FSDB
elog
(
NOTICE
,
"
LO
close(%d)"
,
fd
);
elog
(
NOTICE
,
"
lo_
close(%d)"
,
fd
);
#endif
Assert
(
fscxt
!=
NULL
);
...
...
@@ -127,13 +135,19 @@ lo_close(int fd)
MemoryContextSwitchTo
(
currentContext
);
deleteLOfd
(
fd
);
return
0
;
PG_RETURN_INT32
(
0
);
}
/*
/*****************************************************************************
* Bare Read/Write operations --- these are not fmgr-callable!
*
* We assume the large object supports byte oriented reads and seeks so
* that our work is easier.
*/
*
*****************************************************************************/
int
lo_read
(
int
fd
,
char
*
buf
,
int
len
)
{
...
...
@@ -157,7 +171,8 @@ lo_read(int fd, char *buf, int len)
status
=
inv_read
(
cookies
[
fd
],
buf
,
len
);
MemoryContextSwitchTo
(
currentContext
);
return
(
status
);
return
status
;
}
int
...
...
@@ -183,25 +198,29 @@ lo_write(int fd, char *buf, int len)
status
=
inv_write
(
cookies
[
fd
],
buf
,
len
);
MemoryContextSwitchTo
(
currentContext
);
return
(
status
);
return
status
;
}
int
lo_lseek
(
int
fd
,
int
offset
,
int
whence
)
Datum
lo_lseek
(
PG_FUNCTION_ARGS
)
{
int32
fd
=
PG_GETARG_INT32
(
0
);
int32
offset
=
PG_GETARG_INT32
(
1
);
int32
whence
=
PG_GETARG_INT32
(
2
);
MemoryContext
currentContext
;
int
status
;
if
(
fd
<
0
||
fd
>=
MAX_LOBJ_FDS
)
{
elog
(
ERROR
,
"lo_lseek: large obj descriptor (%d) out of range"
,
fd
);
return
-
2
;
PG_RETURN_INT32
(
-
2
)
;
}
if
(
cookies
[
fd
]
==
NULL
)
{
elog
(
ERROR
,
"lo_lseek: invalid large obj descriptor (%d)"
,
fd
);
return
-
3
;
PG_RETURN_INT32
(
-
3
)
;
}
Assert
(
fscxt
!=
NULL
);
...
...
@@ -211,12 +230,13 @@ lo_lseek(int fd, int offset, int whence)
MemoryContextSwitchTo
(
currentContext
);
return
status
;
PG_RETURN_INT32
(
status
)
;
}
Oid
lo_creat
(
int
mode
)
Datum
lo_creat
(
PG_FUNCTION_ARGS
)
{
int32
mode
=
PG_GETARG_INT32
(
0
);
LargeObjectDesc
*
lobjDesc
;
MemoryContext
currentContext
;
Oid
lobjId
;
...
...
@@ -231,31 +251,32 @@ lo_creat(int mode)
if
(
lobjDesc
==
NULL
)
{
MemoryContextSwitchTo
(
currentContext
);
return
InvalidOid
;
PG_RETURN_OID
(
InvalidOid
)
;
}
lobjId
=
RelationGetRelid
(
lobjDesc
->
heap_r
);
inv_close
(
lobjDesc
);
/* switch context back to original memory context */
MemoryContextSwitchTo
(
currentContext
);
return
lobjId
;
PG_RETURN_OID
(
lobjId
)
;
}
int
lo_tell
(
int
fd
)
Datum
lo_tell
(
PG_FUNCTION_ARGS
)
{
int32
fd
=
PG_GETARG_INT32
(
0
);
if
(
fd
<
0
||
fd
>=
MAX_LOBJ_FDS
)
{
elog
(
ERROR
,
"lo_tell: large object descriptor (%d) out of range"
,
fd
);
return
-
2
;
PG_RETURN_INT32
(
-
2
)
;
}
if
(
cookies
[
fd
]
==
NULL
)
{
elog
(
ERROR
,
"lo_tell: invalid large object descriptor (%d)"
,
fd
);
return
-
3
;
PG_RETURN_INT32
(
-
3
)
;
}
/*
...
...
@@ -263,12 +284,13 @@ lo_tell(int fd)
* true for now, but is probably more than this module ought to
* assume...
*/
return
inv_tell
(
cookies
[
fd
]
);
PG_RETURN_INT32
(
inv_tell
(
cookies
[
fd
])
);
}
int
lo_unlink
(
Oid
lobjId
)
Datum
lo_unlink
(
PG_FUNCTION_ARGS
)
{
Oid
lobjId
=
PG_GETARG_OID
(
0
);
/*
* inv_drop does not need a context switch, indeed it doesn't touch
...
...
@@ -278,35 +300,42 @@ lo_unlink(Oid lobjId)
* XXX there ought to be some code to clean up any open LOs that
* reference the specified relation... as is, they remain "open".
*/
return
inv_drop
(
lobjId
);
PG_RETURN_INT32
(
inv_drop
(
lobjId
)
);
}
/*****************************************************************************
* Read/Write using
varlen
a
* Read/Write using
byte
a
*****************************************************************************/
struct
varlena
*
loread
(
int
fd
,
int
len
)
Datum
loread
(
PG_FUNCTION_ARGS
)
{
int32
fd
=
PG_GETARG_INT32
(
0
);
int32
len
=
PG_GETARG_INT32
(
1
);
struct
varlena
*
retval
;
int
totalread
=
0
;
int
totalread
;
if
(
len
<
0
)
len
=
0
;
retval
=
(
struct
varlena
*
)
palloc
(
VARHDRSZ
+
len
);
totalread
=
lo_read
(
fd
,
VARDATA
(
retval
),
len
);
VARSIZE
(
retval
)
=
totalread
+
VARHDRSZ
;
return
retval
;
PG_RETURN_POINTER
(
retval
)
;
}
int
lowrite
(
int
fd
,
struct
varlena
*
wbuf
)
Datum
lowrite
(
PG_FUNCTION_ARGS
)
{
int
totalwritten
;
int
bytestowrite
;
int32
fd
=
PG_GETARG_INT32
(
0
);
struct
varlena
*
wbuf
=
PG_GETARG_VARLENA_P
(
1
);
int
bytestowrite
;
int
totalwritten
;
bytestowrite
=
VARSIZE
(
wbuf
)
-
VARHDRSZ
;
totalwritten
=
lo_write
(
fd
,
VARDATA
(
wbuf
),
bytestowrite
);
return
totalwritten
;
PG_RETURN_INT32
(
totalwritten
)
;
}
/*****************************************************************************
...
...
@@ -317,9 +346,10 @@ lowrite(int fd, struct varlena * wbuf)
* lo_import -
* imports a file as an (inversion) large object.
*/
Oid
lo_import
(
text
*
filename
)
Datum
lo_import
(
PG_FUNCTION_ARGS
)
{
text
*
filename
=
PG_GETARG_TEXT_P
(
0
);
File
fd
;
int
nbytes
,
tmp
;
...
...
@@ -379,16 +409,18 @@ lo_import(text *filename)
FileClose
(
fd
);
inv_close
(
lobj
);
return
lobjOid
;
PG_RETURN_OID
(
lobjOid
)
;
}
/*
* lo_export -
* exports an (inversion) large object.
*/
int4
lo_export
(
Oid
lobjId
,
text
*
filename
)
Datum
lo_export
(
PG_FUNCTION_ARGS
)
{
Oid
lobjId
=
PG_GETARG_OID
(
0
);
text
*
filename
=
PG_GETARG_TEXT_P
(
1
);
File
fd
;
int
nbytes
,
tmp
;
...
...
@@ -445,7 +477,7 @@ lo_export(Oid lobjId, text *filename)
inv_close
(
lobj
);
FileClose
(
fd
);
return
1
;
PG_RETURN_INT32
(
1
)
;
}
/*
...
...
src/backend/libpq/crypt.c
View file @
ae526b40
...
...
@@ -9,7 +9,7 @@
* Dec 17, 1997 - Todd A. Brandys
* Orignal Version Completed.
*
* $Id: crypt.c,v 1.2
4 2000/06/02 15:57:20 momjian
Exp $
* $Id: crypt.c,v 1.2
5 2000/06/09 01:11:06 tgl
Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -288,7 +288,8 @@ crypt_verify(Port *port, const char *user, const char *pgpass)
if
(
!
valuntil
||
strcmp
(
valuntil
,
"
\\
N"
)
==
0
)
vuntil
=
INVALID_ABSTIME
;
else
vuntil
=
nabstimein
(
valuntil
);
vuntil
=
DatumGetAbsoluteTime
(
DirectFunctionCall1
(
nabstimein
,
CStringGetDatum
(
valuntil
)));
current
=
GetCurrentAbsoluteTime
();
if
(
vuntil
!=
INVALID_ABSTIME
&&
vuntil
<
current
)
retval
=
STATUS_ERROR
;
...
...
src/backend/utils/adt/arrayfuncs.c
View file @
ae526b40
...
...
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.5
5 2000/06/02 15:57:28 momjian
Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.5
6 2000/06/09 01:11:08 tgl
Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -538,8 +538,11 @@ _ReadLOArray(char *str,
if
(
inputfile
==
NULL
)
elog
(
ERROR
,
"array_in: missing file name"
);
lobjId
=
lo_creat
(
0
);
*
fd
=
lo_open
(
lobjId
,
INV_READ
);
lobjId
=
DatumGetObjectId
(
DirectFunctionCall1
(
lo_creat
,
Int32GetDatum
(
0
)));
*
fd
=
DatumGetInt32
(
DirectFunctionCall2
(
lo_open
,
ObjectIdGetDatum
(
lobjId
),
Int32GetDatum
(
INV_READ
)));
if
(
*
fd
<
0
)
elog
(
ERROR
,
"Large object create failed"
);
retStr
=
inputfile
;
...
...
@@ -877,17 +880,23 @@ array_ref(ArrayType *array,
v
=
_ReadChunkArray1El
(
indx
,
elmlen
,
fd
,
array
,
isNull
);
else
{
if
(
lo_lseek
(
fd
,
offset
,
SEEK_SET
)
<
0
)
if
(
DatumGetInt32
(
DirectFunctionCall3
(
lo_lseek
,
Int32GetDatum
(
fd
),
Int32GetDatum
(
offset
),
Int32GetDatum
(
SEEK_SET
)))
<
0
)
RETURN_NULL
;
#ifdef LOARRAY
v
=
(
struct
varlena
*
)
LOread
(
fd
,
elmlen
);
v
=
(
struct
varlena
*
)
DatumGetPointer
(
DirectFunctionCall2
(
loread
,
Int32GetDatum
(
fd
),
Int32GetDatum
(
elmlen
)));
#endif
}
if
(
*
isNull
)
RETURN_NULL
;
if
(
VARSIZE
(
v
)
-
VARHDRSZ
<
elmlen
)
RETURN_NULL
;
lo_close
(
fd
);
DirectFunctionCall1
(
lo_close
,
Int32GetDatum
(
fd
)
);
retval
=
(
char
*
)
_ArrayCast
((
char
*
)
VARDATA
(
v
),
reftype
,
elmlen
);
if
(
reftype
==
0
)
{
/* not by value */
...
...
@@ -1029,7 +1038,9 @@ array_clip(ArrayType *array,
memmove
(
buff
,
&
rsize
,
VARHDRSZ
);
#ifdef LOARRAY
if
(
!*
isNull
)
bytes
=
LOwrite
(
newfd
,
(
struct
varlena
*
)
buff
);
bytes
=
DatumGetInt32
(
DirectFunctionCall2
(
lowrite
,
Int32GetDatum
(
newfd
),
PointerGetDatum
(
buff
)));
#endif
pfree
(
buff
);
}
...
...
@@ -1140,20 +1151,25 @@ array_set(ArrayType *array,
if
((
fd
=
LOopen
(
lo_name
,
ARR_IS_INV
(
array
)
?
INV_WRITE
:
O_WRONLY
))
<
0
)
return
(
char
*
)
array
;
#endif
if
(
lo_lseek
(
fd
,
offset
,
SEEK_SET
)
<
0
)
if
(
DatumGetInt32
(
DirectFunctionCall3
(
lo_lseek
,
Int32GetDatum
(
fd
),
Int32GetDatum
(
offset
),
Int32GetDatum
(
SEEK_SET
)))
<
0
)
return
(
char
*
)
array
;
v
=
(
struct
varlena
*
)
palloc
(
elmlen
+
VARHDRSZ
);
VARSIZE
(
v
)
=
elmlen
+
VARHDRSZ
;
ArrayCastAndSet
(
dataPtr
,
(
bool
)
reftype
,
elmlen
,
VARDATA
(
v
));
#ifdef LOARRAY
n
=
LOwrite
(
fd
,
v
);
n
=
DatumGetInt32
(
DirectFunctionCall2
(
lowrite
,
Int32GetDatum
(
fd
),
PointerGetDatum
(
v
)));
#endif
/*
* if (n < VARSIZE(v) - VARHDRSZ) RETURN_NULL;
*/
pfree
(
v
);
lo_close
(
fd
);
DirectFunctionCall1
(
lo_close
,
Int32GetDatum
(
fd
)
);
return
(
char
*
)
array
;
}
if
(
elmlen
>
0
)
...
...
@@ -1270,14 +1286,14 @@ array_assgn(ArrayType *array,
return
(
char
*
)
array
;
#endif
_LOArrayRange
(
lowerIndx
,
upperIndx
,
len
,
fd
,
newfd
,
array
,
1
,
isNull
);
lo_close
(
newfd
);
DirectFunctionCall1
(
lo_close
,
Int32GetDatum
(
newfd
)
);
}
else
{
_LOArrayRange
(
lowerIndx
,
upperIndx
,
len
,
fd
,
(
int
)
ARR_DATA_PTR
(
newArr
),
array
,
0
,
isNull
);
}
lo_close
(
fd
);
DirectFunctionCall1
(
lo_close
,
Int32GetDatum
(
fd
)
);
return
(
char
*
)
array
;
}
_ArrayRange
(
lowerIndx
,
upperIndx
,
len
,
ARR_DATA_PTR
(
newArr
),
array
,
0
);
...
...
@@ -1758,7 +1774,10 @@ _LOArrayRange(int *st,
mda_get_prod
(
n
,
dim
,
prod
);
st_pos
=
tuple2linear
(
n
,
st
,
prod
);
offset
=
st_pos
*
bsize
;
if
(
lo_lseek
(
srcfd
,
offset
,
SEEK_SET
)
<
0
)
if
(
DatumGetInt32
(
DirectFunctionCall3
(
lo_lseek
,
Int32GetDatum
(
srcfd
),
Int32GetDatum
(
offset
),
Int32GetDatum
(
SEEK_SET
)))
<
0
)
return
;
mda_get_range
(
n
,
span
,
st
,
endp
);
mda_get_offset_values
(
n
,
dist
,
prod
,
span
);
...
...
@@ -1770,7 +1789,10 @@ _LOArrayRange(int *st,
do
{
offset
+=
(
dist
[
j
]
*
bsize
);
if
(
lo_lseek
(
srcfd
,
offset
,
SEEK_SET
)
<
0
)
if
(
DatumGetInt32
(
DirectFunctionCall3
(
lo_lseek
,
Int32GetDatum
(
srcfd
),
Int32GetDatum
(
offset
),
Int32GetDatum
(
SEEK_SET
)))
<
0
)
return
;
tmp
=
_LOtransfer
((
char
**
)
&
srcfd
,
inc
,
1
,
(
char
**
)
&
destfd
,
isSrcLO
,
1
);
if
(
tmp
<
inc
)
...
...
@@ -1812,7 +1834,10 @@ _ReadArray(int *st,
mda_get_prod
(
n
,
dim
,
prod
);
st_pos
=
tuple2linear
(
n
,
st
,
prod
);
offset
=
st_pos
*
bsize
;
if
(
lo_lseek
(
srcfd
,
offset
,
SEEK_SET
)
<
0
)
if
(
DatumGetInt32
(
DirectFunctionCall3
(
lo_lseek
,
Int32GetDatum
(
srcfd
),
Int32GetDatum
(
offset
),
Int32GetDatum
(
SEEK_SET
)))
<
0
)
return
;
mda_get_range
(
n
,
span
,
st
,
endp
);
mda_get_offset_values
(
n
,
dist
,
prod
,
span
);
...
...
@@ -1824,7 +1849,10 @@ _ReadArray(int *st,
do
{
offset
+=
(
dist
[
j
]
*
bsize
);
if
(
lo_lseek
(
srcfd
,
offset
,
SEEK_SET
)
<
0
)
if
(
DatumGetInt32
(
DirectFunctionCall3
(
lo_lseek
,
Int32GetDatum
(
srcfd
),
Int32GetDatum
(
offset
),
Int32GetDatum
(
SEEK_SET
)))
<
0
)
return
;
tmp
=
_LOtransfer
((
char
**
)
&
destfd
,
inc
,
1
,
(
char
**
)
&
srcfd
,
1
,
isDestLO
);
if
(
tmp
<
inc
)
...
...
@@ -1857,13 +1885,18 @@ _LOtransfer(char **destfd,
resid
>
0
&&
(
inc
=
min
(
resid
,
MAX_READ
))
>
0
;
resid
-=
inc
)
{
#ifdef LOARRAY
v
=
(
struct
varlena
*
)
LOread
((
int
)
*
srcfd
,
inc
);
v
=
(
struct
varlena
*
)
DatumGetPointer
(
DirectFunctionCall2
(
loread
,
Int32GetDatum
((
int32
)
*
srcfd
),
Int32GetDatum
(
inc
)));
if
(
VARSIZE
(
v
)
-
VARHDRSZ
<
inc
)
{
pfree
(
v
);
return
-
1
;
}
tmp
+=
LOwrite
((
int
)
*
destfd
,
v
);
tmp
+=
DatumGetInt32
(
DirectFunctionCall2
(
lowrite
,
Int32GetDatum
((
int32
)
*
destfd
),
PointerGetDatum
(
v
)));
#endif
pfree
(
v
);
...
...
src/backend/utils/adt/chunk.c
View file @
ae526b40
...
...
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/chunk.c,v 1.2
5 2000/01/26 05:57:13 momjian
Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/chunk.c,v 1.2
6 2000/06/09 01:11:08 tgl
Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -385,7 +385,9 @@ write_chunk(struct varlena * a_chunk, int ofile)
int
got_n
=
0
;
#ifdef LOARRAY
got_n
=
LOwrite
(
ofile
,
a_chunk
);
got_n
=
DatumGetInt32
(
DirectFunctionCall2
(
lowrite
,
Int32GetDatum
(
ofile
),
PointerGetDatum
(
a_chunk
)));
#endif
return
got_n
;
}
...
...
@@ -400,13 +402,19 @@ write_chunk(struct varlena * a_chunk, int ofile)
static
int
seek_and_read
(
int
pos
,
int
size
,
char
*
buff
,
int
fp
,
int
from
)
{
struct
varlena
*
v
=
NULL
;
struct
varlena
*
v
;
/* Assuming only one file */
if
(
lo_lseek
(
fp
,
pos
,
from
)
<
0
)
if
(
DatumGetInt32
(
DirectFunctionCall3
(
lo_lseek
,
Int32GetDatum
(
fp
),
Int32GetDatum
(
pos
),
Int32GetDatum
(
from
)))
<
0
)
elog
(
ERROR
,
"File seek error"
);
#ifdef LOARRAY
v
=
(
struct
varlena
*
)
LOread
(
fp
,
size
);
v
=
(
struct
varlena
*
)
DatumGetPointer
(
DirectFunctionCall2
(
loread
,
Int32GetDatum
(
fp
),
Int32GetDatum
(
size
)));
#endif
if
(
VARSIZE
(
v
)
-
VARHDRSZ
<
size
)
elog
(
ERROR
,
"File read error"
);
...
...
@@ -505,7 +513,10 @@ _ReadChunkArray(int *st,
for
(
i
=
j
=
0
;
i
<
n
;
i
++
)
j
+=
chunk_st
[
i
]
*
PC
[
i
];
temp_seek
=
srcOff
=
j
*
csize
*
bsize
;
if
(
lo_lseek
(
fp
,
srcOff
,
SEEK_SET
)
<
0
)
if
(
DatumGetInt32
(
DirectFunctionCall3
(
lo_lseek
,
Int32GetDatum
(
fp
),
Int32GetDatum
(
srcOff
),
Int32GetDatum
(
SEEK_SET
)))
<
0
)
RETURN_NULL
;
jj
=
n
-
1
;
...
...
@@ -526,7 +537,10 @@ _ReadChunkArray(int *st,
bptr
*=
bsize
;
if
(
isDestLO
)
{
if
(
lo_lseek
((
int
)
destfp
,
bptr
,
SEEK_SET
)
<
0
)
if
(
DatumGetInt32
(
DirectFunctionCall3
(
lo_lseek
,
Int32GetDatum
((
int32
)
destfp
),
Int32GetDatum
(
bptr
),
Int32GetDatum
(
SEEK_SET
)))
<
0
)
RETURN_NULL
;
}
else
...
...
@@ -538,7 +552,10 @@ _ReadChunkArray(int *st,
{
temp
=
(
dist
[
jj
]
*
csize
+
block_seek
+
temp_seek
)
*
bsize
;
srcOff
+=
temp
;
if
(
lo_lseek
(
fp
,
srcOff
,
SEEK_SET
)
<
0
)
if
(
DatumGetInt32
(
DirectFunctionCall3
(
lo_lseek
,
Int32GetDatum
(
fp
),
Int32GetDatum
(
srcOff
),
Int32GetDatum
(
SEEK_SET
)))
<
0
)
RETURN_NULL
;
}
for
(
i
=
n
-
1
,
to_read
=
bsize
;
i
>=
0
;
...
...
@@ -550,14 +567,20 @@ _ReadChunkArray(int *st,
if
(
cdist
[
j
])
{
srcOff
+=
(
cdist
[
j
]
*
bsize
);
if
(
lo_lseek
(
fp
,
srcOff
,
SEEK_SET
)
<
0
)
if
(
DatumGetInt32
(
DirectFunctionCall3
(
lo_lseek
,
Int32GetDatum
(
fp
),
Int32GetDatum
(
srcOff
),
Int32GetDatum
(
SEEK_SET
)))
<
0
)
RETURN_NULL
;
}
block_seek
+=
cdist
[
j
];
bptr
+=
adist
[
j
]
*
bsize
;
if
(
isDestLO
)
{
if
(
lo_lseek
((
int
)
destfp
,
bptr
,
SEEK_SET
)
<
0
)
if
(
DatumGetInt32
(
DirectFunctionCall3
(
lo_lseek
,
Int32GetDatum
((
int32
)
destfp
),
Int32GetDatum
(
bptr
),
Int32GetDatum
(
SEEK_SET
)))
<
0
)
RETURN_NULL
;
}
else
...
...
@@ -675,10 +698,16 @@ _ReadChunkArray1El(int *st,
srcOff
+=
(
st
[
i
]
-
chunk_st
[
i
]
*
C
[
i
])
*
PCHUNK
[
i
];
srcOff
*=
bsize
;
if
(
lo_lseek
(
fp
,
srcOff
,
SEEK_SET
)
<
0
)
if
(
DatumGetInt32
(
DirectFunctionCall3
(
lo_lseek
,
Int32GetDatum
(
fp
),
Int32GetDatum
(
srcOff
),
Int32GetDatum
(
SEEK_SET
)))
<
0
)
RETURN_NULL
;
#ifdef LOARRAY
return
(
struct
varlena
*
)
LOread
(
fp
,
bsize
);
return
(
struct
varlena
*
)
DatumGetPointer
(
DirectFunctionCall2
(
loread
,
Int32GetDatum
(
fp
),
Int32GetDatum
(
bsize
)));
#endif
return
(
struct
varlena
*
)
0
;
}
src/backend/utils/adt/date.c
View file @
ae526b40
...
...
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.4
4 2000/04/12 17:15:48 momjian
Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.4
5 2000/06/09 01:11:08 tgl
Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -33,9 +33,10 @@ static int
/* date_in()
* Given date text string, convert to internal date format.
*/
Dat
eADT
date_in
(
char
*
str
)
Dat
um
date_in
(
PG_FUNCTION_ARGS
)
{
char
*
str
=
PG_GETARG_CSTRING
(
0
);
DateADT
date
;
double
fsec
;
struct
tm
tt
,
...
...
@@ -47,11 +48,8 @@ date_in(char *str)
int
ftype
[
MAXDATEFIELDS
];
char
lowstr
[
MAXDATELEN
+
1
];
if
(
!
PointerIsValid
(
str
))
elog
(
ERROR
,
"Bad (null) date external representation"
);
if
((
ParseDateTime
(
str
,
lowstr
,
field
,
ftype
,
MAXDATEFIELDS
,
&
nf
)
!=
0
)
||
(
DecodeDateTime
(
field
,
ftype
,
nf
,
&
dtype
,
tm
,
&
fsec
,
&
tzp
)
!=
0
))
||
(
DecodeDateTime
(
field
,
ftype
,
nf
,
&
dtype
,
tm
,
&
fsec
,
&
tzp
)
!=
0
))
elog
(
ERROR
,
"Bad date external representation '%s'"
,
str
);
switch
(
dtype
)
...
...
@@ -75,15 +73,16 @@ date_in(char *str)
date
=
(
date2j
(
tm
->
tm_year
,
tm
->
tm_mon
,
tm
->
tm_mday
)
-
date2j
(
2000
,
1
,
1
));
return
date
;
}
/* date_in() */
PG_RETURN_DATEADT
(
date
)
;
}
/* date_out()
* Given internal format date, convert to text string.
*/
char
*
date_out
(
DateADT
date
)
Datum
date_out
(
PG_FUNCTION_ARGS
)
{
DateADT
date
=
PG_GETARG_DATEADT
(
0
);
char
*
result
;
struct
tm
tt
,
*
tm
=
&
tt
;
...
...
@@ -94,128 +93,160 @@ date_out(DateADT date)
EncodeDateOnly
(
tm
,
DateStyle
,
buf
);
result
=
palloc
(
strlen
(
buf
)
+
1
);
result
=
pstrdup
(
buf
);
PG_RETURN_CSTRING
(
result
);
}
strcpy
(
result
,
buf
);
Datum
date_eq
(
PG_FUNCTION_ARGS
)
{
DateADT
dateVal1
=
PG_GETARG_DATEADT
(
0
);
DateADT
dateVal2
=
PG_GETARG_DATEADT
(
1
);
return
result
;
}
/* date_out() */
PG_RETURN_BOOL
(
dateVal1
==
dateVal2
)
;
}
bool
date_
eq
(
DateADT
dateVal1
,
DateADT
dateVal2
)
Datum
date_
ne
(
PG_FUNCTION_ARGS
)
{
return
dateVal1
==
dateVal2
;
DateADT
dateVal1
=
PG_GETARG_DATEADT
(
0
);
DateADT
dateVal2
=
PG_GETARG_DATEADT
(
1
);
PG_RETURN_BOOL
(
dateVal1
!=
dateVal2
);
}
bool
date_
ne
(
DateADT
dateVal1
,
DateADT
dateVal2
)
Datum
date_
lt
(
PG_FUNCTION_ARGS
)
{
return
dateVal1
!=
dateVal2
;
DateADT
dateVal1
=
PG_GETARG_DATEADT
(
0
);
DateADT
dateVal2
=
PG_GETARG_DATEADT
(
1
);
PG_RETURN_BOOL
(
dateVal1
<
dateVal2
);
}
bool
date_l
t
(
DateADT
dateVal1
,
DateADT
dateVal2
)
Datum
date_l
e
(
PG_FUNCTION_ARGS
)
{
return
dateVal1
<
dateVal2
;
}
/* date_lt() */
DateADT
dateVal1
=
PG_GETARG_DATEADT
(
0
)
;
DateADT
dateVal2
=
PG_GETARG_DATEADT
(
1
);
bool
date_le
(
DateADT
dateVal1
,
DateADT
dateVal2
)
{
return
dateVal1
<=
dateVal2
;
}
/* date_le() */
PG_RETURN_BOOL
(
dateVal1
<=
dateVal2
);
}
bool
date_gt
(
DateADT
dateVal1
,
DateADT
dateVal2
)
Datum
date_gt
(
PG_FUNCTION_ARGS
)
{
return
dateVal1
>
dateVal2
;
}
/* date_gt() */
DateADT
dateVal1
=
PG_GETARG_DATEADT
(
0
);
DateADT
dateVal2
=
PG_GETARG_DATEADT
(
1
);
PG_RETURN_BOOL
(
dateVal1
>
dateVal2
);
}
bool
date_ge
(
DateADT
dateVal1
,
DateADT
dateVal2
)
Datum
date_ge
(
PG_FUNCTION_ARGS
)
{
return
dateVal1
>=
dateVal2
;
}
/* date_ge() */
DateADT
dateVal1
=
PG_GETARG_DATEADT
(
0
);
DateADT
dateVal2
=
PG_GETARG_DATEADT
(
1
);
PG_RETURN_BOOL
(
dateVal1
>=
dateVal2
);
}
int
date_cmp
(
DateADT
dateVal1
,
DateADT
dateVal2
)
Datum
date_cmp
(
PG_FUNCTION_ARGS
)
{
DateADT
dateVal1
=
PG_GETARG_DATEADT
(
0
);
DateADT
dateVal2
=
PG_GETARG_DATEADT
(
1
);
if
(
dateVal1
<
dateVal2
)
return
-
1
;
PG_RETURN_INT32
(
-
1
)
;
else
if
(
dateVal1
>
dateVal2
)
return
1
;
return
0
;
}
/* date_cmp() */
PG_RETURN_INT32
(
1
)
;
PG_RETURN_INT32
(
0
)
;
}
Dat
eADT
date_larger
(
DateADT
dateVal1
,
DateADT
dateVal2
)
Dat
um
date_larger
(
PG_FUNCTION_ARGS
)
{
return
date_gt
(
dateVal1
,
dateVal2
)
?
dateVal1
:
dateVal2
;
}
/* date_larger() */
DateADT
dateVal1
=
PG_GETARG_DATEADT
(
0
)
;
DateADT
dateVal2
=
PG_GETARG_DATEADT
(
1
);
DateADT
date_smaller
(
DateADT
dateVal1
,
DateADT
dateVal2
)
PG_RETURN_DATEADT
((
dateVal1
>
dateVal2
)
?
dateVal1
:
dateVal2
);
}
Datum
date_smaller
(
PG_FUNCTION_ARGS
)
{
return
date_lt
(
dateVal1
,
dateVal2
)
?
dateVal1
:
dateVal2
;
}
/* date_smaller() */
DateADT
dateVal1
=
PG_GETARG_DATEADT
(
0
);
DateADT
dateVal2
=
PG_GETARG_DATEADT
(
1
);
PG_RETURN_DATEADT
((
dateVal1
<
dateVal2
)
?
dateVal1
:
dateVal2
);
}
/* Compute difference between two dates in days.
*/
int4
date_mi
(
DateADT
dateVal1
,
DateADT
dateVal2
)
Datum
date_mi
(
PG_FUNCTION_ARGS
)
{
return
dateVal1
-
dateVal2
;
}
/* date_mi() */
DateADT
dateVal1
=
PG_GETARG_DATEADT
(
0
);
DateADT
dateVal2
=
PG_GETARG_DATEADT
(
1
);
PG_RETURN_INT32
((
int32
)
(
dateVal1
-
dateVal2
));
}
/* Add a number of days to a date, giving a new date.
* Must handle both positive and negative numbers of days.
*/
Dat
eADT
date_pli
(
DateADT
dateVal
,
int4
days
)
Dat
um
date_pli
(
PG_FUNCTION_ARGS
)
{
return
dateVal
+
days
;
}
/* date_pli() */
DateADT
dateVal
=
PG_GETARG_DATEADT
(
0
);
int32
days
=
PG_GETARG_INT32
(
1
);
PG_RETURN_DATEADT
(
dateVal
+
days
);
}
/* Subtract a number of days from a date, giving a new date.
*/
Dat
eADT
date_mii
(
DateADT
dateVal
,
int4
days
)
Dat
um
date_mii
(
PG_FUNCTION_ARGS
)
{
return
date_pli
(
dateVal
,
-
days
);
}
/* date_mii() */
DateADT
dateVal
=
PG_GETARG_DATEADT
(
0
);
int32
days
=
PG_GETARG_INT32
(
1
);
PG_RETURN_DATEADT
(
dateVal
-
days
);
}
/* date_timestamp()
* Convert date to timestamp data type.
*/
Timestamp
*
date_timestamp
(
DateADT
dateVal
)
Datum
date_timestamp
(
PG_FUNCTION_ARGS
)
{
Timestamp
*
result
;
DateADT
dateVal
=
PG_GETARG_DATEADT
(
0
);
Timestamp
result
;
struct
tm
tt
,
*
tm
=
&
tt
;
int
tz
;
double
fsec
=
0
;
char
*
tzn
;
result
=
palloc
(
sizeof
(
*
result
));
if
(
date2tm
(
dateVal
,
&
tz
,
tm
,
&
fsec
,
&
tzn
)
!=
0
)
elog
(
ERROR
,
"Unable to convert date to timestamp"
);
if
(
tm2timestamp
(
tm
,
fsec
,
&
tz
,
result
)
!=
0
)
if
(
tm2timestamp
(
tm
,
fsec
,
&
tz
,
&
result
)
!=
0
)
elog
(
ERROR
,
"Timestamp out of range"
);
return
result
;
}
/* date_timestamp() */
PG_RETURN_TIMESTAMP
(
result
)
;
}
/* timestamp_date()
* Convert timestamp to date data type.
*/
Dat
eADT
timestamp_date
(
Timestamp
*
timestamp
)
Dat
um
timestamp_date
(
PG_FUNCTION_ARGS
)
{
Timestamp
timestamp
=
PG_GETARG_TIMESTAMP
(
0
);
DateADT
result
;
struct
tm
tt
,
*
tm
=
&
tt
;
...
...
@@ -223,40 +254,36 @@ timestamp_date(Timestamp *timestamp)
double
fsec
;
char
*
tzn
;
if
(
!
PointerIsValid
(
timestamp
))
elog
(
ERROR
,
"Unable to convert null timestamp to date"
);
if
(
TIMESTAMP_NOT_FINITE
(
*
timestamp
))
if
(
TIMESTAMP_NOT_FINITE
(
timestamp
))
elog
(
ERROR
,
"Unable to convert timestamp to date"
);
if
(
TIMESTAMP_IS_EPOCH
(
*
timestamp
))
if
(
TIMESTAMP_IS_EPOCH
(
timestamp
))
{
timestamp2tm
(
SetTimestamp
(
*
timestamp
),
NULL
,
tm
,
&
fsec
,
NULL
);
timestamp2tm
(
SetTimestamp
(
timestamp
),
NULL
,
tm
,
&
fsec
,
NULL
);
}
else
if
(
TIMESTAMP_IS_CURRENT
(
*
timestamp
))
else
if
(
TIMESTAMP_IS_CURRENT
(
timestamp
))
{
timestamp2tm
(
SetTimestamp
(
*
timestamp
),
&
tz
,
tm
,
&
fsec
,
&
tzn
);
timestamp2tm
(
SetTimestamp
(
timestamp
),
&
tz
,
tm
,
&
fsec
,
&
tzn
);
}
else
{
if
(
timestamp2tm
(
*
timestamp
,
&
tz
,
tm
,
&
fsec
,
&
tzn
)
!=
0
)
if
(
timestamp2tm
(
timestamp
,
&
tz
,
tm
,
&
fsec
,
&
tzn
)
!=
0
)
elog
(
ERROR
,
"Unable to convert timestamp to date"
);
}
result
=
(
date2j
(
tm
->
tm_year
,
tm
->
tm_mon
,
tm
->
tm_mday
)
-
date2j
(
2000
,
1
,
1
)
);
result
=
date2j
(
tm
->
tm_year
,
tm
->
tm_mon
,
tm
->
tm_mday
)
-
date2j
(
2000
,
1
,
1
);
return
result
;
}
/* timestamp_date() */
PG_RETURN_DATEADT
(
result
)
;
}
/* abstime_date()
* Convert abstime to date data type.
*/
Dat
eADT
abstime_date
(
AbsoluteTime
abstime
)
Dat
um
abstime_date
(
PG_FUNCTION_ARGS
)
{
AbsoluteTime
abstime
=
PG_GETARG_ABSOLUTETIME
(
0
);
DateADT
result
;
struct
tm
tt
,
*
tm
=
&
tt
;
...
...
@@ -289,8 +316,8 @@ abstime_date(AbsoluteTime abstime)
break
;
}
return
result
;
}
/* abstime_date() */
PG_RETURN_DATEADT
(
result
)
;
}
/* date2tm()
...
...
@@ -372,243 +399,237 @@ date2tm(DateADT dateVal, int *tzp, struct tm * tm, double *fsec, char **tzn)
* Time ADT
*****************************************************************************/
TimeADT
*
time_in
(
char
*
str
)
Datum
time_in
(
PG_FUNCTION_ARGS
)
{
TimeADT
*
time
;
char
*
str
=
PG_GETARG_CSTRING
(
0
)
;
TimeADT
time
;
double
fsec
;
struct
tm
tt
,
*
tm
=
&
tt
;
int
nf
;
char
lowstr
[
MAXDATELEN
+
1
];
char
*
field
[
MAXDATEFIELDS
];
int
dtype
;
int
ftype
[
MAXDATEFIELDS
];
if
(
!
PointerIsValid
(
str
))
elog
(
ERROR
,
"Bad (null) time external representation"
);
if
((
ParseDateTime
(
str
,
lowstr
,
field
,
ftype
,
MAXDATEFIELDS
,
&
nf
)
!=
0
)
||
(
DecodeTimeOnly
(
field
,
ftype
,
nf
,
&
dtype
,
tm
,
&
fsec
,
NULL
)
!=
0
))
elog
(
ERROR
,
"Bad time external representation '%s'"
,
str
);
time
=
palloc
(
sizeof
(
*
time
));
*
time
=
((((
tm
->
tm_hour
*
60
)
+
tm
->
tm_min
)
*
60
)
+
tm
->
tm_sec
+
fsec
);
return
time
;
}
/* time_in() */
time
=
((((
tm
->
tm_hour
*
60
)
+
tm
->
tm_min
)
*
60
)
+
tm
->
tm_sec
+
fsec
);
PG_RETURN_TIMEADT
(
time
);
}
char
*
time_out
(
TimeADT
*
time
)
Datum
time_out
(
PG_FUNCTION_ARGS
)
{
TimeADT
time
=
PG_GETARG_TIMEADT
(
0
);
char
*
result
;
struct
tm
tt
,
*
tm
=
&
tt
;
double
fsec
;
char
buf
[
MAXDATELEN
+
1
];
if
(
!
PointerIsValid
(
time
))
return
NULL
;
tm
->
tm_hour
=
(
*
time
/
(
60
*
60
));
tm
->
tm_min
=
(((
int
)
(
*
time
/
60
))
%
60
);
tm
->
tm_sec
=
(((
int
)
*
time
)
%
60
);
tm
->
tm_hour
=
(
time
/
(
60
*
60
));
tm
->
tm_min
=
(((
int
)
(
time
/
60
))
%
60
);
tm
->
tm_sec
=
(((
int
)
time
)
%
60
);
fsec
=
0
;
EncodeTimeOnly
(
tm
,
fsec
,
NULL
,
DateStyle
,
buf
);
result
=
palloc
(
strlen
(
buf
)
+
1
);
result
=
pstrdup
(
buf
);
PG_RETURN_CSTRING
(
result
);
}
strcpy
(
result
,
buf
);
return
result
;
}
/* time_out() */
Datum
time_eq
(
PG_FUNCTION_ARGS
)
{
TimeADT
time1
=
PG_GETARG_TIMEADT
(
0
);
TimeADT
time2
=
PG_GETARG_TIMEADT
(
1
);
PG_RETURN_BOOL
(
time1
==
time2
);
}
bool
time_
eq
(
TimeADT
*
time1
,
TimeADT
*
time2
)
Datum
time_
ne
(
PG_FUNCTION_ARGS
)
{
if
(
!
PointerIsValid
(
time1
)
||
!
PointerIsValid
(
time2
))
return
FALSE
;
TimeADT
time1
=
PG_GETARG_TIMEADT
(
0
);
TimeADT
time2
=
PG_GETARG_TIMEADT
(
1
)
;
return
*
time1
==
*
time2
;
}
/* time_eq() */
PG_RETURN_BOOL
(
time1
!=
time2
)
;
}
bool
time_
ne
(
TimeADT
*
time1
,
TimeADT
*
time2
)
Datum
time_
lt
(
PG_FUNCTION_ARGS
)
{
if
(
!
PointerIsValid
(
time1
)
||
!
PointerIsValid
(
time2
))
return
FALSE
;
TimeADT
time1
=
PG_GETARG_TIMEADT
(
0
);
TimeADT
time2
=
PG_GETARG_TIMEADT
(
1
)
;
return
*
time1
!=
*
time2
;
}
/* time_eq() */
PG_RETURN_BOOL
(
time1
<
time2
)
;
}
bool
time_l
t
(
TimeADT
*
time1
,
TimeADT
*
time2
)
Datum
time_l
e
(
PG_FUNCTION_ARGS
)
{
if
(
!
PointerIsValid
(
time1
)
||
!
PointerIsValid
(
time2
))
return
FALSE
;
TimeADT
time1
=
PG_GETARG_TIMEADT
(
0
);
TimeADT
time2
=
PG_GETARG_TIMEADT
(
1
)
;
return
(
*
time1
<
*
time2
);
}
/* time_lt() */
PG_RETURN_BOOL
(
time1
<=
time2
);
}
bool
time_
le
(
TimeADT
*
time1
,
TimeADT
*
time2
)
Datum
time_
gt
(
PG_FUNCTION_ARGS
)
{
if
(
!
PointerIsValid
(
time1
)
||
!
PointerIsValid
(
time2
))
return
FALSE
;
TimeADT
time1
=
PG_GETARG_TIMEADT
(
0
);
TimeADT
time2
=
PG_GETARG_TIMEADT
(
1
)
;
return
(
*
time1
<=
*
time2
);
}
/* time_le() */
PG_RETURN_BOOL
(
time1
>
time2
);
}
bool
time_g
t
(
TimeADT
*
time1
,
TimeADT
*
time2
)
Datum
time_g
e
(
PG_FUNCTION_ARGS
)
{
if
(
!
PointerIsValid
(
time1
)
||
!
PointerIsValid
(
time2
))
return
FALSE
;
TimeADT
time1
=
PG_GETARG_TIMEADT
(
0
);
TimeADT
time2
=
PG_GETARG_TIMEADT
(
1
)
;
return
(
*
time1
>
*
time2
);
}
/* time_gt() */
PG_RETURN_BOOL
(
time1
>=
time2
);
}
bool
time_
ge
(
TimeADT
*
time1
,
TimeADT
*
time2
)
Datum
time_
cmp
(
PG_FUNCTION_ARGS
)
{
if
(
!
PointerIsValid
(
time1
)
||
!
PointerIsValid
(
time2
))
return
FALSE
;
TimeADT
time1
=
PG_GETARG_TIMEADT
(
0
);
TimeADT
time2
=
PG_GETARG_TIMEADT
(
1
)
;
return
(
*
time1
>=
*
time2
);
}
/* time_ge() */
if
(
time1
<
time2
)
PG_RETURN_INT32
(
-
1
);
if
(
time1
>
time2
)
PG_RETURN_INT32
(
1
);
PG_RETURN_INT32
(
0
);
}
int
time_
cmp
(
TimeADT
*
time1
,
TimeADT
*
time2
)
Datum
time_
larger
(
PG_FUNCTION_ARGS
)
{
return
(
*
time1
<
*
time2
)
?
-
1
:
(((
*
time1
>
*
time2
)
?
1
:
0
)
);
}
/* time_cmp() */
TimeADT
time1
=
PG_GETARG_TIMEADT
(
0
);
TimeADT
time2
=
PG_GETARG_TIMEADT
(
1
);
TimeADT
*
time_larger
(
TimeADT
*
time1
,
TimeADT
*
time2
)
{
return
time_gt
(
time1
,
time2
)
?
time1
:
time2
;
}
/* time_larger() */
PG_RETURN_TIMEADT
((
time1
>
time2
)
?
time1
:
time2
);
}
TimeADT
*
time_smaller
(
TimeADT
*
time1
,
TimeADT
*
time2
)
Datum
time_smaller
(
PG_FUNCTION_ARGS
)
{
return
time_lt
(
time1
,
time2
)
?
time1
:
time2
;
}
/* time_smaller() */
TimeADT
time1
=
PG_GETARG_TIMEADT
(
0
);
TimeADT
time2
=
PG_GETARG_TIMEADT
(
1
);
PG_RETURN_TIMEADT
((
time1
<
time2
)
?
time1
:
time2
);
}
/* overlaps_time()
* Implements the SQL92 OVERLAPS operator.
* Algorithm from Date and Darwen, 1997
*/
bool
overlaps_time
(
TimeADT
*
ts1
,
TimeADT
*
te1
,
TimeADT
*
ts2
,
TimeADT
*
te2
)
Datum
overlaps_time
(
PG_FUNCTION_ARGS
)
{
TimeADT
ts1
=
PG_GETARG_TIMEADT
(
0
);
TimeADT
te1
=
PG_GETARG_TIMEADT
(
1
);
TimeADT
ts2
=
PG_GETARG_TIMEADT
(
2
);
TimeADT
te2
=
PG_GETARG_TIMEADT
(
3
);
/* Make sure we have ordered pairs... */
if
(
t
ime_gt
(
ts1
,
te1
)
)
if
(
t
s1
>
te1
)
{
TimeADT
*
tt
=
ts1
;
TimeADT
tt
=
ts1
;
ts1
=
te1
;
te1
=
tt
;
}
if
(
t
ime_gt
(
ts2
,
te2
)
)
if
(
t
s2
>
te2
)
{
TimeADT
*
tt
=
ts2
;
TimeADT
tt
=
ts2
;
ts2
=
te2
;
te2
=
tt
;
}
return
((
time_gt
(
ts1
,
ts2
)
&&
(
time_lt
(
ts1
,
te2
)
||
time_lt
(
te1
,
te2
)))
||
(
time_gt
(
ts2
,
ts1
)
&&
(
time_lt
(
ts2
,
te1
)
||
time_lt
(
te2
,
te1
)))
||
time_eq
(
ts1
,
ts2
));
PG_RETURN_BOOL
((
ts1
>
ts2
&&
(
ts1
<
te2
||
te1
<
te2
))
||
(
ts1
<
ts2
&&
(
ts2
<
te1
||
te2
<
te1
))
||
(
ts1
==
ts2
));
}
/* timestamp_time()
* Convert timestamp to time data type.
*/
TimeADT
*
timestamp_time
(
Timestamp
*
timestamp
)
Datum
timestamp_time
(
PG_FUNCTION_ARGS
)
{
TimeADT
*
result
;
Timestamp
timestamp
=
PG_GETARG_TIMESTAMP
(
0
);
TimeADT
result
;
struct
tm
tt
,
*
tm
=
&
tt
;
int
tz
;
double
fsec
;
char
*
tzn
;
if
(
!
PointerIsValid
(
timestamp
))
elog
(
ERROR
,
"Unable to convert null timestamp to date"
);
if
(
TIMESTAMP_NOT_FINITE
(
*
timestamp
))
if
(
TIMESTAMP_NOT_FINITE
(
timestamp
))
elog
(
ERROR
,
"Unable to convert timestamp to date"
);
if
(
TIMESTAMP_IS_EPOCH
(
*
timestamp
))
timestamp2tm
(
SetTimestamp
(
*
timestamp
),
NULL
,
tm
,
&
fsec
,
NULL
);
else
if
(
TIMESTAMP_IS_CURRENT
(
*
timestamp
))
timestamp2tm
(
SetTimestamp
(
*
timestamp
),
&
tz
,
tm
,
&
fsec
,
&
tzn
);
if
(
TIMESTAMP_IS_EPOCH
(
timestamp
))
timestamp2tm
(
SetTimestamp
(
timestamp
),
NULL
,
tm
,
&
fsec
,
NULL
);
else
if
(
TIMESTAMP_IS_CURRENT
(
timestamp
))
timestamp2tm
(
SetTimestamp
(
timestamp
),
&
tz
,
tm
,
&
fsec
,
&
tzn
);
else
{
if
(
timestamp2tm
(
*
timestamp
,
&
tz
,
tm
,
&
fsec
,
&
tzn
)
!=
0
)
if
(
timestamp2tm
(
timestamp
,
&
tz
,
tm
,
&
fsec
,
&
tzn
)
!=
0
)
elog
(
ERROR
,
"Unable to convert timestamp to date"
);
}
result
=
palloc
(
sizeof
(
*
result
));
*
result
=
((((
tm
->
tm_hour
*
60
)
+
tm
->
tm_min
)
*
60
)
+
tm
->
tm_sec
+
fsec
);
result
=
((((
tm
->
tm_hour
*
60
)
+
tm
->
tm_min
)
*
60
)
+
tm
->
tm_sec
+
fsec
);
return
result
;
}
/* timestamp_time() */
PG_RETURN_TIMEADT
(
result
)
;
}
/* datetime_timestamp()
* Convert date and time to timestamp data type.
*/
Timestamp
*
datetime_timestamp
(
DateADT
date
,
TimeADT
*
time
)
Datum
datetime_timestamp
(
PG_FUNCTION_ARGS
)
{
Timestamp
*
result
;
DateADT
date
=
PG_GETARG_DATEADT
(
0
);
TimeADT
time
=
PG_GETARG_TIMEADT
(
1
);
Timestamp
result
;
if
(
!
PointerIsValid
(
time
))
{
result
=
palloc
(
sizeof
(
*
result
));
TIMESTAMP_INVALID
(
*
result
);
}
else
{
result
=
date_timestamp
(
date
);
*
result
+=
*
time
;
}
result
=
DatumGetTimestamp
(
DirectFunctionCall1
(
date_timestamp
,
DateADTGetDatum
(
date
)));
result
+=
time
;
return
result
;
}
/* datetime_timestamp() */
PG_RETURN_TIMESTAMP
(
result
)
;
}
/* time_interval()
* Convert time to interval data type.
*/
Interval
*
time_interval
(
TimeADT
*
time
)
Datum
time_interval
(
PG_FUNCTION_ARGS
)
{
TimeADT
time
=
PG_GETARG_TIMEADT
(
0
);
Interval
*
result
;
if
(
!
PointerIsValid
(
time
))
return
NULL
;
result
=
(
Interval
*
)
palloc
(
sizeof
(
Interval
));
result
=
palloc
(
sizeof
(
*
result
));
result
->
time
=
*
time
;
result
->
time
=
time
;
result
->
month
=
0
;
return
result
;
}
/* time_interval() */
PG_RETURN_INTERVAL_P
(
result
)
;
}
/*****************************************************************************
...
...
@@ -616,52 +637,44 @@ time_interval(TimeADT *time)
*****************************************************************************/
TimeTzADT
*
timetz_in
(
char
*
str
)
Datum
timetz_in
(
PG_FUNCTION_ARGS
)
{
char
*
str
=
PG_GETARG_CSTRING
(
0
);
TimeTzADT
*
time
;
double
fsec
;
struct
tm
tt
,
*
tm
=
&
tt
;
int
tz
;
int
nf
;
char
lowstr
[
MAXDATELEN
+
1
];
char
*
field
[
MAXDATEFIELDS
];
int
dtype
;
int
ftype
[
MAXDATEFIELDS
];
if
(
!
PointerIsValid
(
str
))
elog
(
ERROR
,
"Bad (null) time external representation"
);
if
((
ParseDateTime
(
str
,
lowstr
,
field
,
ftype
,
MAXDATEFIELDS
,
&
nf
)
!=
0
)
||
(
DecodeTimeOnly
(
field
,
ftype
,
nf
,
&
dtype
,
tm
,
&
fsec
,
&
tz
)
!=
0
))
elog
(
ERROR
,
"Bad time external representation '%s'"
,
str
);
time
=
palloc
(
sizeof
(
*
time
));
time
=
(
TimeTzADT
*
)
palloc
(
sizeof
(
TimeTzADT
));
time
->
time
=
((((
tm
->
tm_hour
*
60
)
+
tm
->
tm_min
)
*
60
)
+
tm
->
tm_sec
+
fsec
);
time
->
zone
=
tz
;
return
time
;
}
/* timetz_in() */
PG_RETURN_TIMETZADT_P
(
time
);
}
char
*
timetz_out
(
TimeTzADT
*
time
)
Datum
timetz_out
(
PG_FUNCTION_ARGS
)
{
TimeTzADT
*
time
=
PG_GETARG_TIMETZADT_P
(
0
);
char
*
result
;
struct
tm
tt
,
*
tm
=
&
tt
;
double
fsec
;
int
tz
;
char
buf
[
MAXDATELEN
+
1
];
if
(
!
PointerIsValid
(
time
))
return
NULL
;
tm
->
tm_hour
=
(
time
->
time
/
(
60
*
60
));
tm
->
tm_min
=
(((
int
)
(
time
->
time
/
60
))
%
60
);
tm
->
tm_sec
=
(((
int
)
time
->
time
)
%
60
);
...
...
@@ -671,120 +684,164 @@ timetz_out(TimeTzADT *time)
EncodeTimeOnly
(
tm
,
fsec
,
&
tz
,
DateStyle
,
buf
);
result
=
palloc
(
strlen
(
buf
)
+
1
);
strcpy
(
result
,
buf
);
return
result
;
}
/* timetz_out() */
result
=
pstrdup
(
buf
);
PG_RETURN_CSTRING
(
result
);
}
bool
timetz_eq
(
TimeTzADT
*
time1
,
TimeTzADT
*
time2
)
Datum
timetz_eq
(
PG_FUNCTION_ARGS
)
{
if
(
!
PointerIsValid
(
time1
)
||
!
PointerIsValid
(
time2
))
return
FALSE
;
TimeTzADT
*
time1
=
PG_GETARG_TIMETZADT_P
(
0
);
TimeTzADT
*
time2
=
PG_GETARG_TIMETZADT_P
(
1
)
;
return
((
time1
->
time
+
time1
->
zone
)
==
(
time2
->
time
+
time2
->
zone
));
}
/* timetz_eq() */
PG_RETURN_BOOL
(((
time1
->
time
+
time1
->
zone
)
==
(
time2
->
time
+
time2
->
zone
)
));
}
bool
timetz_ne
(
TimeTzADT
*
time1
,
TimeTzADT
*
time2
)
Datum
timetz_ne
(
PG_FUNCTION_ARGS
)
{
if
(
!
PointerIsValid
(
time1
)
||
!
PointerIsValid
(
time2
))
return
FALSE
;
TimeTzADT
*
time1
=
PG_GETARG_TIMETZADT_P
(
0
);
TimeTzADT
*
time2
=
PG_GETARG_TIMETZADT_P
(
1
)
;
return
((
time1
->
time
+
time1
->
zone
)
!=
(
time2
->
time
+
time2
->
zone
));
}
/* timetz_ne() */
PG_RETURN_BOOL
(((
time1
->
time
+
time1
->
zone
)
!=
(
time2
->
time
+
time2
->
zone
)
));
}
bool
timetz_lt
(
TimeTzADT
*
time1
,
TimeTzADT
*
time2
)
Datum
timetz_lt
(
PG_FUNCTION_ARGS
)
{
if
(
!
PointerIsValid
(
time1
)
||
!
PointerIsValid
(
time2
))
return
FALSE
;
TimeTzADT
*
time1
=
PG_GETARG_TIMETZADT_P
(
0
);
TimeTzADT
*
time2
=
PG_GETARG_TIMETZADT_P
(
1
)
;
return
((
time1
->
time
+
time1
->
zone
)
<
(
time2
->
time
+
time2
->
zone
));
}
/* timetz_lt() */
PG_RETURN_BOOL
(((
time1
->
time
+
time1
->
zone
)
<
(
time2
->
time
+
time2
->
zone
)
));
}
bool
timetz_le
(
TimeTzADT
*
time1
,
TimeTzADT
*
time2
)
Datum
timetz_le
(
PG_FUNCTION_ARGS
)
{
if
(
!
PointerIsValid
(
time1
)
||
!
PointerIsValid
(
time2
))
return
FALSE
;
TimeTzADT
*
time1
=
PG_GETARG_TIMETZADT_P
(
0
);
TimeTzADT
*
time2
=
PG_GETARG_TIMETZADT_P
(
1
)
;
return
((
time1
->
time
+
time1
->
zone
)
<=
(
time2
->
time
+
time2
->
zone
));
}
/* timetz_le() */
PG_RETURN_BOOL
(((
time1
->
time
+
time1
->
zone
)
<=
(
time2
->
time
+
time2
->
zone
)
));
}
bool
timetz_gt
(
TimeTzADT
*
time1
,
TimeTzADT
*
time2
)
Datum
timetz_gt
(
PG_FUNCTION_ARGS
)
{
if
(
!
PointerIsValid
(
time1
)
||
!
PointerIsValid
(
time2
))
return
FALSE
;
TimeTzADT
*
time1
=
PG_GETARG_TIMETZADT_P
(
0
);
TimeTzADT
*
time2
=
PG_GETARG_TIMETZADT_P
(
1
)
;
return
((
time1
->
time
+
time1
->
zone
)
>
(
time2
->
time
+
time2
->
zone
));
}
/* timetz_gt() */
PG_RETURN_BOOL
(((
time1
->
time
+
time1
->
zone
)
>
(
time2
->
time
+
time2
->
zone
)
));
}
bool
timetz_ge
(
TimeTzADT
*
time1
,
TimeTzADT
*
time2
)
Datum
timetz_ge
(
PG_FUNCTION_ARGS
)
{
if
(
!
PointerIsValid
(
time1
)
||
!
PointerIsValid
(
time2
))
return
FALSE
;
TimeTzADT
*
time1
=
PG_GETARG_TIMETZADT_P
(
0
);
TimeTzADT
*
time2
=
PG_GETARG_TIMETZADT_P
(
1
)
;
return
((
time1
->
time
+
time1
->
zone
)
>=
(
time2
->
time
+
time2
->
zone
));
}
/* timetz_ge() */
PG_RETURN_BOOL
(((
time1
->
time
+
time1
->
zone
)
>=
(
time2
->
time
+
time2
->
zone
)
));
}
int
timetz_cmp
(
TimeTzADT
*
time1
,
TimeTzADT
*
time2
)
{
return
(
timetz_lt
(
time1
,
time2
)
?
-
1
:
(
timetz_gt
(
time1
,
time2
)
?
1
:
0
));
}
/* timetz_cmp() */
Datum
timetz_cmp
(
PG_FUNCTION_ARGS
)
{
TimeTzADT
*
time1
=
PG_GETARG_TIMETZADT_P
(
0
);
TimeTzADT
*
time2
=
PG_GETARG_TIMETZADT_P
(
1
);
if
(
DatumGetBool
(
DirectFunctionCall2
(
timetz_lt
,
TimeTzADTPGetDatum
(
time1
),
TimeTzADTPGetDatum
(
time2
))))
PG_RETURN_INT32
(
-
1
);
if
(
DatumGetBool
(
DirectFunctionCall2
(
timetz_gt
,
TimeTzADTPGetDatum
(
time1
),
TimeTzADTPGetDatum
(
time2
))))
PG_RETURN_INT32
(
1
);
PG_RETURN_INT32
(
0
);
}
TimeTzADT
*
timetz_larger
(
TimeTzADT
*
time1
,
TimeTzADT
*
time2
)
Datum
timetz_larger
(
PG_FUNCTION_ARGS
)
{
return
timetz_gt
(
time1
,
time2
)
?
time1
:
time2
;
}
/* timetz_larger() */
TimeTzADT
*
time1
=
PG_GETARG_TIMETZADT_P
(
0
);
TimeTzADT
*
time2
=
PG_GETARG_TIMETZADT_P
(
1
);
if
(
DatumGetBool
(
DirectFunctionCall2
(
timetz_gt
,
TimeTzADTPGetDatum
(
time1
),
TimeTzADTPGetDatum
(
time2
))))
PG_RETURN_TIMETZADT_P
(
time1
);
PG_RETURN_TIMETZADT_P
(
time2
);
}
TimeTzADT
*
timetz_smaller
(
TimeTzADT
*
time1
,
TimeTzADT
*
time2
)
Datum
timetz_smaller
(
PG_FUNCTION_ARGS
)
{
return
timetz_lt
(
time1
,
time2
)
?
time1
:
time2
;
}
/* timetz_smaller() */
TimeTzADT
*
time1
=
PG_GETARG_TIMETZADT_P
(
0
);
TimeTzADT
*
time2
=
PG_GETARG_TIMETZADT_P
(
1
);
if
(
DatumGetBool
(
DirectFunctionCall2
(
timetz_lt
,
TimeTzADTPGetDatum
(
time1
),
TimeTzADTPGetDatum
(
time2
))))
PG_RETURN_TIMETZADT_P
(
time1
);
PG_RETURN_TIMETZADT_P
(
time2
);
}
/* overlaps_timetz()
* Implements the SQL92 OVERLAPS operator.
* Algorithm from Date and Darwen, 1997
*/
bool
overlaps_timetz
(
TimeTzADT
*
ts1
,
TimeTzADT
*
te1
,
TimeTzADT
*
ts2
,
TimeTzADT
*
te2
)
{
Datum
overlaps_timetz
(
PG_FUNCTION_ARGS
)
{
/* The arguments are TimeTzADT *, but we leave them as generic Datums
* for convenience of notation.
*/
Datum
ts1
=
PG_GETARG_DATUM
(
0
);
Datum
te1
=
PG_GETARG_DATUM
(
1
);
Datum
ts2
=
PG_GETARG_DATUM
(
2
);
Datum
te2
=
PG_GETARG_DATUM
(
3
);
#define TIMETZ_GT(t1,t2) \
DatumGetBool(DirectFunctionCall2(timetz_gt,t1,t2))
#define TIMETZ_LT(t1,t2) \
DatumGetBool(DirectFunctionCall2(timetz_lt,t1,t2))
#define TIMETZ_EQ(t1,t2) \
DatumGetBool(DirectFunctionCall2(timetz_eq,t1,t2))
/* Make sure we have ordered pairs... */
if
(
timetz_gt
(
ts1
,
te1
))
if
(
TIMETZ_GT
(
ts1
,
te1
))
{
TimeTzADT
*
tt
=
ts1
;
Datum
tt
=
ts1
;
ts1
=
te1
;
te1
=
tt
;
}
if
(
timetz_gt
(
ts2
,
te2
))
if
(
TIMETZ_GT
(
ts2
,
te2
))
{
TimeTzADT
*
tt
=
ts2
;
Datum
tt
=
ts2
;
ts2
=
te2
;
te2
=
tt
;
}
return
((
timetz_gt
(
ts1
,
ts2
)
&&
(
timetz_lt
(
ts1
,
te2
)
||
timetz_lt
(
te1
,
te2
)))
||
(
timetz_gt
(
ts2
,
ts1
)
&&
(
timetz_lt
(
ts2
,
te1
)
||
timetz_lt
(
te2
,
te1
)))
||
timetz_eq
(
ts1
,
ts2
));
}
/* overlaps_timetz() */
PG_RETURN_BOOL
((
TIMETZ_GT
(
ts1
,
ts2
)
&&
(
TIMETZ_LT
(
ts1
,
te2
)
||
TIMETZ_LT
(
te1
,
te2
)))
||
(
TIMETZ_GT
(
ts2
,
ts1
)
&&
(
TIMETZ_LT
(
ts2
,
te1
)
||
TIMETZ_LT
(
te2
,
te1
)))
||
TIMETZ_EQ
(
ts1
,
ts2
));
#undef TIMETZ_GT
#undef TIMETZ_LT
#undef TIMETZ_EQ
}
/* timestamp_timetz()
* Convert timestamp to timetz data type.
*/
TimeTzADT
*
timestamp_timetz
(
Timestamp
*
timestamp
)
Datum
timestamp_timetz
(
PG_FUNCTION_ARGS
)
{
Timestamp
timestamp
=
PG_GETARG_TIMESTAMP
(
0
);
TimeTzADT
*
result
;
struct
tm
tt
,
*
tm
=
&
tt
;
...
...
@@ -792,32 +849,29 @@ timestamp_timetz(Timestamp *timestamp)
double
fsec
;
char
*
tzn
;
if
(
!
PointerIsValid
(
timestamp
))
elog
(
ERROR
,
"Unable to convert null timestamp to date"
);
if
(
TIMESTAMP_NOT_FINITE
(
*
timestamp
))
if
(
TIMESTAMP_NOT_FINITE
(
timestamp
))
elog
(
ERROR
,
"Unable to convert timestamp to date"
);
if
(
TIMESTAMP_IS_EPOCH
(
*
timestamp
))
if
(
TIMESTAMP_IS_EPOCH
(
timestamp
))
{
timestamp2tm
(
SetTimestamp
(
*
timestamp
),
NULL
,
tm
,
&
fsec
,
NULL
);
timestamp2tm
(
SetTimestamp
(
timestamp
),
NULL
,
tm
,
&
fsec
,
NULL
);
tz
=
0
;
}
else
if
(
TIMESTAMP_IS_CURRENT
(
*
timestamp
))
timestamp2tm
(
SetTimestamp
(
*
timestamp
),
&
tz
,
tm
,
&
fsec
,
&
tzn
);
else
if
(
TIMESTAMP_IS_CURRENT
(
timestamp
))
timestamp2tm
(
SetTimestamp
(
timestamp
),
&
tz
,
tm
,
&
fsec
,
&
tzn
);
else
{
if
(
timestamp2tm
(
*
timestamp
,
&
tz
,
tm
,
&
fsec
,
&
tzn
)
!=
0
)
if
(
timestamp2tm
(
timestamp
,
&
tz
,
tm
,
&
fsec
,
&
tzn
)
!=
0
)
elog
(
ERROR
,
"Unable to convert timestamp to date"
);
}
result
=
palloc
(
sizeof
(
*
result
));
result
=
(
TimeTzADT
*
)
palloc
(
sizeof
(
TimeTzADT
));
result
->
time
=
((((
tm
->
tm_hour
*
60
)
+
tm
->
tm_min
)
*
60
)
+
tm
->
tm_sec
+
fsec
);
result
->
zone
=
tz
;
return
result
;
}
/* timestamp_timetz() */
PG_RETURN_TIMETZADT_P
(
result
)
;
}
/* datetimetz_timestamp()
...
...
@@ -826,30 +880,25 @@ timestamp_timetz(Timestamp *timestamp)
* stored with the timetz to the result.
* - thomas 2000-03-10
*/
Timestamp
*
datetimetz_timestamp
(
DateADT
date
,
TimeTzADT
*
time
)
Datum
datetimetz_timestamp
(
PG_FUNCTION_ARGS
)
{
Timestamp
*
result
;
DateADT
date
=
PG_GETARG_DATEADT
(
0
);
TimeTzADT
*
time
=
PG_GETARG_TIMETZADT_P
(
1
);
Timestamp
result
;
struct
tm
tt
,
*
tm
=
&
tt
;
int
tz
;
double
fsec
=
0
;
char
*
tzn
;
result
=
palloc
(
sizeof
(
*
result
));
if
(
!
PointerIsValid
(
date
)
||
!
PointerIsValid
(
time
))
TIMESTAMP_INVALID
(
*
result
);
else
{
if
(
date2tm
(
date
,
&
tz
,
tm
,
&
fsec
,
&
tzn
)
!=
0
)
elog
(
ERROR
,
"Unable to convert date to timestamp"
);
if
(
date2tm
(
date
,
&
tz
,
tm
,
&
fsec
,
&
tzn
)
!=
0
)
elog
(
ERROR
,
"Unable to convert date to timestamp"
);
if
(
tm2timestamp
(
tm
,
fsec
,
&
time
->
zone
,
result
)
!=
0
)
elog
(
ERROR
,
"Timestamp out of range"
);
if
(
tm2timestamp
(
tm
,
fsec
,
&
time
->
zone
,
&
result
)
!=
0
)
elog
(
ERROR
,
"Timestamp out of range"
);
*
result
+=
time
->
time
;
}
result
+=
time
->
time
;
return
result
;
}
/* datetimetz_timestamp() */
PG_RETURN_TIMESTAMP
(
result
)
;
}
src/backend/utils/adt/formatting.c
View file @
ae526b40
/* -----------------------------------------------------------------------
* formatting.c
*
* $Header: /cvsroot/pgsql/src/backend/utils/adt/formatting.c,v 1.
9 2000/06/05 07:28:51
tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/formatting.c,v 1.
10 2000/06/09 01:11:08
tgl Exp $
*
*
* Portions Copyright (c) 1999-2000, PostgreSQL, Inc
...
...
@@ -2372,9 +2372,11 @@ DCH_cache_search(char *str)
* TIMESTAMP to_char()
* -------------------
*/
text
*
timestamp_to_char
(
Timestamp
*
dt
,
text
*
fmt
)
Datum
timestamp_to_char
(
PG_FUNCTION_ARGS
)
{
Timestamp
dt
=
PG_GETARG_TIMESTAMP
(
0
);
text
*
fmt
=
PG_GETARG_TEXT_P
(
1
);
text
*
result
,
*
result_tmp
;
FormatNode
*
format
;
...
...
@@ -2386,13 +2388,10 @@ timestamp_to_char(Timestamp *dt, text *fmt)
flag
=
0
,
x
=
0
;
if
((
!
PointerIsValid
(
dt
))
||
(
!
PointerIsValid
(
fmt
)))
return
NULL
;
len
=
VARSIZE
(
fmt
)
-
VARHDRSZ
;
if
((
!
len
)
||
(
TIMESTAMP_NOT_FINITE
(
*
dt
)))
return
textin
(
""
);
if
((
!
len
)
||
(
TIMESTAMP_NOT_FINITE
(
dt
)))
return
PointerGetDatum
(
textin
(
""
)
);
tm
->
tm_sec
=
0
;
tm
->
tm_year
=
0
;
...
...
@@ -2404,18 +2403,18 @@ timestamp_to_char(Timestamp *dt, text *fmt)
tm
->
tm_isdst
=
0
;
tm
->
tm_mon
=
1
;
if
(
TIMESTAMP_IS_EPOCH
(
*
dt
))
if
(
TIMESTAMP_IS_EPOCH
(
dt
))
{
x
=
timestamp2tm
(
SetTimestamp
(
*
dt
),
NULL
,
tm
,
&
fsec
,
NULL
);
x
=
timestamp2tm
(
SetTimestamp
(
dt
),
NULL
,
tm
,
&
fsec
,
NULL
);
}
else
if
(
TIMESTAMP_IS_CURRENT
(
*
dt
))
else
if
(
TIMESTAMP_IS_CURRENT
(
dt
))
{
x
=
timestamp2tm
(
SetTimestamp
(
*
dt
),
&
tz
,
tm
,
&
fsec
,
&
tzn
);
x
=
timestamp2tm
(
SetTimestamp
(
dt
),
&
tz
,
tm
,
&
fsec
,
&
tzn
);
}
else
x
=
timestamp2tm
(
*
dt
,
&
tz
,
tm
,
&
fsec
,
&
tzn
);
x
=
timestamp2tm
(
dt
,
&
tz
,
tm
,
&
fsec
,
&
tzn
);
if
(
x
!=
0
)
elog
(
ERROR
,
"to_char(): Unable to convert timestamp to tm"
);
...
...
@@ -2508,7 +2507,7 @@ timestamp_to_char(Timestamp *dt, text *fmt)
VARSIZE
(
result
)
=
len
+
VARHDRSZ
;
pfree
(
result_tmp
);
return
result
;
PG_RETURN_TEXT_P
(
result
)
;
}
...
...
@@ -2519,20 +2518,19 @@ timestamp_to_char(Timestamp *dt, text *fmt)
* ( to_timestamp is reverse to_char() )
* ---------------------
*/
Timestamp
*
to_timestamp
(
text
*
date_str
,
text
*
fmt
)
Datum
to_timestamp
(
PG_FUNCTION_ARGS
)
{
text
*
date_str
=
PG_GETARG_TEXT_P
(
0
);
text
*
fmt
=
PG_GETARG_TEXT_P
(
1
);
FormatNode
*
format
;
int
flag
=
0
;
Timestamp
*
result
;
Timestamp
result
;
char
*
str
;
int
len
=
0
,
fsec
=
0
,
tz
=
0
;
if
((
!
PointerIsValid
(
date_str
))
||
(
!
PointerIsValid
(
fmt
)))
return
NULL
;
tm
->
tm_sec
=
0
;
tm
->
tm_year
=
0
;
tm
->
tm_min
=
0
;
...
...
@@ -2543,8 +2541,6 @@ to_timestamp(text *date_str, text *fmt)
tm
->
tm_isdst
=
0
;
tm
->
tm_mon
=
1
;
result
=
palloc
(
sizeof
(
Timestamp
));
len
=
VARSIZE
(
fmt
)
-
VARHDRSZ
;
if
(
len
)
...
...
@@ -2668,10 +2664,10 @@ to_timestamp(text *date_str, text *fmt)
#ifdef DEBUG_TO_FROM_CHAR
NOTICE_TM
;
#endif
if
(
tm2timestamp
(
tm
,
fsec
,
&
tz
,
result
)
!=
0
)
elog
(
ERROR
,
"to_
datatime
(): can't convert 'tm' to timestamp."
);
if
(
tm2timestamp
(
tm
,
fsec
,
&
tz
,
&
result
)
!=
0
)
elog
(
ERROR
,
"to_
timestamp
(): can't convert 'tm' to timestamp."
);
return
result
;
PG_RETURN_TIMESTAMP
(
result
)
;
}
/* ----------
...
...
@@ -2679,10 +2675,13 @@ to_timestamp(text *date_str, text *fmt)
* Make Date from date_str which is formated at argument 'fmt'
* ----------
*/
Dat
eADT
to_date
(
text
*
date_str
,
text
*
fmt
)
Dat
um
to_date
(
PG_FUNCTION_ARGS
)
{
return
timestamp_date
(
to_timestamp
(
date_str
,
fmt
));
/* Quick hack: since our inputs are just like to_timestamp,
* hand over the whole input info struct...
*/
return
DirectFunctionCall1
(
timestamp_date
,
to_timestamp
(
fcinfo
));
}
/**********************************************************************
...
...
src/backend/utils/adt/nabstime.c
View file @
ae526b40
...
...
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.6
8 2000/05/29 19:16:57
tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.6
9 2000/06/09 01:11:08
tgl Exp $
*
* NOTES
*
...
...
@@ -85,8 +85,14 @@ static AbsoluteTime tm2abstime(struct tm * tm, int tz);
#define INVALID_INTERVAL_STR "Undefined Range"
#define INVALID_INTERVAL_STR_LEN (sizeof(INVALID_INTERVAL_STR)-1)
#define ABSTIMEMIN(t1, t2) abstimele((t1),(t2)) ? (t1) : (t2)
#define ABSTIMEMAX(t1, t2) abstimelt((t1),(t2)) ? (t2) : (t1)
#define ABSTIMEMIN(t1, t2) \
(DatumGetBool(DirectFunctionCall2(abstimele, \
AbsoluteTimeGetDatum(t1), \
AbsoluteTimeGetDatum(t2))) ? (t1) : (t2))
#define ABSTIMEMAX(t1, t2) \
(DatumGetBool(DirectFunctionCall2(abstimelt, \
AbsoluteTimeGetDatum(t1), \
AbsoluteTimeGetDatum(t2))) ? (t2) : (t1))
#ifdef NOT_USED
static
char
*
unit_tab
[]
=
{
...
...
@@ -341,25 +347,21 @@ tm2abstime(struct tm * tm, int tz)
/* nabstimein()
* Decode date/time string and return abstime.
*/
AbsoluteTime
nabstimein
(
char
*
str
)
Datum
nabstimein
(
PG_FUNCTION_ARGS
)
{
char
*
str
=
PG_GETARG_CSTRING
(
0
);
AbsoluteTime
result
;
double
fsec
;
int
tz
=
0
;
struct
tm
date
,
*
tm
=
&
date
;
char
*
field
[
MAXDATEFIELDS
];
char
lowstr
[
MAXDATELEN
+
1
];
int
dtype
;
int
nf
,
ftype
[
MAXDATEFIELDS
];
if
(
!
PointerIsValid
(
str
))
elog
(
ERROR
,
"Bad (null) abstime external representation"
);
if
(
strlen
(
str
)
>
MAXDATELEN
)
elog
(
ERROR
,
"Bad (length) abstime external representation '%s'"
,
str
);
...
...
@@ -399,16 +401,17 @@ nabstimein(char *str)
break
;
};
return
result
;
}
/* nabstimein() */
PG_RETURN_ABSOLUTETIME
(
result
)
;
}
/* nabstimeout()
* Given an AbsoluteTime return the English text version of the date
*/
char
*
nabstimeout
(
AbsoluteTime
time
)
Datum
nabstimeout
(
PG_FUNCTION_ARGS
)
{
AbsoluteTime
time
=
PG_GETARG_ABSOLUTETIME
(
0
);
char
*
result
;
int
tz
;
double
fsec
=
0
;
...
...
@@ -441,11 +444,9 @@ nabstimeout(AbsoluteTime time)
break
;
}
result
=
palloc
(
strlen
(
buf
)
+
1
);
strcpy
(
result
,
buf
);
return
result
;
}
/* nabstimeout() */
result
=
pstrdup
(
buf
);
PG_RETURN_CSTRING
(
result
);
}
/*
...
...
@@ -487,195 +488,204 @@ AbsoluteTimeIsAfter(AbsoluteTime time1, AbsoluteTime time2)
/* abstime_finite()
*/
bool
abstime_finite
(
AbsoluteTime
abstime
)
Datum
abstime_finite
(
PG_FUNCTION_ARGS
)
{
return
((
abstime
!=
INVALID_ABSTIME
)
&&
(
abstime
!=
NOSTART_ABSTIME
)
&&
(
abstime
!=
NOEND_ABSTIME
));
}
/* abstime_finite() */
AbsoluteTime
abstime
=
PG_GETARG_ABSOLUTETIME
(
0
);
PG_RETURN_BOOL
((
abstime
!=
INVALID_ABSTIME
)
&&
(
abstime
!=
NOSTART_ABSTIME
)
&&
(
abstime
!=
NOEND_ABSTIME
));
}
/*
* abstimeeq - returns
1,
iff arguments are equal
* abstimene - returns
1,
iff arguments are not equal
* abstimelt - returns
1,
iff t1 less than t2
* abstimegt - returns
1,
iff t1 greater than t2
* abstimele - returns
1,
iff t1 less than or equal to t2
* abstimege - returns
1,
iff t1 greater than or equal to t2
* abstimeeq - returns
true
iff arguments are equal
* abstimene - returns
true
iff arguments are not equal
* abstimelt - returns
true
iff t1 less than t2
* abstimegt - returns
true
iff t1 greater than t2
* abstimele - returns
true
iff t1 less than or equal to t2
* abstimege - returns
true
iff t1 greater than or equal to t2
*/
bool
abstimeeq
(
AbsoluteTime
t1
,
AbsoluteTime
t2
)
Datum
abstimeeq
(
PG_FUNCTION_ARGS
)
{
AbsoluteTime
t1
=
PG_GETARG_ABSOLUTETIME
(
0
);
AbsoluteTime
t2
=
PG_GETARG_ABSOLUTETIME
(
1
);
if
(
t1
==
INVALID_ABSTIME
||
t2
==
INVALID_ABSTIME
)
return
FALSE
;
PG_RETURN_BOOL
(
false
)
;
if
(
t1
==
CURRENT_ABSTIME
)
t1
=
GetCurrentTransactionStartTime
();
if
(
t2
==
CURRENT_ABSTIME
)
t2
=
GetCurrentTransactionStartTime
();
return
t1
==
t2
;
PG_RETURN_BOOL
(
t1
==
t2
)
;
}
bool
abstimene
(
AbsoluteTime
t1
,
AbsoluteTime
t2
)
Datum
abstimene
(
PG_FUNCTION_ARGS
)
{
AbsoluteTime
t1
=
PG_GETARG_ABSOLUTETIME
(
0
);
AbsoluteTime
t2
=
PG_GETARG_ABSOLUTETIME
(
1
);
if
(
t1
==
INVALID_ABSTIME
||
t2
==
INVALID_ABSTIME
)
return
FALSE
;
PG_RETURN_BOOL
(
false
)
;
if
(
t1
==
CURRENT_ABSTIME
)
t1
=
GetCurrentTransactionStartTime
();
if
(
t2
==
CURRENT_ABSTIME
)
t2
=
GetCurrentTransactionStartTime
();
return
t1
!=
t2
;
PG_RETURN_BOOL
(
t1
!=
t2
)
;
}
bool
abstimelt
(
AbsoluteTime
t1
,
AbsoluteTime
t2
)
Datum
abstimelt
(
PG_FUNCTION_ARGS
)
{
AbsoluteTime
t1
=
PG_GETARG_ABSOLUTETIME
(
0
);
AbsoluteTime
t2
=
PG_GETARG_ABSOLUTETIME
(
1
);
if
(
t1
==
INVALID_ABSTIME
||
t2
==
INVALID_ABSTIME
)
return
FALSE
;
PG_RETURN_BOOL
(
false
)
;
if
(
t1
==
CURRENT_ABSTIME
)
t1
=
GetCurrentTransactionStartTime
();
if
(
t2
==
CURRENT_ABSTIME
)
t2
=
GetCurrentTransactionStartTime
();
return
t1
<
t2
;
PG_RETURN_BOOL
(
t1
<
t2
)
;
}
bool
abstimegt
(
AbsoluteTime
t1
,
AbsoluteTime
t2
)
Datum
abstimegt
(
PG_FUNCTION_ARGS
)
{
AbsoluteTime
t1
=
PG_GETARG_ABSOLUTETIME
(
0
);
AbsoluteTime
t2
=
PG_GETARG_ABSOLUTETIME
(
1
);
if
(
t1
==
INVALID_ABSTIME
||
t2
==
INVALID_ABSTIME
)
return
FALSE
;
PG_RETURN_BOOL
(
false
)
;
if
(
t1
==
CURRENT_ABSTIME
)
t1
=
GetCurrentTransactionStartTime
();
if
(
t2
==
CURRENT_ABSTIME
)
t2
=
GetCurrentTransactionStartTime
();
return
t1
>
t2
;
PG_RETURN_BOOL
(
t1
>
t2
)
;
}
bool
abstimele
(
AbsoluteTime
t1
,
AbsoluteTime
t2
)
Datum
abstimele
(
PG_FUNCTION_ARGS
)
{
AbsoluteTime
t1
=
PG_GETARG_ABSOLUTETIME
(
0
);
AbsoluteTime
t2
=
PG_GETARG_ABSOLUTETIME
(
1
);
if
(
t1
==
INVALID_ABSTIME
||
t2
==
INVALID_ABSTIME
)
return
FALSE
;
PG_RETURN_BOOL
(
false
)
;
if
(
t1
==
CURRENT_ABSTIME
)
t1
=
GetCurrentTransactionStartTime
();
if
(
t2
==
CURRENT_ABSTIME
)
t2
=
GetCurrentTransactionStartTime
();
return
t1
<=
t2
;
PG_RETURN_BOOL
(
t1
<=
t2
)
;
}
bool
abstimege
(
AbsoluteTime
t1
,
AbsoluteTime
t2
)
Datum
abstimege
(
PG_FUNCTION_ARGS
)
{
AbsoluteTime
t1
=
PG_GETARG_ABSOLUTETIME
(
0
);
AbsoluteTime
t2
=
PG_GETARG_ABSOLUTETIME
(
1
);
if
(
t1
==
INVALID_ABSTIME
||
t2
==
INVALID_ABSTIME
)
return
FALSE
;
PG_RETURN_BOOL
(
false
)
;
if
(
t1
==
CURRENT_ABSTIME
)
t1
=
GetCurrentTransactionStartTime
();
if
(
t2
==
CURRENT_ABSTIME
)
t2
=
GetCurrentTransactionStartTime
();
return
t1
>=
t2
;
PG_RETURN_BOOL
(
t1
>=
t2
)
;
}
/* datetime_abstime()
* Convert timestamp to abstime.
*/
AbsoluteTime
timestamp_abstime
(
Timestamp
*
timestamp
)
Datum
timestamp_abstime
(
PG_FUNCTION_ARGS
)
{
Timestamp
timestamp
=
PG_GETARG_TIMESTAMP
(
0
);
AbsoluteTime
result
;
double
fsec
;
struct
tm
tt
,
*
tm
=
&
tt
;
if
(
!
PointerIsValid
(
timestamp
))
if
(
TIMESTAMP_IS_INVALID
(
timestamp
))
{
result
=
INVALID_ABSTIME
;
}
else
if
(
TIMESTAMP_IS_INVALID
(
*
timestamp
))
{
result
=
INVALID_ABSTIME
;
}
else
if
(
TIMESTAMP_IS_NOBEGIN
(
*
timestamp
))
else
if
(
TIMESTAMP_IS_NOBEGIN
(
timestamp
))
{
result
=
NOSTART_ABSTIME
;
}
else
if
(
TIMESTAMP_IS_NOEND
(
*
timestamp
))
else
if
(
TIMESTAMP_IS_NOEND
(
timestamp
))
{
result
=
NOEND_ABSTIME
;
}
else
{
if
(
TIMESTAMP_IS_RELATIVE
(
*
timestamp
))
if
(
TIMESTAMP_IS_RELATIVE
(
timestamp
))
{
timestamp2tm
(
SetTimestamp
(
*
timestamp
),
NULL
,
tm
,
&
fsec
,
NULL
);
timestamp2tm
(
SetTimestamp
(
timestamp
),
NULL
,
tm
,
&
fsec
,
NULL
);
result
=
tm2abstime
(
tm
,
0
);
}
else
if
(
timestamp2tm
(
*
timestamp
,
NULL
,
tm
,
&
fsec
,
NULL
)
==
0
)
else
if
(
timestamp2tm
(
timestamp
,
NULL
,
tm
,
&
fsec
,
NULL
)
==
0
)
{
result
=
tm2abstime
(
tm
,
0
);
}
else
{
result
=
INVALID_ABSTIME
;
}
;
}
;
}
}
return
result
;
}
/* timestamp_abstime() */
PG_RETURN_ABSOLUTETIME
(
result
)
;
}
/* abstime_timestamp()
* Convert abstime to timestamp.
*/
Timestamp
*
abstime_timestamp
(
AbsoluteTime
abstime
)
Datum
abstime_timestamp
(
PG_FUNCTION_ARGS
)
{
Timestamp
*
result
;
if
(
!
PointerIsValid
(
result
=
palloc
(
sizeof
(
Timestamp
))))
elog
(
ERROR
,
"Unable to allocate space to convert abstime to timestamp"
);
AbsoluteTime
abstime
=
PG_GETARG_ABSOLUTETIME
(
0
);
Timestamp
result
;
switch
(
abstime
)
{
case
INVALID_ABSTIME
:
TIMESTAMP_INVALID
(
*
result
);
TIMESTAMP_INVALID
(
result
);
break
;
case
NOSTART_ABSTIME
:
TIMESTAMP_NOBEGIN
(
*
result
);
TIMESTAMP_NOBEGIN
(
result
);
break
;
case
NOEND_ABSTIME
:
TIMESTAMP_NOEND
(
*
result
);
TIMESTAMP_NOEND
(
result
);
break
;
case
EPOCH_ABSTIME
:
TIMESTAMP_EPOCH
(
*
result
);
TIMESTAMP_EPOCH
(
result
);
break
;
case
CURRENT_ABSTIME
:
TIMESTAMP_CURRENT
(
*
result
);
TIMESTAMP_CURRENT
(
result
);
break
;
default:
*
result
=
abstime
+
((
date2j
(
1970
,
1
,
1
)
-
date2j
(
2000
,
1
,
1
))
*
86400
);
result
=
abstime
+
((
date2j
(
1970
,
1
,
1
)
-
date2j
(
2000
,
1
,
1
))
*
86400
);
break
;
};
return
result
;
}
/* abstime_timestamp() */
PG_RETURN_TIMESTAMP
(
result
)
;
}
/*****************************************************************************
...
...
@@ -685,11 +695,11 @@ abstime_timestamp(AbsoluteTime abstime)
/*
* reltimein - converts a reltime string in an internal format
*/
RelativeTime
reltimein
(
char
*
str
)
Datum
reltimein
(
PG_FUNCTION_ARGS
)
{
char
*
str
=
PG_GETARG_CSTRING
(
0
);
RelativeTime
result
;
struct
tm
tt
,
*
tm
=
&
tt
;
double
fsec
;
...
...
@@ -699,9 +709,6 @@ reltimein(char *str)
ftype
[
MAXDATEFIELDS
];
char
lowstr
[
MAXDATELEN
+
1
];
if
(
!
PointerIsValid
(
str
))
elog
(
ERROR
,
"Bad (null) date external representation"
);
if
(
strlen
(
str
)
>
MAXDATELEN
)
elog
(
ERROR
,
"Bad (length) reltime external representation '%s'"
,
str
);
...
...
@@ -714,23 +721,24 @@ reltimein(char *str)
case
DTK_DELTA
:
result
=
((((
tm
->
tm_hour
*
60
)
+
tm
->
tm_min
)
*
60
)
+
tm
->
tm_sec
);
result
+=
(((
tm
->
tm_year
*
365
)
+
(
tm
->
tm_mon
*
30
)
+
tm
->
tm_mday
)
*
(
24
*
60
*
60
));
return
result
;
PG_RETURN_RELATIVETIME
(
result
)
;
default:
return
INVALID_RELTIME
;
PG_RETURN_RELATIVETIME
(
INVALID_RELTIME
)
;
}
elog
(
ERROR
,
"Bad reltime (internal coding error) '%s'"
,
str
);
return
INVALID_RELTIME
;
}
/* reltimein() */
PG_RETURN_RELATIVETIME
(
INVALID_RELTIME
)
;
}
/*
* reltimeout - converts the internal format to a reltime string
*/
char
*
reltimeout
(
RelativeTime
time
)
Datum
reltimeout
(
PG_FUNCTION_ARGS
)
{
RelativeTime
time
=
PG_GETARG_RELATIVETIME
(
0
);
char
*
result
;
struct
tm
tt
,
*
tm
=
&
tt
;
...
...
@@ -739,7 +747,6 @@ reltimeout(RelativeTime time)
if
(
time
==
INVALID_RELTIME
)
{
strcpy
(
buf
,
INVALID_RELTIME_STR
);
}
else
{
...
...
@@ -747,11 +754,9 @@ reltimeout(RelativeTime time)
EncodeTimeSpan
(
tm
,
0
,
DateStyle
,
buf
);
}
result
=
palloc
(
strlen
(
buf
)
+
1
);
strcpy
(
result
,
buf
);
return
result
;
}
/* reltimeout() */
result
=
pstrdup
(
buf
);
PG_RETURN_CSTRING
(
result
);
}
static
void
...
...
@@ -807,17 +812,18 @@ dummyfunc()
/*
* tintervalin - converts an interval string to
an
internal format
* tintervalin - converts an interval string to internal format
*/
TimeInterval
tintervalin
(
char
*
intervalstr
)
Datum
tintervalin
(
PG_FUNCTION_ARGS
)
{
char
*
intervalstr
=
PG_GETARG_CSTRING
(
0
);
TimeInterval
interval
;
int
error
;
AbsoluteTime
i_start
,
i_end
,
t1
,
t2
;
TimeInterval
interval
;
interval
=
(
TimeInterval
)
palloc
(
sizeof
(
TimeIntervalData
));
error
=
istinterval
(
intervalstr
,
&
t1
,
&
t2
);
...
...
@@ -833,7 +839,7 @@ tintervalin(char *intervalstr)
interval
->
data
[
1
]
=
i_end
;
interval
->
status
=
T_INTERVAL_VALID
;
}
return
interval
;
PG_RETURN_TIMEINTERVAL
(
interval
)
;
}
...
...
@@ -841,9 +847,10 @@ tintervalin(char *intervalstr)
* tintervalout - converts an internal interval format to a string
*
*/
char
*
tintervalout
(
TimeInterval
interval
)
Datum
tintervalout
(
PG_FUNCTION_ARGS
)
{
TimeInterval
interval
=
PG_GETARG_TIMEINTERVAL
(
0
);
char
*
i_str
,
*
p
;
...
...
@@ -853,16 +860,18 @@ tintervalout(TimeInterval interval)
strcat
(
i_str
,
INVALID_INTERVAL_STR
);
else
{
p
=
nabstimeout
(
interval
->
data
[
0
]);
p
=
DatumGetCString
(
DirectFunctionCall1
(
nabstimeout
,
AbsoluteTimeGetDatum
(
interval
->
data
[
0
])));
strcat
(
i_str
,
p
);
pfree
(
p
);
strcat
(
i_str
,
"
\"
\"
"
);
p
=
nabstimeout
(
interval
->
data
[
1
]);
p
=
DatumGetCString
(
DirectFunctionCall1
(
nabstimeout
,
AbsoluteTimeGetDatum
(
interval
->
data
[
1
])));
strcat
(
i_str
,
p
);
pfree
(
p
);
}
strcat
(
i_str
,
"
\"
]
\0
"
);
return
i_str
;
PG_RETURN_CSTRING
(
i_str
)
;
}
...
...
@@ -870,21 +879,18 @@ tintervalout(TimeInterval interval)
* PUBLIC ROUTINES *
*****************************************************************************/
RelativeTime
interval_reltime
(
Interval
*
interval
)
Datum
interval_reltime
(
PG_FUNCTION_ARGS
)
{
Interval
*
interval
=
PG_GETARG_INTERVAL_P
(
0
);
RelativeTime
time
;
int
year
,
month
;
double
span
;
if
(
!
PointerIsValid
(
interval
))
time
=
INVALID_RELTIME
;
if
(
INTERVAL_IS_INVALID
(
*
interval
))
{
time
=
INVALID_RELTIME
;
}
else
{
...
...
@@ -892,13 +898,11 @@ interval_reltime(Interval *interval)
{
year
=
0
;
month
=
0
;
}
else
if
(
abs
(
interval
->
month
)
>=
12
)
{
year
=
(
interval
->
month
/
12
);
month
=
(
interval
->
month
%
12
);
}
else
{
...
...
@@ -911,19 +915,19 @@ interval_reltime(Interval *interval)
time
=
(((
span
>
INT_MIN
)
&&
(
span
<
INT_MAX
))
?
span
:
INVALID_RELTIME
);
}
return
time
;
}
/* interval_reltime() */
PG_RETURN_RELATIVETIME
(
time
)
;
}
Interval
*
reltime_interval
(
RelativeTime
reltime
)
Datum
reltime_interval
(
PG_FUNCTION_ARGS
)
{
RelativeTime
reltime
=
PG_GETARG_RELATIVETIME
(
0
);
Interval
*
result
;
int
year
,
month
;
if
(
!
PointerIsValid
(
result
=
palloc
(
sizeof
(
Interval
))))
elog
(
ERROR
,
"Memory allocation failed, can't convert reltime to interval"
);
result
=
(
Interval
*
)
palloc
(
sizeof
(
Interval
));
switch
(
reltime
)
{
...
...
@@ -937,18 +941,21 @@ reltime_interval(RelativeTime reltime)
result
->
time
=
reltime
;
result
->
month
=
((
12
*
year
)
+
month
);
break
;
}
return
result
;
}
/* reltime_interval() */
PG_RETURN_INTERVAL_P
(
result
)
;
}
/*
* mktinterval - creates a time interval with endpoints t1 and t2
*/
TimeInterval
mktinterval
(
AbsoluteTime
t1
,
AbsoluteTime
t2
)
Datum
mktinterval
(
PG_FUNCTION_ARGS
)
{
AbsoluteTime
t1
=
PG_GETARG_ABSOLUTETIME
(
0
);
AbsoluteTime
t2
=
PG_GETARG_ABSOLUTETIME
(
1
);
AbsoluteTime
tstart
=
ABSTIMEMIN
(
t1
,
t2
),
tend
=
ABSTIMEMAX
(
t1
,
t2
);
TimeInterval
interval
;
...
...
@@ -963,7 +970,7 @@ mktinterval(AbsoluteTime t1, AbsoluteTime t2)
interval
->
data
[
1
]
=
tend
;
}
return
interval
;
PG_RETURN_TIMEINTERVAL
(
interval
)
;
}
/*
...
...
@@ -976,9 +983,12 @@ mktinterval(AbsoluteTime t1, AbsoluteTime t2)
/*
* timepl - returns the value of (abstime t1 + relime t2)
*/
AbsoluteTime
timepl
(
AbsoluteTime
t1
,
RelativeTime
t2
)
Datum
timepl
(
PG_FUNCTION_ARGS
)
{
AbsoluteTime
t1
=
PG_GETARG_ABSOLUTETIME
(
0
);
RelativeTime
t2
=
PG_GETARG_RELATIVETIME
(
1
);
if
(
t1
==
CURRENT_ABSTIME
)
t1
=
GetCurrentTransactionStartTime
();
...
...
@@ -986,18 +996,21 @@ timepl(AbsoluteTime t1, RelativeTime t2)
RelativeTimeIsValid
(
t2
)
&&
((
t2
>
0
)
?
(
t1
<
NOEND_ABSTIME
-
t2
)
:
(
t1
>
NOSTART_ABSTIME
-
t2
)))
/* prevent overflow */
return
t1
+
t2
;
PG_RETURN_ABSOLUTETIME
(
t1
+
t2
)
;
return
INVALID_ABSTIME
;
PG_RETURN_ABSOLUTETIME
(
INVALID_ABSTIME
)
;
}
/*
* timemi - returns the value of (abstime t1 - reltime t2)
*/
AbsoluteTime
timemi
(
AbsoluteTime
t1
,
RelativeTime
t2
)
Datum
timemi
(
PG_FUNCTION_ARGS
)
{
AbsoluteTime
t1
=
PG_GETARG_ABSOLUTETIME
(
0
);
RelativeTime
t2
=
PG_GETARG_RELATIVETIME
(
1
);
if
(
t1
==
CURRENT_ABSTIME
)
t1
=
GetCurrentTransactionStartTime
();
...
...
@@ -1005,14 +1018,16 @@ timemi(AbsoluteTime t1, RelativeTime t2)
RelativeTimeIsValid
(
t2
)
&&
((
t2
>
0
)
?
(
t1
>
NOSTART_ABSTIME
+
t2
)
:
(
t1
<
NOEND_ABSTIME
+
t2
)))
/* prevent overflow */
return
t1
-
t2
;
PG_RETURN_ABSOLUTETIME
(
t1
-
t2
)
;
return
INVALID_ABSTIME
;
PG_RETURN_ABSOLUTETIME
(
INVALID_ABSTIME
)
;
}
/*
* abstimemi - returns the value of (abstime t1 - abstime t2)
*
* This is not exported, so it's not been made fmgr-compatible.
*/
static
RelativeTime
abstimemi
(
AbsoluteTime
t1
,
AbsoluteTime
t2
)
...
...
@@ -1031,27 +1046,39 @@ abstimemi(AbsoluteTime t1, AbsoluteTime t2)
/*
* intinterval - returns
1,
iff absolute date is in the interval
* intinterval - returns
true
iff absolute date is in the interval
*/
int
intinterval
(
AbsoluteTime
t
,
TimeInterval
interval
)
Datum
intinterval
(
PG_FUNCTION_ARGS
)
{
AbsoluteTime
t
=
PG_GETARG_ABSOLUTETIME
(
0
);
TimeInterval
interval
=
PG_GETARG_TIMEINTERVAL
(
1
);
if
(
interval
->
status
==
T_INTERVAL_VALID
&&
t
!=
INVALID_ABSTIME
)
return
(
abstimege
(
t
,
interval
->
data
[
0
])
&&
abstimele
(
t
,
interval
->
data
[
1
]));
return
0
;
{
if
(
DatumGetBool
(
DirectFunctionCall2
(
abstimege
,
AbsoluteTimeGetDatum
(
t
),
AbsoluteTimeGetDatum
(
interval
->
data
[
0
])))
&&
DatumGetBool
(
DirectFunctionCall2
(
abstimele
,
AbsoluteTimeGetDatum
(
t
),
AbsoluteTimeGetDatum
(
interval
->
data
[
1
]))))
PG_RETURN_BOOL
(
true
);
}
PG_RETURN_BOOL
(
false
);
}
/*
* tintervalrel - returns relative time corresponding to interval
*/
RelativeTime
tintervalrel
(
TimeInterval
interval
)
Datum
tintervalrel
(
PG_FUNCTION_ARGS
)
{
if
(
interval
->
status
==
T_INTERVAL_VALID
)
return
abstimemi
(
interval
->
data
[
1
],
interval
->
data
[
0
]);
else
return
INVALID_RELTIME
;
TimeInterval
interval
=
PG_GETARG_TIMEINTERVAL
(
0
);
if
(
interval
->
status
!=
T_INTERVAL_VALID
)
PG_RETURN_RELATIVETIME
(
INVALID_RELTIME
);
PG_RETURN_RELATIVETIME
(
abstimemi
(
interval
->
data
[
1
],
interval
->
data
[
0
]));
}
/*
...
...
@@ -1059,101 +1086,131 @@ tintervalrel(TimeInterval interval)
*
* Now AbsoluteTime is time since Jan 1 1970 -mer 7 Feb 1992
*/
AbsoluteTime
timenow
()
Datum
timenow
(
PG_FUNCTION_ARGS
)
{
time_t
sec
;
if
(
time
(
&
sec
)
<
0
)
return
INVALID_ABSTIME
;
return
(
AbsoluteTime
)
sec
;
PG_RETURN_ABSOLUTETIME
(
INVALID_ABSTIME
)
;
PG_RETURN_ABSOLUTETIME
((
AbsoluteTime
)
sec
)
;
}
/*
* reltimeeq - returns
1,
iff arguments are equal
* reltimene - returns
1,
iff arguments are not equal
* reltimelt - returns
1,
iff t1 less than t2
* reltimegt - returns
1,
iff t1 greater than t2
* reltimele - returns
1,
iff t1 less than or equal to t2
* reltimege - returns
1,
iff t1 greater than or equal to t2
* reltimeeq - returns
true
iff arguments are equal
* reltimene - returns
true
iff arguments are not equal
* reltimelt - returns
true
iff t1 less than t2
* reltimegt - returns
true
iff t1 greater than t2
* reltimele - returns
true
iff t1 less than or equal to t2
* reltimege - returns
true
iff t1 greater than or equal to t2
*/
bool
reltimeeq
(
RelativeTime
t1
,
RelativeTime
t2
)
Datum
reltimeeq
(
PG_FUNCTION_ARGS
)
{
RelativeTime
t1
=
PG_GETARG_RELATIVETIME
(
0
);
RelativeTime
t2
=
PG_GETARG_RELATIVETIME
(
1
);
if
(
t1
==
INVALID_RELTIME
||
t2
==
INVALID_RELTIME
)
return
0
;
return
t1
==
t2
;
PG_RETURN_BOOL
(
false
)
;
PG_RETURN_BOOL
(
t1
==
t2
)
;
}
bool
reltimene
(
RelativeTime
t1
,
RelativeTime
t2
)
Datum
reltimene
(
PG_FUNCTION_ARGS
)
{
RelativeTime
t1
=
PG_GETARG_RELATIVETIME
(
0
);
RelativeTime
t2
=
PG_GETARG_RELATIVETIME
(
1
);
if
(
t1
==
INVALID_RELTIME
||
t2
==
INVALID_RELTIME
)
return
0
;
return
t1
!=
t2
;
PG_RETURN_BOOL
(
false
)
;
PG_RETURN_BOOL
(
t1
!=
t2
)
;
}
bool
reltimelt
(
RelativeTime
t1
,
RelativeTime
t2
)
Datum
reltimelt
(
PG_FUNCTION_ARGS
)
{
RelativeTime
t1
=
PG_GETARG_RELATIVETIME
(
0
);
RelativeTime
t2
=
PG_GETARG_RELATIVETIME
(
1
);
if
(
t1
==
INVALID_RELTIME
||
t2
==
INVALID_RELTIME
)
return
0
;
return
t1
<
t2
;
PG_RETURN_BOOL
(
false
)
;
PG_RETURN_BOOL
(
t1
<
t2
)
;
}
bool
reltimegt
(
RelativeTime
t1
,
RelativeTime
t2
)
Datum
reltimegt
(
PG_FUNCTION_ARGS
)
{
RelativeTime
t1
=
PG_GETARG_RELATIVETIME
(
0
);
RelativeTime
t2
=
PG_GETARG_RELATIVETIME
(
1
);
if
(
t1
==
INVALID_RELTIME
||
t2
==
INVALID_RELTIME
)
return
0
;
return
t1
>
t2
;
PG_RETURN_BOOL
(
false
)
;
PG_RETURN_BOOL
(
t1
>
t2
)
;
}
bool
reltimele
(
RelativeTime
t1
,
RelativeTime
t2
)
Datum
reltimele
(
PG_FUNCTION_ARGS
)
{
RelativeTime
t1
=
PG_GETARG_RELATIVETIME
(
0
);
RelativeTime
t2
=
PG_GETARG_RELATIVETIME
(
1
);
if
(
t1
==
INVALID_RELTIME
||
t2
==
INVALID_RELTIME
)
return
0
;
return
t1
<=
t2
;
PG_RETURN_BOOL
(
false
)
;
PG_RETURN_BOOL
(
t1
<=
t2
)
;
}
bool
reltimege
(
RelativeTime
t1
,
RelativeTime
t2
)
Datum
reltimege
(
PG_FUNCTION_ARGS
)
{
RelativeTime
t1
=
PG_GETARG_RELATIVETIME
(
0
);
RelativeTime
t2
=
PG_GETARG_RELATIVETIME
(
1
);
if
(
t1
==
INVALID_RELTIME
||
t2
==
INVALID_RELTIME
)
return
0
;
return
t1
>=
t2
;
PG_RETURN_BOOL
(
false
)
;
PG_RETURN_BOOL
(
t1
>=
t2
)
;
}
/*
* tintervalsame - returns
1,
iff interval i1 is same as interval i2
* tintervalsame - returns
true
iff interval i1 is same as interval i2
* Check begin and end time.
*/
bool
tintervalsame
(
TimeInterval
i1
,
TimeInterval
i2
)
Datum
tintervalsame
(
PG_FUNCTION_ARGS
)
{
TimeInterval
i1
=
PG_GETARG_TIMEINTERVAL
(
0
);
TimeInterval
i2
=
PG_GETARG_TIMEINTERVAL
(
1
);
if
(
i1
->
status
==
T_INTERVAL_INVAL
||
i2
->
status
==
T_INTERVAL_INVAL
)
return
FALSE
;
/* invalid interval */
return
(
abstimeeq
(
i1
->
data
[
0
],
i2
->
data
[
0
])
&&
abstimeeq
(
i1
->
data
[
1
],
i2
->
data
[
1
]));
}
/* tintervalsame() */
PG_RETURN_BOOL
(
false
);
if
(
DatumGetBool
(
DirectFunctionCall2
(
abstimeeq
,
AbsoluteTimeGetDatum
(
i1
->
data
[
0
]),
AbsoluteTimeGetDatum
(
i2
->
data
[
0
])))
&&
DatumGetBool
(
DirectFunctionCall2
(
abstimeeq
,
AbsoluteTimeGetDatum
(
i1
->
data
[
1
]),
AbsoluteTimeGetDatum
(
i2
->
data
[
1
]))))
PG_RETURN_BOOL
(
true
);
PG_RETURN_BOOL
(
false
);
}
/*
* tintervaleq - returns
1,
iff interval i1 is equal to interval i2
* tintervaleq - returns
true
iff interval i1 is equal to interval i2
* Check length of intervals.
*/
bool
tintervaleq
(
TimeInterval
i1
,
TimeInterval
i2
)
Datum
tintervaleq
(
PG_FUNCTION_ARGS
)
{
TimeInterval
i1
=
PG_GETARG_TIMEINTERVAL
(
0
);
TimeInterval
i2
=
PG_GETARG_TIMEINTERVAL
(
1
);
AbsoluteTime
t10
,
t11
,
t20
,
t21
;
if
(
i1
->
status
==
T_INTERVAL_INVAL
||
i2
->
status
==
T_INTERVAL_INVAL
)
return
FALSE
;
/* invalid interval */
PG_RETURN_BOOL
(
false
);
t10
=
i1
->
data
[
0
];
t11
=
i1
->
data
[
1
];
...
...
@@ -1162,7 +1219,7 @@ tintervaleq(TimeInterval i1, TimeInterval i2)
if
((
t10
==
INVALID_ABSTIME
)
||
(
t20
==
INVALID_ABSTIME
)
||
(
t20
==
INVALID_ABSTIME
)
||
(
t21
==
INVALID_ABSTIME
))
return
FALSE
;
PG_RETURN_BOOL
(
false
)
;
if
(
t10
==
CURRENT_ABSTIME
)
t10
=
GetCurrentTransactionStartTime
();
...
...
@@ -1173,23 +1230,21 @@ tintervaleq(TimeInterval i1, TimeInterval i2)
if
(
t21
==
CURRENT_ABSTIME
)
t21
=
GetCurrentTransactionStartTime
();
return
(
t11
-
t10
)
==
(
t21
-
t20
);
}
/* tintervaleq() */
PG_RETURN_BOOL
((
t11
-
t10
)
==
(
t21
-
t20
)
);
}
/*
* tintervalne - returns 1, iff interval i1 is not equal to interval i2
* Check length of intervals.
*/
bool
tintervalne
(
TimeInterval
i1
,
TimeInterval
i2
)
Datum
tintervalne
(
PG_FUNCTION_ARGS
)
{
TimeInterval
i1
=
PG_GETARG_TIMEINTERVAL
(
0
);
TimeInterval
i2
=
PG_GETARG_TIMEINTERVAL
(
1
);
AbsoluteTime
t10
,
t11
,
t20
,
t21
;
if
(
i1
->
status
==
T_INTERVAL_INVAL
||
i2
->
status
==
T_INTERVAL_INVAL
)
return
FALSE
;
/* invalid interval */
PG_RETURN_BOOL
(
false
);
t10
=
i1
->
data
[
0
];
t11
=
i1
->
data
[
1
];
...
...
@@ -1198,7 +1253,7 @@ tintervalne(TimeInterval i1, TimeInterval i2)
if
((
t10
==
INVALID_ABSTIME
)
||
(
t20
==
INVALID_ABSTIME
)
||
(
t20
==
INVALID_ABSTIME
)
||
(
t21
==
INVALID_ABSTIME
))
return
FALSE
;
PG_RETURN_BOOL
(
false
)
;
if
(
t10
==
CURRENT_ABSTIME
)
t10
=
GetCurrentTransactionStartTime
();
...
...
@@ -1209,23 +1264,21 @@ tintervalne(TimeInterval i1, TimeInterval i2)
if
(
t21
==
CURRENT_ABSTIME
)
t21
=
GetCurrentTransactionStartTime
();
return
(
t11
-
t10
)
!=
(
t21
-
t20
);
}
/* tintervalne() */
PG_RETURN_BOOL
((
t11
-
t10
)
!=
(
t21
-
t20
)
);
}
/*
* tintervallt - returns TRUE, iff interval i1 is less than interval i2
* Check length of intervals.
*/
bool
tintervallt
(
TimeInterval
i1
,
TimeInterval
i2
)
Datum
tintervallt
(
PG_FUNCTION_ARGS
)
{
TimeInterval
i1
=
PG_GETARG_TIMEINTERVAL
(
0
);
TimeInterval
i2
=
PG_GETARG_TIMEINTERVAL
(
1
);
AbsoluteTime
t10
,
t11
,
t20
,
t21
;
if
(
i1
->
status
==
T_INTERVAL_INVAL
||
i2
->
status
==
T_INTERVAL_INVAL
)
return
FALSE
;
/* invalid interval */
PG_RETURN_BOOL
(
false
);
t10
=
i1
->
data
[
0
];
t11
=
i1
->
data
[
1
];
...
...
@@ -1234,7 +1287,7 @@ tintervallt(TimeInterval i1, TimeInterval i2)
if
((
t10
==
INVALID_ABSTIME
)
||
(
t20
==
INVALID_ABSTIME
)
||
(
t20
==
INVALID_ABSTIME
)
||
(
t21
==
INVALID_ABSTIME
))
return
FALSE
;
PG_RETURN_BOOL
(
false
)
;
if
(
t10
==
CURRENT_ABSTIME
)
t10
=
GetCurrentTransactionStartTime
();
...
...
@@ -1245,23 +1298,21 @@ tintervallt(TimeInterval i1, TimeInterval i2)
if
(
t21
==
CURRENT_ABSTIME
)
t21
=
GetCurrentTransactionStartTime
();
return
(
t11
-
t10
)
<
(
t21
-
t20
);
}
/* tintervallt() */
PG_RETURN_BOOL
((
t11
-
t10
)
<
(
t21
-
t20
)
);
}
/*
* tintervalle - returns TRUE, iff interval i1 is less than or equal to interval i2
* Check length of intervals.
*/
bool
tintervalle
(
TimeInterval
i1
,
TimeInterval
i2
)
Datum
tintervalle
(
PG_FUNCTION_ARGS
)
{
TimeInterval
i1
=
PG_GETARG_TIMEINTERVAL
(
0
);
TimeInterval
i2
=
PG_GETARG_TIMEINTERVAL
(
1
);
AbsoluteTime
t10
,
t11
,
t20
,
t21
;
if
(
i1
->
status
==
T_INTERVAL_INVAL
||
i2
->
status
==
T_INTERVAL_INVAL
)
return
FALSE
;
/* invalid interval */
PG_RETURN_BOOL
(
false
);
t10
=
i1
->
data
[
0
];
t11
=
i1
->
data
[
1
];
...
...
@@ -1270,7 +1321,7 @@ tintervalle(TimeInterval i1, TimeInterval i2)
if
((
t10
==
INVALID_ABSTIME
)
||
(
t20
==
INVALID_ABSTIME
)
||
(
t20
==
INVALID_ABSTIME
)
||
(
t21
==
INVALID_ABSTIME
))
return
FALSE
;
PG_RETURN_BOOL
(
false
)
;
if
(
t10
==
CURRENT_ABSTIME
)
t10
=
GetCurrentTransactionStartTime
();
...
...
@@ -1281,23 +1332,21 @@ tintervalle(TimeInterval i1, TimeInterval i2)
if
(
t21
==
CURRENT_ABSTIME
)
t21
=
GetCurrentTransactionStartTime
();
return
(
t11
-
t10
)
<=
(
t21
-
t20
);
}
/* tintervalle() */
PG_RETURN_BOOL
((
t11
-
t10
)
<=
(
t21
-
t20
)
);
}
/*
* tintervalgt - returns TRUE, iff interval i1 is less than interval i2
* Check length of intervals.
*/
bool
tintervalgt
(
TimeInterval
i1
,
TimeInterval
i2
)
Datum
tintervalgt
(
PG_FUNCTION_ARGS
)
{
TimeInterval
i1
=
PG_GETARG_TIMEINTERVAL
(
0
);
TimeInterval
i2
=
PG_GETARG_TIMEINTERVAL
(
1
);
AbsoluteTime
t10
,
t11
,
t20
,
t21
;
if
(
i1
->
status
==
T_INTERVAL_INVAL
||
i2
->
status
==
T_INTERVAL_INVAL
)
return
FALSE
;
/* invalid interval */
PG_RETURN_BOOL
(
false
);
t10
=
i1
->
data
[
0
];
t11
=
i1
->
data
[
1
];
...
...
@@ -1306,7 +1355,7 @@ tintervalgt(TimeInterval i1, TimeInterval i2)
if
((
t10
==
INVALID_ABSTIME
)
||
(
t20
==
INVALID_ABSTIME
)
||
(
t20
==
INVALID_ABSTIME
)
||
(
t21
==
INVALID_ABSTIME
))
return
FALSE
;
PG_RETURN_BOOL
(
false
)
;
if
(
t10
==
CURRENT_ABSTIME
)
t10
=
GetCurrentTransactionStartTime
();
...
...
@@ -1317,23 +1366,21 @@ tintervalgt(TimeInterval i1, TimeInterval i2)
if
(
t21
==
CURRENT_ABSTIME
)
t21
=
GetCurrentTransactionStartTime
();
return
(
t11
-
t10
)
>
(
t21
-
t20
);
}
/* tintervalgt() */
PG_RETURN_BOOL
((
t11
-
t10
)
>
(
t21
-
t20
)
);
}
/*
* tintervalge - returns TRUE, iff interval i1 is less than or equal to interval i2
* Check length of intervals.
*/
bool
tintervalge
(
TimeInterval
i1
,
TimeInterval
i2
)
Datum
tintervalge
(
PG_FUNCTION_ARGS
)
{
TimeInterval
i1
=
PG_GETARG_TIMEINTERVAL
(
0
);
TimeInterval
i2
=
PG_GETARG_TIMEINTERVAL
(
1
);
AbsoluteTime
t10
,
t11
,
t20
,
t21
;
if
(
i1
->
status
==
T_INTERVAL_INVAL
||
i2
->
status
==
T_INTERVAL_INVAL
)
return
FALSE
;
/* invalid interval */
PG_RETURN_BOOL
(
false
);
t10
=
i1
->
data
[
0
];
t11
=
i1
->
data
[
1
];
...
...
@@ -1342,7 +1389,7 @@ tintervalge(TimeInterval i1, TimeInterval i2)
if
((
t10
==
INVALID_ABSTIME
)
||
(
t20
==
INVALID_ABSTIME
)
||
(
t20
==
INVALID_ABSTIME
)
||
(
t21
==
INVALID_ABSTIME
))
return
FALSE
;
PG_RETURN_BOOL
(
false
)
;
if
(
t10
==
CURRENT_ABSTIME
)
t10
=
GetCurrentTransactionStartTime
();
...
...
@@ -1353,144 +1400,174 @@ tintervalge(TimeInterval i1, TimeInterval i2)
if
(
t21
==
CURRENT_ABSTIME
)
t21
=
GetCurrentTransactionStartTime
();
return
(
t11
-
t10
)
>=
(
t21
-
t20
);
}
/* tintervalge() */
PG_RETURN_BOOL
((
t11
-
t10
)
>=
(
t21
-
t20
)
);
}
/*
* tintervalleneq - returns
1,
iff length of interval i is equal to
* tintervalleneq - returns
true
iff length of interval i is equal to
* reltime t
* tintervallenne - returns true iff length of interval i is not equal
* to reltime t
* tintervallenlt - returns true iff length of interval i is less than
* reltime t
* tintervallengt - returns true iff length of interval i is greater
* than reltime t
* tintervallenle - returns true iff length of interval i is less or
* equal than reltime t
* tintervallenge - returns true iff length of interval i is greater or
* equal than reltime t
*/
bool
tintervalleneq
(
TimeInterval
i
,
RelativeTime
t
)
Datum
tintervalleneq
(
PG_FUNCTION_ARGS
)
{
TimeInterval
i
=
PG_GETARG_TIMEINTERVAL
(
0
);
RelativeTime
t
=
PG_GETARG_RELATIVETIME
(
1
);
RelativeTime
rt
;
if
((
i
->
status
==
T_INTERVAL_INVAL
)
||
(
t
==
INVALID_RELTIME
))
return
0
;
rt
=
tintervalrel
(
i
);
return
rt
!=
INVALID_RELTIME
&&
rt
==
t
;
if
(
i
->
status
==
T_INTERVAL_INVAL
||
t
==
INVALID_RELTIME
)
PG_RETURN_BOOL
(
false
);
rt
=
DatumGetRelativeTime
(
DirectFunctionCall1
(
tintervalrel
,
TimeIntervalGetDatum
(
i
)));
PG_RETURN_BOOL
(
rt
!=
INVALID_RELTIME
&&
rt
==
t
);
}
/*
* tintervallenne - returns 1, iff length of interval i is not equal
* to reltime t
*/
bool
tintervallenne
(
TimeInterval
i
,
RelativeTime
t
)
Datum
tintervallenne
(
PG_FUNCTION_ARGS
)
{
TimeInterval
i
=
PG_GETARG_TIMEINTERVAL
(
0
);
RelativeTime
t
=
PG_GETARG_RELATIVETIME
(
1
);
RelativeTime
rt
;
if
((
i
->
status
==
T_INTERVAL_INVAL
)
||
(
t
==
INVALID_RELTIME
))
return
0
;
rt
=
tintervalrel
(
i
);
return
rt
!=
INVALID_RELTIME
&&
rt
!=
t
;
if
(
i
->
status
==
T_INTERVAL_INVAL
||
t
==
INVALID_RELTIME
)
PG_RETURN_BOOL
(
false
);
rt
=
DatumGetRelativeTime
(
DirectFunctionCall1
(
tintervalrel
,
TimeIntervalGetDatum
(
i
)));
PG_RETURN_BOOL
(
rt
!=
INVALID_RELTIME
&&
rt
!=
t
);
}
/*
* tintervallenlt - returns 1, iff length of interval i is less than
* reltime t
*/
bool
tintervallenlt
(
TimeInterval
i
,
RelativeTime
t
)
Datum
tintervallenlt
(
PG_FUNCTION_ARGS
)
{
TimeInterval
i
=
PG_GETARG_TIMEINTERVAL
(
0
);
RelativeTime
t
=
PG_GETARG_RELATIVETIME
(
1
);
RelativeTime
rt
;
if
((
i
->
status
==
T_INTERVAL_INVAL
)
||
(
t
==
INVALID_RELTIME
))
return
0
;
rt
=
tintervalrel
(
i
);
return
rt
!=
INVALID_RELTIME
&&
rt
<
t
;
if
(
i
->
status
==
T_INTERVAL_INVAL
||
t
==
INVALID_RELTIME
)
PG_RETURN_BOOL
(
false
);
rt
=
DatumGetRelativeTime
(
DirectFunctionCall1
(
tintervalrel
,
TimeIntervalGetDatum
(
i
)));
PG_RETURN_BOOL
(
rt
!=
INVALID_RELTIME
&&
rt
<
t
);
}
/*
* tintervallengt - returns 1, iff length of interval i is greater than
* reltime t
*/
bool
tintervallengt
(
TimeInterval
i
,
RelativeTime
t
)
Datum
tintervallengt
(
PG_FUNCTION_ARGS
)
{
TimeInterval
i
=
PG_GETARG_TIMEINTERVAL
(
0
);
RelativeTime
t
=
PG_GETARG_RELATIVETIME
(
1
);
RelativeTime
rt
;
if
((
i
->
status
==
T_INTERVAL_INVAL
)
||
(
t
==
INVALID_RELTIME
))
return
0
;
rt
=
tintervalrel
(
i
);
return
rt
!=
INVALID_RELTIME
&&
rt
>
t
;
if
(
i
->
status
==
T_INTERVAL_INVAL
||
t
==
INVALID_RELTIME
)
PG_RETURN_BOOL
(
false
);
rt
=
DatumGetRelativeTime
(
DirectFunctionCall1
(
tintervalrel
,
TimeIntervalGetDatum
(
i
)));
PG_RETURN_BOOL
(
rt
!=
INVALID_RELTIME
&&
rt
>
t
);
}
/*
* tintervallenle - returns 1, iff length of interval i is less or equal
* than reltime t
*/
bool
tintervallenle
(
TimeInterval
i
,
RelativeTime
t
)
Datum
tintervallenle
(
PG_FUNCTION_ARGS
)
{
TimeInterval
i
=
PG_GETARG_TIMEINTERVAL
(
0
);
RelativeTime
t
=
PG_GETARG_RELATIVETIME
(
1
);
RelativeTime
rt
;
if
((
i
->
status
==
T_INTERVAL_INVAL
)
||
(
t
==
INVALID_RELTIME
))
return
0
;
rt
=
tintervalrel
(
i
);
return
rt
!=
INVALID_RELTIME
&&
rt
<=
t
;
if
(
i
->
status
==
T_INTERVAL_INVAL
||
t
==
INVALID_RELTIME
)
PG_RETURN_BOOL
(
false
);
rt
=
DatumGetRelativeTime
(
DirectFunctionCall1
(
tintervalrel
,
TimeIntervalGetDatum
(
i
)));
PG_RETURN_BOOL
(
rt
!=
INVALID_RELTIME
&&
rt
<=
t
);
}
/*
* tintervallenge - returns 1, iff length of interval i is greater or
* equal than reltime t
*/
bool
tintervallenge
(
TimeInterval
i
,
RelativeTime
t
)
Datum
tintervallenge
(
PG_FUNCTION_ARGS
)
{
TimeInterval
i
=
PG_GETARG_TIMEINTERVAL
(
0
);
RelativeTime
t
=
PG_GETARG_RELATIVETIME
(
1
);
RelativeTime
rt
;
if
((
i
->
status
==
T_INTERVAL_INVAL
)
||
(
t
==
INVALID_RELTIME
))
return
0
;
rt
=
tintervalrel
(
i
);
return
rt
!=
INVALID_RELTIME
&&
rt
>=
t
;
if
(
i
->
status
==
T_INTERVAL_INVAL
||
t
==
INVALID_RELTIME
)
PG_RETURN_BOOL
(
false
);
rt
=
DatumGetRelativeTime
(
DirectFunctionCall1
(
tintervalrel
,
TimeIntervalGetDatum
(
i
)));
PG_RETURN_BOOL
(
rt
!=
INVALID_RELTIME
&&
rt
>=
t
);
}
/*
* tintervalct - returns
1,
iff interval i1 contains interval i2
* tintervalct - returns
true
iff interval i1 contains interval i2
*/
bool
tintervalct
(
TimeInterval
i1
,
TimeInterval
i2
)
Datum
tintervalct
(
PG_FUNCTION_ARGS
)
{
TimeInterval
i1
=
PG_GETARG_TIMEINTERVAL
(
0
);
TimeInterval
i2
=
PG_GETARG_TIMEINTERVAL
(
1
);
if
(
i1
->
status
==
T_INTERVAL_INVAL
||
i2
->
status
==
T_INTERVAL_INVAL
)
return
0
;
return
(
abstimele
(
i1
->
data
[
0
],
i2
->
data
[
0
])
&&
abstimege
(
i1
->
data
[
1
],
i2
->
data
[
1
]));
PG_RETURN_BOOL
(
false
);
if
(
DatumGetBool
(
DirectFunctionCall2
(
abstimele
,
AbsoluteTimeGetDatum
(
i1
->
data
[
0
]),
AbsoluteTimeGetDatum
(
i2
->
data
[
0
])))
&&
DatumGetBool
(
DirectFunctionCall2
(
abstimege
,
AbsoluteTimeGetDatum
(
i1
->
data
[
1
]),
AbsoluteTimeGetDatum
(
i2
->
data
[
1
]))))
PG_RETURN_BOOL
(
true
);
PG_RETURN_BOOL
(
false
);
}
/*
* tintervalov - returns
1,
iff interval i1 (partially) overlaps i2
* tintervalov - returns
true
iff interval i1 (partially) overlaps i2
*/
bool
tintervalov
(
TimeInterval
i1
,
TimeInterval
i2
)
Datum
tintervalov
(
PG_FUNCTION_ARGS
)
{
TimeInterval
i1
=
PG_GETARG_TIMEINTERVAL
(
0
);
TimeInterval
i2
=
PG_GETARG_TIMEINTERVAL
(
1
);
if
(
i1
->
status
==
T_INTERVAL_INVAL
||
i2
->
status
==
T_INTERVAL_INVAL
)
return
0
;
return
(
!
(
abstimelt
(
i1
->
data
[
1
],
i2
->
data
[
0
])
||
abstimegt
(
i1
->
data
[
0
],
i2
->
data
[
1
])));
PG_RETURN_BOOL
(
false
);
if
(
DatumGetBool
(
DirectFunctionCall2
(
abstimelt
,
AbsoluteTimeGetDatum
(
i1
->
data
[
1
]),
AbsoluteTimeGetDatum
(
i2
->
data
[
0
])))
||
DatumGetBool
(
DirectFunctionCall2
(
abstimegt
,
AbsoluteTimeGetDatum
(
i1
->
data
[
0
]),
AbsoluteTimeGetDatum
(
i2
->
data
[
1
]))))
PG_RETURN_BOOL
(
false
);
PG_RETURN_BOOL
(
true
);
}
/*
* tintervalstart - returns the start of interval i
*/
AbsoluteTime
tintervalstart
(
TimeInterval
i
)
Datum
tintervalstart
(
PG_FUNCTION_ARGS
)
{
TimeInterval
i
=
PG_GETARG_TIMEINTERVAL
(
0
);
if
(
i
->
status
==
T_INTERVAL_INVAL
)
return
INVALID_ABSTIME
;
return
i
->
data
[
0
]
;
PG_RETURN_ABSOLUTETIME
(
INVALID_ABSTIME
)
;
PG_RETURN_ABSOLUTETIME
(
i
->
data
[
0
])
;
}
/*
* tintervalend - returns the end of interval i
*/
AbsoluteTime
tintervalend
(
TimeInterval
i
)
Datum
tintervalend
(
PG_FUNCTION_ARGS
)
{
TimeInterval
i
=
PG_GETARG_TIMEINTERVAL
(
0
);
if
(
i
->
status
==
T_INTERVAL_INVAL
)
return
INVALID_ABSTIME
;
return
i
->
data
[
1
]
;
PG_RETURN_ABSOLUTETIME
(
INVALID_ABSTIME
)
;
PG_RETURN_ABSOLUTETIME
(
i
->
data
[
1
])
;
}
...
...
@@ -1778,7 +1855,8 @@ istinterval(char *i_string,
p1
++
;
}
/* get the first date */
*
i_start
=
nabstimein
(
p
);
/* first absolute date */
*
i_start
=
DatumGetAbsoluteTime
(
DirectFunctionCall1
(
nabstimein
,
CStringGetDatum
(
p
)));
/* rechange NULL at the end of the first date to a "'" */
*
p1
=
'"'
;
p
=
++
p1
;
...
...
@@ -1805,7 +1883,8 @@ istinterval(char *i_string,
p1
++
;
}
/* get the second date */
*
i_end
=
nabstimein
(
p
);
/* second absolute date */
*
i_end
=
DatumGetAbsoluteTime
(
DirectFunctionCall1
(
nabstimein
,
CStringGetDatum
(
p
)));
/* rechange NULL at the end of the first date to a ''' */
*
p1
=
'"'
;
p
=
++
p1
;
...
...
@@ -1832,10 +1911,13 @@ istinterval(char *i_string,
*
*****************************************************************************/
int32
/* RelativeTime */
int4reltime
(
int32
timevalue
)
Datum
int4reltime
(
PG_FUNCTION_ARGS
)
{
return
timevalue
;
int32
timevalue
=
PG_GETARG_INT32
(
0
);
/* Just coerce it directly to RelativeTime ... */
PG_RETURN_RELATIVETIME
((
RelativeTime
)
timevalue
);
}
/*
...
...
@@ -1845,25 +1927,24 @@ int4reltime(int32 timevalue)
* the Wisconsin benchmark with Illustra whose TimeNow() shows current
* time with precision up to microsecs.) - ay 3/95
*/
text
*
timeofday
(
void
)
Datum
timeofday
(
PG_FUNCTION_ARGS
)
{
struct
timeval
tp
;
struct
timezone
tpz
;
char
templ
[
500
];
char
buf
[
500
];
text
*
tm
;
text
*
result
;
int
len
=
0
;
gettimeofday
(
&
tp
,
&
tpz
);
strftime
(
templ
,
sizeof
(
templ
),
"%a %b %d %H:%M:%S.%%d %Y %Z"
,
localtime
((
time_t
*
)
&
tp
.
tv_sec
));
s
printf
(
buf
,
templ
,
tp
.
tv_usec
);
s
nprintf
(
buf
,
sizeof
(
buf
)
,
templ
,
tp
.
tv_usec
);
len
=
VARHDRSZ
+
strlen
(
buf
);
tm
=
(
text
*
)
palloc
(
len
);
VARSIZE
(
tm
)
=
len
;
strncpy
(
VARDATA
(
tm
),
buf
,
strlen
(
buf
));
return
tm
;
result
=
(
text
*
)
palloc
(
len
);
VARSIZE
(
result
)
=
len
;
memcpy
(
VARDATA
(
result
),
buf
,
strlen
(
buf
));
PG_RETURN_TEXT_P
(
result
)
;
}
src/backend/utils/adt/not_in.c
View file @
ae526b40
...
...
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/not_in.c,v 1.2
2 2000/01/26 05:57:14 momjian
Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/not_in.c,v 1.2
3 2000/06/09 01:11:09 tgl
Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -34,23 +34,28 @@ static int my_varattno(Relation rd, char *a);
*
* ----------------------------------------------------------------
*/
bool
int4notin
(
int32
not_in_arg
,
char
*
relation_and_attr
)
Datum
int4notin
(
PG_FUNCTION_ARGS
)
{
int32
not_in_arg
=
PG_GETARG_INT32
(
0
);
text
*
relation_and_attr
=
PG_GETARG_TEXT_P
(
1
);
Relation
relation_to_scan
;
int32
integer_value
;
HeapTuple
current_tuple
;
HeapScanDesc
scan_descriptor
;
bool
dummy
,
bool
isNull
,
retval
;
int
attrid
;
int
attrid
,
strlength
;
char
*
relation
,
*
attribute
;
char
my_copy
[
NAMEDATALEN
*
2
+
2
];
Datum
value
;
strncpy
(
my_copy
,
relation_and_attr
,
sizeof
(
my_copy
));
my_copy
[
sizeof
(
my_copy
)
-
1
]
=
'\0'
;
strlength
=
VARSIZE
(
relation_and_attr
)
-
VARHDRSZ
+
1
;
if
(
strlength
>
sizeof
(
my_copy
))
strlength
=
sizeof
(
my_copy
);
StrNCpy
(
my_copy
,
VARDATA
(
relation_and_attr
),
strlength
);
relation
=
(
char
*
)
strtok
(
my_copy
,
"."
);
attribute
=
(
char
*
)
strtok
(
NULL
,
"."
);
...
...
@@ -81,7 +86,9 @@ int4notin(int32 not_in_arg, char *relation_and_attr)
value
=
heap_getattr
(
current_tuple
,
(
AttrNumber
)
attrid
,
RelationGetDescr
(
relation_to_scan
),
&
dummy
);
&
isNull
);
if
(
isNull
)
continue
;
integer_value
=
DatumGetInt32
(
value
);
if
(
not_in_arg
==
integer_value
)
{
...
...
@@ -94,15 +101,21 @@ int4notin(int32 not_in_arg, char *relation_and_attr)
heap_endscan
(
scan_descriptor
);
heap_close
(
relation_to_scan
,
AccessShareLock
);
return
retval
;
PG_RETURN_BOOL
(
retval
)
;
}
bool
oidnotin
(
Oid
the_oid
,
char
*
compare
)
Datum
oidnotin
(
PG_FUNCTION_ARGS
)
{
Oid
the_oid
=
PG_GETARG_OID
(
0
);
#ifdef NOT_USED
text
*
relation_and_attr
=
PG_GETARG_TEXT_P
(
1
);
#endif
if
(
the_oid
==
InvalidOid
)
return
false
;
return
int4notin
(
the_oid
,
compare
);
PG_RETURN_BOOL
(
false
);
/* XXX assume oid maps to int4 */
return
int4notin
(
fcinfo
);
}
/*
...
...
@@ -117,7 +130,7 @@ my_varattno(Relation rd, char *a)
for
(
i
=
0
;
i
<
rd
->
rd_rel
->
relnatts
;
i
++
)
{
if
(
!
namestrcmp
(
&
rd
->
rd_att
->
attrs
[
i
]
->
attname
,
a
)
)
if
(
namestrcmp
(
&
rd
->
rd_att
->
attrs
[
i
]
->
attname
,
a
)
==
0
)
return
i
+
1
;
}
return
-
1
;
...
...
src/backend/utils/adt/ruleutils.c
View file @
ae526b40
...
...
@@ -3,7 +3,7 @@
* out of its tuple
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.5
0 2000/05/30 04:24:51
tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.5
1 2000/06/09 01:11:09
tgl Exp $
*
* This software is copyrighted by Jan Wieck - Hamburg.
*
...
...
@@ -319,9 +319,10 @@ pg_get_viewdef(NameData *rname)
* get_indexdef - Get the definition of an index
* ----------
*/
text
*
pg_get_indexdef
(
Oid
indexrelid
)
Datum
pg_get_indexdef
(
PG_FUNCTION_ARGS
)
{
Oid
indexrelid
=
PG_GETARG_OID
(
0
);
text
*
indexdef
;
HeapTuple
ht_idx
;
HeapTuple
ht_idxrel
;
...
...
@@ -541,7 +542,7 @@ pg_get_indexdef(Oid indexrelid)
if
(
SPI_finish
()
!=
SPI_OK_FINISH
)
elog
(
ERROR
,
"get_viewdef: SPI_finish() failed"
);
return
indexdef
;
PG_RETURN_TEXT_P
(
indexdef
)
;
}
...
...
src/backend/utils/adt/selfuncs.c
View file @
ae526b40
...
...
@@ -15,7 +15,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.
69 2000/06/05 07:28:52
tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.
70 2000/06/09 01:11:09
tgl Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -1038,14 +1038,16 @@ convert_timevalue_to_scalar(Datum value, Oid typid)
switch
(
typid
)
{
case
TIMESTAMPOID
:
return
*
((
Timestamp
*
)
DatumGetPointer
(
value
)
);
return
DatumGetTimestamp
(
value
);
case
ABSTIMEOID
:
return
*
abstime_timestamp
(
value
);
return
DatumGetTimestamp
(
DirectFunctionCall1
(
abstime_timestamp
,
value
));
case
DATEOID
:
return
*
date_timestamp
(
value
);
return
DatumGetTimestamp
(
DirectFunctionCall1
(
date_timestamp
,
value
));
case
INTERVALOID
:
{
Interval
*
interval
=
(
Interval
*
)
DatumGetPointer
(
value
);
Interval
*
interval
=
DatumGetIntervalP
(
value
);
/*
* Convert the month part of Interval to days using
...
...
@@ -1056,17 +1058,17 @@ convert_timevalue_to_scalar(Datum value, Oid typid)
interval
->
month
*
(
365
.
25
/
12
.
0
*
24
.
0
*
60
.
0
*
60
.
0
);
}
case
RELTIMEOID
:
return
(
RelativeTime
)
DatumGetInt32
(
value
);
return
DatumGetRelativeTime
(
value
);
case
TINTERVALOID
:
{
TimeInterval
interval
=
(
TimeInterval
)
DatumGetPointer
(
value
);
TimeInterval
interval
=
DatumGetTimeInterval
(
value
);
if
(
interval
->
status
!=
0
)
return
interval
->
data
[
1
]
-
interval
->
data
[
0
];
return
0
;
/* for lack of a better idea */
}
case
TIMEOID
:
return
*
((
TimeADT
*
)
DatumGetPointer
(
value
)
);
return
DatumGetTimeADT
(
value
);
}
/* Can't get here unless someone tries to use scalarltsel/scalargtsel
* on an operator with one timevalue and one non-timevalue operand.
...
...
src/backend/utils/adt/sets.c
View file @
ae526b40
...
...
@@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/sets.c,v 1.3
1 2000/05/28 17:56:06
tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/sets.c,v 1.3
2 2000/06/09 01:11:09
tgl Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -140,8 +140,12 @@ SetDefine(char *querystr, char *typename)
* never executed. At runtime, the OID of the actual set is substituted
* into the :funcid.
*/
int
seteval
(
Oid
funcoid
)
Datum
seteval
(
PG_FUNCTION_ARGS
)
{
return
17
;
Oid
funcoid
=
PG_GETARG_OID
(
0
);
elog
(
ERROR
,
"seteval called for OID %u"
,
funcoid
);
PG_RETURN_INT32
(
0
);
/* keep compiler happy */
}
src/backend/utils/adt/tid.c
View file @
ae526b40
...
...
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/tid.c,v 1.
19 2000/06/08 22:37:28 momjian
Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/tid.c,v 1.
20 2000/06/09 01:11:09 tgl
Exp $
*
* NOTES
* input routine largely stolen from boxin().
...
...
@@ -160,19 +160,21 @@ text_tid(const text *string)
/*
* Functions to get latest tid of a specified tuple.
*
Maybe these implementations is moved
* to another place
*/
ItemPointer
currtid_byreloid
(
Oid
reloid
,
ItemPointer
tid
)
*
*
Maybe these implementations should be moved
to another place
*/
Datum
currtid_byreloid
(
PG_FUNCTION_ARGS
)
{
ItemPointer
result
=
NULL
,
ret
;
Relation
rel
;
Oid
reloid
=
PG_GETARG_OID
(
0
);
ItemPointer
tid
=
(
ItemPointer
)
PG_GETARG_POINTER
(
1
);
ItemPointer
result
,
ret
;
Relation
rel
;
result
=
(
ItemPointer
)
palloc
(
sizeof
(
ItemPointerData
));
ItemPointerSetInvalid
(
result
);
if
(
rel
=
heap_open
(
reloid
,
AccessShareLock
),
rel
)
if
(
(
rel
=
heap_open
(
reloid
,
AccessShareLock
))
!=
NULL
)
{
ret
=
heap_get_latest_tid
(
rel
,
SnapshotNow
,
tid
);
if
(
ret
)
...
...
@@ -182,25 +184,24 @@ currtid_byreloid(Oid reloid, ItemPointer tid)
else
elog
(
ERROR
,
"Relation %u not found"
,
reloid
);
return
result
;
}
/* currtid_byreloid() */
PG_RETURN_POINTER
(
result
)
;
}
ItemPointer
currtid_byrelname
(
const
text
*
relname
,
ItemPointer
tid
)
Datum
currtid_byrelname
(
PG_FUNCTION_ARGS
)
{
ItemPointer
result
=
NULL
,
ret
;
char
*
str
;
Relation
rel
;
if
(
!
relname
)
return
result
;
text
*
relname
=
PG_GETARG_TEXT_P
(
0
);
ItemPointer
tid
=
(
ItemPointer
)
PG_GETARG_POINTER
(
1
);
ItemPointer
result
,
ret
;
char
*
str
;
Relation
rel
;
str
=
textout
(
(
text
*
)
relname
);
str
=
textout
(
relname
);
result
=
(
ItemPointer
)
palloc
(
sizeof
(
ItemPointerData
));
ItemPointerSetInvalid
(
result
);
if
(
rel
=
heap_openr
(
str
,
AccessShareLock
),
rel
)
if
(
(
rel
=
heap_openr
(
str
,
AccessShareLock
))
!=
NULL
)
{
ret
=
heap_get_latest_tid
(
rel
,
SnapshotNow
,
tid
);
if
(
ret
)
...
...
@@ -208,8 +209,9 @@ currtid_byrelname(const text *relname, ItemPointer tid)
heap_close
(
rel
,
AccessShareLock
);
}
else
elog
(
ERROR
,
"Relation %s not found"
,
textout
((
text
*
)
relname
));
elog
(
ERROR
,
"Relation %s not found"
,
str
);
pfree
(
str
);
return
result
;
}
/* currtid_byrelname() */
PG_RETURN_POINTER
(
result
)
;
}
src/backend/utils/adt/timestamp.c
View file @
ae526b40
...
...
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.2
8 2000/06/08 22:37:28 momjian
Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.2
9 2000/06/09 01:11:09 tgl
Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -49,11 +49,11 @@ static int tm2interval(struct tm * tm, double fsec, Interval *span);
/* timestamp_in()
* Convert a string to internal form.
*/
Timestamp
*
timestamp_in
(
char
*
str
)
Datum
timestamp_in
(
PG_FUNCTION_ARGS
)
{
Timestamp
*
result
;
char
*
str
=
PG_GETARG_CSTRING
(
0
)
;
Timestamp
result
;
double
fsec
;
struct
tm
tt
,
*
tm
=
&
tt
;
...
...
@@ -64,55 +64,52 @@ timestamp_in(char *str)
int
ftype
[
MAXDATEFIELDS
];
char
lowstr
[
MAXDATELEN
+
1
];
if
(
!
PointerIsValid
(
str
))
elog
(
ERROR
,
"Bad (null) timestamp external representation"
);
if
((
ParseDateTime
(
str
,
lowstr
,
field
,
ftype
,
MAXDATEFIELDS
,
&
nf
)
!=
0
)
||
(
DecodeDateTime
(
field
,
ftype
,
nf
,
&
dtype
,
tm
,
&
fsec
,
&
tz
)
!=
0
))
elog
(
ERROR
,
"Bad timestamp external representation '%s'"
,
str
);
result
=
palloc
(
sizeof
(
Timestamp
));
switch
(
dtype
)
{
case
DTK_DATE
:
if
(
tm2timestamp
(
tm
,
fsec
,
&
tz
,
result
)
!=
0
)
if
(
tm2timestamp
(
tm
,
fsec
,
&
tz
,
&
result
)
!=
0
)
elog
(
ERROR
,
"Timestamp out of range '%s'"
,
str
);
break
;
case
DTK_EPOCH
:
TIMESTAMP_EPOCH
(
*
result
);
TIMESTAMP_EPOCH
(
result
);
break
;
case
DTK_CURRENT
:
TIMESTAMP_CURRENT
(
*
result
);
TIMESTAMP_CURRENT
(
result
);
break
;
case
DTK_LATE
:
TIMESTAMP_NOEND
(
*
result
);
TIMESTAMP_NOEND
(
result
);
break
;
case
DTK_EARLY
:
TIMESTAMP_NOBEGIN
(
*
result
);
TIMESTAMP_NOBEGIN
(
result
);
break
;
case
DTK_INVALID
:
TIMESTAMP_INVALID
(
*
result
);
TIMESTAMP_INVALID
(
result
);
break
;
default:
elog
(
ERROR
,
"Internal coding error, can't input timestamp '%s'"
,
str
);
TIMESTAMP_INVALID
(
result
);
/* keep compiler quiet */
}
return
result
;
}
/* timestamp_in() */
PG_RETURN_TIMESTAMP
(
result
)
;
}
/* timestamp_out()
* Convert a timestamp to external form.
*/
char
*
timestamp_out
(
Timestamp
*
dt
)
Datum
timestamp_out
(
PG_FUNCTION_ARGS
)
{
Timestamp
dt
=
PG_GETARG_TIMESTAMP
(
0
);
char
*
result
;
int
tz
;
struct
tm
tt
,
...
...
@@ -121,22 +118,16 @@ timestamp_out(Timestamp *dt)
char
*
tzn
;
char
buf
[
MAXDATELEN
+
1
];
if
(
!
PointerIsValid
(
dt
))
return
NULL
;
if
(
TIMESTAMP_IS_RESERVED
(
*
dt
))
EncodeSpecialTimestamp
(
*
dt
,
buf
);
else
if
(
timestamp2tm
(
*
dt
,
&
tz
,
tm
,
&
fsec
,
&
tzn
)
==
0
)
if
(
TIMESTAMP_IS_RESERVED
(
dt
))
EncodeSpecialTimestamp
(
dt
,
buf
);
else
if
(
timestamp2tm
(
dt
,
&
tz
,
tm
,
&
fsec
,
&
tzn
)
==
0
)
EncodeDateTime
(
tm
,
fsec
,
&
tz
,
&
tzn
,
DateStyle
,
buf
);
else
EncodeSpecialTimestamp
(
DT_INVALID
,
buf
);
result
=
palloc
(
strlen
(
buf
)
+
1
);
strcpy
(
result
,
buf
);
return
result
;
}
/* timestamp_out() */
result
=
pstrdup
(
buf
);
PG_RETURN_CSTRING
(
result
);
}
/* interval_in()
...
...
@@ -145,11 +136,11 @@ timestamp_out(Timestamp *dt)
* External format(s):
* Uses the generic date/time parsing and decoding routines.
*/
Interval
*
interval_in
(
char
*
str
)
Datum
interval_in
(
PG_FUNCTION_ARGS
)
{
char
*
str
=
PG_GETARG_CSTRING
(
0
);
Interval
*
span
;
double
fsec
;
struct
tm
tt
,
*
tm
=
&
tt
;
...
...
@@ -167,14 +158,11 @@ interval_in(char *str)
tm
->
tm_sec
=
0
;
fsec
=
0
;
if
(
!
PointerIsValid
(
str
))
elog
(
ERROR
,
"Bad (null) interval external representation"
);
if
((
ParseDateTime
(
str
,
lowstr
,
field
,
ftype
,
MAXDATEFIELDS
,
&
nf
)
!=
0
)
||
(
DecodeDateDelta
(
field
,
ftype
,
nf
,
&
dtype
,
tm
,
&
fsec
)
!=
0
))
elog
(
ERROR
,
"Bad interval external representation '%s'"
,
str
);
span
=
palloc
(
sizeof
(
Interval
));
span
=
(
Interval
*
)
palloc
(
sizeof
(
Interval
));
switch
(
dtype
)
{
...
...
@@ -192,36 +180,31 @@ interval_in(char *str)
elog
(
ERROR
,
"Internal coding error, can't input interval '%s'"
,
str
);
}
return
span
;
}
/* interval_in() */
PG_RETURN_INTERVAL_P
(
span
)
;
}
/* interval_out()
* Convert a time span to external form.
*/
char
*
interval_out
(
Interval
*
span
)
Datum
interval_out
(
PG_FUNCTION_ARGS
)
{
Interval
*
span
=
PG_GETARG_INTERVAL_P
(
0
);
char
*
result
;
struct
tm
tt
,
*
tm
=
&
tt
;
double
fsec
;
char
buf
[
MAXDATELEN
+
1
];
if
(
!
PointerIsValid
(
span
))
return
NULL
;
if
(
interval2tm
(
*
span
,
tm
,
&
fsec
)
!=
0
)
return
NULL
;
PG_RETURN_NULL
()
;
if
(
EncodeTimeSpan
(
tm
,
fsec
,
DateStyle
,
buf
)
!=
0
)
elog
(
ERROR
,
"Unable to format interval"
);
result
=
palloc
(
strlen
(
buf
)
+
1
);
strcpy
(
result
,
buf
);
return
result
;
}
/* interval_out() */
result
=
pstrdup
(
buf
);
PG_RETURN_CSTRING
(
result
);
}
/* EncodeSpecialTimestamp()
...
...
@@ -250,19 +233,17 @@ EncodeSpecialTimestamp(Timestamp dt, char *str)
return
FALSE
;
}
/* EncodeSpecialTimestamp() */
Timestamp
*
now
(
void
)
Datum
now
(
PG_FUNCTION_ARGS
)
{
Timestamp
*
result
;
Timestamp
result
;
AbsoluteTime
sec
;
result
=
palloc
(
sizeof
(
Timestamp
));
sec
=
GetCurrentTransactionStartTime
();
*
result
=
(
sec
-
((
date2j
(
2000
,
1
,
1
)
-
date2j
(
1970
,
1
,
1
))
*
86400
));
result
=
(
sec
-
((
date2j
(
2000
,
1
,
1
)
-
date2j
(
1970
,
1
,
1
))
*
86400
));
return
result
;
PG_RETURN_TIMESTAMP
(
result
)
;
}
static
void
...
...
@@ -498,23 +479,21 @@ dt2local(Timestamp dt, int tz)
*****************************************************************************/
bool
timestamp_finite
(
Timestamp
*
timestamp
)
Datum
timestamp_finite
(
PG_FUNCTION_ARGS
)
{
if
(
!
PointerIsValid
(
timestamp
))
return
FALSE
;
Timestamp
timestamp
=
PG_GETARG_TIMESTAMP
(
0
);
return
!
TIMESTAMP_NOT_FINITE
(
*
timestamp
);
}
/* timestamp_finite() */
PG_RETURN_BOOL
(
!
TIMESTAMP_NOT_FINITE
(
timestamp
)
);
}
bool
interval_finite
(
Interval
*
interval
)
Datum
interval_finite
(
PG_FUNCTION_ARGS
)
{
if
(
!
PointerIsValid
(
interval
))
return
FALSE
;
Interval
*
interval
=
PG_GETARG_INTERVAL_P
(
0
);
return
!
INTERVAL_NOT_FINITE
(
*
interval
);
}
/* interval_finite() */
PG_RETURN_BOOL
(
!
INTERVAL_NOT_FINITE
(
*
interval
)
);
}
/*----------------------------------------------------------
...
...
@@ -563,171 +542,128 @@ SetTimestamp(Timestamp dt)
return
dt
;
}
/* SetTimestamp() */
/* timestamp_relop - is timestamp1 relop timestamp2
/*
* timestamp_relop - is timestamp1 relop timestamp2
*/
bool
timestamp_eq
(
Timestamp
*
timestamp1
,
Timestamp
*
timestamp2
)
Datum
timestamp_eq
(
PG_FUNCTION_ARGS
)
{
Timestamp
dt1
,
dt2
;
if
(
!
PointerIsValid
(
timestamp1
)
||
!
PointerIsValid
(
timestamp2
))
return
FALSE
;
dt1
=
*
timestamp1
;
dt2
=
*
timestamp2
;
Timestamp
dt1
=
PG_GETARG_TIMESTAMP
(
0
);
Timestamp
dt2
=
PG_GETARG_TIMESTAMP
(
1
);
if
(
TIMESTAMP_IS_INVALID
(
dt1
)
||
TIMESTAMP_IS_INVALID
(
dt2
))
return
FALSE
;
PG_RETURN_BOOL
(
false
)
;
if
(
TIMESTAMP_IS_RELATIVE
(
dt1
))
dt1
=
SetTimestamp
(
dt1
);
if
(
TIMESTAMP_IS_RELATIVE
(
dt2
))
dt2
=
SetTimestamp
(
dt2
);
return
dt1
==
dt2
;
}
/* timestamp_eq() */
PG_RETURN_BOOL
(
dt1
==
dt2
)
;
}
bool
timestamp_ne
(
Timestamp
*
timestamp1
,
Timestamp
*
timestamp2
)
Datum
timestamp_ne
(
PG_FUNCTION_ARGS
)
{
Timestamp
dt1
,
dt2
;
if
(
!
PointerIsValid
(
timestamp1
)
||
!
PointerIsValid
(
timestamp2
))
return
FALSE
;
dt1
=
*
timestamp1
;
dt2
=
*
timestamp2
;
Timestamp
dt1
=
PG_GETARG_TIMESTAMP
(
0
);
Timestamp
dt2
=
PG_GETARG_TIMESTAMP
(
1
);
if
(
TIMESTAMP_IS_INVALID
(
dt1
)
||
TIMESTAMP_IS_INVALID
(
dt2
))
return
FALSE
;
PG_RETURN_BOOL
(
false
)
;
if
(
TIMESTAMP_IS_RELATIVE
(
dt1
))
dt1
=
SetTimestamp
(
dt1
);
if
(
TIMESTAMP_IS_RELATIVE
(
dt2
))
dt2
=
SetTimestamp
(
dt2
);
return
dt1
!=
dt2
;
}
/* timestamp_ne() */
PG_RETURN_BOOL
(
dt1
!=
dt2
)
;
}
bool
timestamp_lt
(
Timestamp
*
timestamp1
,
Timestamp
*
timestamp2
)
Datum
timestamp_lt
(
PG_FUNCTION_ARGS
)
{
Timestamp
dt1
,
dt2
;
if
(
!
PointerIsValid
(
timestamp1
)
||
!
PointerIsValid
(
timestamp2
))
return
FALSE
;
dt1
=
*
timestamp1
;
dt2
=
*
timestamp2
;
Timestamp
dt1
=
PG_GETARG_TIMESTAMP
(
0
);
Timestamp
dt2
=
PG_GETARG_TIMESTAMP
(
1
);
if
(
TIMESTAMP_IS_INVALID
(
dt1
)
||
TIMESTAMP_IS_INVALID
(
dt2
))
return
FALSE
;
PG_RETURN_BOOL
(
false
)
;
if
(
TIMESTAMP_IS_RELATIVE
(
dt1
))
dt1
=
SetTimestamp
(
dt1
);
if
(
TIMESTAMP_IS_RELATIVE
(
dt2
))
dt2
=
SetTimestamp
(
dt2
);
return
dt1
<
dt2
;
}
/* timestamp_lt() */
PG_RETURN_BOOL
(
dt1
<
dt2
)
;
}
bool
timestamp_gt
(
Timestamp
*
timestamp1
,
Timestamp
*
timestamp2
)
Datum
timestamp_gt
(
PG_FUNCTION_ARGS
)
{
Timestamp
dt1
,
dt2
;
if
(
!
PointerIsValid
(
timestamp1
)
||
!
PointerIsValid
(
timestamp2
))
return
FALSE
;
dt1
=
*
timestamp1
;
dt2
=
*
timestamp2
;
Timestamp
dt1
=
PG_GETARG_TIMESTAMP
(
0
);
Timestamp
dt2
=
PG_GETARG_TIMESTAMP
(
1
);
if
(
TIMESTAMP_IS_INVALID
(
dt1
)
||
TIMESTAMP_IS_INVALID
(
dt2
))
return
FALSE
;
PG_RETURN_BOOL
(
false
)
;
if
(
TIMESTAMP_IS_RELATIVE
(
dt1
))
dt1
=
SetTimestamp
(
dt1
);
if
(
TIMESTAMP_IS_RELATIVE
(
dt2
))
dt2
=
SetTimestamp
(
dt2
);
return
dt1
>
dt2
;
}
/* timestamp_gt() */
PG_RETURN_BOOL
(
dt1
>
dt2
)
;
}
bool
timestamp_le
(
Timestamp
*
timestamp1
,
Timestamp
*
timestamp2
)
Datum
timestamp_le
(
PG_FUNCTION_ARGS
)
{
Timestamp
dt1
,
dt2
;
if
(
!
PointerIsValid
(
timestamp1
)
||
!
PointerIsValid
(
timestamp2
))
return
FALSE
;
dt1
=
*
timestamp1
;
dt2
=
*
timestamp2
;
Timestamp
dt1
=
PG_GETARG_TIMESTAMP
(
0
);
Timestamp
dt2
=
PG_GETARG_TIMESTAMP
(
1
);
if
(
TIMESTAMP_IS_INVALID
(
dt1
)
||
TIMESTAMP_IS_INVALID
(
dt2
))
return
FALSE
;
PG_RETURN_BOOL
(
false
)
;
if
(
TIMESTAMP_IS_RELATIVE
(
dt1
))
dt1
=
SetTimestamp
(
dt1
);
if
(
TIMESTAMP_IS_RELATIVE
(
dt2
))
dt2
=
SetTimestamp
(
dt2
);
return
dt1
<=
dt2
;
}
/* timestamp_le() */
PG_RETURN_BOOL
(
dt1
<=
dt2
)
;
}
bool
timestamp_ge
(
Timestamp
*
timestamp1
,
Timestamp
*
timestamp2
)
Datum
timestamp_ge
(
PG_FUNCTION_ARGS
)
{
Timestamp
dt1
,
dt2
;
if
(
!
PointerIsValid
(
timestamp1
)
||
!
PointerIsValid
(
timestamp2
))
return
FALSE
;
dt1
=
*
timestamp1
;
dt2
=
*
timestamp2
;
Timestamp
dt1
=
PG_GETARG_TIMESTAMP
(
0
);
Timestamp
dt2
=
PG_GETARG_TIMESTAMP
(
1
);
if
(
TIMESTAMP_IS_INVALID
(
dt1
)
||
TIMESTAMP_IS_INVALID
(
dt2
))
return
FALSE
;
PG_RETURN_BOOL
(
false
)
;
if
(
TIMESTAMP_IS_RELATIVE
(
dt1
))
dt1
=
SetTimestamp
(
dt1
);
if
(
TIMESTAMP_IS_RELATIVE
(
dt2
))
dt2
=
SetTimestamp
(
dt2
);
return
dt1
>=
dt2
;
}
/* timestamp_ge() */
PG_RETURN_BOOL
(
dt1
>=
dt2
)
;
}
/* timestamp_cmp - 3-state comparison for timestamp
* collate invalid timestamp at the end
*/
int
timestamp_cmp
(
Timestamp
*
timestamp1
,
Timestamp
*
timestamp2
)
Datum
timestamp_cmp
(
PG_FUNCTION_ARGS
)
{
Timestamp
dt1
,
dt2
;
if
(
!
PointerIsValid
(
timestamp1
)
||
!
PointerIsValid
(
timestamp2
))
return
0
;
dt1
=
*
timestamp1
;
dt2
=
*
timestamp2
;
Timestamp
dt1
=
PG_GETARG_TIMESTAMP
(
0
);
Timestamp
dt2
=
PG_GETARG_TIMESTAMP
(
1
);
if
(
TIMESTAMP_IS_INVALID
(
dt1
))
{
return
(
TIMESTAMP_IS_INVALID
(
dt2
)
?
0
:
1
);
PG_RETURN_INT32
(
TIMESTAMP_IS_INVALID
(
dt2
)
?
0
:
1
);
}
else
if
(
TIMESTAMP_IS_INVALID
(
dt2
))
{
return
-
1
;
PG_RETURN_INT32
(
-
1
);
}
else
{
...
...
@@ -737,49 +673,49 @@ timestamp_cmp(Timestamp *timestamp1, Timestamp *timestamp2)
dt2
=
SetTimestamp
(
dt2
);
}
return
((
dt1
<
dt2
)
?
-
1
:
((
dt1
>
dt2
)
?
1
:
0
));
}
/* timestamp_cmp() */
PG_RETURN_INT32
((
dt1
<
dt2
)
?
-
1
:
((
dt1
>
dt2
)
?
1
:
0
));
}
/* interval_relop - is interval1 relop interval2
/*
* interval_relop - is interval1 relop interval2
*/
bool
interval_eq
(
Interval
*
interval1
,
Interval
*
interval2
)
Datum
interval_eq
(
PG_FUNCTION_ARGS
)
{
if
(
!
PointerIsValid
(
interval1
)
||
!
PointerIsValid
(
interval2
))
return
FALSE
;
Interval
*
interval1
=
PG_GETARG_INTERVAL_P
(
0
);
Interval
*
interval2
=
PG_GETARG_INTERVAL_P
(
1
)
;
if
(
INTERVAL_IS_INVALID
(
*
interval1
)
||
INTERVAL_IS_INVALID
(
*
interval2
))
return
FALSE
;
PG_RETURN_BOOL
(
false
)
;
return
((
interval1
->
time
==
interval2
->
time
)
&&
(
interval1
->
month
==
interval2
->
month
));
}
/* interval_eq() */
PG_RETURN_BOOL
((
interval1
->
time
==
interval2
->
time
)
&&
(
interval1
->
month
==
interval2
->
month
));
}
bool
interval_ne
(
Interval
*
interval1
,
Interval
*
interval2
)
Datum
interval_ne
(
PG_FUNCTION_ARGS
)
{
if
(
!
PointerIsValid
(
interval1
)
||
!
PointerIsValid
(
interval2
))
return
FALSE
;
Interval
*
interval1
=
PG_GETARG_INTERVAL_P
(
0
);
Interval
*
interval2
=
PG_GETARG_INTERVAL_P
(
1
)
;
if
(
INTERVAL_IS_INVALID
(
*
interval1
)
||
INTERVAL_IS_INVALID
(
*
interval2
))
return
FALSE
;
PG_RETURN_BOOL
(
false
)
;
return
((
interval1
->
time
!=
interval2
->
time
)
||
(
interval1
->
month
!=
interval2
->
month
));
}
/* interval_ne() */
PG_RETURN_BOOL
((
interval1
->
time
!=
interval2
->
time
)
||
(
interval1
->
month
!=
interval2
->
month
));
}
bool
interval_lt
(
Interval
*
interval1
,
Interval
*
interval2
)
Datum
interval_lt
(
PG_FUNCTION_ARGS
)
{
Interval
*
interval1
=
PG_GETARG_INTERVAL_P
(
0
);
Interval
*
interval2
=
PG_GETARG_INTERVAL_P
(
1
);
double
span1
,
span2
;
if
(
!
PointerIsValid
(
interval1
)
||
!
PointerIsValid
(
interval2
))
return
FALSE
;
if
(
INTERVAL_IS_INVALID
(
*
interval1
)
||
INTERVAL_IS_INVALID
(
*
interval2
))
return
FALSE
;
PG_RETURN_BOOL
(
false
)
;
span1
=
interval1
->
time
;
if
(
interval1
->
month
!=
0
)
...
...
@@ -788,20 +724,19 @@ interval_lt(Interval *interval1, Interval *interval2)
if
(
interval2
->
month
!=
0
)
span2
+=
(
interval2
->
month
*
(
30
.
0
*
86400
));
return
span1
<
span2
;
}
/* interval_lt() */
PG_RETURN_BOOL
(
span1
<
span2
)
;
}
bool
interval_gt
(
Interval
*
interval1
,
Interval
*
interval2
)
Datum
interval_gt
(
PG_FUNCTION_ARGS
)
{
Interval
*
interval1
=
PG_GETARG_INTERVAL_P
(
0
);
Interval
*
interval2
=
PG_GETARG_INTERVAL_P
(
1
);
double
span1
,
span2
;
if
(
!
PointerIsValid
(
interval1
)
||
!
PointerIsValid
(
interval2
))
return
FALSE
;
if
(
INTERVAL_IS_INVALID
(
*
interval1
)
||
INTERVAL_IS_INVALID
(
*
interval2
))
return
FALSE
;
PG_RETURN_BOOL
(
false
)
;
span1
=
interval1
->
time
;
if
(
interval1
->
month
!=
0
)
...
...
@@ -810,20 +745,19 @@ interval_gt(Interval *interval1, Interval *interval2)
if
(
interval2
->
month
!=
0
)
span2
+=
(
interval2
->
month
*
(
30
.
0
*
86400
));
return
span1
>
span2
;
}
/* interval_gt() */
PG_RETURN_BOOL
(
span1
>
span2
)
;
}
bool
interval_le
(
Interval
*
interval1
,
Interval
*
interval2
)
Datum
interval_le
(
PG_FUNCTION_ARGS
)
{
Interval
*
interval1
=
PG_GETARG_INTERVAL_P
(
0
);
Interval
*
interval2
=
PG_GETARG_INTERVAL_P
(
1
);
double
span1
,
span2
;
if
(
!
PointerIsValid
(
interval1
)
||
!
PointerIsValid
(
interval2
))
return
FALSE
;
if
(
INTERVAL_IS_INVALID
(
*
interval1
)
||
INTERVAL_IS_INVALID
(
*
interval2
))
return
FALSE
;
PG_RETURN_BOOL
(
false
)
;
span1
=
interval1
->
time
;
if
(
interval1
->
month
!=
0
)
...
...
@@ -832,20 +766,19 @@ interval_le(Interval *interval1, Interval *interval2)
if
(
interval2
->
month
!=
0
)
span2
+=
(
interval2
->
month
*
(
30
.
0
*
86400
));
return
span1
<=
span2
;
}
/* interval_le() */
PG_RETURN_BOOL
(
span1
<=
span2
)
;
}
bool
interval_ge
(
Interval
*
interval1
,
Interval
*
interval2
)
Datum
interval_ge
(
PG_FUNCTION_ARGS
)
{
Interval
*
interval1
=
PG_GETARG_INTERVAL_P
(
0
);
Interval
*
interval2
=
PG_GETARG_INTERVAL_P
(
1
);
double
span1
,
span2
;
if
(
!
PointerIsValid
(
interval1
)
||
!
PointerIsValid
(
interval2
))
return
FALSE
;
if
(
INTERVAL_IS_INVALID
(
*
interval1
)
||
INTERVAL_IS_INVALID
(
*
interval2
))
return
FALSE
;
PG_RETURN_BOOL
(
false
)
;
span1
=
interval1
->
time
;
if
(
interval1
->
month
!=
0
)
...
...
@@ -854,28 +787,24 @@ interval_ge(Interval *interval1, Interval *interval2)
if
(
interval2
->
month
!=
0
)
span2
+=
(
interval2
->
month
*
(
30
.
0
*
86400
));
return
span1
>=
span2
;
}
/* interval_ge() */
PG_RETURN_BOOL
(
span1
>=
span2
)
;
}
/* interval_cmp - 3-state comparison for interval
*/
int
interval_cmp
(
Interval
*
interval1
,
Interval
*
interval2
)
Datum
interval_cmp
(
PG_FUNCTION_ARGS
)
{
Interval
*
interval1
=
PG_GETARG_INTERVAL_P
(
0
);
Interval
*
interval2
=
PG_GETARG_INTERVAL_P
(
1
);
double
span1
,
span2
;
if
(
!
PointerIsValid
(
interval1
)
||
!
PointerIsValid
(
interval2
))
return
0
;
if
(
INTERVAL_IS_INVALID
(
*
interval1
))
{
return
INTERVAL_IS_INVALID
(
*
interval2
)
?
0
:
1
;
}
PG_RETURN_INT32
(
INTERVAL_IS_INVALID
(
*
interval2
)
?
0
:
1
);
else
if
(
INTERVAL_IS_INVALID
(
*
interval2
))
return
-
1
;
PG_RETURN_INT32
(
-
1
)
;
span1
=
interval1
->
time
;
if
(
interval1
->
month
!=
0
)
...
...
@@ -884,36 +813,57 @@ interval_cmp(Interval *interval1, Interval *interval2)
if
(
interval2
->
month
!=
0
)
span2
+=
(
interval2
->
month
*
(
30
.
0
*
86400
));
return
(
span1
<
span2
)
?
-
1
:
(
span1
>
span2
)
?
1
:
0
;
}
/* interval_cmp() */
PG_RETURN_INT32
((
span1
<
span2
)
?
-
1
:
(
span1
>
span2
)
?
1
:
0
)
;
}
/* overlaps_timestamp()
* Implements the SQL92 OVERLAPS operator.
* Algorithm from Date and Darwen, 1997
*/
bool
overlaps_timestamp
(
Timestamp
*
ts1
,
Timestamp
*
te1
,
Timestamp
*
ts2
,
Timestamp
*
te2
)
Datum
overlaps_timestamp
(
PG_FUNCTION_ARGS
)
{
/* The arguments are Timestamps, but we leave them as generic Datums
* to avoid unnecessary conversions between value and reference forms...
*/
Datum
ts1
=
PG_GETARG_DATUM
(
0
);
Datum
te1
=
PG_GETARG_DATUM
(
1
);
Datum
ts2
=
PG_GETARG_DATUM
(
2
);
Datum
te2
=
PG_GETARG_DATUM
(
3
);
#define TIMESTAMP_GT(t1,t2) \
DatumGetBool(DirectFunctionCall2(timestamp_gt,t1,t2))
#define TIMESTAMP_LT(t1,t2) \
DatumGetBool(DirectFunctionCall2(timestamp_lt,t1,t2))
#define TIMESTAMP_EQ(t1,t2) \
DatumGetBool(DirectFunctionCall2(timestamp_eq,t1,t2))
/* Make sure we have ordered pairs... */
if
(
timestamp_gt
(
ts1
,
te1
))
if
(
TIMESTAMP_GT
(
ts1
,
te1
))
{
Timestamp
*
tt
=
ts1
;
Datum
tt
=
ts1
;
ts1
=
te1
;
te1
=
tt
;
}
if
(
timestamp_gt
(
ts2
,
te2
))
if
(
TIMESTAMP_GT
(
ts2
,
te2
))
{
Timestamp
*
tt
=
ts2
;
Datum
tt
=
ts2
;
ts2
=
te2
;
te2
=
tt
;
}
return
((
timestamp_gt
(
ts1
,
ts2
)
&&
(
timestamp_lt
(
ts1
,
te2
)
||
timestamp_lt
(
te1
,
te2
)))
||
(
timestamp_gt
(
ts2
,
ts1
)
&&
(
timestamp_lt
(
ts2
,
te1
)
||
timestamp_lt
(
te2
,
te1
)))
||
timestamp_eq
(
ts1
,
ts2
));
}
/* overlaps_timestamp() */
PG_RETURN_BOOL
((
TIMESTAMP_GT
(
ts1
,
ts2
)
&&
(
TIMESTAMP_LT
(
ts1
,
te2
)
||
TIMESTAMP_LT
(
te1
,
te2
)))
||
(
TIMESTAMP_GT
(
ts2
,
ts1
)
&&
(
TIMESTAMP_LT
(
ts2
,
te1
)
||
TIMESTAMP_LT
(
te2
,
te1
)))
||
TIMESTAMP_EQ
(
ts1
,
ts2
));
#undef TIMESTAMP_GT
#undef TIMESTAMP_LT
#undef TIMESTAMP_EQ
}
/*----------------------------------------------------------
...
...
@@ -924,21 +874,12 @@ overlaps_timestamp(Timestamp *ts1, Timestamp *te1, Timestamp *ts2, Timestamp *te
* actual value.
*---------------------------------------------------------*/
Timestamp
*
timestamp_smaller
(
Timestamp
*
timestamp1
,
Timestamp
*
timestamp2
)
Datum
timestamp_smaller
(
PG_FUNCTION_ARGS
)
{
Timestamp
*
result
;
Timestamp
dt1
,
dt2
;
if
(
!
PointerIsValid
(
timestamp1
)
||
!
PointerIsValid
(
timestamp2
))
return
NULL
;
dt1
=
*
timestamp1
;
dt2
=
*
timestamp2
;
result
=
palloc
(
sizeof
(
Timestamp
));
Timestamp
dt1
=
PG_GETARG_TIMESTAMP
(
0
);
Timestamp
dt2
=
PG_GETARG_TIMESTAMP
(
1
);
Timestamp
result
;
if
(
TIMESTAMP_IS_RELATIVE
(
dt1
))
dt1
=
SetTimestamp
(
dt1
);
...
...
@@ -946,30 +887,21 @@ timestamp_smaller(Timestamp *timestamp1, Timestamp *timestamp2)
dt2
=
SetTimestamp
(
dt2
);
if
(
TIMESTAMP_IS_INVALID
(
dt1
))
*
result
=
dt2
;
result
=
dt2
;
else
if
(
TIMESTAMP_IS_INVALID
(
dt2
))
*
result
=
dt1
;
result
=
dt1
;
else
*
result
=
((
dt2
<
dt1
)
?
dt2
:
dt1
);
result
=
((
dt2
<
dt1
)
?
dt2
:
dt1
);
return
result
;
}
/* timestamp_smaller() */
PG_RETURN_TIMESTAMP
(
result
)
;
}
Timestamp
*
timestamp_larger
(
Timestamp
*
timestamp1
,
Timestamp
*
timestamp2
)
Datum
timestamp_larger
(
PG_FUNCTION_ARGS
)
{
Timestamp
*
result
;
Timestamp
dt1
,
dt2
;
if
(
!
PointerIsValid
(
timestamp1
)
||
!
PointerIsValid
(
timestamp2
))
return
NULL
;
dt1
=
*
timestamp1
;
dt2
=
*
timestamp2
;
result
=
palloc
(
sizeof
(
Timestamp
));
Timestamp
dt1
=
PG_GETARG_TIMESTAMP
(
0
);
Timestamp
dt2
=
PG_GETARG_TIMESTAMP
(
1
);
Timestamp
result
;
if
(
TIMESTAMP_IS_RELATIVE
(
dt1
))
dt1
=
SetTimestamp
(
dt1
);
...
...
@@ -977,31 +909,24 @@ timestamp_larger(Timestamp *timestamp1, Timestamp *timestamp2)
dt2
=
SetTimestamp
(
dt2
);
if
(
TIMESTAMP_IS_INVALID
(
dt1
))
*
result
=
dt2
;
result
=
dt2
;
else
if
(
TIMESTAMP_IS_INVALID
(
dt2
))
*
result
=
dt1
;
result
=
dt1
;
else
*
result
=
((
dt2
>
dt1
)
?
dt2
:
dt1
);
result
=
((
dt2
>
dt1
)
?
dt2
:
dt1
);
return
result
;
}
/* timestamp_larger() */
PG_RETURN_TIMESTAMP
(
result
)
;
}
Interval
*
timestamp_mi
(
Timestamp
*
timestamp1
,
Timestamp
*
timestamp2
)
Datum
timestamp_mi
(
PG_FUNCTION_ARGS
)
{
Timestamp
dt1
=
PG_GETARG_TIMESTAMP
(
0
);
Timestamp
dt2
=
PG_GETARG_TIMESTAMP
(
1
);
Interval
*
result
;
Timestamp
dt1
,
dt2
;
if
(
!
PointerIsValid
(
timestamp1
)
||
!
PointerIsValid
(
timestamp2
))
return
NULL
;
dt1
=
*
timestamp1
;
dt2
=
*
timestamp2
;
result
=
palloc
(
sizeof
(
Interval
));
result
=
(
Interval
*
)
palloc
(
sizeof
(
Interval
));
if
(
TIMESTAMP_IS_RELATIVE
(
dt1
))
dt1
=
SetTimestamp
(
dt1
);
...
...
@@ -1010,16 +935,13 @@ timestamp_mi(Timestamp *timestamp1, Timestamp *timestamp2)
if
(
TIMESTAMP_IS_INVALID
(
dt1
)
||
TIMESTAMP_IS_INVALID
(
dt2
))
{
TIMESTAMP_INVALID
(
result
->
time
);
}
else
result
->
time
=
JROUND
(
dt1
-
dt2
);
result
->
month
=
0
;
return
result
;
}
/* timestamp_mi() */
PG_RETURN_INTERVAL_P
(
result
)
;
}
/* timestamp_pl_span()
...
...
@@ -1031,32 +953,23 @@ timestamp_mi(Timestamp *timestamp1, Timestamp *timestamp2)
* to the last day of month.
* Lastly, add in the "quantitative time".
*/
Timestamp
*
timestamp_pl_span
(
Timestamp
*
timestamp
,
Interval
*
span
)
Datum
timestamp_pl_span
(
PG_FUNCTION_ARGS
)
{
Timestamp
*
result
;
Timestamp
timestamp
=
PG_GETARG_TIMESTAMP
(
0
);
Interval
*
span
=
PG_GETARG_INTERVAL_P
(
1
);
Timestamp
result
;
Timestamp
dt
;
int
tz
;
char
*
tzn
;
if
((
!
PointerIsValid
(
timestamp
))
||
(
!
PointerIsValid
(
span
)))
return
NULL
;
result
=
palloc
(
sizeof
(
Timestamp
));
if
(
TIMESTAMP_NOT_FINITE
(
*
timestamp
))
{
*
result
=
*
timestamp
;
}
if
(
TIMESTAMP_NOT_FINITE
(
timestamp
))
result
=
timestamp
;
else
if
(
INTERVAL_IS_INVALID
(
*
span
))
{
TIMESTAMP_INVALID
(
*
result
);
}
TIMESTAMP_INVALID
(
result
);
else
{
dt
=
(
TIMESTAMP_IS_RELATIVE
(
*
timestamp
)
?
SetTimestamp
(
*
timestamp
)
:
*
timestamp
);
dt
=
(
TIMESTAMP_IS_RELATIVE
(
timestamp
)
?
SetTimestamp
(
timestamp
)
:
timestamp
);
if
(
span
->
month
!=
0
)
{
...
...
@@ -1096,71 +1009,63 @@ timestamp_pl_span(Timestamp *timestamp, Interval *span)
dt
+=
span
->
time
;
#endif
*
result
=
dt
;
result
=
dt
;
}
return
result
;
}
/* timestamp_pl_span() */
PG_RETURN_TIMESTAMP
(
result
)
;
}
Timestamp
*
timestamp_mi_span
(
Timestamp
*
timestamp
,
Interval
*
span
)
Datum
timestamp_mi_span
(
PG_FUNCTION_ARGS
)
{
Timestamp
*
result
;
Timestamp
timestamp
=
PG_GETARG_TIMESTAMP
(
0
);
Interval
*
span
=
PG_GETARG_INTERVAL_P
(
1
);
Interval
tspan
;
if
(
!
PointerIsValid
(
timestamp
)
||
!
PointerIsValid
(
span
))
return
NULL
;
tspan
.
month
=
-
span
->
month
;
tspan
.
time
=
-
span
->
time
;
tspan
.
month
=
-
span
->
month
;
tspan
.
time
=
-
span
->
time
;
re
sult
=
timestamp_pl_span
(
timestamp
,
&
tspan
);
return
result
;
}
/* timestamp_mi_span() */
re
turn
DirectFunctionCall2
(
timestamp_pl_span
,
TimestampGetDatum
(
timestamp
),
PointerGetDatum
(
&
tspan
))
;
}
Interval
*
interval_um
(
Interval
*
interval
)
Datum
interval_um
(
PG_FUNCTION_ARGS
)
{
Interval
*
interval
=
PG_GETARG_INTERVAL_P
(
0
);
Interval
*
result
;
if
(
!
PointerIsValid
(
interval
))
return
NULL
;
result
=
palloc
(
sizeof
(
Interval
));
result
=
(
Interval
*
)
palloc
(
sizeof
(
Interval
));
result
->
time
=
-
(
interval
->
time
);
result
->
month
=
-
(
interval
->
month
);
return
result
;
}
/* interval_um() */
PG_RETURN_INTERVAL_P
(
result
)
;
}
Interval
*
interval_smaller
(
Interval
*
interval1
,
Interval
*
interval2
)
Datum
interval_smaller
(
PG_FUNCTION_ARGS
)
{
Interval
*
interval1
=
PG_GETARG_INTERVAL_P
(
0
);
Interval
*
interval2
=
PG_GETARG_INTERVAL_P
(
1
);
Interval
*
result
;
double
span1
,
span2
;
if
(
!
PointerIsValid
(
interval1
)
||
!
PointerIsValid
(
interval2
))
return
NULL
;
result
=
palloc
(
sizeof
(
Interval
));
result
=
(
Interval
*
)
palloc
(
sizeof
(
Interval
));
if
(
INTERVAL_IS_INVALID
(
*
interval1
))
{
result
->
time
=
interval2
->
time
;
result
->
month
=
interval2
->
month
;
}
else
if
(
INTERVAL_IS_INVALID
(
*
interval2
))
{
result
->
time
=
interval1
->
time
;
result
->
month
=
interval1
->
month
;
}
else
{
...
...
@@ -1175,7 +1080,6 @@ interval_smaller(Interval *interval1, Interval *interval2)
{
result
->
time
=
interval2
->
time
;
result
->
month
=
interval2
->
month
;
}
else
{
...
...
@@ -1184,33 +1088,29 @@ interval_smaller(Interval *interval1, Interval *interval2)
}
}
return
result
;
}
/* interval_smaller() */
PG_RETURN_INTERVAL_P
(
result
)
;
}
Interval
*
interval_larger
(
Interval
*
interval1
,
Interval
*
interval2
)
Datum
interval_larger
(
PG_FUNCTION_ARGS
)
{
Interval
*
interval1
=
PG_GETARG_INTERVAL_P
(
0
);
Interval
*
interval2
=
PG_GETARG_INTERVAL_P
(
1
);
Interval
*
result
;
double
span1
,
span2
;
if
(
!
PointerIsValid
(
interval1
)
||
!
PointerIsValid
(
interval2
))
return
NULL
;
result
=
palloc
(
sizeof
(
Interval
));
result
=
(
Interval
*
)
palloc
(
sizeof
(
Interval
));
if
(
INTERVAL_IS_INVALID
(
*
interval1
))
{
result
->
time
=
interval2
->
time
;
result
->
month
=
interval2
->
month
;
}
else
if
(
INTERVAL_IS_INVALID
(
*
interval2
))
{
result
->
time
=
interval1
->
time
;
result
->
month
=
interval1
->
month
;
}
else
{
...
...
@@ -1225,7 +1125,6 @@ interval_larger(Interval *interval1, Interval *interval2)
{
result
->
time
=
interval2
->
time
;
result
->
month
=
interval2
->
month
;
}
else
{
...
...
@@ -1234,92 +1133,90 @@ interval_larger(Interval *interval1, Interval *interval2)
}
}
return
result
;
}
/* interval_larger() */
PG_RETURN_INTERVAL_P
(
result
)
;
}
Interval
*
interval_pl
(
Interval
*
span1
,
Interval
*
span2
)
Datum
interval_pl
(
PG_FUNCTION_ARGS
)
{
Interval
*
span1
=
PG_GETARG_INTERVAL_P
(
0
);
Interval
*
span2
=
PG_GETARG_INTERVAL_P
(
1
);
Interval
*
result
;
if
((
!
PointerIsValid
(
span1
))
||
(
!
PointerIsValid
(
span2
)))
return
NULL
;
result
=
palloc
(
sizeof
(
Interval
));
result
=
(
Interval
*
)
palloc
(
sizeof
(
Interval
));
result
->
month
=
(
span1
->
month
+
span2
->
month
);
result
->
time
=
JROUND
(
span1
->
time
+
span2
->
time
);
return
result
;
}
/* interval_pl() */
PG_RETURN_INTERVAL_P
(
result
)
;
}
Interval
*
interval_mi
(
Interval
*
span1
,
Interval
*
span2
)
Datum
interval_mi
(
PG_FUNCTION_ARGS
)
{
Interval
*
span1
=
PG_GETARG_INTERVAL_P
(
0
);
Interval
*
span2
=
PG_GETARG_INTERVAL_P
(
1
);
Interval
*
result
;
if
((
!
PointerIsValid
(
span1
))
||
(
!
PointerIsValid
(
span2
)))
return
NULL
;
result
=
palloc
(
sizeof
(
Interval
));
result
=
(
Interval
*
)
palloc
(
sizeof
(
Interval
));
result
->
month
=
(
span1
->
month
-
span2
->
month
);
result
->
time
=
JROUND
(
span1
->
time
-
span2
->
time
);
return
result
;
}
/* interval_mi() */
PG_RETURN_INTERVAL_P
(
result
)
;
}
Interval
*
interval_mul
(
Interval
*
span1
,
float8
*
factor
)
Datum
interval_mul
(
PG_FUNCTION_ARGS
)
{
Interval
*
span1
=
PG_GETARG_INTERVAL_P
(
0
);
float8
factor
=
PG_GETARG_FLOAT8
(
1
);
Interval
*
result
;
double
months
;
if
((
!
PointerIsValid
(
span1
))
||
(
!
PointerIsValid
(
factor
)))
return
NULL
;
result
=
(
Interval
*
)
palloc
(
sizeof
(
Interval
));
if
(
!
PointerIsValid
(
result
=
palloc
(
sizeof
(
Interval
))))
elog
(
ERROR
,
"Memory allocation failed, can't multiply interval"
);
months
=
(
span1
->
month
*
*
factor
);
months
=
(
span1
->
month
*
factor
);
result
->
month
=
rint
(
months
);
result
->
time
=
JROUND
(
span1
->
time
*
*
factor
);
result
->
time
=
JROUND
(
span1
->
time
*
factor
);
/* evaluate fractional months as 30 days */
result
->
time
+=
JROUND
((
months
-
result
->
month
)
*
30
*
86400
);
return
result
;
}
/* interval_mul() */
PG_RETURN_INTERVAL_P
(
result
)
;
}
Interval
*
mul_d_interval
(
float8
*
factor
,
Interval
*
span1
)
Datum
mul_d_interval
(
PG_FUNCTION_ARGS
)
{
return
interval_mul
(
span1
,
factor
);
}
/* mul_d_interval() */
/* Args are float8 and Interval *, but leave them as generic Datum */
Datum
factor
=
PG_GETARG_DATUM
(
0
);
Datum
span1
=
PG_GETARG_DATUM
(
1
);
Interval
*
interval_div
(
Interval
*
span1
,
float8
*
factor
)
return
DirectFunctionCall2
(
interval_mul
,
span1
,
factor
);
}
Datum
interval_div
(
PG_FUNCTION_ARGS
)
{
Interval
*
span1
=
PG_GETARG_INTERVAL_P
(
0
);
float8
factor
=
PG_GETARG_FLOAT8
(
1
);
Interval
*
result
;
double
months
;
if
((
!
PointerIsValid
(
span1
))
||
(
!
PointerIsValid
(
factor
)))
return
NULL
;
if
(
!
PointerIsValid
(
result
=
palloc
(
sizeof
(
Interval
))))
elog
(
ERROR
,
"Memory allocation failed, can't divide interval"
);
result
=
(
Interval
*
)
palloc
(
sizeof
(
Interval
));
if
(
*
factor
==
0
.
0
)
if
(
factor
==
0
.
0
)
elog
(
ERROR
,
"interval_div: divide by 0.0 error"
);
months
=
(
span1
->
month
/
*
factor
);
months
=
(
span1
->
month
/
factor
);
result
->
month
=
rint
(
months
);
result
->
time
=
JROUND
(
span1
->
time
/
*
factor
);
result
->
time
=
JROUND
(
span1
->
time
/
factor
);
/* evaluate fractional months as 30 days */
result
->
time
+=
JROUND
((
months
-
result
->
month
)
*
30
*
86400
);
return
result
;
}
/* interval_div() */
PG_RETURN_INTERVAL_P
(
result
)
;
}
/* timestamp_age()
* Calculate time difference while retaining year/month fields.
...
...
@@ -1327,13 +1224,12 @@ interval_div(Interval *span1, float8 *factor)
* since year and month are out of context once the arithmetic
* is done.
*/
Interval
*
timestamp_age
(
Timestamp
*
timestamp1
,
Timestamp
*
timestamp2
)
Datum
timestamp_age
(
PG_FUNCTION_ARGS
)
{
Timestamp
dt1
=
PG_GETARG_TIMESTAMP
(
0
);
Timestamp
dt2
=
PG_GETARG_TIMESTAMP
(
1
);
Interval
*
result
;
Timestamp
dt1
,
dt2
;
double
fsec
,
fsec1
,
fsec2
;
...
...
@@ -1344,13 +1240,7 @@ timestamp_age(Timestamp *timestamp1, Timestamp *timestamp2)
struct
tm
tt2
,
*
tm2
=
&
tt2
;
if
(
!
PointerIsValid
(
timestamp1
)
||
!
PointerIsValid
(
timestamp2
))
return
NULL
;
result
=
palloc
(
sizeof
(
Interval
));
dt1
=
*
timestamp1
;
dt2
=
*
timestamp2
;
result
=
(
Interval
*
)
palloc
(
sizeof
(
Interval
));
if
(
TIMESTAMP_IS_RELATIVE
(
dt1
))
dt1
=
SetTimestamp
(
dt1
);
...
...
@@ -1361,7 +1251,6 @@ timestamp_age(Timestamp *timestamp1, Timestamp *timestamp2)
||
TIMESTAMP_IS_INVALID
(
dt2
))
{
TIMESTAMP_INVALID
(
result
->
time
);
}
else
if
((
timestamp2tm
(
dt1
,
NULL
,
tm1
,
&
fsec1
,
NULL
)
==
0
)
&&
(
timestamp2tm
(
dt2
,
NULL
,
tm2
,
&
fsec2
,
NULL
)
==
0
))
...
...
@@ -1438,13 +1327,12 @@ timestamp_age(Timestamp *timestamp1, Timestamp *timestamp2)
if
(
tm2interval
(
tm
,
fsec
,
result
)
!=
0
)
elog
(
ERROR
,
"Unable to decode timestamp"
);
}
else
elog
(
ERROR
,
"Unable to decode timestamp"
);
return
result
;
}
/* timestamp_age() */
PG_RETURN_INTERVAL_P
(
result
)
;
}
/*----------------------------------------------------------
...
...
@@ -1455,20 +1343,16 @@ timestamp_age(Timestamp *timestamp1, Timestamp *timestamp2)
/* timestamp_text()
* Convert timestamp to text data type.
*/
text
*
timestamp_text
(
Timestamp
*
timestamp
)
Datum
timestamp_text
(
PG_FUNCTION_ARGS
)
{
/* Input is a Timestamp, but may as well leave it in Datum form */
Datum
timestamp
=
PG_GETARG_DATUM
(
0
);
text
*
result
;
char
*
str
;
int
len
;
if
(
!
PointerIsValid
(
timestamp
))
return
NULL
;
str
=
timestamp_out
(
timestamp
);
if
(
!
PointerIsValid
(
str
))
return
NULL
;
str
=
DatumGetCString
(
DirectFunctionCall1
(
timestamp_out
,
timestamp
));
len
=
(
strlen
(
str
)
+
VARHDRSZ
);
...
...
@@ -1479,8 +1363,8 @@ timestamp_text(Timestamp *timestamp)
pfree
(
str
);
return
result
;
}
/* timestamp_text() */
PG_RETURN_TEXT_P
(
result
)
;
}
/* text_timestamp()
...
...
@@ -1488,17 +1372,17 @@ timestamp_text(Timestamp *timestamp)
* Text type is not null terminated, so use temporary string
* then call the standard input routine.
*/
Timestamp
*
text_timestamp
(
text
*
str
)
Datum
text_timestamp
(
PG_FUNCTION_ARGS
)
{
Timestamp
*
result
;
text
*
str
=
PG_GETARG_TEXT_P
(
0
)
;
int
i
;
char
*
sp
,
*
dp
,
dstr
[
MAXDATELEN
+
1
];
if
(
!
PointerIsValid
(
str
)
)
return
NULL
;
if
(
VARSIZE
(
str
)
-
VARHDRSZ
>
MAXDATELEN
)
elog
(
ERROR
,
"Bad timestamp external representation (too long)"
)
;
sp
=
VARDATA
(
str
);
dp
=
dstr
;
...
...
@@ -1506,29 +1390,24 @@ text_timestamp(text *str)
*
dp
++
=
*
sp
++
;
*
dp
=
'\0'
;
result
=
timestamp_in
(
dstr
);
return
result
;
}
/* text_timestamp() */
return
DirectFunctionCall1
(
timestamp_in
,
CStringGetDatum
(
dstr
));
}
/* interval_text()
* Convert interval to text data type.
*/
text
*
interval_text
(
Interval
*
interval
)
Datum
interval_text
(
PG_FUNCTION_ARGS
)
{
Interval
*
interval
=
PG_GETARG_INTERVAL_P
(
0
);
text
*
result
;
char
*
str
;
int
len
;
if
(
!
PointerIsValid
(
interval
))
return
NULL
;
str
=
interval_out
(
interval
);
if
(
!
PointerIsValid
(
str
))
return
NULL
;
str
=
DatumGetCString
(
DirectFunctionCall1
(
interval_out
,
IntervalPGetDatum
(
interval
)));
len
=
(
strlen
(
str
)
+
VARHDRSZ
);
...
...
@@ -1539,8 +1418,8 @@ interval_text(Interval *interval)
pfree
(
str
);
return
result
;
}
/* interval_text() */
PG_RETURN_TEXT_P
(
result
)
;
}
/* text_interval()
...
...
@@ -1548,37 +1427,35 @@ interval_text(Interval *interval)
* Text type may not be null terminated, so copy to temporary string
* then call the standard input routine.
*/
Interval
*
text_interval
(
text
*
str
)
Datum
text_interval
(
PG_FUNCTION_ARGS
)
{
Interval
*
result
;
text
*
str
=
PG_GETARG_TEXT_P
(
0
)
;
int
i
;
char
*
sp
,
*
dp
,
dstr
[
MAXDATELEN
+
1
];
if
(
!
PointerIsValid
(
str
))
return
NULL
;
if
(
VARSIZE
(
str
)
-
VARHDRSZ
>
MAXDATELEN
)
elog
(
ERROR
,
"Bad interval external representation (too long)"
);
sp
=
VARDATA
(
str
);
dp
=
dstr
;
for
(
i
=
0
;
i
<
(
VARSIZE
(
str
)
-
VARHDRSZ
);
i
++
)
*
dp
++
=
*
sp
++
;
*
dp
=
'\0'
;
result
=
interval_in
(
dstr
);
return
result
;
}
/* text_interval() */
return
DirectFunctionCall1
(
interval_in
,
CStringGetDatum
(
dstr
));
}
/* timestamp_trunc()
* Extract specified field from timestamp.
*/
Timestamp
*
timestamp_trunc
(
text
*
units
,
Timestamp
*
timestamp
)
Datum
timestamp_trunc
(
PG_FUNCTION_ARGS
)
{
Timestamp
*
result
;
text
*
units
=
PG_GETARG_TEXT_P
(
0
);
Timestamp
timestamp
=
PG_GETARG_TIMESTAMP
(
1
);
Timestamp
result
;
Timestamp
dt
;
int
tz
;
int
type
,
...
...
@@ -1592,11 +1469,8 @@ timestamp_trunc(text *units, Timestamp *timestamp)
struct
tm
tt
,
*
tm
=
&
tt
;
if
((
!
PointerIsValid
(
units
))
||
(
!
PointerIsValid
(
timestamp
)))
return
NULL
;
result
=
palloc
(
sizeof
(
Timestamp
));
if
(
VARSIZE
(
units
)
-
VARHDRSZ
>
MAXDATELEN
)
elog
(
ERROR
,
"Interval units '%s' not recognized"
,
textout
(
units
));
up
=
VARDATA
(
units
);
lp
=
lowunits
;
for
(
i
=
0
;
i
<
(
VARSIZE
(
units
)
-
VARHDRSZ
);
i
++
)
...
...
@@ -1605,18 +1479,18 @@ timestamp_trunc(text *units, Timestamp *timestamp)
type
=
DecodeUnits
(
0
,
lowunits
,
&
val
);
if
(
TIMESTAMP_NOT_FINITE
(
*
timestamp
))
if
(
TIMESTAMP_NOT_FINITE
(
timestamp
))
{
#if NOT_USED
/* should return null but Postgres doesn't like that currently. - tgl 97/06/12 */
elog
(
ERROR
,
"Timestamp is not finite"
,
NULL
);
elog
(
ERROR
,
"Timestamp is not finite"
);
#endif
*
result
=
0
;
result
=
0
;
}
else
{
dt
=
(
TIMESTAMP_IS_RELATIVE
(
*
timestamp
)
?
SetTimestamp
(
*
timestamp
)
:
*
timestamp
);
dt
=
(
TIMESTAMP_IS_RELATIVE
(
timestamp
)
?
SetTimestamp
(
timestamp
)
:
timestamp
);
if
((
type
==
UNITS
)
&&
(
timestamp2tm
(
dt
,
&
tz
,
tm
,
&
fsec
,
&
tzn
)
==
0
))
{
...
...
@@ -1654,7 +1528,7 @@ timestamp_trunc(text *units, Timestamp *timestamp)
default:
elog
(
ERROR
,
"Timestamp units '%s' not supported"
,
lowunits
);
result
=
NULL
;
result
=
0
;
}
if
(
IS_VALID_UTIME
(
tm
->
tm_year
,
tm
->
tm_mon
,
tm
->
tm_mday
))
...
...
@@ -1692,36 +1566,35 @@ timestamp_trunc(text *units, Timestamp *timestamp)
tz
=
0
;
}
if
(
tm2timestamp
(
tm
,
fsec
,
&
tz
,
result
)
!=
0
)
if
(
tm2timestamp
(
tm
,
fsec
,
&
tz
,
&
result
)
!=
0
)
elog
(
ERROR
,
"Unable to truncate timestamp to '%s'"
,
lowunits
);
#if NOT_USED
}
#if NOT_USED
else
if
((
type
==
RESERV
)
&&
(
val
==
DTK_EPOCH
))
{
TIMESTAMP_EPOCH
(
*
result
);
*
result
=
dt
-
SetTimestamp
(
*
result
);
#endif
TIMESTAMP_EPOCH
(
result
);
result
=
dt
-
SetTimestamp
(
result
);
}
#endif
else
{
elog
(
ERROR
,
"Timestamp units '%s' not recognized"
,
lowunits
);
result
=
NULL
;
result
=
0
;
}
}
return
result
;
}
/* timestamp_trunc() */
PG_RETURN_TIMESTAMP
(
result
)
;
}
/* interval_trunc()
* Extract specified field from interval.
*/
Interval
*
interval_trunc
(
text
*
units
,
Interval
*
interval
)
Datum
interval_trunc
(
PG_FUNCTION_ARGS
)
{
text
*
units
=
PG_GETARG_TEXT_P
(
0
);
Interval
*
interval
=
PG_GETARG_INTERVAL_P
(
1
);
Interval
*
result
;
int
type
,
val
;
int
i
;
...
...
@@ -1732,11 +1605,10 @@ interval_trunc(text *units, Interval *interval)
struct
tm
tt
,
*
tm
=
&
tt
;
if
((
!
PointerIsValid
(
units
))
||
(
!
PointerIsValid
(
interval
)))
return
NULL
;
result
=
palloc
(
sizeof
(
Interval
));
result
=
(
Interval
*
)
palloc
(
sizeof
(
Interval
));
if
(
VARSIZE
(
units
)
-
VARHDRSZ
>
MAXDATELEN
)
elog
(
ERROR
,
"Interval units '%s' not recognized"
,
textout
(
units
));
up
=
VARDATA
(
units
);
lp
=
lowunits
;
for
(
i
=
0
;
i
<
(
VARSIZE
(
units
)
-
VARHDRSZ
);
i
++
)
...
...
@@ -1748,14 +1620,12 @@ interval_trunc(text *units, Interval *interval)
if
(
INTERVAL_IS_INVALID
(
*
interval
))
{
#if NOT_USED
elog
(
ERROR
,
"Interval is not finite"
,
NULL
);
elog
(
ERROR
,
"Interval is not finite"
);
#endif
result
=
NULL
;
PG_RETURN_NULL
();
}
else
if
(
type
==
UNITS
)
{
if
(
interval2tm
(
*
interval
,
tm
,
&
fsec
)
==
0
)
{
switch
(
val
)
...
...
@@ -1792,7 +1662,7 @@ interval_trunc(text *units, Interval *interval)
default:
elog
(
ERROR
,
"Interval units '%s' not supported"
,
lowunits
);
result
=
NULL
;
PG_RETURN_NULL
()
;
}
if
(
tm2interval
(
tm
,
fsec
,
result
)
!=
0
)
...
...
@@ -1802,11 +1672,11 @@ interval_trunc(text *units, Interval *interval)
else
{
elog
(
NOTICE
,
"Interval out of range"
);
result
=
NULL
;
PG_RETURN_NULL
()
;
}
#if NOT_USED
}
#if NOT_USED
else
if
((
type
==
RESERV
)
&&
(
val
==
DTK_EPOCH
))
{
*
result
=
interval
->
time
;
...
...
@@ -1815,27 +1685,27 @@ interval_trunc(text *units, Interval *interval)
*
result
+=
((
365
.
25
*
86400
)
*
(
interval
->
month
/
12
));
*
result
+=
((
30
*
86400
)
*
(
interval
->
month
%
12
));
}
#endif
}
#endif
else
{
elog
(
ERROR
,
"Interval units '%s' not recognized"
,
textout
(
units
));
result
=
NULL
;
PG_RETURN_NULL
()
;
}
return
result
;
}
/* interval_trunc() */
PG_RETURN_INTERVAL_P
(
result
)
;
}
/* timestamp_part()
* Extract specified field from timestamp.
*/
float64
timestamp_part
(
text
*
units
,
Timestamp
*
timestamp
)
Datum
timestamp_part
(
PG_FUNCTION_ARGS
)
{
float64
result
;
text
*
units
=
PG_GETARG_TEXT_P
(
0
);
Timestamp
timestamp
=
PG_GETARG_TIMESTAMP
(
1
);
float8
result
;
Timestamp
dt
;
int
tz
;
int
type
,
...
...
@@ -1850,11 +1720,8 @@ timestamp_part(text *units, Timestamp *timestamp)
struct
tm
tt
,
*
tm
=
&
tt
;
if
((
!
PointerIsValid
(
units
))
||
(
!
PointerIsValid
(
timestamp
)))
return
NULL
;
result
=
palloc
(
sizeof
(
float64data
));
if
(
VARSIZE
(
units
)
-
VARHDRSZ
>
MAXDATELEN
)
elog
(
ERROR
,
"Interval units '%s' not recognized"
,
textout
(
units
));
up
=
VARDATA
(
units
);
lp
=
lowunits
;
for
(
i
=
0
;
i
<
(
VARSIZE
(
units
)
-
VARHDRSZ
);
i
++
)
...
...
@@ -1865,67 +1732,66 @@ timestamp_part(text *units, Timestamp *timestamp)
if
(
type
==
IGNORE
)
type
=
DecodeSpecial
(
0
,
lowunits
,
&
val
);
if
(
TIMESTAMP_NOT_FINITE
(
*
timestamp
))
if
(
TIMESTAMP_NOT_FINITE
(
timestamp
))
{
#if NOT_USED
/* should return null but Postgres doesn't like that currently. - tgl 97/06/12 */
elog
(
ERROR
,
"Timestamp is not finite"
,
NULL
);
#endif
*
result
=
0
;
PG_RETURN_NULL
();
}
else
{
dt
=
(
TIMESTAMP_IS_RELATIVE
(
*
timestamp
)
?
SetTimestamp
(
*
timestamp
)
:
*
timestamp
);
dt
=
(
TIMESTAMP_IS_RELATIVE
(
timestamp
)
?
SetTimestamp
(
timestamp
)
:
timestamp
);
if
((
type
==
UNITS
)
&&
(
timestamp2tm
(
dt
,
&
tz
,
tm
,
&
fsec
,
&
tzn
)
==
0
))
{
switch
(
val
)
{
case
DTK_TZ
:
*
result
=
tz
;
result
=
tz
;
break
;
case
DTK_TZ_MINUTE
:
*
result
=
tz
/
60
;
TMODULO
(
*
result
,
dummy
,
60e0
);
result
=
tz
/
60
;
TMODULO
(
result
,
dummy
,
60e0
);
break
;
case
DTK_TZ_HOUR
:
dummy
=
tz
;
TMODULO
(
dummy
,
*
result
,
3600e0
);
TMODULO
(
dummy
,
result
,
3600e0
);
break
;
case
DTK_MICROSEC
:
*
result
=
(
fsec
*
1000000
);
result
=
(
fsec
*
1000000
);
break
;
case
DTK_MILLISEC
:
*
result
=
(
fsec
*
1000
);
result
=
(
fsec
*
1000
);
break
;
case
DTK_SECOND
:
*
result
=
(
tm
->
tm_sec
+
fsec
);
result
=
(
tm
->
tm_sec
+
fsec
);
break
;
case
DTK_MINUTE
:
*
result
=
tm
->
tm_min
;
result
=
tm
->
tm_min
;
break
;
case
DTK_HOUR
:
*
result
=
tm
->
tm_hour
;
result
=
tm
->
tm_hour
;
break
;
case
DTK_DAY
:
*
result
=
tm
->
tm_mday
;
result
=
tm
->
tm_mday
;
break
;
case
DTK_MONTH
:
*
result
=
tm
->
tm_mon
;
result
=
tm
->
tm_mon
;
break
;
case
DTK_QUARTER
:
*
result
=
(
tm
->
tm_mon
/
4
)
+
1
;
result
=
(
tm
->
tm_mon
/
4
)
+
1
;
break
;
case
DTK_WEEK
:
...
...
@@ -1945,40 +1811,40 @@ timestamp_part(text *units, Timestamp *timestamp)
/* day0 == offset to first day of week (Monday) */
day0
=
(
j2day
(
day4
-
1
)
%
7
);
}
*
result
=
(((
dayn
-
(
day4
-
day0
))
/
7
)
+
1
);
result
=
(((
dayn
-
(
day4
-
day0
))
/
7
)
+
1
);
/* Sometimes the last few days in a year will fall into
* the first week of the next year, so check for this.
*/
if
(
*
result
>=
53
)
if
(
result
>=
53
)
{
day4
=
date2j
((
tm
->
tm_year
+
1
),
1
,
4
);
/* day0 == offset to first day of week (Monday) */
day0
=
(
j2day
(
day4
-
1
)
%
7
);
if
(
dayn
>=
(
day4
-
day0
))
*
result
=
(((
dayn
-
(
day4
-
day0
))
/
7
)
+
1
);
result
=
(((
dayn
-
(
day4
-
day0
))
/
7
)
+
1
);
}
}
break
;
case
DTK_YEAR
:
*
result
=
tm
->
tm_year
;
result
=
tm
->
tm_year
;
break
;
case
DTK_DECADE
:
*
result
=
(
tm
->
tm_year
/
10
);
result
=
(
tm
->
tm_year
/
10
);
break
;
case
DTK_CENTURY
:
*
result
=
(
tm
->
tm_year
/
100
);
result
=
(
tm
->
tm_year
/
100
);
break
;
case
DTK_MILLENNIUM
:
*
result
=
(
tm
->
tm_year
/
1000
);
result
=
(
tm
->
tm_year
/
1000
);
break
;
default:
elog
(
ERROR
,
"Timestamp units '%s' not supported"
,
lowunits
);
*
result
=
0
;
result
=
0
;
}
}
...
...
@@ -1987,50 +1853,51 @@ timestamp_part(text *units, Timestamp *timestamp)
switch
(
val
)
{
case
DTK_EPOCH
:
TIMESTAMP_EPOCH
(
*
result
);
*
result
=
dt
-
SetTimestamp
(
*
result
);
TIMESTAMP_EPOCH
(
result
);
result
=
dt
-
SetTimestamp
(
result
);
break
;
case
DTK_DOW
:
if
(
timestamp2tm
(
dt
,
&
tz
,
tm
,
&
fsec
,
&
tzn
)
!=
0
)
elog
(
ERROR
,
"Unable to encode timestamp"
);
*
result
=
j2day
(
date2j
(
tm
->
tm_year
,
tm
->
tm_mon
,
tm
->
tm_mday
));
result
=
j2day
(
date2j
(
tm
->
tm_year
,
tm
->
tm_mon
,
tm
->
tm_mday
));
break
;
case
DTK_DOY
:
if
(
timestamp2tm
(
dt
,
&
tz
,
tm
,
&
fsec
,
&
tzn
)
!=
0
)
elog
(
ERROR
,
"Unable to encode timestamp"
);
*
result
=
(
date2j
(
tm
->
tm_year
,
tm
->
tm_mon
,
tm
->
tm_mday
)
result
=
(
date2j
(
tm
->
tm_year
,
tm
->
tm_mon
,
tm
->
tm_mday
)
-
date2j
(
tm
->
tm_year
,
1
,
1
)
+
1
);
break
;
default:
elog
(
ERROR
,
"Timestamp units '%s' not supported"
,
lowunits
);
*
result
=
0
;
result
=
0
;
}
}
else
{
elog
(
ERROR
,
"Timestamp units '%s' not recognized"
,
lowunits
);
*
result
=
0
;
result
=
0
;
}
}
return
result
;
}
/* timestamp_part() */
PG_RETURN_FLOAT8
(
result
)
;
}
/* interval_part()
* Extract specified field from interval.
*/
float64
interval_part
(
text
*
units
,
Interval
*
interval
)
Datum
interval_part
(
PG_FUNCTION_ARGS
)
{
float64
result
;
text
*
units
=
PG_GETARG_TEXT_P
(
0
);
Interval
*
interval
=
PG_GETARG_INTERVAL_P
(
1
);
float8
result
;
int
type
,
val
;
int
i
;
...
...
@@ -2041,11 +1908,8 @@ interval_part(text *units, Interval *interval)
struct
tm
tt
,
*
tm
=
&
tt
;
if
((
!
PointerIsValid
(
units
))
||
(
!
PointerIsValid
(
interval
)))
return
NULL
;
result
=
palloc
(
sizeof
(
float64data
));
if
(
VARSIZE
(
units
)
-
VARHDRSZ
>
MAXDATELEN
)
elog
(
ERROR
,
"Interval units '%s' not recognized"
,
textout
(
units
));
up
=
VARDATA
(
units
);
lp
=
lowunits
;
for
(
i
=
0
;
i
<
(
VARSIZE
(
units
)
-
VARHDRSZ
);
i
++
)
...
...
@@ -2061,105 +1925,103 @@ interval_part(text *units, Interval *interval)
#if NOT_USED
elog
(
ERROR
,
"Interval is not finite"
);
#endif
*
result
=
0
;
result
=
0
;
}
else
if
(
type
==
UNITS
)
{
if
(
interval2tm
(
*
interval
,
tm
,
&
fsec
)
==
0
)
{
switch
(
val
)
{
case
DTK_MICROSEC
:
*
result
=
(
fsec
*
1000000
);
result
=
(
fsec
*
1000000
);
break
;
case
DTK_MILLISEC
:
*
result
=
(
fsec
*
1000
);
result
=
(
fsec
*
1000
);
break
;
case
DTK_SECOND
:
*
result
=
(
tm
->
tm_sec
+
fsec
);
result
=
(
tm
->
tm_sec
+
fsec
);
break
;
case
DTK_MINUTE
:
*
result
=
tm
->
tm_min
;
result
=
tm
->
tm_min
;
break
;
case
DTK_HOUR
:
*
result
=
tm
->
tm_hour
;
result
=
tm
->
tm_hour
;
break
;
case
DTK_DAY
:
*
result
=
tm
->
tm_mday
;
result
=
tm
->
tm_mday
;
break
;
case
DTK_MONTH
:
*
result
=
tm
->
tm_mon
;
result
=
tm
->
tm_mon
;
break
;
case
DTK_QUARTER
:
*
result
=
(
tm
->
tm_mon
/
4
)
+
1
;
result
=
(
tm
->
tm_mon
/
4
)
+
1
;
break
;
case
DTK_YEAR
:
*
result
=
tm
->
tm_year
;
result
=
tm
->
tm_year
;
break
;
case
DTK_DECADE
:
*
result
=
(
tm
->
tm_year
/
10
);
result
=
(
tm
->
tm_year
/
10
);
break
;
case
DTK_CENTURY
:
*
result
=
(
tm
->
tm_year
/
100
);
result
=
(
tm
->
tm_year
/
100
);
break
;
case
DTK_MILLENNIUM
:
*
result
=
(
tm
->
tm_year
/
1000
);
result
=
(
tm
->
tm_year
/
1000
);
break
;
default:
elog
(
ERROR
,
"Interval units '%s' not yet supported"
,
textout
(
units
));
result
=
NULL
;
elog
(
ERROR
,
"Interval units '%s' not yet supported"
,
textout
(
units
));
result
=
0
;
}
}
else
{
elog
(
NOTICE
,
"Interval out of range"
);
*
result
=
0
;
result
=
0
;
}
}
else
if
((
type
==
RESERV
)
&&
(
val
==
DTK_EPOCH
))
{
*
result
=
interval
->
time
;
result
=
interval
->
time
;
if
(
interval
->
month
!=
0
)
{
*
result
+=
((
365
.
25
*
86400
)
*
(
interval
->
month
/
12
));
*
result
+=
((
30
*
86400
)
*
(
interval
->
month
%
12
));
result
+=
((
365
.
25
*
86400
)
*
(
interval
->
month
/
12
));
result
+=
((
30
*
86400
)
*
(
interval
->
month
%
12
));
}
}
else
{
elog
(
ERROR
,
"Interval units '%s' not recognized"
,
textout
(
units
));
*
result
=
0
;
result
=
0
;
}
return
result
;
}
/* interval_part() */
PG_RETURN_FLOAT8
(
result
)
;
}
/* timestamp_zone()
* Encode timestamp type with specified time zone.
*/
text
*
timestamp_zone
(
text
*
zone
,
Timestamp
*
timestamp
)
Datum
timestamp_zone
(
PG_FUNCTION_ARGS
)
{
text
*
zone
=
PG_GETARG_TEXT_P
(
0
);
Timestamp
timestamp
=
PG_GETARG_TIMESTAMP
(
1
);
text
*
result
;
Timestamp
dt
;
int
tz
;
int
type
,
...
...
@@ -2176,9 +2038,8 @@ timestamp_zone(text *zone, Timestamp *timestamp)
char
buf
[
MAXDATELEN
+
1
];
int
len
;
if
((
!
PointerIsValid
(
zone
))
||
(
!
PointerIsValid
(
timestamp
)))
return
NULL
;
if
(
VARSIZE
(
zone
)
-
VARHDRSZ
>
MAXDATELEN
)
elog
(
ERROR
,
"Time zone '%s' not recognized"
,
textout
(
zone
));
up
=
VARDATA
(
zone
);
lp
=
lowzone
;
for
(
i
=
0
;
i
<
(
VARSIZE
(
zone
)
-
VARHDRSZ
);
i
++
)
...
...
@@ -2187,23 +2048,24 @@ timestamp_zone(text *zone, Timestamp *timestamp)
type
=
DecodeSpecial
(
0
,
lowzone
,
&
val
);
if
(
TIMESTAMP_NOT_FINITE
(
*
timestamp
))
if
(
TIMESTAMP_NOT_FINITE
(
timestamp
))
{
/*
* could return null but Postgres doesn't like that currently. -
* tgl 97/06/12
*
* Could do it now if you wanted ... the other tgl 2000/06/08
*/
elog
(
ERROR
,
"Timestamp is not finite"
);
result
=
NULL
;
}
else
if
((
type
==
TZ
)
||
(
type
==
DTZ
))
{
tm
->
tm_isdst
=
((
type
==
DTZ
)
?
1
:
0
);
tz
=
val
*
60
;
dt
=
(
TIMESTAMP_IS_RELATIVE
(
*
timestamp
)
?
SetTimestamp
(
*
timestamp
)
:
*
timestamp
);
dt
=
(
TIMESTAMP_IS_RELATIVE
(
timestamp
)
?
SetTimestamp
(
timestamp
)
:
timestamp
);
dt
=
dt2local
(
dt
,
tz
);
if
(
timestamp2tm
(
dt
,
NULL
,
tm
,
&
fsec
,
NULL
)
!=
0
)
...
...
@@ -2224,7 +2086,6 @@ timestamp_zone(text *zone, Timestamp *timestamp)
VARSIZE
(
result
)
=
len
;
memmove
(
VARDATA
(
result
),
buf
,
(
len
-
VARHDRSZ
));
}
else
{
...
...
@@ -2232,5 +2093,5 @@ timestamp_zone(text *zone, Timestamp *timestamp)
result
=
NULL
;
}
return
result
;
}
/* timestamp_zone() */
PG_RETURN_TEXT_P
(
result
)
;
}
src/include/catalog/catversion.h
View file @
ae526b40
...
...
@@ -37,7 +37,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: catversion.h,v 1.2
6 2000/06/07 04:09:44 momjian
Exp $
* $Id: catversion.h,v 1.2
7 2000/06/09 01:11:10 tgl
Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -53,6 +53,6 @@
*/
/* yyyymmddN */
#define CATALOG_VERSION_NO 2000060
7
1
#define CATALOG_VERSION_NO 2000060
8
1
#endif
src/include/catalog/pg_proc.h
View file @
ae526b40
...
...
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: pg_proc.h,v 1.13
6 2000/06/05 07:28:59
tgl Exp $
* $Id: pg_proc.h,v 1.13
7 2000/06/09 01:11:10
tgl Exp $
*
* NOTES
* The script catalog/genbki.sh reads this file and generates .bki
...
...
@@ -500,77 +500,77 @@ DESCR("convert float4 to int2");
DATA
(
insert
OID
=
239
(
line_distance
PGUID
11
f
t
t
t
2
f
701
"628 628"
100
0
0
100
line_distance
-
));
DESCR
(
"distance between"
);
DATA
(
insert
OID
=
240
(
nabstimein
PGUID
1
1
f
t
f
t
1
f
702
"0"
100
0
0
100
nabstimein
-
));
DATA
(
insert
OID
=
240
(
nabstimein
PGUID
1
2
f
t
f
t
1
f
702
"0"
100
0
0
100
nabstimein
-
));
DESCR
(
"(internal)"
);
DATA
(
insert
OID
=
241
(
nabstimeout
PGUID
1
1
f
t
f
t
1
f
23
"0"
100
0
0
100
nabstimeout
-
));
DATA
(
insert
OID
=
241
(
nabstimeout
PGUID
1
2
f
t
f
t
1
f
23
"0"
100
0
0
100
nabstimeout
-
));
DESCR
(
"(internal)"
);
DATA
(
insert
OID
=
242
(
reltimein
PGUID
1
1
f
t
f
t
1
f
703
"0"
100
0
0
100
reltimein
-
));
DATA
(
insert
OID
=
242
(
reltimein
PGUID
1
2
f
t
f
t
1
f
703
"0"
100
0
0
100
reltimein
-
));
DESCR
(
"(internal)"
);
DATA
(
insert
OID
=
243
(
reltimeout
PGUID
1
1
f
t
f
t
1
f
23
"0"
100
0
0
100
reltimeout
-
));
DATA
(
insert
OID
=
243
(
reltimeout
PGUID
1
2
f
t
f
t
1
f
23
"0"
100
0
0
100
reltimeout
-
));
DESCR
(
"(internal)"
);
DATA
(
insert
OID
=
244
(
timepl
PGUID
1
1
f
t
f
t
2
f
702
"702 703"
100
0
0
100
timepl
-
));
DATA
(
insert
OID
=
244
(
timepl
PGUID
1
2
f
t
f
t
2
f
702
"702 703"
100
0
0
100
timepl
-
));
DESCR
(
"addition"
);
DATA
(
insert
OID
=
245
(
timemi
PGUID
1
1
f
t
f
t
2
f
702
"702 703"
100
0
0
100
timemi
-
));
DATA
(
insert
OID
=
245
(
timemi
PGUID
1
2
f
t
f
t
2
f
702
"702 703"
100
0
0
100
timemi
-
));
DESCR
(
"subtract"
);
DATA
(
insert
OID
=
246
(
tintervalin
PGUID
1
1
f
t
f
t
1
f
704
"0"
100
0
0
100
tintervalin
-
));
DATA
(
insert
OID
=
246
(
tintervalin
PGUID
1
2
f
t
f
t
1
f
704
"0"
100
0
0
100
tintervalin
-
));
DESCR
(
"(internal)"
);
DATA
(
insert
OID
=
247
(
tintervalout
PGUID
1
1
f
t
f
t
1
f
23
"0"
100
0
0
100
tintervalout
-
));
DATA
(
insert
OID
=
247
(
tintervalout
PGUID
1
2
f
t
f
t
1
f
23
"0"
100
0
0
100
tintervalout
-
));
DESCR
(
"(internal)"
);
DATA
(
insert
OID
=
248
(
intinterval
PGUID
1
1
f
t
f
t
2
f
16
"702 704"
100
0
0
100
intinterval
-
));
DATA
(
insert
OID
=
248
(
intinterval
PGUID
1
2
f
t
f
t
2
f
16
"702 704"
100
0
0
100
intinterval
-
));
DESCR
(
"abstime in tinterval"
);
DATA
(
insert
OID
=
249
(
tintervalrel
PGUID
1
1
f
t
f
t
1
f
703
"704"
100
0
0
100
tintervalrel
-
));
DATA
(
insert
OID
=
249
(
tintervalrel
PGUID
1
2
f
t
f
t
1
f
703
"704"
100
0
0
100
tintervalrel
-
));
DESCR
(
""
);
DATA
(
insert
OID
=
250
(
timenow
PGUID
1
1
f
t
f
t
0
f
702
"0"
100
0
0
100
timenow
-
));
DATA
(
insert
OID
=
250
(
timenow
PGUID
1
2
f
t
f
t
0
f
702
"0"
100
0
0
100
timenow
-
));
DESCR
(
"Current date and time (abstime)"
);
DATA
(
insert
OID
=
251
(
abstimeeq
PGUID
1
1
f
t
f
t
2
f
16
"702 702"
100
0
0
100
abstimeeq
-
));
DATA
(
insert
OID
=
251
(
abstimeeq
PGUID
1
2
f
t
f
t
2
f
16
"702 702"
100
0
0
100
abstimeeq
-
));
DESCR
(
"equal"
);
DATA
(
insert
OID
=
252
(
abstimene
PGUID
1
1
f
t
f
t
2
f
16
"702 702"
100
0
0
100
abstimene
-
));
DATA
(
insert
OID
=
252
(
abstimene
PGUID
1
2
f
t
f
t
2
f
16
"702 702"
100
0
0
100
abstimene
-
));
DESCR
(
"not equal"
);
DATA
(
insert
OID
=
253
(
abstimelt
PGUID
1
1
f
t
f
t
2
f
16
"702 702"
100
0
0
100
abstimelt
-
));
DATA
(
insert
OID
=
253
(
abstimelt
PGUID
1
2
f
t
f
t
2
f
16
"702 702"
100
0
0
100
abstimelt
-
));
DESCR
(
"less-than"
);
DATA
(
insert
OID
=
254
(
abstimegt
PGUID
1
1
f
t
f
t
2
f
16
"702 702"
100
0
0
100
abstimegt
-
));
DATA
(
insert
OID
=
254
(
abstimegt
PGUID
1
2
f
t
f
t
2
f
16
"702 702"
100
0
0
100
abstimegt
-
));
DESCR
(
"greater-than"
);
DATA
(
insert
OID
=
255
(
abstimele
PGUID
1
1
f
t
f
t
2
f
16
"702 702"
100
0
0
100
abstimele
-
));
DATA
(
insert
OID
=
255
(
abstimele
PGUID
1
2
f
t
f
t
2
f
16
"702 702"
100
0
0
100
abstimele
-
));
DESCR
(
"less-than-or-equal"
);
DATA
(
insert
OID
=
256
(
abstimege
PGUID
1
1
f
t
f
t
2
f
16
"702 702"
100
0
0
100
abstimege
-
));
DATA
(
insert
OID
=
256
(
abstimege
PGUID
1
2
f
t
f
t
2
f
16
"702 702"
100
0
0
100
abstimege
-
));
DESCR
(
"greater-than-or-equal"
);
DATA
(
insert
OID
=
257
(
reltimeeq
PGUID
1
1
f
t
t
t
2
f
16
"703 703"
100
0
0
100
reltimeeq
-
));
DATA
(
insert
OID
=
257
(
reltimeeq
PGUID
1
2
f
t
t
t
2
f
16
"703 703"
100
0
0
100
reltimeeq
-
));
DESCR
(
"equal"
);
DATA
(
insert
OID
=
258
(
reltimene
PGUID
1
1
f
t
t
t
2
f
16
"703 703"
100
0
0
100
reltimene
-
));
DATA
(
insert
OID
=
258
(
reltimene
PGUID
1
2
f
t
t
t
2
f
16
"703 703"
100
0
0
100
reltimene
-
));
DESCR
(
"not equal"
);
DATA
(
insert
OID
=
259
(
reltimelt
PGUID
1
1
f
t
t
t
2
f
16
"703 703"
100
0
0
100
reltimelt
-
));
DATA
(
insert
OID
=
259
(
reltimelt
PGUID
1
2
f
t
t
t
2
f
16
"703 703"
100
0
0
100
reltimelt
-
));
DESCR
(
"less-than"
);
DATA
(
insert
OID
=
260
(
reltimegt
PGUID
1
1
f
t
t
t
2
f
16
"703 703"
100
0
0
100
reltimegt
-
));
DATA
(
insert
OID
=
260
(
reltimegt
PGUID
1
2
f
t
t
t
2
f
16
"703 703"
100
0
0
100
reltimegt
-
));
DESCR
(
"greater-than"
);
DATA
(
insert
OID
=
261
(
reltimele
PGUID
1
1
f
t
t
t
2
f
16
"703 703"
100
0
0
100
reltimele
-
));
DATA
(
insert
OID
=
261
(
reltimele
PGUID
1
2
f
t
t
t
2
f
16
"703 703"
100
0
0
100
reltimele
-
));
DESCR
(
"less-than-or-equal"
);
DATA
(
insert
OID
=
262
(
reltimege
PGUID
1
1
f
t
t
t
2
f
16
"703 703"
100
0
0
100
reltimege
-
));
DATA
(
insert
OID
=
262
(
reltimege
PGUID
1
2
f
t
t
t
2
f
16
"703 703"
100
0
0
100
reltimege
-
));
DESCR
(
"greater-than-or-equal"
);
DATA
(
insert
OID
=
263
(
tintervalsame
PGUID
1
1
f
t
f
t
2
f
16
"704 704"
100
0
0
100
tintervalsame
-
));
DATA
(
insert
OID
=
263
(
tintervalsame
PGUID
1
2
f
t
f
t
2
f
16
"704 704"
100
0
0
100
tintervalsame
-
));
DESCR
(
"same as"
);
DATA
(
insert
OID
=
264
(
tintervalct
PGUID
1
1
f
t
f
t
2
f
16
"704 704"
100
0
0
100
tintervalct
-
));
DATA
(
insert
OID
=
264
(
tintervalct
PGUID
1
2
f
t
f
t
2
f
16
"704 704"
100
0
0
100
tintervalct
-
));
DESCR
(
"less-than"
);
DATA
(
insert
OID
=
265
(
tintervalov
PGUID
1
1
f
t
f
t
2
f
16
"704 704"
100
0
0
100
tintervalov
-
));
DATA
(
insert
OID
=
265
(
tintervalov
PGUID
1
2
f
t
f
t
2
f
16
"704 704"
100
0
0
100
tintervalov
-
));
DESCR
(
"overlaps"
);
DATA
(
insert
OID
=
266
(
tintervalleneq
PGUID
1
1
f
t
f
t
2
f
16
"704 703"
100
0
0
100
tintervalleneq
-
));
DATA
(
insert
OID
=
266
(
tintervalleneq
PGUID
1
2
f
t
f
t
2
f
16
"704 703"
100
0
0
100
tintervalleneq
-
));
DESCR
(
"length equal"
);
DATA
(
insert
OID
=
267
(
tintervallenne
PGUID
1
1
f
t
f
t
2
f
16
"704 703"
100
0
0
100
tintervallenne
-
));
DATA
(
insert
OID
=
267
(
tintervallenne
PGUID
1
2
f
t
f
t
2
f
16
"704 703"
100
0
0
100
tintervallenne
-
));
DESCR
(
"length not equal to"
);
DATA
(
insert
OID
=
268
(
tintervallenlt
PGUID
1
1
f
t
f
t
2
f
16
"704 703"
100
0
0
100
tintervallenlt
-
));
DATA
(
insert
OID
=
268
(
tintervallenlt
PGUID
1
2
f
t
f
t
2
f
16
"704 703"
100
0
0
100
tintervallenlt
-
));
DESCR
(
"length less-than"
);
DATA
(
insert
OID
=
269
(
tintervallengt
PGUID
1
1
f
t
f
t
2
f
16
"704 703"
100
0
0
100
tintervallengt
-
));
DATA
(
insert
OID
=
269
(
tintervallengt
PGUID
1
2
f
t
f
t
2
f
16
"704 703"
100
0
0
100
tintervallengt
-
));
DESCR
(
"length greater-than"
);
DATA
(
insert
OID
=
270
(
tintervallenle
PGUID
1
1
f
t
f
t
2
f
16
"704 703"
100
0
0
100
tintervallenle
-
));
DATA
(
insert
OID
=
270
(
tintervallenle
PGUID
1
2
f
t
f
t
2
f
16
"704 703"
100
0
0
100
tintervallenle
-
));
DESCR
(
"length less-than-or-equal"
);
DATA
(
insert
OID
=
271
(
tintervallenge
PGUID
1
1
f
t
f
t
2
f
16
"704 703"
100
0
0
100
tintervallenge
-
));
DATA
(
insert
OID
=
271
(
tintervallenge
PGUID
1
2
f
t
f
t
2
f
16
"704 703"
100
0
0
100
tintervallenge
-
));
DESCR
(
"length greater-than-or-equal"
);
DATA
(
insert
OID
=
272
(
tintervalstart
PGUID
1
1
f
t
f
t
1
f
702
"704"
100
0
0
100
tintervalstart
-
));
DATA
(
insert
OID
=
272
(
tintervalstart
PGUID
1
2
f
t
f
t
1
f
702
"704"
100
0
0
100
tintervalstart
-
));
DESCR
(
"start of interval"
);
DATA
(
insert
OID
=
273
(
tintervalend
PGUID
1
1
f
t
f
t
1
f
702
"704"
100
0
0
100
tintervalend
-
));
DATA
(
insert
OID
=
273
(
tintervalend
PGUID
1
2
f
t
f
t
1
f
702
"704"
100
0
0
100
tintervalend
-
));
DESCR
(
""
);
DATA
(
insert
OID
=
274
(
timeofday
PGUID
1
1
f
t
f
t
0
f
25
"0"
100
0
0
100
timeofday
-
));
DATA
(
insert
OID
=
274
(
timeofday
PGUID
1
2
f
t
f
t
0
f
25
"0"
100
0
0
100
timeofday
-
));
DESCR
(
"Current date and time with microseconds"
);
DATA
(
insert
OID
=
275
(
isfinite
PGUID
1
1
f
t
f
t
1
f
16
"702"
100
0
0
100
abstime_finite
-
));
DATA
(
insert
OID
=
275
(
isfinite
PGUID
1
2
f
t
f
t
1
f
16
"702"
100
0
0
100
abstime_finite
-
));
DESCR
(
""
);
DATA
(
insert
OID
=
276
(
int2fac
PGUID
12
f
t
t
t
1
f
23
"21"
100
0
0
100
int2fac
-
));
...
...
@@ -748,7 +748,7 @@ DATA(insert OID = 356 ( btoidcmp PGUID 12 f t t t 2 f 23 "26 26" 100 0 0 10
DESCR
(
"btree less-equal-greater"
);
DATA
(
insert
OID
=
404
(
btoidvectorcmp
PGUID
12
f
t
t
t
2
f
23
"30 30"
100
0
0
100
btoidvectorcmp
-
));
DESCR
(
"btree less-equal-greater"
);
DATA
(
insert
OID
=
357
(
btabstimecmp
PGUID
1
1
f
t
f
t
2
f
23
"702 702"
100
0
0
100
btabstimecmp
-
));
DATA
(
insert
OID
=
357
(
btabstimecmp
PGUID
1
2
f
t
f
t
2
f
23
"702 702"
100
0
0
100
btabstimecmp
-
));
DESCR
(
"btree less-equal-greater"
);
DATA
(
insert
OID
=
358
(
btcharcmp
PGUID
12
f
t
t
t
2
f
23
"18 18"
100
0
0
100
btcharcmp
-
));
DESCR
(
"btree less-equal-greater"
);
...
...
@@ -894,9 +894,9 @@ DESCR("convert float8 to int8");
/* OIDS 600 - 699 */
DATA
(
insert
OID
=
1285
(
int4notin
PGUID
1
1
f
t
f
t
2
f
16
"23 0
"
100
0
0
100
int4notin
-
));
DATA
(
insert
OID
=
1285
(
int4notin
PGUID
1
2
f
t
f
t
2
f
16
"23 25
"
100
0
0
100
int4notin
-
));
DESCR
(
"not in"
);
DATA
(
insert
OID
=
1286
(
oidnotin
PGUID
1
1
f
t
f
t
2
f
16
"26 0
"
100
0
0
100
oidnotin
-
));
DATA
(
insert
OID
=
1286
(
oidnotin
PGUID
1
2
f
t
f
t
2
f
16
"26 25
"
100
0
0
100
oidnotin
-
));
DESCR
(
"not in"
);
DATA
(
insert
OID
=
1287
(
int44in
PGUID
12
f
t
t
t
1
f
22
"0"
100
0
0
100
int44in
-
));
DESCR
(
"(internal)"
);
...
...
@@ -918,7 +918,7 @@ DESCR("truncate char()");
DATA
(
insert
OID
=
669
(
varchar
PGUID
11
f
t
t
t
2
f
1043
"1043 23"
100
0
0
100
varchar
-
));
DESCR
(
"truncate varchar()"
);
DATA
(
insert
OID
=
676
(
mktinterval
PGUID
1
1
f
t
f
t
2
f
704
"702 702"
100
0
0
100
mktinterval
-
));
DATA
(
insert
OID
=
676
(
mktinterval
PGUID
1
2
f
t
f
t
2
f
704
"702 702"
100
0
0
100
mktinterval
-
));
DESCR
(
"convert to tinterval"
);
DATA
(
insert
OID
=
619
(
oidvectorne
PGUID
12
f
t
t
t
2
f
16
"30 30"
100
0
0
100
oidvectorne
-
));
DESCR
(
"less-than"
);
...
...
@@ -1012,9 +1012,9 @@ DESCR("storage manager");
DATA
(
insert
OID
=
763
(
smgrne
PGUID
12
f
t
f
t
2
f
16
"210 210"
100
0
0
100
smgrne
-
));
DESCR
(
"storage manager"
);
DATA
(
insert
OID
=
764
(
lo_import
PGUID
1
1
f
t
f
t
1
f
26
"25"
100
0
0
100
lo_import
-
));
DATA
(
insert
OID
=
764
(
lo_import
PGUID
1
2
f
t
f
t
1
f
26
"25"
100
0
0
100
lo_import
-
));
DESCR
(
"large object import"
);
DATA
(
insert
OID
=
765
(
lo_export
PGUID
1
1
f
t
f
t
2
f
23
"26 25"
100
0
0
100
lo_export
-
));
DATA
(
insert
OID
=
765
(
lo_export
PGUID
1
2
f
t
f
t
2
f
23
"26 25"
100
0
0
100
lo_export
-
));
DESCR
(
"large object export"
);
DATA
(
insert
OID
=
766
(
int4inc
PGUID
12
f
t
t
t
1
f
23
"23"
100
0
0
100
int4inc
-
));
...
...
@@ -1051,17 +1051,17 @@ DESCR("gist(internal)");
DATA
(
insert
OID
=
782
(
gistbuild
PGUID
11
f
t
f
t
9
f
23
"0"
100
0
0
100
gistbuild
-
));
DESCR
(
"gist(internal)"
);
DATA
(
insert
OID
=
784
(
tintervaleq
PGUID
1
1
f
t
f
t
2
f
16
"704 704"
100
0
0
100
tintervaleq
-
));
DATA
(
insert
OID
=
784
(
tintervaleq
PGUID
1
2
f
t
f
t
2
f
16
"704 704"
100
0
0
100
tintervaleq
-
));
DESCR
(
"equal"
);
DATA
(
insert
OID
=
785
(
tintervalne
PGUID
1
1
f
t
f
t
2
f
16
"704 704"
100
0
0
100
tintervalne
-
));
DATA
(
insert
OID
=
785
(
tintervalne
PGUID
1
2
f
t
f
t
2
f
16
"704 704"
100
0
0
100
tintervalne
-
));
DESCR
(
"not equal"
);
DATA
(
insert
OID
=
786
(
tintervallt
PGUID
1
1
f
t
f
t
2
f
16
"704 704"
100
0
0
100
tintervallt
-
));
DATA
(
insert
OID
=
786
(
tintervallt
PGUID
1
2
f
t
f
t
2
f
16
"704 704"
100
0
0
100
tintervallt
-
));
DESCR
(
"less-than"
);
DATA
(
insert
OID
=
787
(
tintervalgt
PGUID
1
1
f
t
f
t
2
f
16
"704 704"
100
0
0
100
tintervalgt
-
));
DATA
(
insert
OID
=
787
(
tintervalgt
PGUID
1
2
f
t
f
t
2
f
16
"704 704"
100
0
0
100
tintervalgt
-
));
DESCR
(
"greater-than"
);
DATA
(
insert
OID
=
788
(
tintervalle
PGUID
1
1
f
t
f
t
2
f
16
"704 704"
100
0
0
100
tintervalle
-
));
DATA
(
insert
OID
=
788
(
tintervalle
PGUID
1
2
f
t
f
t
2
f
16
"704 704"
100
0
0
100
tintervalle
-
));
DESCR
(
"less-than-or-equal"
);
DATA
(
insert
OID
=
789
(
tintervalge
PGUID
1
1
f
t
f
t
2
f
16
"704 704"
100
0
0
100
tintervalge
-
));
DATA
(
insert
OID
=
789
(
tintervalge
PGUID
1
2
f
t
f
t
2
f
16
"704 704"
100
0
0
100
tintervalge
-
));
DESCR
(
"greater-than-or-equal"
);
/* OIDS 800 - 899 */
...
...
@@ -1204,19 +1204,19 @@ DESCR("bool is true (not false or unknown)");
DATA
(
insert
OID
=
951
(
isfalse
PGUID
12
f
t
t
f
1
f
16
"16"
100
0
0
100
isfalse
-
));
DESCR
(
"bool is false (not true or unknown)"
);
DATA
(
insert
OID
=
952
(
lo_open
PGUID
1
1
f
t
f
t
2
f
23
"26 23"
100
0
0
100
lo_open
-
));
DATA
(
insert
OID
=
952
(
lo_open
PGUID
1
2
f
t
f
t
2
f
23
"26 23"
100
0
0
100
lo_open
-
));
DESCR
(
"large object open"
);
DATA
(
insert
OID
=
953
(
lo_close
PGUID
1
1
f
t
f
t
1
f
23
"23"
100
0
0
100
lo_close
-
));
DATA
(
insert
OID
=
953
(
lo_close
PGUID
1
2
f
t
f
t
1
f
23
"23"
100
0
0
100
lo_close
-
));
DESCR
(
"large object close"
);
DATA
(
insert
OID
=
954
(
loread
PGUID
1
1
f
t
f
t
2
f
17
"23 23"
100
0
0
100
loread
-
));
DATA
(
insert
OID
=
954
(
loread
PGUID
1
2
f
t
f
t
2
f
17
"23 23"
100
0
0
100
loread
-
));
DESCR
(
"large object read"
);
DATA
(
insert
OID
=
955
(
lowrite
PGUID
1
1
f
t
f
t
2
f
23
"23 17"
100
0
0
100
lowrite
-
));
DATA
(
insert
OID
=
955
(
lowrite
PGUID
1
2
f
t
f
t
2
f
23
"23 17"
100
0
0
100
lowrite
-
));
DESCR
(
"large object write"
);
DATA
(
insert
OID
=
956
(
lo_lseek
PGUID
1
1
f
t
f
t
3
f
23
"23 23 23"
100
0
0
100
lo_lseek
-
));
DATA
(
insert
OID
=
956
(
lo_lseek
PGUID
1
2
f
t
f
t
3
f
23
"23 23 23"
100
0
0
100
lo_lseek
-
));
DESCR
(
"large object seek"
);
DATA
(
insert
OID
=
957
(
lo_creat
PGUID
1
1
f
t
f
t
1
f
26
"23"
100
0
0
100
lo_creat
-
));
DATA
(
insert
OID
=
957
(
lo_creat
PGUID
1
2
f
t
f
t
1
f
26
"23"
100
0
0
100
lo_creat
-
));
DESCR
(
"large object create"
);
DATA
(
insert
OID
=
958
(
lo_tell
PGUID
1
1
f
t
f
t
1
f
23
"23"
100
0
0
100
lo_tell
-
));
DATA
(
insert
OID
=
958
(
lo_tell
PGUID
1
2
f
t
f
t
1
f
23
"23"
100
0
0
100
lo_tell
-
));
DESCR
(
"large object position"
);
DATA
(
insert
OID
=
959
(
on_pl
PGUID
11
f
t
t
t
2
f
16
"600 628"
100
0
10
100
on_pl
-
));
...
...
@@ -1230,7 +1230,7 @@ DESCR("closest point to line segment on line");
DATA
(
insert
OID
=
963
(
close_lb
PGUID
11
f
t
t
t
2
f
600
"628 603"
100
0
10
100
close_lb
-
));
DESCR
(
"closest point to line on box"
);
DATA
(
insert
OID
=
964
(
lo_unlink
PGUID
1
1
f
t
f
t
1
f
23
"26"
100
0
0
100
lo_unlink
-
));
DATA
(
insert
OID
=
964
(
lo_unlink
PGUID
1
2
f
t
f
t
1
f
23
"26"
100
0
0
100
lo_unlink
-
));
DESCR
(
"large object unlink(delete)"
);
DATA
(
insert
OID
=
972
(
regproctooid
PGUID
12
f
t
t
t
1
f
26
"24"
100
0
0
100
regproctooid
-
));
DESCR
(
"get oid for regproc"
);
...
...
@@ -1302,7 +1302,7 @@ DATA(insert OID = 1036 ( aclremove PGUID 11 f t f t 2 f 1034 "1034 1033" 10
DESCR
(
"subtract"
);
DATA
(
insert
OID
=
1037
(
aclcontains
PGUID
11
f
t
f
t
2
f
16
"1034 1033"
100
0
0
100
aclcontains
-
));
DESCR
(
"matches regex., case-sensitive"
);
DATA
(
insert
OID
=
1038
(
seteval
PGUID
1
1
f
t
f
t
1
f
23
"26"
100
0
0
100
seteval
-
));
DATA
(
insert
OID
=
1038
(
seteval
PGUID
1
2
f
t
f
t
1
f
23
"26"
100
0
0
100
seteval
-
));
DESCR
(
""
);
DATA
(
insert
OID
=
1044
(
bpcharin
PGUID
11
f
t
t
t
3
f
1042
"0 0 23"
100
0
0
100
bpcharin
-
));
DESCR
(
"(internal)"
);
...
...
@@ -1345,54 +1345,54 @@ DESCR("hash");
DATA
(
insert
OID
=
1081
(
hashvarchar
PGUID
11
f
t
t
t
1
f
23
"1043"
100
0
0
100
hashvarchar
-
));
DESCR
(
"hash"
);
DATA
(
insert
OID
=
1084
(
date_in
PGUID
1
1
f
t
f
t
1
f
1082
"0"
100
0
0
100
date_in
-
));
DATA
(
insert
OID
=
1084
(
date_in
PGUID
1
2
f
t
f
t
1
f
1082
"0"
100
0
0
100
date_in
-
));
DESCR
(
"(internal)"
);
DATA
(
insert
OID
=
1085
(
date_out
PGUID
1
1
f
t
f
t
1
f
23
"0"
100
0
0
100
date_out
-
));
DATA
(
insert
OID
=
1085
(
date_out
PGUID
1
2
f
t
f
t
1
f
23
"0"
100
0
0
100
date_out
-
));
DESCR
(
"(internal)"
);
DATA
(
insert
OID
=
1086
(
date_eq
PGUID
1
1
f
t
t
t
2
f
16
"1082 1082"
100
0
0
100
date_eq
-
));
DATA
(
insert
OID
=
1086
(
date_eq
PGUID
1
2
f
t
t
t
2
f
16
"1082 1082"
100
0
0
100
date_eq
-
));
DESCR
(
"equal"
);
DATA
(
insert
OID
=
1087
(
date_lt
PGUID
1
1
f
t
t
t
2
f
16
"1082 1082"
100
0
0
100
date_lt
-
));
DATA
(
insert
OID
=
1087
(
date_lt
PGUID
1
2
f
t
t
t
2
f
16
"1082 1082"
100
0
0
100
date_lt
-
));
DESCR
(
"less-than"
);
DATA
(
insert
OID
=
1088
(
date_le
PGUID
1
1
f
t
t
t
2
f
16
"1082 1082"
100
0
0
100
date_le
-
));
DATA
(
insert
OID
=
1088
(
date_le
PGUID
1
2
f
t
t
t
2
f
16
"1082 1082"
100
0
0
100
date_le
-
));
DESCR
(
"less-than-or-equal"
);
DATA
(
insert
OID
=
1089
(
date_gt
PGUID
1
1
f
t
t
t
2
f
16
"1082 1082"
100
0
0
100
date_gt
-
));
DATA
(
insert
OID
=
1089
(
date_gt
PGUID
1
2
f
t
t
t
2
f
16
"1082 1082"
100
0
0
100
date_gt
-
));
DESCR
(
"greater-than"
);
DATA
(
insert
OID
=
1090
(
date_ge
PGUID
1
1
f
t
t
t
2
f
16
"1082 1082"
100
0
0
100
date_ge
-
));
DATA
(
insert
OID
=
1090
(
date_ge
PGUID
1
2
f
t
t
t
2
f
16
"1082 1082"
100
0
0
100
date_ge
-
));
DESCR
(
"greater-than-or-equal"
);
DATA
(
insert
OID
=
1091
(
date_ne
PGUID
1
1
f
t
t
t
2
f
16
"1082 1082"
100
0
0
100
date_ne
-
));
DATA
(
insert
OID
=
1091
(
date_ne
PGUID
1
2
f
t
t
t
2
f
16
"1082 1082"
100
0
0
100
date_ne
-
));
DESCR
(
"not equal"
);
DATA
(
insert
OID
=
1092
(
date_cmp
PGUID
1
1
f
t
t
t
2
f
23
"1082 1082"
100
0
0
100
date_cmp
-
));
DATA
(
insert
OID
=
1092
(
date_cmp
PGUID
1
2
f
t
t
t
2
f
23
"1082 1082"
100
0
0
100
date_cmp
-
));
DESCR
(
"less-equal-greater"
);
/* OIDS 1100 - 1199 */
DATA
(
insert
OID
=
1102
(
time_lt
PGUID
1
1
f
t
t
t
2
f
16
"1083 1083"
100
0
0
100
time_lt
-
));
DATA
(
insert
OID
=
1102
(
time_lt
PGUID
1
2
f
t
t
t
2
f
16
"1083 1083"
100
0
0
100
time_lt
-
));
DESCR
(
"less-than"
);
DATA
(
insert
OID
=
1103
(
time_le
PGUID
1
1
f
t
t
t
2
f
16
"1083 1083"
100
0
0
100
time_le
-
));
DATA
(
insert
OID
=
1103
(
time_le
PGUID
1
2
f
t
t
t
2
f
16
"1083 1083"
100
0
0
100
time_le
-
));
DESCR
(
"less-than-or-equal"
);
DATA
(
insert
OID
=
1104
(
time_gt
PGUID
1
1
f
t
t
t
2
f
16
"1083 1083"
100
0
0
100
time_gt
-
));
DATA
(
insert
OID
=
1104
(
time_gt
PGUID
1
2
f
t
t
t
2
f
16
"1083 1083"
100
0
0
100
time_gt
-
));
DESCR
(
"greater-than"
);
DATA
(
insert
OID
=
1105
(
time_ge
PGUID
1
1
f
t
t
t
2
f
16
"1083 1083"
100
0
0
100
time_ge
-
));
DATA
(
insert
OID
=
1105
(
time_ge
PGUID
1
2
f
t
t
t
2
f
16
"1083 1083"
100
0
0
100
time_ge
-
));
DESCR
(
"greater-than-or-equal"
);
DATA
(
insert
OID
=
1106
(
time_ne
PGUID
1
1
f
t
t
t
2
f
16
"1083 1083"
100
0
0
100
time_ne
-
));
DATA
(
insert
OID
=
1106
(
time_ne
PGUID
1
2
f
t
t
t
2
f
16
"1083 1083"
100
0
0
100
time_ne
-
));
DESCR
(
"not equal"
);
DATA
(
insert
OID
=
1107
(
time_cmp
PGUID
1
1
f
t
t
t
2
f
23
"1083 1083"
100
0
0
100
time_cmp
-
));
DATA
(
insert
OID
=
1107
(
time_cmp
PGUID
1
2
f
t
t
t
2
f
23
"1083 1083"
100
0
0
100
time_cmp
-
));
DESCR
(
"less-equal-greater"
);
DATA
(
insert
OID
=
1138
(
date_larger
PGUID
1
1
f
t
t
t
2
f
1082
"1082 1082"
100
0
0
100
date_larger
-
));
DATA
(
insert
OID
=
1138
(
date_larger
PGUID
1
2
f
t
t
t
2
f
1082
"1082 1082"
100
0
0
100
date_larger
-
));
DESCR
(
"larger of two"
);
DATA
(
insert
OID
=
1139
(
date_smaller
PGUID
1
1
f
t
t
t
2
f
1082
"1082 1082"
100
0
0
100
date_smaller
-
));
DATA
(
insert
OID
=
1139
(
date_smaller
PGUID
1
2
f
t
t
t
2
f
1082
"1082 1082"
100
0
0
100
date_smaller
-
));
DESCR
(
"smaller of two"
);
DATA
(
insert
OID
=
1140
(
date_mi
PGUID
1
1
f
t
t
t
2
f
23
"1082 1082"
100
0
0
100
date_mi
-
));
DATA
(
insert
OID
=
1140
(
date_mi
PGUID
1
2
f
t
t
t
2
f
23
"1082 1082"
100
0
0
100
date_mi
-
));
DESCR
(
"subtract"
);
DATA
(
insert
OID
=
1141
(
date_pli
PGUID
1
1
f
t
t
t
2
f
1082
"1082 23"
100
0
0
100
date_pli
-
));
DATA
(
insert
OID
=
1141
(
date_pli
PGUID
1
2
f
t
t
t
2
f
1082
"1082 23"
100
0
0
100
date_pli
-
));
DESCR
(
"addition"
);
DATA
(
insert
OID
=
1142
(
date_mii
PGUID
1
1
f
t
t
t
2
f
1082
"1082 23"
100
0
0
100
date_mii
-
));
DATA
(
insert
OID
=
1142
(
date_mii
PGUID
1
2
f
t
t
t
2
f
1082
"1082 23"
100
0
0
100
date_mii
-
));
DESCR
(
"subtract"
);
DATA
(
insert
OID
=
1143
(
time_in
PGUID
1
1
f
t
f
t
1
f
1083
"0"
100
0
0
100
time_in
-
));
DATA
(
insert
OID
=
1143
(
time_in
PGUID
1
2
f
t
f
t
1
f
1083
"0"
100
0
0
100
time_in
-
));
DESCR
(
"(internal)"
);
DATA
(
insert
OID
=
1144
(
time_out
PGUID
1
1
f
t
f
t
1
f
23
"0"
100
0
0
100
time_out
-
));
DATA
(
insert
OID
=
1144
(
time_out
PGUID
1
2
f
t
f
t
1
f
23
"0"
100
0
0
100
time_out
-
));
DESCR
(
"(internal)"
);
DATA
(
insert
OID
=
1145
(
time_eq
PGUID
1
1
f
t
t
t
2
f
16
"1083 1083"
100
0
0
100
time_eq
-
));
DATA
(
insert
OID
=
1145
(
time_eq
PGUID
1
2
f
t
t
t
2
f
16
"1083 1083"
100
0
0
100
time_eq
-
));
DESCR
(
"equal"
);
DATA
(
insert
OID
=
1146
(
circle_add_pt
PGUID
11
f
t
t
t
2
f
718
"718 600"
100
0
0
100
circle_add_pt
-
));
...
...
@@ -1404,100 +1404,100 @@ DESCR("multiply");
DATA
(
insert
OID
=
1149
(
circle_div_pt
PGUID
11
f
t
t
t
2
f
718
"718 600"
100
0
0
100
circle_div_pt
-
));
DESCR
(
"divide"
);
DATA
(
insert
OID
=
1150
(
timestamp_in
PGUID
1
1
f
t
f
t
1
f
1184
"0"
100
0
0
100
timestamp_in
-
));
DATA
(
insert
OID
=
1150
(
timestamp_in
PGUID
1
2
f
t
f
t
1
f
1184
"0"
100
0
0
100
timestamp_in
-
));
DESCR
(
"(internal)"
);
DATA
(
insert
OID
=
1151
(
timestamp_out
PGUID
1
1
f
t
f
t
1
f
23
"0"
100
0
0
100
timestamp_out
-
));
DATA
(
insert
OID
=
1151
(
timestamp_out
PGUID
1
2
f
t
f
t
1
f
23
"0"
100
0
0
100
timestamp_out
-
));
DESCR
(
"(internal)"
);
DATA
(
insert
OID
=
1152
(
timestamp_eq
PGUID
1
1
f
t
f
t
2
f
16
"1184 1184"
100
0
0
100
timestamp_eq
-
));
DATA
(
insert
OID
=
1152
(
timestamp_eq
PGUID
1
2
f
t
f
t
2
f
16
"1184 1184"
100
0
0
100
timestamp_eq
-
));
DESCR
(
"equal"
);
DATA
(
insert
OID
=
1153
(
timestamp_ne
PGUID
1
1
f
t
f
t
2
f
16
"1184 1184"
100
0
0
100
timestamp_ne
-
));
DATA
(
insert
OID
=
1153
(
timestamp_ne
PGUID
1
2
f
t
f
t
2
f
16
"1184 1184"
100
0
0
100
timestamp_ne
-
));
DESCR
(
"not equal"
);
DATA
(
insert
OID
=
1154
(
timestamp_lt
PGUID
1
1
f
t
f
t
2
f
16
"1184 1184"
100
0
0
100
timestamp_lt
-
));
DATA
(
insert
OID
=
1154
(
timestamp_lt
PGUID
1
2
f
t
f
t
2
f
16
"1184 1184"
100
0
0
100
timestamp_lt
-
));
DESCR
(
"less-than"
);
DATA
(
insert
OID
=
1155
(
timestamp_le
PGUID
1
1
f
t
f
t
2
f
16
"1184 1184"
100
0
0
100
timestamp_le
-
));
DATA
(
insert
OID
=
1155
(
timestamp_le
PGUID
1
2
f
t
f
t
2
f
16
"1184 1184"
100
0
0
100
timestamp_le
-
));
DESCR
(
"less-than-or-equal"
);
DATA
(
insert
OID
=
1156
(
timestamp_ge
PGUID
1
1
f
t
f
t
2
f
16
"1184 1184"
100
0
0
100
timestamp_ge
-
));
DATA
(
insert
OID
=
1156
(
timestamp_ge
PGUID
1
2
f
t
f
t
2
f
16
"1184 1184"
100
0
0
100
timestamp_ge
-
));
DESCR
(
"greater-than-or-equal"
);
DATA
(
insert
OID
=
1157
(
timestamp_gt
PGUID
1
1
f
t
f
t
2
f
16
"1184 1184"
100
0
0
100
timestamp_gt
-
));
DATA
(
insert
OID
=
1157
(
timestamp_gt
PGUID
1
2
f
t
f
t
2
f
16
"1184 1184"
100
0
0
100
timestamp_gt
-
));
DESCR
(
"greater-than"
);
DATA
(
insert
OID
=
1159
(
timezone
PGUID
1
1
f
t
f
t
2
f
25
"25 1184"
100
0
0
100
timestamp_zone
-
));
DATA
(
insert
OID
=
1159
(
timezone
PGUID
1
2
f
t
f
t
2
f
25
"25 1184"
100
0
0
100
timestamp_zone
-
));
DESCR
(
"time zone"
);
DATA
(
insert
OID
=
1160
(
interval_in
PGUID
1
1
f
t
f
t
1
f
1186
"0"
100
0
0
100
interval_in
-
));
DATA
(
insert
OID
=
1160
(
interval_in
PGUID
1
2
f
t
f
t
1
f
1186
"0"
100
0
0
100
interval_in
-
));
DESCR
(
"(internal)"
);
DATA
(
insert
OID
=
1161
(
interval_out
PGUID
1
1
f
t
f
t
1
f
23
"0"
100
0
0
100
interval_out
-
));
DATA
(
insert
OID
=
1161
(
interval_out
PGUID
1
2
f
t
f
t
1
f
23
"0"
100
0
0
100
interval_out
-
));
DESCR
(
"(internal)"
);
DATA
(
insert
OID
=
1162
(
interval_eq
PGUID
1
1
f
t
f
t
2
f
16
"1186 1186"
100
0
0
100
interval_eq
-
));
DATA
(
insert
OID
=
1162
(
interval_eq
PGUID
1
2
f
t
f
t
2
f
16
"1186 1186"
100
0
0
100
interval_eq
-
));
DESCR
(
"equal"
);
DATA
(
insert
OID
=
1163
(
interval_ne
PGUID
1
1
f
t
f
t
2
f
16
"1186 1186"
100
0
0
100
interval_ne
-
));
DATA
(
insert
OID
=
1163
(
interval_ne
PGUID
1
2
f
t
f
t
2
f
16
"1186 1186"
100
0
0
100
interval_ne
-
));
DESCR
(
"not equal"
);
DATA
(
insert
OID
=
1164
(
interval_lt
PGUID
1
1
f
t
f
t
2
f
16
"1186 1186"
100
0
0
100
interval_lt
-
));
DATA
(
insert
OID
=
1164
(
interval_lt
PGUID
1
2
f
t
f
t
2
f
16
"1186 1186"
100
0
0
100
interval_lt
-
));
DESCR
(
"less-than"
);
DATA
(
insert
OID
=
1165
(
interval_le
PGUID
1
1
f
t
f
t
2
f
16
"1186 1186"
100
0
0
100
interval_le
-
));
DATA
(
insert
OID
=
1165
(
interval_le
PGUID
1
2
f
t
f
t
2
f
16
"1186 1186"
100
0
0
100
interval_le
-
));
DESCR
(
"less-than-or-equal"
);
DATA
(
insert
OID
=
1166
(
interval_ge
PGUID
1
1
f
t
f
t
2
f
16
"1186 1186"
100
0
0
100
interval_ge
-
));
DATA
(
insert
OID
=
1166
(
interval_ge
PGUID
1
2
f
t
f
t
2
f
16
"1186 1186"
100
0
0
100
interval_ge
-
));
DESCR
(
"greater-than-or-equal"
);
DATA
(
insert
OID
=
1167
(
interval_gt
PGUID
1
1
f
t
f
t
2
f
16
"1186 1186"
100
0
0
100
interval_gt
-
));
DATA
(
insert
OID
=
1167
(
interval_gt
PGUID
1
2
f
t
f
t
2
f
16
"1186 1186"
100
0
0
100
interval_gt
-
));
DESCR
(
"greater-than"
);
DATA
(
insert
OID
=
1168
(
interval_um
PGUID
1
1
f
t
f
t
1
f
1186
"1186"
100
0
0
100
interval_um
-
));
DATA
(
insert
OID
=
1168
(
interval_um
PGUID
1
2
f
t
f
t
1
f
1186
"1186"
100
0
0
100
interval_um
-
));
DESCR
(
"subtract"
);
DATA
(
insert
OID
=
1169
(
interval_pl
PGUID
1
1
f
t
f
t
2
f
1186
"1186 1186"
100
0
0
100
interval_pl
-
));
DATA
(
insert
OID
=
1169
(
interval_pl
PGUID
1
2
f
t
f
t
2
f
1186
"1186 1186"
100
0
0
100
interval_pl
-
));
DESCR
(
"addition"
);
DATA
(
insert
OID
=
1170
(
interval_mi
PGUID
1
1
f
t
f
t
2
f
1186
"1186 1186"
100
0
0
100
interval_mi
-
));
DATA
(
insert
OID
=
1170
(
interval_mi
PGUID
1
2
f
t
f
t
2
f
1186
"1186 1186"
100
0
0
100
interval_mi
-
));
DESCR
(
"subtract"
);
DATA
(
insert
OID
=
1171
(
date_part
PGUID
1
1
f
t
f
t
2
f
701
"25 1184"
100
0
0
100
timestamp_part
-
));
DATA
(
insert
OID
=
1171
(
date_part
PGUID
1
2
f
t
f
t
2
f
701
"25 1184"
100
0
0
100
timestamp_part
-
));
DESCR
(
"extract field from timestamp"
);
DATA
(
insert
OID
=
1172
(
date_part
PGUID
1
1
f
t
f
t
2
f
701
"25 1186"
100
0
0
100
interval_part
-
));
DATA
(
insert
OID
=
1172
(
date_part
PGUID
1
2
f
t
f
t
2
f
701
"25 1186"
100
0
0
100
interval_part
-
));
DESCR
(
"extract field from interval"
);
DATA
(
insert
OID
=
1173
(
timestamp
PGUID
1
1
f
t
f
t
1
f
1184
"702"
100
0
0
100
abstime_timestamp
-
));
DATA
(
insert
OID
=
1173
(
timestamp
PGUID
1
2
f
t
f
t
1
f
1184
"702"
100
0
0
100
abstime_timestamp
-
));
DESCR
(
"convert abstime to timestamp"
);
DATA
(
insert
OID
=
1174
(
timestamp
PGUID
1
1
f
t
f
t
1
f
1184
"1082"
100
0
0
100
date_timestamp
-
));
DATA
(
insert
OID
=
1174
(
timestamp
PGUID
1
2
f
t
f
t
1
f
1184
"1082"
100
0
0
100
date_timestamp
-
));
DESCR
(
"convert date to timestamp"
);
DATA
(
insert
OID
=
1176
(
timestamp
PGUID
1
1
f
t
f
t
2
f
1184
"1082 1083"
100
0
0
100
datetime_timestamp
-
));
DATA
(
insert
OID
=
1176
(
timestamp
PGUID
1
2
f
t
f
t
2
f
1184
"1082 1083"
100
0
0
100
datetime_timestamp
-
));
DESCR
(
"convert date and time to timestamp"
);
DATA
(
insert
OID
=
1177
(
interval
PGUID
1
1
f
t
f
t
1
f
1186
"703"
100
0
0
100
reltime_interval
-
));
DATA
(
insert
OID
=
1177
(
interval
PGUID
1
2
f
t
f
t
1
f
1186
"703"
100
0
0
100
reltime_interval
-
));
DESCR
(
"convert reltime to interval"
);
DATA
(
insert
OID
=
1178
(
date
PGUID
1
1
f
t
f
t
1
f
1082
"1184"
100
0
0
100
timestamp_date
-
));
DATA
(
insert
OID
=
1178
(
date
PGUID
1
2
f
t
f
t
1
f
1082
"1184"
100
0
0
100
timestamp_date
-
));
DESCR
(
"convert timestamp to date"
);
DATA
(
insert
OID
=
1179
(
date
PGUID
1
1
f
t
f
t
1
f
1082
"702"
100
0
0
100
abstime_date
-
));
DATA
(
insert
OID
=
1179
(
date
PGUID
1
2
f
t
f
t
1
f
1082
"702"
100
0
0
100
abstime_date
-
));
DESCR
(
"convert abstime to date"
);
DATA
(
insert
OID
=
1180
(
abstime
PGUID
1
1
f
t
f
t
1
f
702
"1184"
100
0
0
100
timestamp_abstime
-
));
DATA
(
insert
OID
=
1180
(
abstime
PGUID
1
2
f
t
f
t
1
f
702
"1184"
100
0
0
100
timestamp_abstime
-
));
DESCR
(
"convert timestamp to abstime"
);
DATA
(
insert
OID
=
1188
(
timestamp_mi
PGUID
1
1
f
t
f
t
2
f
1186
"1184 1184"
100
0
0
100
timestamp_mi
-
));
DATA
(
insert
OID
=
1188
(
timestamp_mi
PGUID
1
2
f
t
f
t
2
f
1186
"1184 1184"
100
0
0
100
timestamp_mi
-
));
DESCR
(
"subtract"
);
DATA
(
insert
OID
=
1189
(
timestamp_pl_span
PGUID
1
1
f
t
f
t
2
f
1184
"1184 1186"
100
0
0
100
timestamp_pl_span
-
));
DATA
(
insert
OID
=
1189
(
timestamp_pl_span
PGUID
1
2
f
t
f
t
2
f
1184
"1184 1186"
100
0
0
100
timestamp_pl_span
-
));
DESCR
(
"plus"
);
DATA
(
insert
OID
=
1190
(
timestamp_mi_span
PGUID
1
1
f
t
f
t
2
f
1184
"1184 1186"
100
0
0
100
timestamp_mi_span
-
));
DATA
(
insert
OID
=
1190
(
timestamp_mi_span
PGUID
1
2
f
t
f
t
2
f
1184
"1184 1186"
100
0
0
100
timestamp_mi_span
-
));
DESCR
(
"minus"
);
DATA
(
insert
OID
=
1191
(
timestamp
PGUID
1
1
f
t
f
t
1
f
1184
"25"
100
0
0
100
text_timestamp
-
));
DATA
(
insert
OID
=
1191
(
timestamp
PGUID
1
2
f
t
f
t
1
f
1184
"25"
100
0
0
100
text_timestamp
-
));
DESCR
(
"convert text to timestamp"
);
DATA
(
insert
OID
=
1192
(
text
PGUID
1
1
f
t
f
t
1
f
25
"1184"
100
0
0
100
timestamp_text
-
));
DATA
(
insert
OID
=
1192
(
text
PGUID
1
2
f
t
f
t
1
f
25
"1184"
100
0
0
100
timestamp_text
-
));
DESCR
(
"convert timestamp to text"
);
DATA
(
insert
OID
=
1193
(
text
PGUID
1
1
f
t
f
t
1
f
25
"1186"
100
0
0
100
interval_text
-
));
DATA
(
insert
OID
=
1193
(
text
PGUID
1
2
f
t
f
t
1
f
25
"1186"
100
0
0
100
interval_text
-
));
DESCR
(
"convert interval to text"
);
DATA
(
insert
OID
=
1194
(
reltime
PGUID
1
1
f
t
f
t
1
f
703
"1186"
100
0
0
100
interval_reltime
-
));
DATA
(
insert
OID
=
1194
(
reltime
PGUID
1
2
f
t
f
t
1
f
703
"1186"
100
0
0
100
interval_reltime
-
));
DESCR
(
"convert interval to reltime"
);
DATA
(
insert
OID
=
1195
(
timestamp_smaller
PGUID
1
1
f
t
f
t
2
f
1184
"1184 1184"
100
0
0
100
timestamp_smaller
-
));
DATA
(
insert
OID
=
1195
(
timestamp_smaller
PGUID
1
2
f
t
f
t
2
f
1184
"1184 1184"
100
0
0
100
timestamp_smaller
-
));
DESCR
(
"smaller of two"
);
DATA
(
insert
OID
=
1196
(
timestamp_larger
PGUID
1
1
f
t
f
t
2
f
1184
"1184 1184"
100
0
0
100
timestamp_larger
-
));
DATA
(
insert
OID
=
1196
(
timestamp_larger
PGUID
1
2
f
t
f
t
2
f
1184
"1184 1184"
100
0
0
100
timestamp_larger
-
));
DESCR
(
"larger of two"
);
DATA
(
insert
OID
=
1197
(
interval_smaller
PGUID
1
1
f
t
f
t
2
f
1186
"1186 1186"
100
0
0
100
interval_smaller
-
));
DATA
(
insert
OID
=
1197
(
interval_smaller
PGUID
1
2
f
t
f
t
2
f
1186
"1186 1186"
100
0
0
100
interval_smaller
-
));
DESCR
(
"smaller of two"
);
DATA
(
insert
OID
=
1198
(
interval_larger
PGUID
1
1
f
t
f
t
2
f
1186
"1186 1186"
100
0
0
100
interval_larger
-
));
DATA
(
insert
OID
=
1198
(
interval_larger
PGUID
1
2
f
t
f
t
2
f
1186
"1186 1186"
100
0
0
100
interval_larger
-
));
DESCR
(
"larger of two"
);
DATA
(
insert
OID
=
1199
(
age
PGUID
1
1
f
t
f
t
2
f
1186
"1184 1184"
100
0
0
100
timestamp_age
-
));
DATA
(
insert
OID
=
1199
(
age
PGUID
1
2
f
t
f
t
2
f
1186
"1184 1184"
100
0
0
100
timestamp_age
-
));
DESCR
(
"date difference preserving months and years"
);
/* OIDS 1200 - 1299 */
DATA
(
insert
OID
=
1200
(
reltime
PGUID
1
1
f
t
t
t
1
f
703
"23"
100
0
0
100
int4reltime
-
));
DATA
(
insert
OID
=
1200
(
reltime
PGUID
1
2
f
t
t
t
1
f
703
"23"
100
0
0
100
int4reltime
-
));
DESCR
(
"convert int4 to reltime"
);
DATA
(
insert
OID
=
1217
(
date_trunc
PGUID
1
1
f
t
f
t
2
f
1184
"25 1184"
100
0
0
100
timestamp_trunc
-
));
DATA
(
insert
OID
=
1217
(
date_trunc
PGUID
1
2
f
t
f
t
2
f
1184
"25 1184"
100
0
0
100
timestamp_trunc
-
));
DESCR
(
"truncate timestamp to specified units"
);
DATA
(
insert
OID
=
1218
(
date_trunc
PGUID
1
1
f
t
f
t
2
f
1186
"25 1186"
100
0
0
100
interval_trunc
-
));
DATA
(
insert
OID
=
1218
(
date_trunc
PGUID
1
2
f
t
f
t
2
f
1186
"25 1186"
100
0
0
100
interval_trunc
-
));
DESCR
(
"truncate interval to specified units"
);
DATA
(
insert
OID
=
1230
(
int8abs
PGUID
11
f
t
t
t
1
f
20
"20"
100
0
0
100
int8abs
-
));
...
...
@@ -1522,12 +1522,12 @@ DESCR("absolute value");
DATA
(
insert
OID
=
1253
(
int2abs
PGUID
12
f
t
t
t
1
f
21
"21"
100
0
0
100
int2abs
-
));
DESCR
(
"absolute value"
);
DATA
(
insert
OID
=
1263
(
interval
PGUID
1
1
f
t
f
t
1
f
1186
"25"
100
0
0
100
text_interval
-
));
DATA
(
insert
OID
=
1263
(
interval
PGUID
1
2
f
t
f
t
1
f
1186
"25"
100
0
0
100
text_interval
-
));
DESCR
(
"convert text to interval"
);
DATA
(
insert
OID
=
1271
(
overlaps
PGUID
1
1
f
t
t
t
4
f
16
"1266 1266 1266 1266"
100
0
1
0
overlaps_timetz
-
));
DATA
(
insert
OID
=
1271
(
overlaps
PGUID
1
2
f
t
t
t
4
f
16
"1266 1266 1266 1266"
100
0
1
0
overlaps_timetz
-
));
DESCR
(
"SQL92 interval comparison"
);
DATA
(
insert
OID
=
1272
(
datetime_pl
PGUID
1
1
f
t
f
t
2
f
1184
"1082 1083"
100
0
0
100
datetime_timestamp
-
));
DATA
(
insert
OID
=
1272
(
datetime_pl
PGUID
1
2
f
t
f
t
2
f
1184
"1082 1083"
100
0
0
100
datetime_timestamp
-
));
DESCR
(
"convert date and time to timestamp"
);
DATA
(
insert
OID
=
1274
(
int84pl
PGUID
11
f
t
t
t
2
f
20
"20 23"
100
0
0
100
int84pl
-
));
...
...
@@ -1559,18 +1559,18 @@ DESCR("truncate _varchar()");
DATA
(
insert
OID
=
1292
(
tideq
PGUID
11
f
t
f
t
2
f
16
"27 27"
100
0
0
100
tideq
-
));
DESCR
(
"equal"
);
DATA
(
insert
OID
=
1293
(
currtid
PGUID
1
1
f
t
f
t
2
f
27
"26 27"
100
0
0
100
currtid_byreloid
-
));
DATA
(
insert
OID
=
1293
(
currtid
PGUID
1
2
f
t
f
t
2
f
27
"26 27"
100
0
0
100
currtid_byreloid
-
));
DESCR
(
"latest tid of a tuple"
);
DATA
(
insert
OID
=
1294
(
currtid2
PGUID
1
1
f
t
f
t
2
f
27
"25 27"
100
0
0
100
currtid_byrelname
-
));
DATA
(
insert
OID
=
1294
(
currtid2
PGUID
1
2
f
t
f
t
2
f
27
"25 27"
100
0
0
100
currtid_byrelname
-
));
DESCR
(
"latest tid of a tuple"
);
DATA
(
insert
OID
=
1296
(
timedate_pl
PGUID
14
f
t
f
t
2
f
1184
"1083 1082"
100
0
0
100
"select datetime_pl($2, $1)"
-
));
DESCR
(
"convert time and date to timestamp"
);
DATA
(
insert
OID
=
1297
(
datetimetz_pl
PGUID
1
1
f
t
f
t
2
f
1184
"1082 1266"
100
0
0
100
datetimetz_timestamp
-
));
DATA
(
insert
OID
=
1297
(
datetimetz_pl
PGUID
1
2
f
t
f
t
2
f
1184
"1082 1266"
100
0
0
100
datetimetz_timestamp
-
));
DESCR
(
"convert date and time with time zone to timestamp"
);
DATA
(
insert
OID
=
1298
(
timetzdate_pl
PGUID
14
f
t
f
t
2
f
1184
"1266 1082"
100
0
0
100
"select datetimetz_pl($2, $1)"
-
));
DESCR
(
"convert time with time zone and date to timestamp"
);
DATA
(
insert
OID
=
1299
(
now
PGUID
1
1
f
t
f
t
0
f
1184
"0"
100
0
0
100
now
-
));
DATA
(
insert
OID
=
1299
(
now
PGUID
1
2
f
t
f
t
0
f
1184
"0"
100
0
0
100
now
-
));
DESCR
(
"current transaction time"
);
/* OIDS 1300 - 1399 */
...
...
@@ -1584,7 +1584,7 @@ DESCR("restriction selectivity for containment comparison operators");
DATA
(
insert
OID
=
1303
(
contjoinsel
PGUID
12
f
t
f
t
5
f
701
"26 26 21 26 21"
100
0
0
100
contjoinsel
-
));
DESCR
(
"join selectivity for containment comparison operators"
);
DATA
(
insert
OID
=
1304
(
overlaps
PGUID
1
1
f
t
t
t
4
f
16
"1184 1184 1184 1184"
100
0
1
0
overlaps_timestamp
-
));
DATA
(
insert
OID
=
1304
(
overlaps
PGUID
1
2
f
t
t
t
4
f
16
"1184 1184 1184 1184"
100
0
1
0
overlaps_timestamp
-
));
DESCR
(
"SQL92 interval comparison"
);
DATA
(
insert
OID
=
1305
(
overlaps
PGUID
14
f
t
t
t
4
f
16
"1184 1186 1184 1186"
100
0
1
0
"select overlaps($1, ($1 + $2), $3, ($3 + $4))"
-
));
DESCR
(
"SQL92 interval comparison"
);
...
...
@@ -1593,7 +1593,7 @@ DESCR("SQL92 interval comparison");
DATA
(
insert
OID
=
1307
(
overlaps
PGUID
14
f
t
t
t
4
f
16
"1184 1186 1184 1184"
100
0
1
0
"select overlaps($1, ($1 + $2), $3, $4)"
-
));
DESCR
(
"SQL92 interval comparison"
);
DATA
(
insert
OID
=
1308
(
overlaps
PGUID
1
1
f
t
t
t
4
f
16
"1083 1083 1083 1083"
100
0
1
0
overlaps_time
-
));
DATA
(
insert
OID
=
1308
(
overlaps
PGUID
1
2
f
t
t
t
4
f
16
"1083 1083 1083 1083"
100
0
1
0
overlaps_time
-
));
DESCR
(
"SQL92 interval comparison"
);
DATA
(
insert
OID
=
1309
(
overlaps
PGUID
14
f
t
t
t
4
f
16
"1083 1186 1083 1186"
100
0
1
0
"select overlaps($1, ($1 + $2), $3, ($3 + $4))"
-
));
DESCR
(
"SQL92 interval comparison"
);
...
...
@@ -1602,11 +1602,11 @@ DESCR("SQL92 interval comparison");
DATA
(
insert
OID
=
1311
(
overlaps
PGUID
14
f
t
t
t
4
f
16
"1083 1186 1083 1083"
100
0
1
0
"select overlaps($1, ($1 + $2), $3, $4)"
-
));
DESCR
(
"SQL92 interval comparison"
);
DATA
(
insert
OID
=
1314
(
timestamp_cmp
PGUID
1
1
f
t
f
t
2
f
23
"1184 1184"
100
0
0
100
timestamp_cmp
-
));
DATA
(
insert
OID
=
1314
(
timestamp_cmp
PGUID
1
2
f
t
f
t
2
f
23
"1184 1184"
100
0
0
100
timestamp_cmp
-
));
DESCR
(
"less-equal-greater"
);
DATA
(
insert
OID
=
1315
(
interval_cmp
PGUID
1
1
f
t
f
t
2
f
23
"1186 1186"
100
0
0
100
interval_cmp
-
));
DATA
(
insert
OID
=
1315
(
interval_cmp
PGUID
1
2
f
t
f
t
2
f
23
"1186 1186"
100
0
0
100
interval_cmp
-
));
DESCR
(
"less-equal-greater"
);
DATA
(
insert
OID
=
1316
(
time
PGUID
1
1
f
t
f
t
1
f
1083
"1184"
100
0
0
100
timestamp_time
-
));
DATA
(
insert
OID
=
1316
(
time
PGUID
1
2
f
t
f
t
1
f
1083
"1184"
100
0
0
100
timestamp_time
-
));
DESCR
(
"convert timestamp to time"
);
DATA
(
insert
OID
=
1317
(
length
PGUID
11
f
t
t
t
1
f
23
"25"
100
0
1
0
textlen
-
));
...
...
@@ -1616,7 +1616,7 @@ DESCR("character length");
DATA
(
insert
OID
=
1319
(
length
PGUID
11
f
t
t
t
1
f
23
"1043"
100
0
0
100
varcharlen
-
));
DESCR
(
"character length"
);
DATA
(
insert
OID
=
1326
(
interval_div
PGUID
1
1
f
t
f
t
2
f
1186
"1186 701"
100
0
0
100
interval_div
-
));
DATA
(
insert
OID
=
1326
(
interval_div
PGUID
1
2
f
t
f
t
2
f
1186
"1186 701"
100
0
0
100
interval_div
-
));
DESCR
(
"divide"
);
DATA
(
insert
OID
=
1339
(
dlog10
PGUID
11
f
t
t
t
1
f
701
"701"
100
0
0
100
dlog10
-
));
...
...
@@ -1644,25 +1644,25 @@ DATA(insert OID = 1349 ( oidvectortypes PGUID 12 f t f t 1 f 25 "30" 100 0 0
DESCR
(
"print type names of oidvector field"
);
DATA
(
insert
OID
=
1350
(
timetz_in
PGUID
1
1
f
t
f
t
1
f
1266
"0"
100
0
0
100
timetz_in
-
));
DATA
(
insert
OID
=
1350
(
timetz_in
PGUID
1
2
f
t
f
t
1
f
1266
"0"
100
0
0
100
timetz_in
-
));
DESCR
(
"(internal)"
);
DATA
(
insert
OID
=
1351
(
timetz_out
PGUID
1
1
f
t
f
t
1
f
23
"0"
100
0
0
100
timetz_out
-
));
DATA
(
insert
OID
=
1351
(
timetz_out
PGUID
1
2
f
t
f
t
1
f
23
"0"
100
0
0
100
timetz_out
-
));
DESCR
(
"(internal)"
);
DATA
(
insert
OID
=
1352
(
timetz_eq
PGUID
1
1
f
t
t
t
2
f
16
"1266 1266"
100
0
0
100
timetz_eq
-
));
DATA
(
insert
OID
=
1352
(
timetz_eq
PGUID
1
2
f
t
t
t
2
f
16
"1266 1266"
100
0
0
100
timetz_eq
-
));
DESCR
(
"equal"
);
DATA
(
insert
OID
=
1353
(
timetz_ne
PGUID
1
1
f
t
t
t
2
f
16
"1266 1266"
100
0
0
100
timetz_ne
-
));
DATA
(
insert
OID
=
1353
(
timetz_ne
PGUID
1
2
f
t
t
t
2
f
16
"1266 1266"
100
0
0
100
timetz_ne
-
));
DESCR
(
"not equal"
);
DATA
(
insert
OID
=
1354
(
timetz_lt
PGUID
1
1
f
t
t
t
2
f
16
"1266 1266"
100
0
0
100
timetz_lt
-
));
DATA
(
insert
OID
=
1354
(
timetz_lt
PGUID
1
2
f
t
t
t
2
f
16
"1266 1266"
100
0
0
100
timetz_lt
-
));
DESCR
(
"less-than"
);
DATA
(
insert
OID
=
1355
(
timetz_le
PGUID
1
1
f
t
t
t
2
f
16
"1266 1266"
100
0
0
100
timetz_le
-
));
DATA
(
insert
OID
=
1355
(
timetz_le
PGUID
1
2
f
t
t
t
2
f
16
"1266 1266"
100
0
0
100
timetz_le
-
));
DESCR
(
"less-than-or-equal"
);
DATA
(
insert
OID
=
1356
(
timetz_ge
PGUID
1
1
f
t
t
t
2
f
16
"1266 1266"
100
0
0
100
timetz_ge
-
));
DATA
(
insert
OID
=
1356
(
timetz_ge
PGUID
1
2
f
t
t
t
2
f
16
"1266 1266"
100
0
0
100
timetz_ge
-
));
DESCR
(
"greater-than-or-equal"
);
DATA
(
insert
OID
=
1357
(
timetz_gt
PGUID
1
1
f
t
t
t
2
f
16
"1266 1266"
100
0
0
100
timetz_gt
-
));
DATA
(
insert
OID
=
1357
(
timetz_gt
PGUID
1
2
f
t
t
t
2
f
16
"1266 1266"
100
0
0
100
timetz_gt
-
));
DESCR
(
"greater-than"
);
DATA
(
insert
OID
=
1358
(
timetz_cmp
PGUID
1
1
f
t
t
t
2
f
23
"1266 1266"
100
0
0
100
timetz_cmp
-
));
DATA
(
insert
OID
=
1358
(
timetz_cmp
PGUID
1
2
f
t
t
t
2
f
23
"1266 1266"
100
0
0
100
timetz_cmp
-
));
DESCR
(
"less-equal-greater"
);
DATA
(
insert
OID
=
1359
(
timestamp
PGUID
1
1
f
t
f
t
2
f
1184
"1082 1266"
100
0
0
100
datetimetz_timestamp
-
));
DATA
(
insert
OID
=
1359
(
timestamp
PGUID
1
2
f
t
f
t
2
f
1184
"1082 1266"
100
0
0
100
datetimetz_timestamp
-
));
DESCR
(
"convert date and time with time zone to timestamp"
);
DATA
(
insert
OID
=
1362
(
time
PGUID
14
f
t
t
t
1
f
1083
"1083"
100
0
0
100
"select $1"
-
));
...
...
@@ -1677,7 +1677,7 @@ DATA(insert OID = 1368 ( timestamp PGUID 14 f t f t 1 f 1184 "1184" 100 0 0
DESCR
(
"convert (noop)"
);
DATA
(
insert
OID
=
1369
(
interval
PGUID
14
f
t
t
t
1
f
1186
"1186"
100
0
0
100
"select $1"
-
));
DESCR
(
"convert (noop)"
);
DATA
(
insert
OID
=
1370
(
interval
PGUID
1
1
f
t
f
t
1
f
1186
"1083"
100
0
0
100
time_interval
-
));
DATA
(
insert
OID
=
1370
(
interval
PGUID
1
2
f
t
f
t
1
f
1186
"1083"
100
0
0
100
time_interval
-
));
DESCR
(
"convert time to interval"
);
DATA
(
insert
OID
=
1371
(
date
PGUID
14
f
t
t
t
1
f
1082
"1082"
100
0
0
100
"select $1"
-
));
DESCR
(
"convert (noop)"
);
...
...
@@ -1693,13 +1693,13 @@ DESCR("octet length");
DATA
(
insert
OID
=
1376
(
octet_length
PGUID
11
f
t
t
t
1
f
23
"1043"
100
0
0
100
varcharoctetlen
-
));
DESCR
(
"octet length"
);
DATA
(
insert
OID
=
1377
(
time_larger
PGUID
1
1
f
t
t
t
2
f
1083
"1083 1083"
100
0
0
100
time_larger
-
));
DATA
(
insert
OID
=
1377
(
time_larger
PGUID
1
2
f
t
t
t
2
f
1083
"1083 1083"
100
0
0
100
time_larger
-
));
DESCR
(
"larger of two"
);
DATA
(
insert
OID
=
1378
(
time_smaller
PGUID
1
1
f
t
t
t
2
f
1083
"1083 1083"
100
0
0
100
time_smaller
-
));
DATA
(
insert
OID
=
1378
(
time_smaller
PGUID
1
2
f
t
t
t
2
f
1083
"1083 1083"
100
0
0
100
time_smaller
-
));
DESCR
(
"smaller of two"
);
DATA
(
insert
OID
=
1379
(
timetz_larger
PGUID
1
1
f
t
t
t
2
f
1083
"1266 1266"
100
0
0
100
timetz_larger
-
));
DATA
(
insert
OID
=
1379
(
timetz_larger
PGUID
1
2
f
t
t
t
2
f
1266
"1266 1266"
100
0
0
100
timetz_larger
-
));
DESCR
(
"larger of two"
);
DATA
(
insert
OID
=
1380
(
timetz_smaller
PGUID
1
1
f
t
t
t
2
f
1083
"1266 1266"
100
0
0
100
timetz_smaller
-
));
DATA
(
insert
OID
=
1380
(
timetz_smaller
PGUID
1
2
f
t
t
t
2
f
1266
"1266 1266"
100
0
0
100
timetz_smaller
-
));
DESCR
(
"smaller of two"
);
DATA
(
insert
OID
=
1381
(
char_length
PGUID
11
f
t
t
t
1
f
23
"25"
100
0
1
0
textlen
-
));
...
...
@@ -1718,12 +1718,12 @@ DESCR("date difference from today preserving months and years");
DATA
(
insert
OID
=
1387
(
timetz
PGUID
14
f
t
f
t
1
f
1266
"1266"
100
0
0
100
"select $1"
-
));
DESCR
(
"noop conversion"
);
DATA
(
insert
OID
=
1388
(
timetz
PGUID
1
1
f
t
f
t
1
f
1266
"1184"
100
0
0
100
timestamp_timetz
-
));
DESCR
(
"convert timestamp to time"
);
DATA
(
insert
OID
=
1388
(
timetz
PGUID
1
2
f
t
f
t
1
f
1266
"1184"
100
0
0
100
timestamp_timetz
-
));
DESCR
(
"convert timestamp to time
tz
"
);
DATA
(
insert
OID
=
1389
(
isfinite
PGUID
1
1
f
t
f
t
1
f
16
"1184"
100
0
0
100
timestamp_finite
-
));
DATA
(
insert
OID
=
1389
(
isfinite
PGUID
1
2
f
t
f
t
1
f
16
"1184"
100
0
0
100
timestamp_finite
-
));
DESCR
(
"boolean test"
);
DATA
(
insert
OID
=
1390
(
isfinite
PGUID
1
1
f
t
f
t
1
f
16
"1186"
100
0
0
100
interval_finite
-
));
DATA
(
insert
OID
=
1390
(
isfinite
PGUID
1
2
f
t
f
t
1
f
16
"1186"
100
0
0
100
interval_finite
-
));
DESCR
(
"boolean test"
);
...
...
@@ -1915,7 +1915,7 @@ DATA(insert OID = 1479 ( circle PGUID 11 f t t t 1 f 718 "603" 100 0 1 0 box_
DESCR
(
"convert box to circle"
);
DATA
(
insert
OID
=
1480
(
box
PGUID
11
f
t
t
t
1
f
603
"718"
100
0
1
0
circle_box
-
));
DESCR
(
"convert circle to box"
);
DATA
(
insert
OID
=
1481
(
tinterval
PGUID
1
1
f
t
f
t
2
f
704
"702 702"
100
0
0
100
mktinterval
-
));
DATA
(
insert
OID
=
1481
(
tinterval
PGUID
1
2
f
t
f
t
2
f
704
"702 702"
100
0
0
100
mktinterval
-
));
DESCR
(
"convert to tinterval"
);
DATA
(
insert
OID
=
1482
(
lseg_ne
PGUID
11
f
t
t
t
2
f
16
"601 601"
100
0
0
100
lseg_ne
-
));
...
...
@@ -2060,7 +2060,7 @@ DESCR("radians to degrees");
DATA
(
insert
OID
=
1610
(
pi
PGUID
11
f
t
t
t
0
f
701
"0"
100
0
0
100
dpi
-
));
DESCR
(
"PI"
);
DATA
(
insert
OID
=
1618
(
interval_mul
PGUID
1
1
f
t
t
t
2
f
1186
"1186 701"
100
0
0
100
interval_mul
-
));
DATA
(
insert
OID
=
1618
(
interval_mul
PGUID
1
2
f
t
t
t
2
f
1186
"1186 701"
100
0
0
100
interval_mul
-
));
DESCR
(
"multiply interval"
);
DATA
(
insert
OID
=
1619
(
varchar
PGUID
12
f
t
t
t
1
f
1043
"23"
100
0
0
100
int4_text
-
));
DESCR
(
"convert int4 to varchar"
);
...
...
@@ -2074,7 +2074,7 @@ DESCR("replicate string int4 times");
DATA
(
insert
OID
=
1623
(
varchar
PGUID
11
f
t
t
t
1
f
1043
"20"
100
0
0
100
int8_text
-
));
DESCR
(
"convert int8 to varchar"
);
DATA
(
insert
OID
=
1624
(
mul_d_interval
PGUID
1
1
f
t
t
t
2
f
1186
"701 1186"
100
0
0
100
mul_d_interval
-
));
DATA
(
insert
OID
=
1624
(
mul_d_interval
PGUID
1
2
f
t
t
t
2
f
1186
"701 1186"
100
0
0
100
mul_d_interval
-
));
/* OID's 1625 - 1639 LZTEXT data type */
DATA
(
insert
OID
=
1626
(
lztextin
PGUID
11
f
t
t
t
1
f
1625
"0"
100
0
0
100
lztextin
-
));
...
...
@@ -2164,7 +2164,7 @@ DATA(insert OID = 1641 ( pg_get_viewdef PGUID 11 f t f t 1 f 25 "19" 100 0 0
DESCR
(
"select statement of a view"
);
DATA
(
insert
OID
=
1642
(
pg_get_userbyid
PGUID
11
f
t
f
t
1
f
19
"23"
100
0
0
100
pg_get_userbyid
-
));
DESCR
(
"user name by UID (with fallback)"
);
DATA
(
insert
OID
=
1643
(
pg_get_indexdef
PGUID
1
1
f
t
f
t
1
f
25
"26"
100
0
0
100
pg_get_indexdef
-
));
DATA
(
insert
OID
=
1643
(
pg_get_indexdef
PGUID
1
2
f
t
f
t
1
f
25
"26"
100
0
0
100
pg_get_indexdef
-
));
DESCR
(
"index description"
);
/* Generic referential integrity constraint triggers */
...
...
@@ -2425,7 +2425,7 @@ DATA(insert OID = 1783 ( int2 PGUID 12 f t t t 1 f 21 "1700" 100 0 0 100 nu
DESCR
(
"(internal)"
);
/* formatting */
DATA
(
insert
OID
=
1770
(
to_char
PGUID
1
1
f
t
f
t
2
f
25
"1184 25"
100
0
0
100
timestamp_to_char
-
));
DATA
(
insert
OID
=
1770
(
to_char
PGUID
1
2
f
t
f
t
2
f
25
"1184 25"
100
0
0
100
timestamp_to_char
-
));
DESCR
(
"format timestamp to text"
);
DATA
(
insert
OID
=
1772
(
to_char
PGUID
11
f
t
f
t
2
f
25
"1700 25"
100
0
0
100
numeric_to_char
-
));
DESCR
(
"format numeric to text"
);
...
...
@@ -2439,9 +2439,9 @@ DATA(insert OID = 1776 ( to_char PGUID 11 f t f t 2 f 25 "701 25" 100 0 0 100
DESCR
(
"format float8 to text"
);
DATA
(
insert
OID
=
1777
(
to_number
PGUID
11
f
t
f
t
2
f
1700
"25 25"
100
0
0
100
numeric_to_number
-
));
DESCR
(
"convert text to numeric"
);
DATA
(
insert
OID
=
1778
(
to_timestamp
PGUID
1
1
f
t
f
t
2
f
1184
"25 25"
100
0
0
100
to_timestamp
-
));
DATA
(
insert
OID
=
1778
(
to_timestamp
PGUID
1
2
f
t
f
t
2
f
1184
"25 25"
100
0
0
100
to_timestamp
-
));
DESCR
(
"convert text to timestamp"
);
DATA
(
insert
OID
=
1780
(
to_date
PGUID
1
1
f
t
f
t
2
f
1082
"25 25"
100
0
0
100
to_date
-
));
DATA
(
insert
OID
=
1780
(
to_date
PGUID
1
2
f
t
f
t
2
f
1082
"25 25"
100
0
0
100
to_date
-
));
DESCR
(
"convert text to date"
);
DATA
(
insert
OID
=
1798
(
oidin
PGUID
12
f
t
t
t
1
f
26
"0"
100
0
0
100
oidin
-
));
...
...
src/include/libpq/be-fsstubs.h
View file @
ae526b40
...
...
@@ -7,39 +7,43 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: be-fsstubs.h,v 1.1
0 2000/01/26 05:58:12 momjian
Exp $
* $Id: be-fsstubs.h,v 1.1
1 2000/06/09 01:11:12 tgl
Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef BE_FSSTUBS_H
#define BE_FSSTUBS_H
/* Redefine names LOread() and LOwrite() to be lowercase to allow calling
* using the new v6.1 case-insensitive SQL parser. Define macros to allow
* the existing code to stay the same. - tgl 97/05/03
#include "fmgr.h"
/*
* LO functions available via pg_proc entries
*/
extern
Datum
lo_import
(
PG_FUNCTION_ARGS
);
extern
Datum
lo_export
(
PG_FUNCTION_ARGS
);
extern
Datum
lo_creat
(
PG_FUNCTION_ARGS
);
#define LOread(f,l) loread(f,l)
#define LOwrite(f,b) lowrite(f,b)
extern
Datum
lo_open
(
PG_FUNCTION_ARGS
);
extern
Datum
lo_close
(
PG_FUNCTION_ARGS
);
extern
Oid
lo_import
(
text
*
filename
);
extern
int4
lo_export
(
Oid
lobjId
,
text
*
filename
);
extern
Datum
loread
(
PG_FUNCTION_ARGS
);
extern
Datum
lowrite
(
PG_FUNCTION_ARGS
);
extern
Oid
lo_creat
(
int
mode
);
extern
Datum
lo_lseek
(
PG_FUNCTION_ARGS
);
extern
Datum
lo_tell
(
PG_FUNCTION_ARGS
);
extern
Datum
lo_unlink
(
PG_FUNCTION_ARGS
);
extern
int
lo_open
(
Oid
lobjId
,
int
mode
);
extern
int
lo_close
(
int
fd
);
/*
* These are not fmgr-callable, but are available to C code.
* Probably these should have had the underscore-free names,
* but too late now...
*/
extern
int
lo_read
(
int
fd
,
char
*
buf
,
int
len
);
extern
int
lo_write
(
int
fd
,
char
*
buf
,
int
len
);
extern
int
lo_lseek
(
int
fd
,
int
offset
,
int
whence
);
extern
int
lo_tell
(
int
fd
);
extern
int
lo_unlink
(
Oid
lobjId
);
extern
struct
varlena
*
loread
(
int
fd
,
int
len
);
extern
int
lowrite
(
int
fd
,
struct
varlena
*
wbuf
);
/*
*
Added for buffer leak prevention
[ Pascal Andr <andre@via.ecp.fr> ]
*
Cleanup LOs at xact commit/abort
[ Pascal Andr <andre@via.ecp.fr> ]
*/
extern
void
lo_commit
(
bool
isCommit
);
...
...
src/include/utils/builtins.h
View file @
ae526b40
...
...
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: builtins.h,v 1.11
4 2000/06/08 22:37:58 momjian
Exp $
* $Id: builtins.h,v 1.11
5 2000/06/09 01:11:14 tgl
Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -180,7 +180,7 @@ extern Datum btfloat4cmp(PG_FUNCTION_ARGS);
extern
Datum
btfloat8cmp
(
PG_FUNCTION_ARGS
);
extern
Datum
btoidcmp
(
PG_FUNCTION_ARGS
);
extern
Datum
btoidvectorcmp
(
PG_FUNCTION_ARGS
);
extern
int32
btabstimecmp
(
AbsoluteTime
a
,
AbsoluteTime
b
);
extern
Datum
btabstimecmp
(
PG_FUNCTION_ARGS
);
extern
Datum
btcharcmp
(
PG_FUNCTION_ARGS
);
extern
Datum
btnamecmp
(
PG_FUNCTION_ARGS
);
extern
Datum
bttextcmp
(
PG_FUNCTION_ARGS
);
...
...
@@ -309,8 +309,8 @@ extern Datum oidsrand(PG_FUNCTION_ARGS);
extern
Datum
userfntest
(
PG_FUNCTION_ARGS
);
/* not_in.c */
extern
bool
int4notin
(
int32
not_in_arg
,
char
*
relation_and_attr
);
extern
bool
oidnotin
(
Oid
the_oid
,
char
*
compare
);
extern
Datum
int4notin
(
PG_FUNCTION_ARGS
);
extern
Datum
oidnotin
(
PG_FUNCTION_ARGS
);
/* oid.c */
extern
Datum
oidvectorin
(
PG_FUNCTION_ARGS
);
...
...
@@ -353,7 +353,7 @@ extern Datum regproctooid(PG_FUNCTION_ARGS);
/* ruleutils.c */
extern
text
*
pg_get_ruledef
(
NameData
*
rname
);
extern
text
*
pg_get_viewdef
(
NameData
*
rname
);
extern
text
*
pg_get_indexdef
(
Oid
indexrelid
);
extern
Datum
pg_get_indexdef
(
PG_FUNCTION_ARGS
);
extern
NameData
*
pg_get_userbyid
(
int32
uid
);
extern
char
*
deparse_expression
(
Node
*
expr
,
List
*
rangetables
,
bool
forceprefix
);
...
...
@@ -407,8 +407,8 @@ extern char *make_greater_string(const char *str, Oid datatype);
extern
ItemPointer
tidin
(
const
char
*
str
);
extern
char
*
tidout
(
ItemPointer
itemPtr
);
extern
bool
tideq
(
ItemPointer
,
ItemPointer
);
extern
ItemPointer
currtid_byreloid
(
Oid
relOid
,
ItemPointer
);
extern
ItemPointer
currtid_byrelname
(
const
text
*
relName
,
ItemPointer
);
extern
Datum
currtid_byreloid
(
PG_FUNCTION_ARGS
);
extern
Datum
currtid_byrelname
(
PG_FUNCTION_ARGS
);
/* varchar.c */
...
...
src/include/utils/date.h
View file @
ae526b40
...
...
@@ -7,13 +7,16 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: date.h,v 1.
3 2000/04/12 17:16:54 momjian
Exp $
* $Id: date.h,v 1.
4 2000/06/09 01:11:15 tgl
Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef DATE_H
#define DATE_H
#include "fmgr.h"
typedef
int32
DateADT
;
typedef
float8
TimeADT
;
...
...
@@ -25,56 +28,77 @@ typedef struct
int4
zone
;
/* numeric time zone, in seconds */
}
TimeTzADT
;
/*
* Macros for fmgr-callable functions.
*
* For TimeADT, we make use of the same support routines as for float8.
* Therefore TimeADT is pass-by-reference if and only if float8 is!
*/
#define DatumGetDateADT(X) ((DateADT) DatumGetInt32(X))
#define DatumGetTimeADT(X) ((TimeADT) DatumGetFloat8(X))
#define DatumGetTimeTzADTP(X) ((TimeTzADT *) DatumGetPointer(X))
#define DateADTGetDatum(X) Int32GetDatum(X)
#define TimeADTGetDatum(X) Float8GetDatum(X)
#define TimeTzADTPGetDatum(X) PointerGetDatum(X)
#define PG_GETARG_DATEADT(n) DatumGetDateADT(PG_GETARG_DATUM(n))
#define PG_GETARG_TIMEADT(n) DatumGetTimeADT(PG_GETARG_DATUM(n))
#define PG_GETARG_TIMETZADT_P(n) DatumGetTimeTzADTP(PG_GETARG_DATUM(n))
#define PG_RETURN_DATEADT(x) return DateADTGetDatum(x)
#define PG_RETURN_TIMEADT(x) return TimeADTGetDatum(x)
#define PG_RETURN_TIMETZADT_P(x) return TimeTzADTPGetDatum(x)
/* date.c */
extern
Dat
eADT
date_in
(
char
*
datestr
);
extern
char
*
date_out
(
DateADT
dateVal
);
extern
bool
date_eq
(
DateADT
dateVal1
,
DateADT
dateVal2
);
extern
bool
date_ne
(
DateADT
dateVal1
,
DateADT
dateVal2
);
extern
bool
date_lt
(
DateADT
dateVal1
,
DateADT
dateVal2
);
extern
bool
date_le
(
DateADT
dateVal1
,
DateADT
dateVal2
);
extern
bool
date_gt
(
DateADT
dateVal1
,
DateADT
dateVal2
);
extern
bool
date_ge
(
DateADT
dateVal1
,
DateADT
dateVal2
);
extern
int
date_cmp
(
DateADT
dateVal1
,
DateADT
dateVal2
);
extern
Dat
eADT
date_larger
(
DateADT
dateVal1
,
DateADT
dateVal2
);
extern
Dat
eADT
date_smaller
(
DateADT
dateVal1
,
DateADT
dateVal2
);
extern
int32
date_mi
(
DateADT
dateVal1
,
DateADT
dateVal2
);
extern
Dat
eADT
date_pli
(
DateADT
dateVal
,
int32
days
);
extern
Dat
eADT
date_mii
(
DateADT
dateVal
,
int32
days
);
extern
Timestamp
*
date_timestamp
(
DateADT
date
);
extern
Dat
eADT
timestamp_date
(
Timestamp
*
timestamp
);
extern
Timestamp
*
datetime_timestamp
(
DateADT
date
,
TimeADT
*
time
);
extern
Dat
eADT
abstime_date
(
AbsoluteTime
abstime
);
extern
Dat
um
date_in
(
PG_FUNCTION_ARGS
);
extern
Datum
date_out
(
PG_FUNCTION_ARGS
);
extern
Datum
date_eq
(
PG_FUNCTION_ARGS
);
extern
Datum
date_ne
(
PG_FUNCTION_ARGS
);
extern
Datum
date_lt
(
PG_FUNCTION_ARGS
);
extern
Datum
date_le
(
PG_FUNCTION_ARGS
);
extern
Datum
date_gt
(
PG_FUNCTION_ARGS
);
extern
Datum
date_ge
(
PG_FUNCTION_ARGS
);
extern
Datum
date_cmp
(
PG_FUNCTION_ARGS
);
extern
Dat
um
date_larger
(
PG_FUNCTION_ARGS
);
extern
Dat
um
date_smaller
(
PG_FUNCTION_ARGS
);
extern
Datum
date_mi
(
PG_FUNCTION_ARGS
);
extern
Dat
um
date_pli
(
PG_FUNCTION_ARGS
);
extern
Dat
um
date_mii
(
PG_FUNCTION_ARGS
);
extern
Datum
date_timestamp
(
PG_FUNCTION_ARGS
);
extern
Dat
um
timestamp_date
(
PG_FUNCTION_ARGS
);
extern
Datum
datetime_timestamp
(
PG_FUNCTION_ARGS
);
extern
Dat
um
abstime_date
(
PG_FUNCTION_ARGS
);
extern
TimeADT
*
time_in
(
char
*
timestr
);
extern
char
*
time_out
(
TimeADT
*
time
);
extern
bool
time_eq
(
TimeADT
*
time1
,
TimeADT
*
time2
);
extern
bool
time_ne
(
TimeADT
*
time1
,
TimeADT
*
time2
);
extern
bool
time_lt
(
TimeADT
*
time1
,
TimeADT
*
time2
);
extern
bool
time_le
(
TimeADT
*
time1
,
TimeADT
*
time2
);
extern
bool
time_gt
(
TimeADT
*
time1
,
TimeADT
*
time2
);
extern
bool
time_ge
(
TimeADT
*
time1
,
TimeADT
*
time2
);
extern
int
time_cmp
(
TimeADT
*
time1
,
TimeADT
*
time2
);
extern
bool
overlaps_time
(
TimeADT
*
time1
,
TimeADT
*
time2
,
TimeADT
*
time3
,
TimeADT
*
time4
);
extern
TimeADT
*
time_larger
(
TimeADT
*
time1
,
TimeADT
*
time2
);
extern
TimeADT
*
time_smaller
(
TimeADT
*
time1
,
TimeADT
*
time2
);
extern
TimeADT
*
timestamp_time
(
Timestamp
*
timestamp
);
extern
Interval
*
time_interval
(
TimeADT
*
time
);
extern
Datum
time_in
(
PG_FUNCTION_ARGS
);
extern
Datum
time_out
(
PG_FUNCTION_ARGS
);
extern
Datum
time_eq
(
PG_FUNCTION_ARGS
);
extern
Datum
time_ne
(
PG_FUNCTION_ARGS
);
extern
Datum
time_lt
(
PG_FUNCTION_ARGS
);
extern
Datum
time_le
(
PG_FUNCTION_ARGS
);
extern
Datum
time_gt
(
PG_FUNCTION_ARGS
);
extern
Datum
time_ge
(
PG_FUNCTION_ARGS
);
extern
Datum
time_cmp
(
PG_FUNCTION_ARGS
);
extern
Datum
overlaps_time
(
PG_FUNCTION_ARGS
);
extern
Datum
time_larger
(
PG_FUNCTION_ARGS
);
extern
Datum
time_smaller
(
PG_FUNCTION_ARGS
);
extern
Datum
timestamp_time
(
PG_FUNCTION_ARGS
);
extern
Datum
time_interval
(
PG_FUNCTION_ARGS
);
extern
TimeTzADT
*
timetz_in
(
char
*
timestr
);
extern
char
*
timetz_out
(
TimeTzADT
*
time
);
extern
bool
timetz_eq
(
TimeTzADT
*
time1
,
TimeTzADT
*
time2
);
extern
bool
timetz_ne
(
TimeTzADT
*
time1
,
TimeTzADT
*
time2
);
extern
bool
timetz_lt
(
TimeTzADT
*
time1
,
TimeTzADT
*
time2
);
extern
bool
timetz_le
(
TimeTzADT
*
time1
,
TimeTzADT
*
time2
);
extern
bool
timetz_gt
(
TimeTzADT
*
time1
,
TimeTzADT
*
time2
);
extern
bool
timetz_ge
(
TimeTzADT
*
time1
,
TimeTzADT
*
time2
);
extern
int
timetz_cmp
(
TimeTzADT
*
time1
,
TimeTzADT
*
time2
);
extern
bool
overlaps_timetz
(
TimeTzADT
*
time1
,
TimeTzADT
*
time2
,
TimeTzADT
*
time3
,
TimeTzADT
*
time4
);
extern
TimeTzADT
*
timetz_larger
(
TimeTzADT
*
time1
,
TimeTzADT
*
time2
);
extern
TimeTzADT
*
timetz_smaller
(
TimeTzADT
*
time1
,
TimeTzADT
*
time2
);
extern
TimeTzADT
*
timestamp_timetz
(
Timestamp
*
timestamp
);
extern
Timestamp
*
datetimetz_timestamp
(
DateADT
date
,
TimeTzADT
*
time
);
extern
Datum
timetz_in
(
PG_FUNCTION_ARGS
);
extern
Datum
timetz_out
(
PG_FUNCTION_ARGS
);
extern
Datum
timetz_eq
(
PG_FUNCTION_ARGS
);
extern
Datum
timetz_ne
(
PG_FUNCTION_ARGS
);
extern
Datum
timetz_lt
(
PG_FUNCTION_ARGS
);
extern
Datum
timetz_le
(
PG_FUNCTION_ARGS
);
extern
Datum
timetz_gt
(
PG_FUNCTION_ARGS
);
extern
Datum
timetz_ge
(
PG_FUNCTION_ARGS
);
extern
Datum
timetz_cmp
(
PG_FUNCTION_ARGS
);
extern
Datum
overlaps_timetz
(
PG_FUNCTION_ARGS
);
extern
Datum
timetz_larger
(
PG_FUNCTION_ARGS
);
extern
Datum
timetz_smaller
(
PG_FUNCTION_ARGS
);
extern
Datum
timestamp_timetz
(
PG_FUNCTION_ARGS
);
extern
Datum
datetimetz_timestamp
(
PG_FUNCTION_ARGS
);
#endif
/* DATE_H */
src/include/utils/formatting.h
View file @
ae526b40
...
...
@@ -2,7 +2,7 @@
/* -----------------------------------------------------------------------
* formatting.h
*
* $Id: formatting.h,v 1.
4 2000/04/12 17:16:55 momjian
Exp $
* $Id: formatting.h,v 1.
5 2000/06/09 01:11:15 tgl
Exp $
*
*
* Portions Copyright (c) 1999-2000, PostgreSQL, Inc
...
...
@@ -18,9 +18,12 @@
#ifndef _FORMATTING_H_
#define _FORMATTING_H_
extern
text
*
timestamp_to_char
(
Timestamp
*
dt
,
text
*
fmt
);
extern
Timestamp
*
to_timestamp
(
text
*
date_str
,
text
*
fmt
);
extern
DateADT
to_date
(
text
*
date_str
,
text
*
fmt
);
#include "fmgr.h"
extern
Datum
timestamp_to_char
(
PG_FUNCTION_ARGS
);
extern
Datum
to_timestamp
(
PG_FUNCTION_ARGS
);
extern
Datum
to_date
(
PG_FUNCTION_ARGS
);
extern
Numeric
numeric_to_number
(
text
*
value
,
text
*
fmt
);
extern
text
*
numeric_to_char
(
Numeric
value
,
text
*
fmt
);
extern
text
*
int4_to_char
(
int32
value
,
text
*
fmt
);
...
...
src/include/utils/nabstime.h
View file @
ae526b40
...
...
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: nabstime.h,v 1.2
5 2000/04/12 17:16:55 momjian
Exp $
* $Id: nabstime.h,v 1.2
6 2000/06/09 01:11:15 tgl
Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -15,13 +15,15 @@
#define NABSTIME_H
#include <time.h>
#include "fmgr.h"
#include "utils/timestamp.h"
#include "utils/datetime.h"
/* ----------------------------------------------------------------
* time types + support macros
*
* time types + support macros
*
* ----------------------------------------------------------------
*/
...
...
@@ -39,8 +41,28 @@ typedef struct
int32
status
;
AbsoluteTime
data
[
2
];
}
TimeIntervalData
;
typedef
TimeIntervalData
*
TimeInterval
;
/*
* Macros for fmgr-callable functions.
*/
#define DatumGetAbsoluteTime(X) ((AbsoluteTime) DatumGetInt32(X))
#define DatumGetRelativeTime(X) ((RelativeTime) DatumGetInt32(X))
#define DatumGetTimeInterval(X) ((TimeInterval) DatumGetPointer(X))
#define AbsoluteTimeGetDatum(X) Int32GetDatum(X)
#define RelativeTimeGetDatum(X) Int32GetDatum(X)
#define TimeIntervalGetDatum(X) PointerGetDatum(X)
#define PG_GETARG_ABSOLUTETIME(n) DatumGetAbsoluteTime(PG_GETARG_DATUM(n))
#define PG_GETARG_RELATIVETIME(n) DatumGetRelativeTime(PG_GETARG_DATUM(n))
#define PG_GETARG_TIMEINTERVAL(n) DatumGetTimeInterval(PG_GETARG_DATUM(n))
#define PG_RETURN_ABSOLUTETIME(x) return AbsoluteTimeGetDatum(x)
#define PG_RETURN_RELATIVETIME(x) return RelativeTimeGetDatum(x)
#define PG_RETURN_TIMEINTERVAL(x) return TimeIntervalGetDatum(x)
/*
* Reserved values
* Epoch is Unix system time zero, but needs to be kept as a reserved
...
...
@@ -78,21 +100,9 @@ typedef TimeIntervalData *TimeInterval;
((bool) (((AbsoluteTime) time) < NOEND_ABSTIME && \
((AbsoluteTime) time) > NOSTART_ABSTIME))
/* have to include this because EPOCH_ABSTIME used to be invalid - yuk */
#define AbsoluteTimeIsBackwardCompatiblyValid(time) \
((bool) (((AbsoluteTime) time) != INVALID_ABSTIME && \
((AbsoluteTime) time) > EPOCH_ABSTIME))
#define AbsoluteTimeIsBackwardCompatiblyReal(time) \
((bool) (((AbsoluteTime) time) < NOEND_ABSTIME && \
((AbsoluteTime) time) > NOSTART_ABSTIME && \
((AbsoluteTime) time) > EPOCH_ABSTIME))
#define RelativeTimeIsValid(time) \
((bool) (((RelativeTime) time) != INVALID_RELTIME))
extern
AbsoluteTime
GetCurrentAbsoluteTime
(
void
);
/*
* getSystemTime
* Returns system time.
...
...
@@ -104,62 +114,62 @@ extern AbsoluteTime GetCurrentAbsoluteTime(void);
/*
* nabstime.c prototypes
*/
extern
AbsoluteTime
nabstimein
(
char
*
timestr
);
extern
char
*
nabstimeout
(
AbsoluteTime
time
);
extern
bool
abstimeeq
(
AbsoluteTime
t1
,
AbsoluteTime
t2
);
extern
bool
abstimene
(
AbsoluteTime
t1
,
AbsoluteTime
t2
);
extern
bool
abstimelt
(
AbsoluteTime
t1
,
AbsoluteTime
t2
);
extern
bool
abstimegt
(
AbsoluteTime
t1
,
AbsoluteTime
t2
);
extern
bool
abstimele
(
AbsoluteTime
t1
,
AbsoluteTime
t2
);
extern
bool
abstimege
(
AbsoluteTime
t1
,
AbsoluteTime
t2
);
extern
bool
abstime_finite
(
AbsoluteTime
time
);
extern
AbsoluteTime
timestamp_abstime
(
Timestamp
*
timestamp
);
extern
Timestamp
*
abstime_timestamp
(
AbsoluteTime
abstime
);
extern
Datum
nabstimein
(
PG_FUNCTION_ARGS
);
extern
Datum
nabstimeout
(
PG_FUNCTION_ARGS
);
extern
Datum
abstimeeq
(
PG_FUNCTION_ARGS
);
extern
Datum
abstimene
(
PG_FUNCTION_ARGS
);
extern
Datum
abstimelt
(
PG_FUNCTION_ARGS
);
extern
Datum
abstimegt
(
PG_FUNCTION_ARGS
);
extern
Datum
abstimele
(
PG_FUNCTION_ARGS
);
extern
Datum
abstimege
(
PG_FUNCTION_ARGS
);
extern
Datum
abstime_finite
(
PG_FUNCTION_ARGS
);
extern
Datum
timestamp_abstime
(
PG_FUNCTION_ARGS
);
extern
Datum
abstime_timestamp
(
PG_FUNCTION_ARGS
);
extern
Datum
reltimein
(
PG_FUNCTION_ARGS
);
extern
Datum
reltimeout
(
PG_FUNCTION_ARGS
);
extern
Datum
tintervalin
(
PG_FUNCTION_ARGS
);
extern
Datum
tintervalout
(
PG_FUNCTION_ARGS
);
extern
Datum
interval_reltime
(
PG_FUNCTION_ARGS
);
extern
Datum
reltime_interval
(
PG_FUNCTION_ARGS
);
extern
Datum
mktinterval
(
PG_FUNCTION_ARGS
);
extern
Datum
timepl
(
PG_FUNCTION_ARGS
);
extern
Datum
timemi
(
PG_FUNCTION_ARGS
);
extern
Datum
intinterval
(
PG_FUNCTION_ARGS
);
extern
Datum
tintervalrel
(
PG_FUNCTION_ARGS
);
extern
Datum
timenow
(
PG_FUNCTION_ARGS
);
extern
Datum
reltimeeq
(
PG_FUNCTION_ARGS
);
extern
Datum
reltimene
(
PG_FUNCTION_ARGS
);
extern
Datum
reltimelt
(
PG_FUNCTION_ARGS
);
extern
Datum
reltimegt
(
PG_FUNCTION_ARGS
);
extern
Datum
reltimele
(
PG_FUNCTION_ARGS
);
extern
Datum
reltimege
(
PG_FUNCTION_ARGS
);
extern
Datum
tintervalsame
(
PG_FUNCTION_ARGS
);
extern
Datum
tintervaleq
(
PG_FUNCTION_ARGS
);
extern
Datum
tintervalne
(
PG_FUNCTION_ARGS
);
extern
Datum
tintervallt
(
PG_FUNCTION_ARGS
);
extern
Datum
tintervalgt
(
PG_FUNCTION_ARGS
);
extern
Datum
tintervalle
(
PG_FUNCTION_ARGS
);
extern
Datum
tintervalge
(
PG_FUNCTION_ARGS
);
extern
Datum
tintervalleneq
(
PG_FUNCTION_ARGS
);
extern
Datum
tintervallenne
(
PG_FUNCTION_ARGS
);
extern
Datum
tintervallenlt
(
PG_FUNCTION_ARGS
);
extern
Datum
tintervallengt
(
PG_FUNCTION_ARGS
);
extern
Datum
tintervallenle
(
PG_FUNCTION_ARGS
);
extern
Datum
tintervallenge
(
PG_FUNCTION_ARGS
);
extern
Datum
tintervalct
(
PG_FUNCTION_ARGS
);
extern
Datum
tintervalov
(
PG_FUNCTION_ARGS
);
extern
Datum
tintervalstart
(
PG_FUNCTION_ARGS
);
extern
Datum
tintervalend
(
PG_FUNCTION_ARGS
);
extern
Datum
int4reltime
(
PG_FUNCTION_ARGS
);
extern
Datum
timeofday
(
PG_FUNCTION_ARGS
);
/* non-fmgr-callable support routines */
extern
AbsoluteTime
GetCurrentAbsoluteTime
(
void
);
extern
bool
AbsoluteTimeIsBefore
(
AbsoluteTime
time1
,
AbsoluteTime
time2
);
extern
void
abstime2tm
(
AbsoluteTime
time
,
int
*
tzp
,
struct
tm
*
tm
,
char
*
tzn
);
extern
RelativeTime
reltimein
(
char
*
timestring
);
extern
char
*
reltimeout
(
RelativeTime
timevalue
);
extern
TimeInterval
tintervalin
(
char
*
intervalstr
);
extern
char
*
tintervalout
(
TimeInterval
interval
);
extern
RelativeTime
interval_reltime
(
Interval
*
interval
);
extern
Interval
*
reltime_interval
(
RelativeTime
reltime
);
extern
TimeInterval
mktinterval
(
AbsoluteTime
t1
,
AbsoluteTime
t2
);
extern
AbsoluteTime
timepl
(
AbsoluteTime
t1
,
RelativeTime
t2
);
extern
AbsoluteTime
timemi
(
AbsoluteTime
t1
,
RelativeTime
t2
);
/* extern RelativeTime abstimemi(AbsoluteTime t1, AbsoluteTime t2); static*/
extern
int
intinterval
(
AbsoluteTime
t
,
TimeInterval
interval
);
extern
RelativeTime
tintervalrel
(
TimeInterval
interval
);
extern
AbsoluteTime
timenow
(
void
);
extern
bool
reltimeeq
(
RelativeTime
t1
,
RelativeTime
t2
);
extern
bool
reltimene
(
RelativeTime
t1
,
RelativeTime
t2
);
extern
bool
reltimelt
(
RelativeTime
t1
,
RelativeTime
t2
);
extern
bool
reltimegt
(
RelativeTime
t1
,
RelativeTime
t2
);
extern
bool
reltimele
(
RelativeTime
t1
,
RelativeTime
t2
);
extern
bool
reltimege
(
RelativeTime
t1
,
RelativeTime
t2
);
extern
bool
tintervalsame
(
TimeInterval
i1
,
TimeInterval
i2
);
extern
bool
tintervaleq
(
TimeInterval
i1
,
TimeInterval
i2
);
extern
bool
tintervalne
(
TimeInterval
i1
,
TimeInterval
i2
);
extern
bool
tintervallt
(
TimeInterval
i1
,
TimeInterval
i2
);
extern
bool
tintervalgt
(
TimeInterval
i1
,
TimeInterval
i2
);
extern
bool
tintervalle
(
TimeInterval
i1
,
TimeInterval
i2
);
extern
bool
tintervalge
(
TimeInterval
i1
,
TimeInterval
i2
);
extern
bool
tintervalleneq
(
TimeInterval
i
,
RelativeTime
t
);
extern
bool
tintervallenne
(
TimeInterval
i
,
RelativeTime
t
);
extern
bool
tintervallenlt
(
TimeInterval
i
,
RelativeTime
t
);
extern
bool
tintervallengt
(
TimeInterval
i
,
RelativeTime
t
);
extern
bool
tintervallenle
(
TimeInterval
i
,
RelativeTime
t
);
extern
bool
tintervallenge
(
TimeInterval
i
,
RelativeTime
t
);
extern
bool
tintervalct
(
TimeInterval
i1
,
TimeInterval
i2
);
extern
bool
tintervalov
(
TimeInterval
i1
,
TimeInterval
i2
);
extern
AbsoluteTime
tintervalstart
(
TimeInterval
i
);
extern
AbsoluteTime
tintervalend
(
TimeInterval
i
);
extern
int32
int4reltime
(
int32
timevalue
);
extern
text
*
timeofday
(
void
);
#endif
/* NABSTIME_H */
src/include/utils/sets.h
View file @
ae526b40
...
...
@@ -7,17 +7,20 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: sets.h,v 1.
6 2000/01/26 05:58:38 momjian
Exp $
* $Id: sets.h,v 1.
7 2000/06/09 01:11:15 tgl
Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef SETS_H
#define SETS_H
#include "fmgr.h"
/* Temporary name of set, before SetDefine changes it. */
#define GENERICSETNAME "zyxset"
extern
Oid
SetDefine
(
char
*
querystr
,
char
*
typename
);
extern
int
seteval
(
Oid
funcoid
);
extern
Datum
seteval
(
PG_FUNCTION_ARGS
);
#endif
/* SETS_H */
src/include/utils/timestamp.h
View file @
ae526b40
...
...
@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: timestamp.h,v 1.
5 2000/06/08 22:37:58 momjian
Exp $
* $Id: timestamp.h,v 1.
6 2000/06/09 01:11:15 tgl
Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -17,6 +17,9 @@
#include <math.h>
#include <limits.h>
#include "fmgr.h"
/*
* Timestamp represents absolute time.
* Interval represents delta time. Keep track of months (and years)
...
...
@@ -38,6 +41,25 @@ typedef struct
}
Interval
;
/*
* Macros for fmgr-callable functions.
*
* For Timestamp, we make use of the same support routines as for float8.
* Therefore Timestamp is pass-by-reference if and only if float8 is!
*/
#define DatumGetTimestamp(X) ((Timestamp) DatumGetFloat8(X))
#define DatumGetIntervalP(X) ((Interval *) DatumGetPointer(X))
#define TimestampGetDatum(X) Float8GetDatum(X)
#define IntervalPGetDatum(X) PointerGetDatum(X)
#define PG_GETARG_TIMESTAMP(n) DatumGetTimestamp(PG_GETARG_DATUM(n))
#define PG_GETARG_INTERVAL_P(n) DatumGetIntervalP(PG_GETARG_DATUM(n))
#define PG_RETURN_TIMESTAMP(x) return TimestampGetDatum(x)
#define PG_RETURN_INTERVAL_P(x) return IntervalPGetDatum(x)
#ifdef NAN
#define DT_INVALID (NAN)
#else
...
...
@@ -105,59 +127,63 @@ extern int timestamp_is_epoch(double j);
* timestamp.c prototypes
*/
extern
Timestamp
*
timestamp_in
(
char
*
str
);
extern
char
*
timestamp_out
(
Timestamp
*
dt
);
extern
bool
timestamp_eq
(
Timestamp
*
dt1
,
Timestamp
*
dt2
);
extern
bool
timestamp_ne
(
Timestamp
*
dt1
,
Timestamp
*
dt2
);
extern
bool
timestamp_lt
(
Timestamp
*
dt1
,
Timestamp
*
dt2
);
extern
bool
timestamp_le
(
Timestamp
*
dt1
,
Timestamp
*
dt2
);
extern
bool
timestamp_ge
(
Timestamp
*
dt1
,
Timestamp
*
dt2
);
extern
bool
timestamp_gt
(
Timestamp
*
dt1
,
Timestamp
*
dt2
);
extern
bool
timestamp_finite
(
Timestamp
*
timestamp
);
extern
int
timestamp_cmp
(
Timestamp
*
dt1
,
Timestamp
*
dt2
);
extern
Timestamp
*
timestamp_smaller
(
Timestamp
*
dt1
,
Timestamp
*
dt2
);
extern
Timestamp
*
timestamp_larger
(
Timestamp
*
dt1
,
Timestamp
*
dt2
);
extern
Interval
*
interval_in
(
char
*
str
);
extern
char
*
interval_out
(
Interval
*
span
);
extern
bool
interval_eq
(
Interval
*
span1
,
Interval
*
span2
);
extern
bool
interval_ne
(
Interval
*
span1
,
Interval
*
span2
);
extern
bool
interval_lt
(
Interval
*
span1
,
Interval
*
span2
);
extern
bool
interval_le
(
Interval
*
span1
,
Interval
*
span2
);
extern
bool
interval_ge
(
Interval
*
span1
,
Interval
*
span2
);
extern
bool
interval_gt
(
Interval
*
span1
,
Interval
*
span2
);
extern
bool
interval_finite
(
Interval
*
span
);
extern
int
interval_cmp
(
Interval
*
span1
,
Interval
*
span2
);
extern
Interval
*
interval_smaller
(
Interval
*
span1
,
Interval
*
span2
);
extern
Interval
*
interval_larger
(
Interval
*
span1
,
Interval
*
span2
);
extern
text
*
timestamp_text
(
Timestamp
*
timestamp
);
extern
Timestamp
*
text_timestamp
(
text
*
str
);
extern
text
*
interval_text
(
Interval
*
interval
);
extern
Interval
*
text_interval
(
text
*
str
);
extern
Timestamp
*
timestamp_trunc
(
text
*
units
,
Timestamp
*
timestamp
);
extern
Interval
*
interval_trunc
(
text
*
units
,
Interval
*
interval
);
extern
float64
timestamp_part
(
text
*
units
,
Timestamp
*
timestamp
);
extern
float64
interval_part
(
text
*
units
,
Interval
*
interval
);
extern
text
*
timestamp_zone
(
text
*
zone
,
Timestamp
*
timestamp
);
extern
Interval
*
interval_um
(
Interval
*
span
);
extern
Interval
*
interval_pl
(
Interval
*
span1
,
Interval
*
span2
);
extern
Interval
*
interval_mi
(
Interval
*
span1
,
Interval
*
span2
);
extern
Interval
*
interval_mul
(
Interval
*
span1
,
float8
*
factor
);
extern
Interval
*
mul_d_interval
(
float8
*
factor
,
Interval
*
span1
);
extern
Interval
*
interval_div
(
Interval
*
span1
,
float8
*
factor
);
extern
Interval
*
timestamp_mi
(
Timestamp
*
dt1
,
Timestamp
*
dt2
);
extern
Timestamp
*
timestamp_pl_span
(
Timestamp
*
dt
,
Interval
*
span
);
extern
Timestamp
*
timestamp_mi_span
(
Timestamp
*
dt
,
Interval
*
span
);
extern
Interval
*
timestamp_age
(
Timestamp
*
dt1
,
Timestamp
*
dt2
);
extern
bool
overlaps_timestamp
(
Timestamp
*
dt1
,
Timestamp
*
dt2
,
Timestamp
*
dt3
,
Timestamp
*
dt4
);
extern
Datum
timestamp_in
(
PG_FUNCTION_ARGS
);
extern
Datum
timestamp_out
(
PG_FUNCTION_ARGS
);
extern
Datum
timestamp_eq
(
PG_FUNCTION_ARGS
);
extern
Datum
timestamp_ne
(
PG_FUNCTION_ARGS
);
extern
Datum
timestamp_lt
(
PG_FUNCTION_ARGS
);
extern
Datum
timestamp_le
(
PG_FUNCTION_ARGS
);
extern
Datum
timestamp_ge
(
PG_FUNCTION_ARGS
);
extern
Datum
timestamp_gt
(
PG_FUNCTION_ARGS
);
extern
Datum
timestamp_finite
(
PG_FUNCTION_ARGS
);
extern
Datum
timestamp_cmp
(
PG_FUNCTION_ARGS
);
extern
Datum
timestamp_smaller
(
PG_FUNCTION_ARGS
);
extern
Datum
timestamp_larger
(
PG_FUNCTION_ARGS
);
extern
Datum
interval_in
(
PG_FUNCTION_ARGS
);
extern
Datum
interval_out
(
PG_FUNCTION_ARGS
);
extern
Datum
interval_eq
(
PG_FUNCTION_ARGS
);
extern
Datum
interval_ne
(
PG_FUNCTION_ARGS
);
extern
Datum
interval_lt
(
PG_FUNCTION_ARGS
);
extern
Datum
interval_le
(
PG_FUNCTION_ARGS
);
extern
Datum
interval_ge
(
PG_FUNCTION_ARGS
);
extern
Datum
interval_gt
(
PG_FUNCTION_ARGS
);
extern
Datum
interval_finite
(
PG_FUNCTION_ARGS
);
extern
Datum
interval_cmp
(
PG_FUNCTION_ARGS
);
extern
Datum
interval_smaller
(
PG_FUNCTION_ARGS
);
extern
Datum
interval_larger
(
PG_FUNCTION_ARGS
);
extern
Datum
timestamp_text
(
PG_FUNCTION_ARGS
);
extern
Datum
text_timestamp
(
PG_FUNCTION_ARGS
);
extern
Datum
interval_text
(
PG_FUNCTION_ARGS
);
extern
Datum
text_interval
(
PG_FUNCTION_ARGS
);
extern
Datum
timestamp_trunc
(
PG_FUNCTION_ARGS
);
extern
Datum
interval_trunc
(
PG_FUNCTION_ARGS
);
extern
Datum
timestamp_part
(
PG_FUNCTION_ARGS
);
extern
Datum
interval_part
(
PG_FUNCTION_ARGS
);
extern
Datum
timestamp_zone
(
PG_FUNCTION_ARGS
);
extern
Datum
interval_um
(
PG_FUNCTION_ARGS
);
extern
Datum
interval_pl
(
PG_FUNCTION_ARGS
);
extern
Datum
interval_mi
(
PG_FUNCTION_ARGS
);
extern
Datum
interval_mul
(
PG_FUNCTION_ARGS
);
extern
Datum
mul_d_interval
(
PG_FUNCTION_ARGS
);
extern
Datum
interval_div
(
PG_FUNCTION_ARGS
);
extern
Datum
timestamp_mi
(
PG_FUNCTION_ARGS
);
extern
Datum
timestamp_pl_span
(
PG_FUNCTION_ARGS
);
extern
Datum
timestamp_mi_span
(
PG_FUNCTION_ARGS
);
extern
Datum
timestamp_age
(
PG_FUNCTION_ARGS
);
extern
Datum
overlaps_timestamp
(
PG_FUNCTION_ARGS
);
extern
Datum
now
(
PG_FUNCTION_ARGS
);
/* Internal routines (not fmgr-callable) */
extern
int
tm2timestamp
(
struct
tm
*
tm
,
double
fsec
,
int
*
tzp
,
Timestamp
*
dt
);
extern
int
timestamp2tm
(
Timestamp
dt
,
int
*
tzp
,
struct
tm
*
tm
,
double
*
fsec
,
char
**
tzn
);
extern
int
timestamp2tm
(
Timestamp
dt
,
int
*
tzp
,
struct
tm
*
tm
,
double
*
fsec
,
char
**
tzn
);
extern
Timestamp
SetTimestamp
(
Timestamp
timestamp
);
extern
Timestamp
*
now
(
void
);
#endif
/* TIMESTAMP_H */
src/tutorial/beard.c
View file @
ae526b40
...
...
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/tutorial/Attic/beard.c,v 1.
3 2000/01/26 05:58:51 momjian
Exp $
* $Header: /cvsroot/pgsql/src/tutorial/Attic/beard.c,v 1.
4 2000/06/09 01:11:16 tgl
Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -34,7 +34,10 @@ beard(Oid picture)
char
buf
[
BUFSIZE
];
int
cc
;
if
((
pic_fd
=
lo_open
(
picture
,
INV_READ
))
==
-
1
)
pic_fd
=
DatumGetInt32
(
DirectFunctionCall2
(
lo_open
,
ObjectIdGetDatum
(
picture
),
Int32GetDatum
(
INV_READ
)));
if
(
pic_fd
<
0
)
elog
(
ERROR
,
"Cannot access picture large object"
);
if
(
lo_read
(
pic_fd
,
(
char
*
)
&
ihdr
,
sizeof
(
ihdr
))
!=
sizeof
(
ihdr
))
...
...
@@ -45,21 +48,31 @@ beard(Oid picture)
/*
* new large object
*/
if
((
beard
=
lo_creat
(
INV_MD
))
==
0
)
/* ?? is this right? */
beard
=
DatumGetObjectId
(
DirectFunctionCall1
(
lo_creat
,
Int32GetDatum
(
INV_MD
)));
if
(
beard
==
InvalidOid
)
elog
(
ERROR
,
"Cannot create new large object"
);
if
((
beard_fd
=
lo_open
(
beard
,
INV_WRITE
))
==
-
1
)
beard_fd
=
DatumGetInt32
(
DirectFunctionCall2
(
lo_open
,
ObjectIdGetDatum
(
beard
),
Int32GetDatum
(
INV_WRITE
)));
if
(
beard_fd
<
0
)
elog
(
ERROR
,
"Cannot access beard large object"
);
lo_lseek
(
pic_fd
,
beardOffset
,
SET_CUR
);
if
(
DatumGetInt32
(
DirectFunctionCall3
(
lo_lseek
,
Int32GetDatum
(
pic_fd
),
Int32GetDatum
(
beardOffset
),
Int32GetDatum
(
SEEK_SET
)))
<
0
)
elog
(
ERROR
,
"Cannot seek in picture large object"
);
while
((
cc
=
lo_read
(
pic_fd
,
buf
,
BUFSIZE
))
>
0
)
{
if
(
lo_write
(
beard_fd
,
buf
,
cc
)
!=
cc
)
elog
(
ERROR
,
"error while writing large object"
);
}
lo_close
(
pic_fd
);
lo_close
(
beard_fd
);
DirectFunctionCall1
(
lo_close
,
Int32GetDatum
(
pic_fd
)
);
DirectFunctionCall1
(
lo_close
,
Int32GetDatum
(
beard_fd
)
);
return
beard
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment