473,750 Members | 2,557 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','ed it','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_acc essright_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_accessrigh t_admin,set_acc essright_admin)
RETURNS bool
AS '/tmp/libtypes.so'
LANGUAGE 'c';

CREATE FUNCTION find_in_set (set_accessrigh t_admin,set_acc essright_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('access right_accessrig ht_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','h ome');
INSERT INTO accessright VALUES (2,1,'visit','l ogin');
INSERT INTO accessright VALUES (3,1,'visit','g etimage');
INSERT INTO accessright VALUES (4,5,'visit','c ron');
INSERT INTO accessright VALUES (5,1,'visit','a dmin');
INSERT INTO accessright VALUES (6,1,'visit','u tility');
INSERT INTO accessright VALUES (7,1,'visit','g lobal');
INSERT INTO accessright VALUES (8,1,'visit','a bout');
INSERT INTO accessright VALUES (9,1,'visit','r egistration');
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('accessr ight_accessrigh t_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_admi n

public | set_accessright _admin_eq | boolean
| set_accessright _admin, set_a
ccessright_admi n

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

http://archives.postgresql.org

Nov 23 '05 #1
0 2810

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

Similar topics

4
4780
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 Handler class and use that, but I would like to use the System.EventArgs class so that my event can be handled by different controls. For example:
2
2287
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 Functions return Text which is the same as the Caption of the sub-sub-menu items. I would like to reference the Custom Popup Caption of these sub-sub-menus and pass it through one Function for input in a form. *** Sent via Developersdex...
22
3816
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 am now thinking about upgrading the database from Access to SQL Server. If I do, how can I implement the custom row functions? Is Visual Basic integrated with SQL Server just as it is with Access? Or does T-SQL in SQL Server offer the...
3
2137
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 Smalltalk 6. I haven't had problems consuming other web-services but c# seems to choke with "Collection" return types. If you'd like to try to see an example of this problem you can add the following web-reference to your project:
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 String Public Sub New() MyBase.New() 'custom code here End Sub 'Custom properties here 'Custom subs and functions here
15
1925
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 two? (1)
19
4918
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 exception of custom Collection Classes. Background: I'm developing an A2K .mdb to be deployed as an .mde at my current job-site. It has several custom controls which utilize custom classes to wrap built-in controls, and add additional functionality....
0
1474
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 Financial, Statistical, etc. The place I want my help-text to be available is in the Insert->Function. Here, we can select a category and function. The corresponding help text is displayed. Now, my automation add-in is
1
5577
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 users will be running the apps under 'Runtime Access 2007' Here is my dilema... This application is used as a 'stand alone', basically, my users get a copy of the 'master' database and enter their data specifically for one account, each account they...
0
9583
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
9396
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...
1
9342
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9256
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8263
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
6808
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
6081
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4716
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
4888
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.