473,594 Members | 2,756 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CREATE TYPE in Postgres 7.3.4

This is probably really basic, but I can't seem to get it to work. I'm
trying to create an enumerated type, using the following code:

CREATE FUNCTION enum_gender_in (cstring) RETURNS enum_gender IMMUTABLE AS
'DECLARE invalue ALIAS FOR $1;
BEGIN
IF invalue=''Male' ' OR invalue=''0'' THEN RETURN 0; END IF;
IF invalue=''Femal e'' OR invalue=''1'' THEN RETURN 1; END IF;
RAISE EXCEPTION ''Incorrect input value: %'', invalue;
END;'
LANGUAGE 'plpgsql';

CREATE FUNCTION enum_gender_out (enum_gender) RETURNS cstring IMMUTABLE AS
'DECLARE outvalue ALIAS FOR $1;
BEGIN
IF outvalue=0 THEN RETURN ''Male''; END IF;
IF outvalue=1 THEN RETURN ''Female''; END IF;
RAISE EXCEPTION ''Incorrect output value: %'', outvalue;
END;'
LANGUAGE 'plpgsql';

CREATE TYPE enum_gender (
INPUT = enum_gender_in,
OUTPUT = enum_gender_out ,
INTERNALLENGTH = 2,
PASSEDBYVALUE
);

According to the Postgres documentation, when I create the input
function, it should create a placeholder entry in pg_type for
enum_gender and wait for the type to be created. However, when I execute
the CREATE FUNCTION statement, I get:

ERROR: Type "enum_gende r" does not exist

If I try to create the type first, I get:

ERROR: TypeCreate: function enum_gender_in( cstring) does not exist

How do I create this type and these functions?

Alex
--
Mail: Alex Page <al*******@canc er.org.uk>
Real: Systems/Network Assistant, Epidemiology Unit, Oxford
Tel: 01865 302 223 (external) / 223 (internal)
PGP: 8868 21D7 3D35 DD77 9D06 BF0A 0746 2DE6 55EA 367E

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQE/xfFYB0Yt5lXqNn4 RApV1AJ4tx2IQhC tQxMS+Hb34CrB5B hUMVQCdEsWK
JVXphgxj6MyIj3x 6a1TTGU4=
=AzZo
-----END PGP SIGNATURE-----

Nov 12 '05 #1
4 2740
Alex Page wrote:

[...creates enum_gender_in and enum_gender_out as PL/pgSQL functions...]
CREATE TYPE enum_gender (
INPUT = enum_gender_in,
OUTPUT = enum_gender_out ,
INTERNALLENGTH = 2,
PASSEDBYVALUE
);

According to the Postgres documentation, when I create the input
function, it should create a placeholder entry in pg_type for
enum_gender and wait for the type to be created. However, when I execute
the CREATE FUNCTION statement, I get:


According to the docs, you cannot use PL/pgSQL functions for I/O
conversion functions. See
http://www.postgresql.org/docs/curre...PGSQL-OVERVIEW
where it says:
"Except for input/output conversion and calculation functions for
user-defined types, anything that can be defined in C language
functions can also be done with PL/pgSQL."

In general, I don't think I/O functions can be anything other than C
functions.

On this page
http://www.postgresql.org/docs/curre...reatetype.html
it says:
"The support functions input_function and output_function are
required, while the functions receive_functio n and send_function are
optional. Generally these functions have to be coded in C or another
low-level language."

Joe
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 12 '05 #2
On Thu, 2003-11-27 at 12:43, Alex Page wrote:
This is probably really basic, but I can't seem to get it to work. I'm
trying to create an enumerated type, using the following code:

CREATE FUNCTION enum_gender_in (cstring) RETURNS enum_gender IMMUTABLE AS

....

Why not just use a CHECK constraint?

CREATE TABLE xxx (
...
gender CHAR(1) CONSTRAINT "valid gender"
CHECK (gender IN ('M', 'F')),
...
);
--
Oliver Elphick Ol************@ lfix.co.uk
Isle of Wight, UK http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C
=============== =============== ==========
"But grow in grace, and in the knowledge of our Lord
and Saviour Jesus Christ. To him be glory both now and
for ever. Amen." II Peter 3:18
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postg resql.org

Nov 12 '05 #3
On Sun, Nov 30, 2003 at 09:01:01PM +0000, Oliver Elphick wrote:
On Thu, 2003-11-27 at 12:43, Alex Page wrote:
This is probably really basic, but I can't seem to get it to work. I'm
trying to create an enumerated type, using the following code: CREATE FUNCTION enum_gender_in (cstring) RETURNS enum_gender IMMUTABLE AS

...

Why not just use a CHECK constraint?


I'm fairly sure that a CHECK constraint will be a lot slower (even with
an index) than my own TYPE with an internal integer representation. I'd
like to check this, but of course I can't do any benchmarks until I've
got the CREATE TYPE working :)

Alex
--
Mail: Alex Page <al*******@canc er.org.uk>
Real: Systems/Network Assistant, Epidemiology Unit, Oxford
Tel: 01865 302 223 (external) / 223 (internal)
PGP: 8868 21D7 3D35 DD77 9D06 BF0A 0746 2DE6 55EA 367E

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQE/zMjDB0Yt5lXqNn4 RAoZmAJ9mWSt18T 1QuYKMk9Lqayb3B IV4BwCffCQP
/oUxh5awE7nPdaxI Nz0SJck=
=jt1X
-----END PGP SIGNATURE-----

