Python Forum
How to check if the data is empty in a database?
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to check if the data is empty in a database?
#9
Chris,
It has been some time since I've done database work and time has not permitted me to read this entire thread... but if you could answer a few questions...
1 - What kind of database are you trying to query? Is it written in Python ( or an off the shelf product?
2 - Is it a flat-file (single table) or a relational db (set of tables) linked together by primary keys or what?
3 - Are you querying a single table in the db or are attempting to query multiple tables?
4 - If a single table roughly how many records (rows)? 100, 1,000, 10,000 or more?
5 - Ditto for the record set you would expect to get back from a multi-table query
6 - Considering the resultant record set a virtual table are you attempting to...
.. search for the first row that contains the "target text" in column N...
.. then examine Column N in the previous row to see if it is either null or blank?
7 - If the rows are un-ordered how can you write a query to look for the "previous" row ? (Maybe that is your question)
8 - Have you considered...
.. importing one row at at time into a simple python list variable...
.. use a Python counter keep up with what row is the current row...
.. then examining the n'th element of that list for your target...
.. and if found...
.. read in the previous row and examine the same element to see if it is null or blank.
.. if not found import the next row of the table into the list variable and inc the counter and repeat... or whatever

# Basically ( I think) you would
.. use SQL to return the ROW and Python to put the results into a "list"
.. use Python to keep up with which ROW is the current row under investigation
.. use Python to examine the n'th element of the list
.. etc

I'm probably way off here as haven't done any db work in a long time and am very new to Python... but maybe answering my questions and reading my comments will spark an idea.

Actually I'm asking this as I am interested in using Python with a database I have in mind... also just Googled and see SQLite3... is that what you are working with?
Reply


Messages In This Thread
RE: How to check if the data is empty in a database? - by Fran_3 - Aug-28-2017, 12:03 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with to check an Input list data with a data read from an external source sacharyya 3 409 Mar-09-2024, 12:33 PM
Last Post: Pedroski55
  how do you style data frame that has empty rows. gsaray101 0 532 Sep-08-2023, 05:20 PM
Last Post: gsaray101
  How to detect abnormal data in big database python vanphuht91 5 1,147 Jun-27-2023, 11:22 PM
Last Post: Skaperen
  Database that can compress a column, or all data, automatically? Calab 3 1,180 May-22-2023, 03:25 AM
Last Post: Calab
  [SOLVED] [sqilte3] Check if column not empty? Winfried 5 1,125 Jan-28-2023, 12:53 PM
Last Post: Winfried
  Basic SQL query using Py: Inserting or querying sqlite3 database not returning data marlonbown 3 1,386 Nov-08-2022, 07:16 PM
Last Post: marlonbown
  Showing an empty chart, then input data via function kgall89 0 981 Jun-02-2022, 01:53 AM
Last Post: kgall89
  I need help parsing through data and creating a database using beautiful soup username369 1 1,715 Sep-22-2021, 08:45 PM
Last Post: Larz60+
  SaltStack: MySQL returner save less data into Database table columns xtc14 2 2,168 Jul-02-2021, 02:19 PM
Last Post: xtc14
  Looping to read data in database CEC68 1 1,716 Sep-24-2020, 08:54 PM
Last Post: scidam

Forum Jump:

User Panel Messages

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