return value of a version-1 C function - Mailing list pgsql-general

From Francesco Casadei
Subject return value of a version-1 C function
Date
Msg-id 20010604022605.A13111@goku.kasby
Whole thread Raw
List pgsql-general
Hi,
I need a function that generates a code matching the regular expression
^[a-zA-Z0-9]{8}$. The returned value will be stored in a field of type CHAR(8).
I have an array of char declared as (in the upper executor context):

char cod[8];

Which macro should I use to return cod? I tried PG_RETURN_BPCHAR_P(cod) but it
didn't work. The error message was: "ERROR:  MemoryContextAlloc: invalid
request size 1148672594".

My system is:
FreeBSD goku.kasby 4.3-STABLE FreeBSD 4.3-STABLE #0: Sun Apr 22 00:48:09 CEST
2001     root@goku.kasby:/usr/obj/usr/src/sys/GOKU  i386

PostgreSQL version is:
PostgreSQL 7.1.2 on i386--freebsd4.3, compiled by GCC 2.95.3

The C code is attached. I compiled the function with:

gcc -fpic -c -o funland-funcs.o \
    -I/usr/ports/databases/postgresql7/work/postgresql-7.1.2/src/include/ \
    funland-funcs.c

ld -shared -o funland-funcs.so funland-funcs.o

The function is created with:

CREATE FUNCTION genera_codice (name, name) RETURNS bpchar
       AS '/usr/local/pgsql/data/funland-funcs.so'
       LANGUAGE 'C';

One of the table that calls the function is created with:

CREATE TABLE persone (
        codice         CHAR(8)        DEFAULT genera_codice('persone', 'codice') PRIMARY KEY,
        nome           VARCHAR(255)   NOT NULL,
        cognome        VARCHAR(255)   NOT NULL,
        luogo_nascita  VARCHAR(255)   NOT NULL,
        data_nascita   DATE           NOT NULL,
        sesso          CHAR           CHECK (sesso = 'M' OR sesso = 'F') NOT NULL,
        codice_fiscale CHAR(16)       NOT NULL,-- aggiungere CHECK per il calcolo del codice fiscale
        citta          VARCHAR(255)   NOT NULL,
        provincia      CHAR(2)        NOT NULL,
        email          VARCHAR(255)   CHECK (email ~ '^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+$'),
        sito           VARCHAR(255)   -- Check come da RFC2396
);

The INSERT that didn't work is:

INSERT INTO persone
(
   nome,
   cognome,
   luogo_nascita,
   data_nascita,
   sesso,
   codice_fiscale,
   citta,
   provincia
)
VALUES
(
   'Francesco',
   'Casadei',
   'Terni',
   '1977-05-18',
   'M',
   'CSDFNC77E18L117J',
   'Terni',
   'TR'
);

What's wrong?

    Francesco Casadei

Attachment

pgsql-general by date:

Previous
From: Adam Haberlach
Date:
Subject: Current value of a sequence?
Next
From:
Date:
Subject: PostgreSQL: Elephant book TOC