473,883 Members | 2,092 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Moving from MySQL to PGSQL....some questions

Hello

I have been working with Access and MySQL for pretty
long time. Very simple and able to perform their jobs.
I dont need to start a flame anymore :)

I have to work with PGSQL for my companies current
project.

I have been able to setup postgresql in my rh box and
i can connect and work with psql. I even downloaded
pgadmin III so that i can get to work with a GUI
interface.

As I starting...I see the architecture of PGSQL is
quite complex...or thats what I feel....maybe its for
good :) Here are some of my doubts :

1.) What is template1 and template0? I assume these
are system databases. Am I right?

2.) When I create a database using CREATE DATABASE
stmt. a new DB is created where it has 4 schemas and
around 100 tables. These are the system tables keeping
information about everything in the database? I hope I
am correct :)

3.) To get all the database is the server we use query
like -

select datname from pg_database

I means that there exists a table pg_database in all
the database and all the pg_database table(s) are
updated whenever a user issues CREATE DATABASE stmt.

Why I am saying so coz in PgAdmin III i can see these
tables in all the databases?

4.) I couldnot find any query to change the context of
database like in MySQL :

use database;

or am i missing something?

5.) In MySQL, there are many command like show tables,
show databases etc. to get object details. I cant see
anything similar in PGSQL. After searching the net i
find that i have to execute certain queries to fetch
those queries. Is this the only way?

Any help would be appreciated.

Regards
Karam

_______________ _______________ ____
Do you Yahoo!?
Yahoo! Mail SpamGuard - Read only the mail you want.
http://antispam.yahoo.com/tools

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

http://archives.postgresql.org

Nov 22 '05
34 5087
There is no problem with MySQL but how you build this functionality in
PgSQL?????

Lincoln Yeoh wrote:
Uh, which behaviour do you want? The one Scott just got, or the one
you claimed to get earlier (which is not the same as what Scott got).
I'm not sure how you can do on MySQL what you claimed to get on MySQL
with just the autoincrement feature.

Do you require a contiguous sequence of numbers - no skipped numbers,
or ascending unique numbers will do?

At 06:45 AM 3/3/2004 +0100, Paulovič Michal wrote:
Yes I know,

But how you do this at PgSQL????
scott.marlowe wrote:
On Tue, 2 Mar 2004, [UTF-8] PauloviÄ Michal wrote:

how you solve the problem with multilevel autoicrement?

In MySQL you create table with col1, col2. Col 2 is AUTOICREMENT
and you have to create UNIQUE INDEX (Col1, Col2). If you insert to
this table for col1 volume 1, col2 automaticaly increase by one.

Example:
Insert into table values (1);
Insert into table values (1);
Insert into table values (2);
Insert into table values (1);
Insert into table values (2);
I did this in MySQL and got this:

create table test (id1 int, id2 int auto_increment, primary key(id2));
Query OK, 0 rows affected (0.00 sec)