Nov 12 '05 #4
On Thu, Nov 27, 2003 at 07:48:46AM -0800, Joe Conway wrote:
Alex Page wrote: [...creates enum_gender_in and enum_gender_out as PL/pgSQL functions...] According to the docs, you cannot use PL/pgSQL functions for I/O
conversion functions. See
http://www.postgresql.org/docs/curre...PGSQL-OVERVIEW
where it says:
"Except for input/output conversion and calculation functions for
user-defined types, anything that can be defined in C language
functions can also be done with PL/pgSQL."


Fair enough; I was looking at the reference manual for 7.3, which
doesn't mention this limitation under either CREATE TYPE or CREATE
FUNCTION. This has changed in 7.4, where the documentation for CREATE
TYPE reads:

"The support functions input_function and output_function are required,
while the functions receive_functio n and send_function are optional.
Generally these functions have to be coded in C or another low-level
language."

Alex
--
Mail: Alex Page <al*******@canc er.org.uk>
Real: Systems/Network Assistant, Epidemiology Unit, Oxford
Tel: 01865 302 223 (external) / 223 (internal)
PGP: 8868 21D7 3D35 DD77 9D06 BF0A 0746 2DE6 55EA 367E

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQE/zMueB0Yt5lXqNn4 RAlblAJ4tfDUGvt xXjv4D9ZcvEMgV4 SFpRACeP6iC
0PoZYbOAOitPzC1 JAyTu3UU=
=ENvb
-----END PGP SIGNATURE-----

Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2955
by: dcrespo | last post by:
Hi to all, I have functions defined in an xml-rpc server. Some functions query to a Postgres database (using adodb) and return its recordset. So, if some xml-rpc client runs the mentioned function, it will retrieve the recordset. The problem is that if a retrieved field has the Null value or the Date value (DateTime Database format), then, the retrieved recordset in the python program will have the 'None' value or the DateTime type...
2
10639
by: Robert Creager | last post by:
I'm receiving the following error during startup: Aug 10 14:11:27 thunder postgres: LOG: failed to create socket: Address family not supported by protocol Aug 10 14:11:27 thunder postgres: LOG: database system was shut down at 2003-08-10 14:11:11 MDT Aug 10 14:11:27 thunder postgres: LOG: checkpoint record is at 4/E28389B4
0
732
by: DanPerlman | last post by:
Hi, I am using the following to write data from an access table to a postgres table. I need to create an index on the "partnumber" field in the Bpb (odbc pg database) so I can seek on that field. Need to be able to locate and update records that already exist in the postgres table. It appears that the "partnumber" field is a memo field. Thanks,
20
2418
by: My Internet | last post by:
Hello, I am in the process to define if our product can use PostgreSQL. Do you know what type of application use PostgreSQL, and also what is the size of the database for these projects? Our application has a table with more than 300000 rows. There are complexe query with many joins. And we must respect some time constraints. Also the application is running 24 hours per day, so the product must be stable, with
1
4442
by: Barbara Lindsey | last post by:
I am a postgres newbie. I am trying to create a trigger that will put a copy of a record into a backup table before update or delete. As I understand it, in order to do this I must have a function created to do this task. The function I am trying to create is as follows: CREATE FUNCTION customer_bak_proc(integer) RETURNS boolean as 'INSERT INTO customer_bak (SELECT * from customer where id = $1 )' LANGUAGE 'SQL';
3
8681
by: warwick.poole | last post by:
I am interested in finding out about Enterprise scale Postgres installations and clustering, especially on Linux. Essentially I would like to know the possibility that Postgres can store the database data in a central location (ex: on a SAN fiber array) and have a cluster of machines sharing processor/RAM/IO bandwidth to do the application processing. Or perhaps there is another solution similar to what www.emicnetworks.com have...
17
8474
by: Jeffrey W. Baker | last post by:
Greetings, I have a 23GB data table upon which I am building a primary key of three columns. The data is mounted in a 137GB device and pg_xlog is mounted on a separate 3.5GB device. I have configured 24 checkpoint segments, which I expect gives me a worst-case usage in pg_xlog of 384MB. Unfortunately, during the CREATE INDEX, pg_xlog becomes full!
18
5117
by: Joe Lester | last post by:
This thread was renamed. It used to be: "shared_buffers Question". The old thread kind of died out. I'm hoping to get some more direction by rephrasing the problem, along with some extra observations I've recently made. The core of the problem is that Postgres is filling up my hard drive with swap files at the rate of around 3 to 7 GB per week (that's Gigabytes not Megabytes) . At this rate it takes roughly two months to fill up my 40...
1
6829
by: Leo Martin Orfei | last post by:
Hi, Anybody know/have functions or package to create text file from postgres function? I want to execute a function to take some fields from a table and save it in a text file (or xml format). I need function like: createfile(filename); appendtofile(filename,text);
0
7946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7876
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8251
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
6654
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5739
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3859
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3897
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2385
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.