I am migrating the data from one DB to another (both postgresql). I want to concatenate the value of firstname and lastname columns from the source DB to name column of the destination DB. When I try to run the query, I am getting an error: psycopg2.ProgrammingError: more than one row returned by a subquery used as an expression
Checking other threads here in SO, I found this concatenate. I added LIMIT 1 to the code but it gives me the first and last name of the existing name in the table.
My code:
cur_t.execute("""
SELECT firstname, lastname
FROM authors;
""")
for row in cur_t:
cur_p.execute("""
INSERT INTO lib_author (
created, modified, last_name,
first_name, country,
school_id, name)
VALUES (current_timestamp, current_timestamp, %s, %s, %s,
(SELECT id FROM ed_school WHERE name='My Test School'),
(SELECT CONCAT(first_name, ',', last_name) AS name FROM lib_author LIMIT 1)
)
""", (row['lastname'], row['firstname'], ''))
How can I call the firstname and lastname column from the source DB?