mysql> alter table test add unique index (id1, id2);
Query OK, 0 rows affected (0.09 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> insert into test (id1) values (1);
Query OK, 1 row affected (0.00 sec)

mysql> insert into test (id1) values (1);
Query OK, 1 row affected (0.00 sec)

mysql> insert into test (id1) values (2);
Query OK, 1 row affected (0.00 sec)

mysql> insert into test (id1) values (1);
Query OK, 1 row affected (0.00 sec)

mysql> insert into test (id1) values (2);
Query OK, 1 row affected (0.00 sec)

mysql> select * from test;
+------+-----+
| id1 | id2 |
+------+-----+
| 1 | 1 |
| 1 | 2 |
| 1 | 4 |
| 2 | 3 |
| 2 | 5 |
+------+-----+
5 rows in set (0.00 sec)

I'm running an older flavor of 3.23.41, it's what came with RH 7.2

Or did I do something different?
Result is:
1,1
1,2
2,1
1,3
2,2

How you convert this functionality from MySQL to PgSQL???

---------------------------(end of
broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to
ma*******@postg resql.org
________ Information from NOD32 ________
This message was checked by NOD32 Antivirus System for Linux Mail
Server.
http://www.nod32.com

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend


________ Information from NOD32 ________
This message was checked by NOD32 Antivirus System for Linux Mail Server.
http://www.nod32.com

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 23 '05 #21
Harald Fuchs wrote:
In article <Pi************ *************** **********@css1 20.ihs.com>,
"scott.marlowe " <sc***********@ ihs.com> writes:


On Tue, 2 Mar 2004, [UTF-8] Paulovič Michal wrote:

how you solve the problem with multilevel autoicrement?

In MySQL you create table with col1, col2. Col 2 is AUTOICREMENT and you
have to create UNIQUE INDEX (Col1, Col2). If you insert to this table
for col1 volume 1, col2 automaticaly increase by one.

Example:
Insert into table values (1);
Insert into table values (1);
Insert into table values (2);
Insert into table values (1);
Insert into table values (2);



I did this in MySQL and got this:



create table test (id1 int, id2 int auto_increment, primary key(id2));
Query OK, 0 rows affected (0.00 sec)


mysql> alter table test add unique index (id1, id2);

Query OK, 0 rows affected (0.09 sec)
Records: 0 Duplicates: 0 Warnings: 0


You can't have a multi-level autoincrement if you make the second
level unique. Use the following instead:

create table test (id1 int, id2 int auto_increment, primary key(id1,id2));

Note that this trick works only for the MyISAM and BDB table types,
not for InnoDB.
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddres sHere" to ma*******@postg resql.org)
________ Information from NOD32 ________
This message was checked by NOD32 Antivirus System for Linux Mail Server.
http://www.nod32.com


You don't build secent level unique
You have to create uniqe index under both levels (first and second)
together. But in MySQL there is no problem.
I alredy have table with mulitlevel autoincrement (in MySQL) but now I
want move this to PostgreSQL 7.1, and i have problem with this. It
doesn't work :-((((

Nov 23 '05 #22
On Wed, Mar 03, 2004 at 18:12:18 +0100,
Paulovi?? Michal <mi****@paulovi c.sk> wrote:
You don't build secent level unique
You have to create uniqe index under both levels (first and second)
together. But in MySQL there is no problem.
I alredy have table with mulitlevel autoincrement (in MySQL) but now I
want move this to PostgreSQL 7.1, and i have problem with this. It
doesn't work :-((((


That isn't an appropiate use of sequences. You should only be using
their uniqeness. If the values are supposed to have some other semantics
you should be using another mechanism.

Also Posgtesql 7.1 is very old. You really should upgrade to something
more recent. 7.4.2 is due out in a few days.

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddres sHere" to ma*******@postg resql.org)

Nov 23 '05 #23
Bruno Wolff III wrote:
On Wed, Mar 03, 2004 at 18:12:18 +0100,
Paulovi?? Michal <mi****@paulovi c.sk> wrote:

You don't build secent level unique
You have to create uniqe index under both levels (first and second)
together. But in MySQL there is no problem.
I alredy have table with mulitlevel autoincrement (in MySQL) but now I
want move this to PostgreSQL 7.1, and i have problem with this. It
doesn't work :-((((


That isn't an appropiate use of sequences. You should only be using
their uniqeness. If the values are supposed to have some other semantics
you should be using another mechanism.

Also Posgtesql 7.1 is very old. You really should upgrade to something
more recent. 7.4.2 is due out in a few days.

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddres sHere" to ma*******@postg resql.org)
________ Information from NOD32 ________
This message was checked by NOD32 Antivirus System for Linux Mail Server.
http://www.nod32.com

Yes, :(
I have thought about this issue. Upgrade of PgSQL might by first step -
probably.
In other node at this formu other colegue give me an idea but it works
on 7.2 and newer.........
Yes – I have to try negotiate with provider of my DB enviroment for
upgrading version of PgSQL.

tnx a lot for all

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 23 '05 #24
On Wed, 3 Mar 2004, [UTF-8] Paulovič Michal wrote:
Yes I know,

But how you do this at PgSQL????


OK, I just read the response where someone showed me how to make such a
table in mysql. What an odd, and non-intuitive behaviour that is.

Anyway, first off, upgrade your version of postgresql to 7.4.x . 7.1 is
VERY old, and is no longer maintained. IT would suck to develop all this
for 7.1 only to find out some minor bug fix gets in your way of upgrading.

Next, what you need is a before trigger that will take any row being
inserted, select the max(id2) where id1 = whatwereinserti ng adds one to it
and makes that the new id2.

Look up before triggers. plpgsql is a good language to do this in. Note
that on large tables it WILL BE SLOW.

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postg resql.org so that your
message can get through to the mailing list cleanly

Nov 23 '05 #25
On Wed, Mar 03, 2004 at 06:45:56AM +0100, Paulovi?? Michal wrote:
Yes I know,

But how you do this at PgSQL????


You have to lock the table exclusively, get the max value for your
particular "id1", increment it, insert the row, and commit:

begin;
lock table test in exclusive mode;
insert into test values (1,(select max(id2) from test where id1=1)+1);
commit;

It's not pretty, and it'll probably slow down as the table grows. MySQL
probably suffers the same problem.

Michael
--
Michael Darrin Chaney
md******@michae lchaney.com
http://www.michaelchaney.com/

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 23 '05 #26

On 2004.03.03 12:43 scott.marlowe wrote:

Next, what you need is a before trigger that will take any row being
inserted, select the max(id2) where id1 = whatwereinserti ng adds one
to it
and makes that the new id2.

Look up before triggers. plpgsql is a good language to do this in.
Note
that on large tables it WILL BE SLOW.


To make it fast, you'd want to keep the max(id2) value on the table
keyed by id1. Your trigger would update the max(id2) value as well
as alter the row being inserted. To keep from having problems with
concurrent inserts, you'd need to perform all inserts inside
serialized transactions. The only problem I see is that there's
a note in the documentation that says that postgresql's serialization
dosen't always work. Anybody know if it would work in this case?

Karl <ko*@meme.com >
Free Software: "You don't pay back, you pay forward."
-- Robert A. Heinlein

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postg resql.org so that your
message can get through to the mailing list cleanly

Nov 23 '05 #27
Michael Chaney <md******@micha elchaney.com> writes:
begin;
lock table test in exclusive mode;
insert into test values (1,(select max(id2) from test where id1=1)+1);
commit; It's not pretty, and it'll probably slow down as the table grows.


As-is, that will definitely get pretty slow on large tables. You could
avoid the slowdown with the standard hack for replacing max() with an
index probe:

insert into test values (1,
(select id2+1 from test where id1=1 order by id1 desc, id2 desc limit 1)
);

This will be fast if there is a double-column index on (id1, id2).

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 23 '05 #28
On Wed, Mar 03, 2004 at 17:22:44 -0600,
"Karl O. Pinc" <ko*@meme.com > wrote:

To make it fast, you'd want to keep the max(id2) value on the table
keyed by id1. Your trigger would update the max(id2) value as well
as alter the row being inserted. To keep from having problems with
concurrent inserts, you'd need to perform all inserts inside
serialized transactions. The only problem I see is that there's
a note in the documentation that says that postgresql's serialization
dosen't always work. Anybody know if it would work in this case?


There was a discussion about predicate locking some time ago (I think
last summer). Postgres doesn't do this and it is possible for two
parallel transactions to get results that aren't consistant with
one transaction occurring before the other. I think the particular
example was inserting some rows and then counting them in each of
two parallel transactions. The answer you get won't be the same as
if either of the two transactions occurred entirely before the other.
This might be what you are referring to.

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddres sHere" to ma*******@postg resql.org)

Nov 23 '05 #29

On 2004.03.03 22:48 Bruno Wolff III wrote:
On Wed, Mar 03, 2004 at 17:22:44 -0600,
"Karl O. Pinc" <ko*@meme.com > wrote:

To make it fast, you'd want to keep the max(id2) value on the table
keyed by id1. Your trigger would update the max(id2) value as well
as alter the row being inserted. To keep from having problems with
concurrent inserts, you'd need to perform all inserts inside
serialized transactions. The only problem I see is that there's
a note in the documentation that says that postgresql's

serialization
dosen't always work. Anybody know if it would work in this case?


There was a discussion about predicate locking some time ago (I think
last summer). Postgres doesn't do this and it is possible for two
parallel transactions to get results that aren't consistant with
one transaction occurring before the other. I think the particular
example was inserting some rows and then counting them in each of
two parallel transactions. The answer you get won't be the same as
if either of the two transactions occurred entirely before the other.
This might be what you are referring to.


Yes. That's it.

So it sounds like this would be a concurrency safe way to perform
the operation. It also sounds like it might be a good idea
to do SELECT FOR UPDATE on the table/row keyed by id1 to keep
the serialized transactions from stepping on each other's toes.

Karl <ko*@meme.com >
Free Software: "You don't pay back, you pay forward."
-- Robert A. Heinlein

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 23 '05 #30

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

Similar topics

2
2189
by: Jeff Skeith | last post by:
first, i would like the thoughts of some folks with more experience than i have. i want to learn pgsql. i have some vb and msaccess experience and would like to learn how to use php and pgsql to develop some nice website / application functionality. however, i'm not sure the hurdle of relatively miniscule documentation and tutorials is worth the effort. i'm now thinking i should just use mysql to start and, if the need really...
9
2727
by: Google Mike | last post by:
To my surprise last month, my dad wanted to start dabbling in PHP and MySQL or pgSQL. I've been helping him out a bit. He's into athletic medicine and wants to have a website to help athletes and physical therapists improve performance. His current web hosting provider -- Earthlink -- doesn't give him anything but PHP 3.0.x. I want to get him at least on PHP 4.2.x (or better) along with either MySQL or PostgreSQL (pgSQL) support. I've...
33
5613
by: Joshua D. Drake | last post by:
Hello, I think the below just about says it all: http://www.commandprompt.com/images/mammoth_versus_dolphin_500.jpg Sincerely, Joshua Drake
74
8090
by: John Wells | last post by:
Yes, I know you've seen the above subject before, so please be gentle with the flamethrowers. I'm preparing to enter a discussion with management at my company regarding going forward as either a MySql shop or a Postgresql shop. It's my opinion that we should be using PG, because of the full ACID support, and the license involved. A consultant my company hired before bringing me in is pushing hard for MySql, citing speed and community...
175
11556
by: Sai Hertz And Control Systems | last post by:
Dear all, Their was a huge rore about MySQL recently for something in java functions now theirs one more http://www.mysql.com/doc/en/News-5.0.x.html Does this concern anyone. What I think is PostgreSQL would have less USP's (Uniqe Selling Points
67
12580
by: Bob Powell | last post by:
To whom it may concern: I find the recent articles in various trade publications a little disturbing due to the lack of PostgrSQL mention. I continue to see articles about how IBM may be considering MYSQL for development an open_source web database. Why isn't PostgreSQL being considered or talked about by major industry giants? As a DBA I know that Postgres is far superior to MYSQL but if the industry directs it's energies towards...
0
9945
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, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9797
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,...
1
10863
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,...
1
7978
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
5807
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
6006
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4622
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
2
4229
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3241
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.