Moving from MySQL to PGSQL....some questions

Started by Karam Chandabout 22 years ago36 messagesgeneral
Jump to latest
#1Karam Chand
karam_chand03@yahoo.com

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

#2Dave Cramer
pg@fastcrypt.com
In reply to: Karam Chand (#1)
Re: Moving from MySQL to PGSQL....some questions

Karam,

try \? to get answers to your questions.

Dave
On Wed, 2004-02-25 at 09:57, Karam Chand wrote:

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

--
Dave Cramer
519 939 0336
ICQ # 14675561

#3Shridhar Daithankar
shridhar@frodo.hserus.net
In reply to: Karam Chand (#1)
Re: Moving from MySQL to PGSQL....some questions

Karam Chand wrote:

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

Yes. whenever a new database is created, these databases are copied there. So
these are like initial master copies.

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 :)

Yes.

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?

Some tables such as users/passwords/groups and databases are shared across all
the databases. You are looking at same data.

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

use database;

or am i missing something?

Any postgresql session has to connect to a database. To connect to different
database, you need to initiate a new connection or drop existing one and create
new one.

You can not switch the database-connected-to on the fly.

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?

No. Simplest would be issuing \? on psql prompt. It will tell you plethora of
options/commands using which you can accomplish many task. Just remember that
these are not SQL command provided by server. It is the psql application which
provide these commands. So you cannot use them in say php.

Any help would be appreciated.

HTH

Shridhar

#4Dennis Bjorklund
db@zigo.dhs.org
In reply to: Karam Chand (#1)
Re: Moving from MySQL to PGSQL....some questions

On Wed, 25 Feb 2004, Karam Chand wrote:

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

When you create a new database what you get is a copy of template1.

template0 is alsmost not used. If you mess up template1 so you can't
create usable new databases one can use template0 to create a new
template1.

The system tables are a bit complexed and some are shared between all
databases.

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

select datname from pg_database

or \l in psql

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.

yes, pg_database is a shared table.

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

use database;

\c in psql.

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?

\d and others.

\? is a useful command. Also the man page (man psql) can help.

--
/Dennis Bj�rklund

#5Karam Chand
karam_chand03@yahoo.com
In reply to: Shridhar Daithankar (#3)
Re: Moving from MySQL to PGSQL....some questions

Thanks. That was very helpful

One more thing (it might be slightly off topic):

I have two computers on network, one is running RH
Linux and one running WInXP. My PostgreSQL is running
in Linux box.

I downloaded PgAdmin III for both OS. When I am
connecting from the Linux box I am able to view the
three system schemas :

pg_catalog
pg_temp_1
pg_toast

When I am accessing it using PgAdmin III on Windows I
can only see the 'public' schema and its tables? Why
is it so?

Regards
Karam

-- Shridhar Daithankar <shridhar@frodo.hserus.net>
wrote:

Karam Chand wrote:

1.) What is template1 and template0? I assume

these

are system databases. Am I right?

Yes. whenever a new database is created, these
databases are copied there. So
these are like initial master copies.

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 :)

Yes.

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?

Some tables such as users/passwords/groups and
databases are shared across all
the databases. You are looking at same data.

4.) I couldnot find any query to change the

context of

database like in MySQL :

use database;

or am i missing something?

Any postgresql session has to connect to a database.
To connect to different
database, you need to initiate a new connection or
drop existing one and create
new one.

You can not switch the database-connected-to on the
fly.

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?

No. Simplest would be issuing \? on psql prompt. It
will tell you plethora of
options/commands using which you can accomplish many
task. Just remember that
these are not SQL command provided by server. It is
the psql application which
provide these commands. So you cannot use them in
say php.

Any help would be appreciated.

HTH

Shridhar

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

