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 18:01:13
Message-ID: 008a01cbde83$fab921f0$f02b65d0$@yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

SELECT username, count(username) FROM phpbb_users
GROUP BY username
HAVING count(username) > 1;

If anything shows up then (phpbb_users .username) is not a unique field but
you are trying to insert it into one that is (drupal_users.uid)

-----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:48 AM
To: pgsql-general(at)postgresql(dot)org
Subject: Re: [GENERAL] Copying data from one table to another - how to
specify fields?

Hello Raymond and others,

thank you for looking at my problem!

It is a core Drupal 7 table, with a prefix "drupal_"
(you can set it while installing Drupal 7 in adv. options).

I have only 2 records in that target table:

# 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 | 1299753672
(2 rows)

I've tried you suggestion and the conflicting record is 'Alex':

# select username, user_id from phpbb_users where exists (select 1 from
drupal_users
where drupal_users.name = phpbb_users.username); username | user_id
----------+---------
Alex | 2
(1 row)

But isn't that record excluded by the conditions below?

# 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 and username <> 'Alex';
ERROR: duplicate key value violates unique constraint
"drupal_users_name_key"

--
Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org) To make
changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2011-03-09 18:05:34 Re: Why length(to_char(1::integer, '9')) = 2 ?
Previous Message Jaiswal Dhaval Sudhirkumar 2011-03-09 18:00:01 Re: about memory size reported by system.