473,506 Members | 13,088 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to use custom functions created by my2pg.pl?

The my2pg.pl script creates custom functions that help with the MySQL
"set" column type. I can't figure out how to use the functions once I
have the database migrated into Postgres.

Can someone please explain how to make use of them?

In MySQL, the table exists:

CREATE TABLE accessright (
accessright_id int(10) unsigned NOT NULL auto_increment,
entity_ptr int(10) unsigned NOT NULL default '0',
rights set('admin','edit','visit') default NULL,
ar_area_key varchar(60) default NULL,
PRIMARY KEY (accessright_id),
KEY entity_index (entity_ptr),
KEY rights_index (rights),
KEY area_key_index (ar_area_key)
) TYPE=MyISAM;

You can:
SELECT rights+0 FROM accessright WHERE condition;
.... and get the numeric bitmask back (1,2, or 4) in the above table's case.

I need to be able to do the same thing in the Postgres version of this.

Here's the relevant code and data structure created by the my2pg script:

CREATE SEQUENCE accessright_accessright_id_s;
CREATE FUNCTION set_accessright_admin_in (opaque)
RETURNS set_accessright_admin
AS '/tmp/libtypes.so'
LANGUAGE 'c';

CREATE FUNCTION set_accessright_admin_out (opaque)
RETURNS opaque
AS '/tmp/libtypes.so'
LANGUAGE 'c';

CREATE TYPE set_accessright_admin (
internallength = 2,
input = set_accessright_admin_in,
output = set_accessright_admin_out
);

CREATE FUNCTION set_accessright_admin_eq
(set_accessright_admin,set_accessright_admin)
RETURNS bool
AS '/tmp/libtypes.so'
LANGUAGE 'c';

CREATE FUNCTION find_in_set (set_accessright_admin,set_accessright_admin)
RETURNS bool
AS '/tmp/libtypes.so'
LANGUAGE 'c';

CREATE OPERATOR = (
leftarg = set_accessright_admin,
rightarg = set_accessright_admin,
commutator = =,
procedure = set_accessright_admin_eq
);

CREATE OPERATOR <> (
leftarg = set_accessright_admin,
rightarg = set_accessright_admin,
commutator = <>,
negator = =,
procedure = set_accessright_admin_eq
);
CREATE TABLE accessright (
accessright_id INT4 DEFAULT nextval('accessright_accessright_id_s'),
entity_ptr INT4 NOT NULL DEFAULT '0',
rights set_accessright_admin DEFAULT NULL,
ar_area_key varchar(60) DEFAULT NULL,
PRIMARY KEY (accessright_id),
CHECK (entity_ptr>=0)

);

INSERT INTO accessright VALUES (1,1,'visit','home');
INSERT INTO accessright VALUES (2,1,'visit','login');
INSERT INTO accessright VALUES (3,1,'visit','getimage');
INSERT INTO accessright VALUES (4,5,'visit','cron');
INSERT INTO accessright VALUES (5,1,'visit','admin');
INSERT INTO accessright VALUES (6,1,'visit','utility');
INSERT INTO accessright VALUES (7,1,'visit','global');
INSERT INTO accessright VALUES (8,1,'visit','about');
INSERT INTO accessright VALUES (9,1,'visit','registration');
INSERT INTO accessright VALUES (10,1,'visit','focus_lists');
INSERT INTO accessright VALUES (11,1,'visit','tracking');
INSERT INTO accessright VALUES (12,1,'visit','marketplace');
INSERT INTO accessright VALUES (13,1,'visit','profile');
INSERT INTO accessright VALUES (14,1,'visit','registration');
INSERT INTO accessright VALUES (15,1,'visit','resources');
INSERT INTO accessright VALUES (16,1,'visit','private');

SELECT SETVAL('accessright_accessright_id_s',(select case when
max(accessright_id)>0 then max(accessright_id)+1 else 1 end from
accessright));

Here's the relevant output from \df in psql:

Schema | Name | Result data type
|
Argument data types
public | find_in_set | boolean
| set_accessright_admin, set_a
ccessright_admin

public | set_accessright_admin_eq | boolean
| set_accessright_admin, set_a
ccessright_admin

TIA,
Scott
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 23 '05 #1
0 2768

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

Similar topics

4
4743
by: Steve Amey | last post by:
Hi all I am creating a basic control to perform some tasks, and I want to declare some events to be raised so they can be handled from the form that the control is on. I can create my own Event...
2
2264
by: Sean Mullaly | last post by:
I have a custom Access menu with sub-menus and sub-sub-menus. (220 items). Right now I have created 220 Functions and attached each individual Function to the specific OnAction property. The...
22
3770
by: TC | last post by:
I have an Access database application with a lot of custom row functions written in VBA. In other words, a lot of queries contain calculated fields which use functions defined in the modules. I...
3
2132
by: hellrazor | last post by:
Hi there, I'm trying to consume a web-service that is supposed to return a collection of a custom object. The web-service was not created with C# or VS.net. It was created with IBM VisualAge...
0
237
by: SMFX | last post by:
Okay, this should be a simple thing, but I can't seemto find the right documentation on it. I created a custom class that inherits from a well known class. For example: Class MyString Inherits...
15
1875
by: Sam Kong | last post by:
Hello! I got recently intrigued with JavaScript's prototype-based object-orientation. However, I still don't understand the mechanism clearly. What's the difference between the following...
19
4891
by: Jamey Shuemaker | last post by:
I'm in the process of expanding my knowledge and use of Class Modules. I've perused MSDN and this and other sites, and I'm pretty comfortable with my understanding of Class Modules with the...
0
1445
by: jim4u | last post by:
Hi gurus, I have an automation add-in created using C# for Excel, in which I am exposing a number of functions. Is there any way I can add help-text the way excel does for other categories like...
1
5560
by: ncsthbell | last post by:
I have a dilemia, I have an application that I am having to make some changes to in order for it to run sucessfully under Runtime 2007. We are currently working on upgrading from 2000 to 2007. The...
0
7220
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,...
0
7105
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...
1
7023
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7479
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5617
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,...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3188
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...
0
1534
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 ...
0
410
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.