In reply to: Karam Chand (#5)
Re: Moving from MySQL to PGSQL....some questions

Le Mercredi 25 Février 2004 16:45, Karam Chand a écrit :

When I am accessing it using PgAdmin III on Windows I
can only see the 'public' schema and its tables? Why
is it so?

Have a deeper look at pgAdmin III menu:
Display>-System objects

pgAdmin III includes the documentation of PostgreSQL.
It is highly recommended to dig into the documentation.

By the way, if one of you was interested by translating pgAdmin into any
language not yet supported, you are welcome.

Cheers,
Jean-Michel

#7Bill Moran
wmoran@potentialtech.com
In reply to: Dennis Bjorklund (#4)
Re: Moving from MySQL to PGSQL....some questions

Dennis Bjorklund wrote:

On Wed, 25 Feb 2004, Karam Chand wrote:

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

When you create a new database what you get is a copy of template1.

template0 is alsmost not used. If you mess up template1 so you can't
create usable new databases one can use template0 to create a new
template1.

More specifically (as I understand it) template1 is intended to be a
template (with default settings and the like) for creating new databases.
So (for example) if your business policy is that all created databases
use plpgsql, you can createlang it into template1, and every database
created thereafter will already have plpgsql. If you have specific
tables or the like that every database on that server should have, you
can put them in template1 so they are always there.

template0 is what you use to fix things, if you mess up template1
somehow.

--
Bill Moran
Potential Technologies
http://www.potentialtech.com

#8Michael Chaney
mdchaney@michaelchaney.com
In reply to: Karam Chand (#1)
Re: Moving from MySQL to PGSQL....some questions

On Wed, Feb 25, 2004 at 06:57:04AM -0800, Karam Chand wrote:

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

use database;

Your other questions were answered more than adequately by others, but I
thought I'd provide more details here.

If you're in the command line psql, then use "\c database" to accomplish
this. The drawback is that you cannot change the database in that
manner programmatically. If you're using Perl or PHP, for instance, you
must connect to the other database explicitly using the proper function.
In Perl, this means you must use DBI->connect again with the new
database name.

In MySQL, you can get data from another database by using the construct
"datbase.table" to refer to the table. This doesn't work in Postgres.

If you need to do something like that, you likely need to be using
schemas.

I've put together a quick list of minor differences between MySQL and
Postgres (besides the obvious "real RDBMS" features that exist only in
Postgres) that should help you get started:

http://www.michaelchaney.com/mysql-to-postgres.html

That includes information on date handling, literal quoting, basically
anything that I ran in to while converting an application. But it
should help you get started quickly.

Michael
--
Michael Darrin Chaney
mdchaney@michaelchaney.com
http://www.michaelchaney.com/

#9Shachar Shemesh
psql@shemesh.biz
In reply to: Shridhar Daithankar (#3)
Re: Moving from MySQL to PGSQL....some questions

Shridhar Daithankar wrote:

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?

5.) In MySQL, there are many command like show tables,

No. Simplest would be issuing \? on psql prompt. It will tell you
plethora of options/commands using which you can accomplish many task.
Just remember that these are not SQL command provided by server. It is
the psql application which provide these commands. So you cannot use
them in say php.

If you run psql with the "-E" parameter, whenever you execute a psql
command that translates to a query, that query will be displayed on
screen. This allows you to check out what queries you need for certain
operations.

For example - to check all the tables in the current database/schema:
$ psql -E db
Welcome to psql 7.4.1, the PostgreSQL interactive terminal.

Type: \copyright for distribution terms
\h for help with SQL commands
\? for help on internal slash commands
\g or terminate with semicolon to execute query
\q to quit

db=# \dt
********* QUERY **********
SELECT n.nspname as "Schema",
c.relname as "Name",
CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'i'
THEN 'index' WHEN 'S' THEN 'sequence' WHEN 's' THEN 'special' END as "Type",
u.usename as "Owner"
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_user u ON u.usesysid = c.relowner
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind IN ('r','')
AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
AND pg_catalog.pg_table_is_visible(c.oid)
ORDER BY 1,2;
**************************

List of relations
Schema | Name | Type | Owner
--------+--------------+-------+-------

Check out the rest of the \d* commands for more listings (\? will give
you the list).

Also, it pays to look up the meaning of the above in the documentation.
The system tables are documented in
http://www.postgresql.org/docs/7.4/static/catalogs.html

Any help would be appreciated.

Shachar

--
Shachar Shemesh
Lingnu Open Systems Consulting
http://www.lingnu.com/

#10codeWarrior
gpatnude@hotmail.com
In reply to: Karam Chand (#1)
Re: Moving from MySQL to PGSQL....some questions

In PGAdmin III -- you might want to UNCHECK the "Display system objects"
option under the "Display" menu option -- this will prevent you from seeing
all of the non-public schema's and limit your view in PGAdmin to just the
databases you created...

Most people dont really need to dink around with the system tables anyway...

As you probably noticed -- postgreSQL is a different beast than MS Access
and mySQL -- postgreSQL is a true RDBMS like Sybase, Orale, and SQL
Server... postgrSQL is a true 'client/server' RDBMS -- it does not contain
it's own GUI client like MS Access

postgreSQL is NOT just a high-powered version of MS Access or mySQL -- there
are quite a few differences --

Not to be rude -- but the postgreSQL docs (the Preface, Tutorial, and SQL
Language sections) would be good for you to read...

--
Greg Patnude / The Digital Demention
2916 East Upper Hayden Lake Road
Hayden Lake, ID 83835
(208) 762-0762

"Karam Chand" <karam_chand03@yahoo.com> wrote in message
news:20040225145704.40397.qmail@web60804.mail.yahoo.com...

Show quoted text

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

#11Michael Chaney
mdchaney@michaelchaney.com
In reply to: Karam Chand (#1)
Re: Moving from MySQL to PGSQL....some questions

One other note, for those converting a database from MySQL to
PostgreSQL, I have a table creation conversion script here:

http://www.michaelchaney.com/downloads/m2p.pl

I know that two come with PostgreSQL in the contrib directory, but I
wrote this because those two didn't do what I needed. With this, you
should be able to take the MySQL table creation scripts (as created by
mysqldump --tab=x) and directly build the tables and load the data into
a PostgreSQL db with little effort.

Michael
--
Michael Darrin Chaney
mdchaney@michaelchaney.com
http://www.michaelchaney.com/

#12Karl O. Pinc
kop@meme.com
In reply to: codeWarrior (#10)
Re: Moving from MySQL to PGSQL....some questions

"Karam Chand" <karam_chand03@yahoo.com> wrote in message
news:20040225145704.40397.qmail@web60804.mail.yahoo.com...

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?

One easy way is to use the psql command line program
and the \d command. It lists all your tables,
lists all the columns in a table, etc.

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

#13Shawn Harrison
harrison@tbc.net
In reply to: Karam Chand (#1)
Database metadata queries (WAS Re: Moving from MySQL to PGSQL....some questions)

Shachar,

This is a very helpful tidbit that I hadn't realized and it will save me a
significant amount of time figuring out such queries in the coming weeks.
Thank you.

Would it be worthwhile to move many of these \d queries into the system
schema, as views on various system tables? I've thought that it would be
very useful to be able to access these things through the web or other
clients. I could see the benefit of providing users with a consistent
interface
to such "database metadata", no matter what client one is using. (OTOH, one
could argue, learning to do that is a pgsql rite-of-passage. ;-> ).

Shawn Harrison

----- Original Message -----

If you run psql with the "-E" parameter, whenever you execute a psql
command that translates to a query, that query will be displayed on
screen. This allows you to check out what queries you need for certain
operations.

For example - to check all the tables in the current database/schema:
$ psql -E db
Welcome to psql 7.4.1, the PostgreSQL interactive terminal.

Type: \copyright for distribution terms
\h for help with SQL commands
\? for help on internal slash commands
\g or terminate with semicolon to execute query
\q to quit

db=# \dt
********* QUERY **********
SELECT n.nspname as "Schema",
c.relname as "Name",
CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'i'
THEN 'index' WHEN 'S' THEN 'sequence' WHEN 's' THEN 'special' END as

"Type",

Show quoted text

u.usename as "Owner"
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_user u ON u.usesysid = c.relowner
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind IN ('r','')
AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
AND pg_catalog.pg_table_is_visible(c.oid)
ORDER BY 1,2;
**************************

List of relations
Schema | Name | Type | Owner
--------+--------------+-------+-------

Check out the rest of the \d* commands for more listings (\? will give
you the list).

Also, it pays to look up the meaning of the above in the documentation.
The system tables are documented in
http://www.postgresql.org/docs/7.4/static/catalogs.html

Any help would be appreciated.

Shachar

--
Shachar Shemesh
Lingnu Open Systems Consulting
http://www.lingnu.com/

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

#14Tom Lane
tgl@sss.pgh.pa.us
In reply to: Shawn Harrison (#13)
Re: Database metadata queries (WAS Re: Moving from MySQL to PGSQL....some questions)

"Shawn Harrison" <harrison@tbc.net> writes:

Would it be worthwhile to move many of these \d queries into the system
schema, as views on various system tables?

There's been talk of that in the past, but no one's gotten around to
doing much about it. If you are interested in working on it, look
into the mail list archives for past discussions.

regards, tom lane

#15Bruno Wolff III
bruno@wolff.to
In reply to: Shawn Harrison (#13)
Re: Database metadata queries (WAS Re: Moving from MySQL to PGSQL....some questions)

On Mon, Mar 01, 2004 at 11:09:32 -0600,
Shawn Harrison <harrison@tbc.net> wrote:

Would it be worthwhile to move many of these \d queries into the system
schema, as views on various system tables? I've thought that it would be
very useful to be able to access these things through the web or other
clients. I could see the benefit of providing users with a consistent
interface
to such "database metadata", no matter what client one is using. (OTOH, one
could argue, learning to do that is a pgsql rite-of-passage. ;-> ).

If you are using 7.4.x look at the information_schema schema. This is going
to provide a stable way to get meta data.

#16Bruce Momjian
bruce@momjian.us
In reply to: Michael Chaney (#11)
Re: Moving from MySQL to PGSQL....some questions

Michael Chaney wrote:

One other note, for those converting a database from MySQL to
PostgreSQL, I have a table creation conversion script here:

http://www.michaelchaney.com/downloads/m2p.pl

I know that two come with PostgreSQL in the contrib directory, but I
wrote this because those two didn't do what I needed. With this, you
should be able to take the MySQL table creation scripts (as created by
mysqldump --tab=x) and directly build the tables and load the data into
a PostgreSQL db with little effort.

Please share what yours does that the /contrib doesn't, and ideally,
send in a patch or let us add your version to /contrib.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
#17Paulovič Michal
michal@paulovic.sk
In reply to: Bruce Momjian (#16)
Re: Moving from MySQL to PGSQL....some questions (multilevel

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);

Result is:
1,1
1,2
2,1
1,3
2,2

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

--------------------------------------
Bruce Momjian wrote:

Show quoted text

Michael Chaney wrote:

One other note, for those converting a database from MySQL to
PostgreSQL, I have a table creation conversion script here:

http://www.michaelchaney.com/downloads/m2p.pl

I know that two come with PostgreSQL in the contrib directory, but I
wrote this because those two didn't do what I needed. With this, you
should be able to take the MySQL table creation scripts (as created by
mysqldump --tab=x) and directly build the tables and load the data into
a PostgreSQL db with little effort.

Please share what yours does that the /contrib doesn't, and ideally,
send in a patch or let us add your version to /contrib.

#18scott.marlowe
scott.marlowe@ihs.com
In reply to: Paulovič Michal (#17)
Re: Moving from MySQL to PGSQL....some questions (multilevel

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?

Show quoted text

Result is:
1,1
1,2
2,1
1,3
2,2

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

#19Paulovič Michal
michal@paulovic.sk
In reply to: scott.marlowe (#18)
Re: Moving from MySQL to PGSQL....some questions (multilevel

Yes I know,

But how you do this at PgSQL????

scott.marlowe wrote:

Show quoted text

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 majordomo@postgresql.org

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

#20Lincoln Yeoh
lyeoh@pop.jaring.my
In reply to: Paulovič Michal (#19)
Re: Moving from MySQL to PGSQL....some questions

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:

Show quoted text

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 majordomo@postgresql.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

#21Harald Fuchs
hf118@protecting.net
In reply to: Paulovič Michal (#17)
#22Paulovič Michal
michal@paulovic.sk
In reply to: Lincoln Yeoh (#20)
#23Paulovič Michal
michal@paulovic.sk
In reply to: Harald Fuchs (#21)
#24Bruno Wolff III
bruno@wolff.to
In reply to: Paulovič Michal (#23)
#25Paulovič Michal
michal@paulovic.sk
In reply to: Bruno Wolff III (#24)
#26Michael Chaney
mdchaney@michaelchaney.com
In reply to: Paulovič Michal (#19)
#27scott.marlowe
scott.marlowe@ihs.com
In reply to: Paulovič Michal (#19)
#28Karl O. Pinc
kop@meme.com
In reply to: scott.marlowe (#27)
#29Tom Lane
tgl@sss.pgh.pa.us
In reply to: Michael Chaney (#26)
#30Bruno Wolff III
bruno@wolff.to
In reply to: Karl O. Pinc (#28)
#31Karl O. Pinc
kop@meme.com
In reply to: Bruno Wolff III (#30)
#32Bruno Wolff III
bruno@wolff.to
In reply to: Karl O. Pinc (#31)
#33Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bruno Wolff III (#32)
#34Karl O. Pinc
kop@meme.com
In reply to: Bruno Wolff III (#32)
#35Michael Chaney
mdchaney@michaelchaney.com
In reply to: Tom Lane (#33)
#36Mike Mascari
mascarm@mascari.com
In reply to: Michael Chaney (#35)