1996-07-09 08:22:35 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* oid.c
|
1997-09-07 07:04:48 +02:00
|
|
|
* Functions for the built-in type Oid.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
2000-08-01 20:29:35 +02:00
|
|
|
* $Header: /cvsroot/pgsql/src/backend/utils/adt/oid.c,v 1.38 2000/08/01 18:29:35 tgl Exp $
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
1996-11-06 11:32:10 +01:00
|
|
|
|
|
|
|
|
2000-01-10 16:41:34 +01:00
|
|
|
#include <ctype.h>
|
1996-07-09 08:22:35 +02:00
|
|
|
#include "postgres.h"
|
1999-07-16 05:14:30 +02:00
|
|
|
#include "utils/builtins.h"
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* USER I/O ROUTINES *
|
1996-07-09 08:22:35 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
/*
|
2000-01-10 17:13:23 +01:00
|
|
|
* oidvectorin - converts "num num ..." to internal form
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* Note:
|
2000-06-05 09:29:25 +02:00
|
|
|
* Fills any unsupplied positions with InvalidOid.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
2000-06-05 09:29:25 +02:00
|
|
|
Datum
|
|
|
|
oidvectorin(PG_FUNCTION_ARGS)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2000-06-05 09:29:25 +02:00
|
|
|
char *oidString = PG_GETARG_CSTRING(0);
|
1998-09-22 22:28:15 +02:00
|
|
|
Oid *result;
|
2000-01-10 05:36:37 +01:00
|
|
|
int slot;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-01-10 05:36:37 +01:00
|
|
|
result = (Oid *) palloc(sizeof(Oid[INDEX_MAX_KEYS]));
|
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
for (slot = 0; *oidString && slot < INDEX_MAX_KEYS; slot++)
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
2000-01-10 05:36:37 +01:00
|
|
|
if (sscanf(oidString, "%u", &result[slot]) != 1)
|
|
|
|
break;
|
2000-06-14 20:18:01 +02:00
|
|
|
while (*oidString && isspace((int) *oidString))
|
2000-01-10 16:41:34 +01:00
|
|
|
oidString++;
|
2000-06-14 20:18:01 +02:00
|
|
|
while (*oidString && !isspace((int) *oidString))
|
2000-01-10 05:36:37 +01:00
|
|
|
oidString++;
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
2000-06-14 20:18:01 +02:00
|
|
|
while (*oidString && isspace((int) *oidString))
|
2000-01-10 16:41:34 +01:00
|
|
|
oidString++;
|
|
|
|
if (*oidString)
|
2000-04-12 19:17:23 +02:00
|
|
|
elog(ERROR, "oidvector value has too many values");
|
2000-01-10 05:36:37 +01:00
|
|
|
while (slot < INDEX_MAX_KEYS)
|
2000-06-05 09:29:25 +02:00
|
|
|
result[slot++] = InvalidOid;
|
2000-01-10 05:36:37 +01:00
|
|
|
|
2000-06-05 09:29:25 +02:00
|
|
|
PG_RETURN_POINTER(result);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-01-10 17:13:23 +01:00
|
|
|
* oidvectorout - converts internal form to "num num ..."
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
2000-06-05 09:29:25 +02:00
|
|
|
Datum
|
|
|
|
oidvectorout(PG_FUNCTION_ARGS)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2000-06-05 09:29:25 +02:00
|
|
|
Oid *oidArray = (Oid *) PG_GETARG_POINTER(0);
|
2000-04-12 19:17:23 +02:00
|
|
|
int num,
|
|
|
|
maxnum;
|
1998-02-26 05:46:47 +01:00
|
|
|
char *rp;
|
1997-09-08 04:41:22 +02:00
|
|
|
char *result;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-01-10 16:41:34 +01:00
|
|
|
/* find last non-zero value in vector */
|
2000-04-12 19:17:23 +02:00
|
|
|
for (maxnum = INDEX_MAX_KEYS - 1; maxnum >= 0; maxnum--)
|
2000-01-10 16:41:34 +01:00
|
|
|
if (oidArray[maxnum] != 0)
|
|
|
|
break;
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/* assumes sign, 10 digits, ' ' */
|
2000-04-12 19:17:23 +02:00
|
|
|
rp = result = (char *) palloc((maxnum + 1) * 12 + 1);
|
2000-01-10 16:41:34 +01:00
|
|
|
for (num = 0; num <= maxnum; num++)
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
2000-01-10 16:41:34 +01:00
|
|
|
if (num != 0)
|
|
|
|
*rp++ = ' ';
|
2000-08-01 20:29:35 +02:00
|
|
|
pg_ltoa((int32) oidArray[num], rp);
|
1997-09-07 07:04:48 +02:00
|
|
|
while (*++rp != '\0')
|
|
|
|
;
|
|
|
|
}
|
2000-01-10 16:41:34 +01:00
|
|
|
*rp = '\0';
|
2000-06-05 09:29:25 +02:00
|
|
|
PG_RETURN_CSTRING(result);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
2000-06-05 09:29:25 +02:00
|
|
|
Datum
|
|
|
|
oidin(PG_FUNCTION_ARGS)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2000-06-05 09:29:25 +02:00
|
|
|
char *s = PG_GETARG_CSTRING(0);
|
|
|
|
|
|
|
|
/* XXX should use an unsigned-int conversion here */
|
|
|
|
return DirectFunctionCall1(int4in, CStringGetDatum(s));
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
2000-06-05 09:29:25 +02:00
|
|
|
Datum
|
|
|
|
oidout(PG_FUNCTION_ARGS)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2000-06-05 09:29:25 +02:00
|
|
|
Oid o = PG_GETARG_OID(0);
|
|
|
|
|
|
|
|
/* XXX should use an unsigned-int conversion here */
|
|
|
|
return DirectFunctionCall1(int4out, ObjectIdGetDatum(o));
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* PUBLIC ROUTINES *
|
1996-07-09 08:22:35 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
|
2000-06-05 09:29:25 +02:00
|
|
|
Datum
|
|
|
|
oideq(PG_FUNCTION_ARGS)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2000-06-05 09:29:25 +02:00
|
|
|
Oid arg1 = PG_GETARG_OID(0);
|
|
|
|
Oid arg2 = PG_GETARG_OID(1);
|
|
|
|
|
|
|
|
PG_RETURN_BOOL(arg1 == arg2);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
2000-06-05 09:29:25 +02:00
|
|
|
Datum
|
|
|
|
oidne(PG_FUNCTION_ARGS)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2000-06-05 09:29:25 +02:00
|
|
|
Oid arg1 = PG_GETARG_OID(0);
|
|
|
|
Oid arg2 = PG_GETARG_OID(1);
|
|
|
|
|
|
|
|
PG_RETURN_BOOL(arg1 != arg2);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
2000-06-05 09:29:25 +02:00
|
|
|
Datum
|
|
|
|
oidvectoreq(PG_FUNCTION_ARGS)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2000-06-05 09:29:25 +02:00
|
|
|
Oid *arg1 = (Oid *) PG_GETARG_POINTER(0);
|
|
|
|
Oid *arg2 = (Oid *) PG_GETARG_POINTER(1);
|
|
|
|
|
|
|
|
PG_RETURN_BOOL(memcmp(arg1, arg2, INDEX_MAX_KEYS * sizeof(Oid)) == 0);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
2000-06-05 09:29:25 +02:00
|
|
|
Datum
|
|
|
|
oidvectorne(PG_FUNCTION_ARGS)
|
1998-10-29 19:07:09 +01:00
|
|
|
{
|
2000-06-05 09:29:25 +02:00
|
|
|
Oid *arg1 = (Oid *) PG_GETARG_POINTER(0);
|
|
|
|
Oid *arg2 = (Oid *) PG_GETARG_POINTER(1);
|
|
|
|
|
|
|
|
PG_RETURN_BOOL(memcmp(arg1, arg2, INDEX_MAX_KEYS * sizeof(Oid)) != 0);
|
1998-10-29 19:07:09 +01:00
|
|
|
}
|
|
|
|
|
2000-06-05 09:29:25 +02:00
|
|
|
Datum
|
|
|
|
oidvectorlt(PG_FUNCTION_ARGS)
|
1998-08-19 04:04:17 +02:00
|
|
|
{
|
2000-06-05 09:29:25 +02:00
|
|
|
Oid *arg1 = (Oid *) PG_GETARG_POINTER(0);
|
|
|
|
Oid *arg2 = (Oid *) PG_GETARG_POINTER(1);
|
1998-09-01 06:40:42 +02:00
|
|
|
int i;
|
|
|
|
|
2000-01-10 05:36:37 +01:00
|
|
|
for (i = 0; i < INDEX_MAX_KEYS; i++)
|
2000-06-05 09:29:25 +02:00
|
|
|
if (arg1[i] != arg2[i])
|
|
|
|
PG_RETURN_BOOL(arg1[i] < arg2[i]);
|
|
|
|
PG_RETURN_BOOL(false);
|
1998-08-19 04:04:17 +02:00
|
|
|
}
|
|
|
|
|
2000-06-05 09:29:25 +02:00
|
|
|
Datum
|
|
|
|
oidvectorle(PG_FUNCTION_ARGS)
|
1998-08-19 04:04:17 +02:00
|
|
|
{
|
2000-06-05 09:29:25 +02:00
|
|
|
Oid *arg1 = (Oid *) PG_GETARG_POINTER(0);
|
|
|
|
Oid *arg2 = (Oid *) PG_GETARG_POINTER(1);
|
1998-09-01 06:40:42 +02:00
|
|
|
int i;
|
|
|
|
|
2000-01-10 05:36:37 +01:00
|
|
|
for (i = 0; i < INDEX_MAX_KEYS; i++)
|
2000-06-05 09:29:25 +02:00
|
|
|
if (arg1[i] != arg2[i])
|
|
|
|
PG_RETURN_BOOL(arg1[i] <= arg2[i]);
|
|
|
|
PG_RETURN_BOOL(true);
|
1998-08-19 04:04:17 +02:00
|
|
|
}
|
|
|
|
|
2000-06-05 09:29:25 +02:00
|
|
|
Datum
|
|
|
|
oidvectorge(PG_FUNCTION_ARGS)
|
1998-08-19 04:04:17 +02:00
|
|
|
{
|
2000-06-05 09:29:25 +02:00
|
|
|
Oid *arg1 = (Oid *) PG_GETARG_POINTER(0);
|
|
|
|
Oid *arg2 = (Oid *) PG_GETARG_POINTER(1);
|
1998-09-01 06:40:42 +02:00
|
|
|
int i;
|
|
|
|
|
2000-01-10 05:36:37 +01:00
|
|
|
for (i = 0; i < INDEX_MAX_KEYS; i++)
|
2000-06-05 09:29:25 +02:00
|
|
|
if (arg1[i] != arg2[i])
|
|
|
|
PG_RETURN_BOOL(arg1[i] >= arg2[i]);
|
|
|
|
PG_RETURN_BOOL(true);
|
1998-08-19 04:04:17 +02:00
|
|
|
}
|
|
|
|
|
2000-06-05 09:29:25 +02:00
|
|
|
Datum
|
|
|
|
oidvectorgt(PG_FUNCTION_ARGS)
|
1998-08-19 04:04:17 +02:00
|
|
|
{
|
2000-06-05 09:29:25 +02:00
|
|
|
Oid *arg1 = (Oid *) PG_GETARG_POINTER(0);
|
|
|
|
Oid *arg2 = (Oid *) PG_GETARG_POINTER(1);
|
1998-09-01 06:40:42 +02:00
|
|
|
int i;
|
|
|
|
|
2000-01-10 05:36:37 +01:00
|
|
|
for (i = 0; i < INDEX_MAX_KEYS; i++)
|
2000-06-05 09:29:25 +02:00
|
|
|
if (arg1[i] != arg2[i])
|
|
|
|
PG_RETURN_BOOL(arg1[i] > arg2[i]);
|
|
|
|
PG_RETURN_BOOL(false);
|
1998-08-19 04:04:17 +02:00
|
|
|
}
|
|
|
|
|
2000-06-05 09:29:25 +02:00
|
|
|
Datum
|
|
|
|
oideqint4(PG_FUNCTION_ARGS)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2000-06-05 09:29:25 +02:00
|
|
|
Oid arg1 = PG_GETARG_OID(0);
|
|
|
|
int32 arg2 = PG_GETARG_INT32(1);
|
|
|
|
|
|
|
|
/* oid is unsigned, but int4 is signed */
|
|
|
|
PG_RETURN_BOOL(arg2 >= 0 && arg1 == arg2);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
2000-06-05 09:29:25 +02:00
|
|
|
Datum
|
|
|
|
int4eqoid(PG_FUNCTION_ARGS)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2000-06-05 09:29:25 +02:00
|
|
|
int32 arg1 = PG_GETARG_INT32(0);
|
|
|
|
Oid arg2 = PG_GETARG_OID(1);
|
|
|
|
|
|
|
|
/* oid is unsigned, but int4 is signed */
|
|
|
|
PG_RETURN_BOOL(arg1 >= 0 && arg1 == arg2);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
1997-10-25 07:21:54 +02:00
|
|
|
|
2000-06-05 09:29:25 +02:00
|
|
|
Datum
|
|
|
|
oid_text(PG_FUNCTION_ARGS)
|
1997-10-25 07:21:54 +02:00
|
|
|
{
|
2000-06-05 09:29:25 +02:00
|
|
|
Oid oid = PG_GETARG_OID(0);
|
1998-02-26 05:46:47 +01:00
|
|
|
text *result;
|
|
|
|
int len;
|
|
|
|
char *str;
|
1997-10-25 07:21:54 +02:00
|
|
|
|
2000-06-05 09:29:25 +02:00
|
|
|
str = DatumGetCString(DirectFunctionCall1(oidout,
|
|
|
|
ObjectIdGetDatum(oid)));
|
|
|
|
len = strlen(str) + VARHDRSZ;
|
1997-10-25 07:21:54 +02:00
|
|
|
|
2000-06-05 09:29:25 +02:00
|
|
|
result = (text *) palloc(len);
|
1997-10-25 07:21:54 +02:00
|
|
|
|
2000-07-04 01:10:14 +02:00
|
|
|
VARATT_SIZEP(result) = len;
|
2000-06-05 09:29:25 +02:00
|
|
|
memcpy(VARDATA(result), str, (len - VARHDRSZ));
|
1998-01-07 19:47:07 +01:00
|
|
|
pfree(str);
|
1997-10-25 07:21:54 +02:00
|
|
|
|
2000-06-05 09:29:25 +02:00
|
|
|
PG_RETURN_TEXT_P(result);
|
|
|
|
}
|
1997-10-25 07:21:54 +02:00
|
|
|
|
2000-06-05 09:29:25 +02:00
|
|
|
Datum
|
|
|
|
text_oid(PG_FUNCTION_ARGS)
|
1997-10-25 07:21:54 +02:00
|
|
|
{
|
2000-06-05 09:29:25 +02:00
|
|
|
text *string = PG_GETARG_TEXT_P(0);
|
1998-02-26 05:46:47 +01:00
|
|
|
Oid result;
|
|
|
|
int len;
|
|
|
|
char *str;
|
1997-10-25 07:21:54 +02:00
|
|
|
|
1998-02-26 05:46:47 +01:00
|
|
|
len = (VARSIZE(string) - VARHDRSZ);
|
1997-10-25 07:21:54 +02:00
|
|
|
|
1998-02-26 05:46:47 +01:00
|
|
|
str = palloc(len + 1);
|
2000-06-05 09:29:25 +02:00
|
|
|
memcpy(str, VARDATA(string), len);
|
1998-02-26 05:46:47 +01:00
|
|
|
*(str + len) = '\0';
|
1997-10-25 07:21:54 +02:00
|
|
|
|
2000-06-05 09:29:25 +02:00
|
|
|
result = DatumGetObjectId(DirectFunctionCall1(oidin,
|
|
|
|
CStringGetDatum(str)));
|
1998-01-07 19:47:07 +01:00
|
|
|
pfree(str);
|
1997-10-25 07:21:54 +02:00
|
|
|
|
2000-06-05 09:29:25 +02:00
|
|
|
PG_RETURN_OID(result);
|
|
|
|
}
|