Solved

MYSQL to POSTGRESQL Translation

Posted on 2007-11-30
3
2,358 Views
Last Modified: 2008-02-01
Would this translation be correct
Mysql syntax
CREATE TABLE `voicemessages` (
  `id` int(11) NOT NULL auto_increment,
  `msgnum` int(11) NOT NULL default '0',
  `dir` varchar(80) default '',
  `context` varchar(80) default '',
  `macrocontext` varchar(80) default '',
  `callerid` varchar(40) default '',
  `origtime` varchar(40) default '',
  `duration` varchar(20) default '',
  `mailboxuser` varchar(80) default '',
  `mailboxcontext` varchar(80) default '',
  `recording` longblob,
  PRIMARY KEY  (`id`),
  KEY `dir` (`dir`)
) ENGINE=MyISAM;

To this postgresql syntax

CREATE TABLE voicemessages (
id      integer CONSTRAINT no_null NOT NULL CONSTRAINT firstkey PRIMARY KEY,
msgnum      integer NOT NULL default '0',
dir      varchar default '',
context      varchar default '',
macrocontext      varchar (80) default '',
callerid      varchar (40) default '',
origtime      varchar (40) default '',
duration      varchar (20) default '',
mailboxuser      varchar (80) default '',
mailboxcontext      varchar (80) default '',
recording      bytea,
UNIQUE      (dir)
);
ALTER TABLE voicemessages ALTER COLUMN recording SET STORAGE EXTENDED;

I'm not sure if I chose the best matching data types in postgresql.

0
Comment
Question by:sean-keys
3 Comments
 
LVL 22

Accepted Solution

by:
earth man2 earned 500 total points
ID: 20385850
CREATE TABLE voicemessages (
id  bigserial PRIMARY KEY,
msgnum  int NOT NULL default 0,
dir text,
context text,
macrocontext      varchar (80),
callerid      varchar (40),
origtime      varchar (40),
duration      varchar (20),
mailboxuser      varchar (80),
mailboxcontext      varchar (80),
recording      bytea,
CONSTRAiNT UNIQUE (dir)
);
0
 
LVL 50

Expert Comment

by:Steve Bink
ID: 20385993
Are you worried about something in particular?  The only real difference I see is that you did not supply a character limit on the varchar fields `dir` and `context`.  

As far as matching data types, the only question would be for longblob.  PostgreSQL states that the bytea type is for long binary storage, and while the type is handled slightly differently than a longblob, the function provided for it are roughly the same.
0
 

Author Comment

by:sean-keys
ID: 20386401
I'm trying to get postgresql to work with asterisk, it uses longblob in mysql for voice mail data.  We'll see what happens.

0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now