Skip site navigation (1) Skip section navigation (2)

Re: [HACKERS] bug(?) if int8 as primary key

From: Michael Contzen <mcontzen(at)dohle(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [HACKERS] bug(?) if int8 as primary key
Date: 1998-12-29 09:43:33
Message-ID: (view raw or whole thread)
Lists: pgsql-hackers
Hello David, hello Thomas,

a couple of weeks ago I had a similar problem, I solved it by a little
shell-script, (sorry, no pg-sql) which registers the missing operators.
As I thought it4s going to be fixed in the next version, I didn4t post
it. But untill then, perhaps it helps ....
First you need the int8cmp-Operator (I something like a
signature-function of the difference). Than you should register this

Kind regards

Michael Contzen

-------------- int8cmp.c ---------------


 * int8cmp.c--
 *        Internal 64-bit integer operations

#include <stdio.h>                              /* for sprintf proto,
etc. */
#include <stdlib.h>                             /* for strtod, etc. */
#include <string.h>
#include <ctype.h>
#include <time.h>
#include <math.h>
#include <float.h>
#include <limits.h>

#include "postgres.h"
#include "utils/palloc.h"

#define MAXINT8LEN              25

#if defined(__alpha) || defined(__GNUC__)
#define HAVE_64BIT_INTS 1

#ifndef HAVE_64BIT_INTS
typedef char[8] int64;

#elif defined(__alpha)
typedef long int int64;

#define INT64_FORMAT "%ld"

#elif defined(__GNUC__)
typedef long long int int64;

#define INT64_FORMAT "%Ld"

typedef long int int64;

#define INT64_FORMAT "%ld"

int32      int8cmp(int64 * val1, int64 * val2);

int8cmp(int64 * val1, int64 * val2)
        if (*val1 > *val2) return 1;
        if (*val1 < *val2) return -1;
        return 0;
}       /* int8cmp() */

------------------ End of int8cmp.c ------------------

------------------ -----------------

SQL="psql -t MYDATABASE  "

OPS=`$SQL -c  "SELECT am.amname, opc.opcname, opr.oprname
    FROM pg_am am, pg_amop amop,
         pg_opclass opc, pg_operator opr
    WHERE amop.amopid = am.oid AND
          amop.amopclaid = opc.oid AND
          amop.amopopr = opr.oid AND
    ORDER BY am.amname, opc.opcname"`

if [ "$OPS" != "" ]; then
 echo "int8-btree ops already registerd."
 exit 0

TYPE=`$SQL -c  "select oid from pg_type where typname='int8'"`
echo "TYP=$TYPE"
if [ "$TYPE" = "" ]; then
 echo "No int8-type found!"
 exit -1

$SQL </usr/local/pgsql/lib/int8cmp.sql

$SQL -c  "delete from pg_opclass where opcname='int8_ops'"
OPCLOID=`$SQL -c  "insert into pg_opclass values('int8_ops', $TYPE)" |
cut -f2 -d" "`

OP1=`$SQL -c  "select oid from pg_operator where oprname='<' and
oprleft=$TYPE and oprright=$TYPE"`
OP2=`$SQL -c  "select oid from pg_operator where oprname='<=' and
oprleft=$TYPE and oprright=$TYPE"`
OP3=`$SQL -c  "select oid from pg_operator where oprname='=' and
oprleft=$TYPE and oprright=$TYPE"`
OP4=`$SQL -c  "select oid from pg_operator where oprname='>=' and
oprleft=$TYPE and oprright=$TYPE"`
OP5=`$SQL -c  "select oid from pg_operator where oprname='>' and
oprleft=$TYPE and oprright=$TYPE"`
OP6=`$SQL -c  "select oid from pg_proc where proname='int8cmp' "`

AMOID=`$SQL -c  "select oid from pg_am where amname='btree'"`


if [ "$OP6" = "" ]; then
 echo "No int8cmp found!"

$SQL -c  "insert into pg_amop values ($AMOID, $OPCLOID, $OP1, 1,
'btreesel', 'btreenpage')"
$SQL -c  "insert into pg_amop values ($AMOID, $OPCLOID, $OP2, 2,
'btreesel', 'btreenpage')"
$SQL -c  "insert into pg_amop values ($AMOID, $OPCLOID, $OP3, 3,
'btreesel', 'btreenpage')"
$SQL -c  "insert into pg_amop values ($AMOID, $OPCLOID, $OP4, 4,
'btreesel', 'btreenpage')"
$SQL -c  "insert into pg_amop values ($AMOID, $OPCLOID, $OP5, 5,
'btreesel', 'btreenpage')"
$SQL -c  "insert into pg_amproc(amid, amopclaid, amproc, amprocnum)
          values ($AMOID, $OPCLOID, $OP6, 1)"

------------------- end ---------------

pgsql-hackers by date

Next:From: Samara CITDate: 1998-12-29 10:25:17
Previous:From: John PolstraDate: 1998-12-29 06:06:57
Subject: RE: Forgot how to set up cvsup

Privacy Policy | About PostgreSQL
Copyright © 1996-2015 The PostgreSQL Global Development Group