Re: Copying data from one table to another - how to specify fields?

From: "David Johnston" <polobo(at)yahoo(dot)com>
To: "'Alexander Farber'" <alexander(dot)farber(at)gmail(dot)com>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: Copying data from one table to another - how to specify fields?
Date: 2011-03-09 15:02:50
Message-ID: 005d01cbde6b$0fc46ff0$2f4d4fd0$@yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

2 Possibilities (assuming there is a single record with name == 'Alex' in
the drupal_users table; not counting uid 0)

1. There is a record with username = 'Alex' in the phpbb_users table
2. Username is not UNIQUE within phpbb_users

Write a select statement to extract username from phpbb_user for BOTH these
conditions.

Decide how you want to modify those records so that can be imported into
drupal_users.

David J.

-----Original Message-----
From: pgsql-general-owner(at)postgresql(dot)org
[mailto:pgsql-general-owner(at)postgresql(dot)org] On Behalf Of Alexander Farber
Sent: Wednesday, March 09, 2011 9:21 AM
To: pgsql-general(at)postgresql(dot)org
Subject: Re: [GENERAL] Copying data from one table to another - how to
specify fields?

Oh it is called "INSERT INTO", thank you!

I still have a problem though:

# select uid, name, mail, created, access from drupal_users;
uid | name | mail | created | access
-----+------+----------------------------+------------+------------
0 | | | 0 | 0
1 | Alex | Alexander(dot)Farber(at)gmail(dot)com | 1299512207 | 1299751991
(2 rows)

# INSERT INTO drupal_users (uid, name, mail, created, access) SELECT
user_id, username, user_email, user_regdate, user_lastvisit
FROM phpbb_users
WHERE user_id > 50 and length(username) > 0;
ERROR: duplicate key value violates unique constraint
"drupal_users_name_key"

I don't understand, what is wrong with "name" here and how to find the
troublemaking record in my 4700 lines table

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Merlin Moncure 2011-03-09 15:13:31 Re: equivalent of mysql's SET type?
Previous Message Alexander Farber 2011-03-09 14:54:38 Re: Copying data from one table to another - how to specify fields?