Re: Copying data from one table to another - how to specify fields? - Mailing list pgsql-general

From Alexander Farber
Subject Re: Copying data from one table to another - how to specify fields?
Date
Msg-id AANLkTikjgK_0yKXHvN8gSN50RMj3JHzAqmB3D4USX4tD@mail.gmail.com
Whole thread Raw
In response to Re: Copying data from one table to another - how to specify fields?  (Raymond O'Donnell <rod@iol.ie>)
Responses Re: Copying data from one table to another - how to specify fields?
Re: Copying data from one table to another - how to specify fields?
List pgsql-general
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.Farber@gmail.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"

pgsql-general by date:

Previous
From: Andrew Sullivan
Date:
Subject: Re: Transaction wraparound vacuum synchronicity
Next
From: Andrew Sullivan
Date:
Subject: Re: FW: backup using pg_dump postgreSQL 8.3.8