Concatenate 2 Column Values For One Column

Поиск
Список
Период
Сортировка
От tango ward
Тема Concatenate 2 Column Values For One Column
Дата
Msg-id CAA6wQLJQFX6swLQfwcmqh+Pnp2=HUH11jAZg2XucTgYpi1U5Mg@mail.gmail.com
обсуждение исходный текст
Ответы Re: Concatenate 2 Column Values For One Column  ("David G. Johnston" <david.g.johnston@gmail.com>)
Re: Concatenate 2 Column Values For One Column  (Adrian Klaver <adrian.klaver@aklaver.com>)
Список pgsql-general
Hi,

Sorry for asking question again.

I am trying to concatenate the value of column firstname and lastname from source DB to name column of destination DB.

My code so far:

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'], ''))

The code will take the first and lastname of the FIRST data existing on the destination table. I modified the code, instead of running SELECT and CONCAT, I passed string formatter and call the row['firstname'], row['lastname']

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'),
                             %s
                            )
                    """, (row['lastname'], row['firstname'], '', (row['firstname'], row['lastname']) )

The second code works but it includes the parenthesis in the DB.

How can I remove the ( ) in the DB? I can't call the row['firstname'] and row['lastname'] as values without using ( ).

Any suggestion is highly appreciated.

Thanks,
J

В списке pgsql-general по дате отправления:

Предыдущее
От: "chandru.aroor@yahoo.com"
Дата:
Сообщение: New install of 9.5.12 missing default PostgreSQL DB
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: Concatenate 2 Column Values For One Column