return value of a version-1 C function

From: Francesco Casadei <f_casadei(at)libero(dot)it>
To: pgsql-general(at)postgresql(dot)org
Subject: return value of a version-1 C function
Date: 2001-06-04 00:26:05
Message-ID: 20010604022605.A13111@goku.kasby
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)goku(dot)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(dot)_-]+(at)[a-zA-Z0-9(dot)_-]+$'),
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 Content-Type Size
funland-funcs.c text/plain 2.4 KB

Browse pgsql-general by date

  From Date Subject
Next Message pgsql-general 2001-06-04 00:43:16 PostgreSQL: Elephant book TOC
Previous Message Adam Haberlach 2001-06-03 19:34:22 Current value of a sequence?