Solved

MYSQL to POSTGRESQL Translation

Posted on 2007-11-30
3
2,414 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
Steps to create a PostgreSQL RDS instance in the Amazon cloud. We will cover some of the default settings and show how to connect to the instance once it is up and running.
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…

821 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