Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sqlite CONCAT columns
#5
This code does not update the database, it's a SELECT query.
If you have FirstName and LastName it's generally against DB design principles to have also FullName as column. Keep atomic data. Note that SQLite3 does not support computed columns if you are after that.
You can create a view, if you want to have a full name and run queries against the view.
If after all you want to do it and create a new column in the table, then you need to create a column FullName and update its values from the other two columns:
import sqlite3
with sqlite3.connect('test.db') as db:
    curr = db.cursor()
    curr.execute("ALTER TABLE Employee ADD COLUMN FullName TEXT;")
    curr.execute("UPDATE Employee SET FullName = FirstName || ' ' || LastName;")
    db.commit()
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
Sqlite CONCAT columns - by issac_n - Mar-22-2020, 08:00 AM
RE: Sqlite CONCAT columns - by ndc85430 - Mar-22-2020, 08:11 AM
RE: Sqlite CONCAT columns - by buran - Mar-22-2020, 08:24 AM
RE: Sqlite CONCAT columns - by issac_n - Mar-22-2020, 09:08 AM
RE: Sqlite CONCAT columns - by buran - Mar-22-2020, 09:31 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  DataFRame.concat() nafshar 3 772 Jul-14-2023, 04:41 PM
Last Post: nafshar
  Pandas AttributeError: 'DataFrame' object has no attribute 'concat' Sameer33 5 5,592 Feb-17-2023, 06:01 PM
Last Post: Sameer33
  Concat Strings paulo79 5 1,442 Apr-15-2022, 09:58 PM
Last Post: snippsat
  [SOLVED] Concat data from dictionary? Winfried 4 1,718 Mar-30-2022, 02:55 PM
Last Post: Winfried
  Create SQLite columns from a list or tuple? snakes 6 8,669 May-04-2021, 12:06 PM
Last Post: snakes
  pd.concat Problem WiPi 1 1,756 May-27-2020, 07:42 AM
Last Post: WiPi
  Concat multiple Excel sheets with exclusion alessandrotk 1 2,841 Jan-10-2020, 04:43 AM
Last Post: sandeep_ganga
  SQLite DB integration duplicate columns rachitmishra25 1 5,372 Oct-27-2017, 11:20 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020