Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6533181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:05:38+00:00 2026-05-25T10:05:38+00:00

First of all, I am using Postgres 9.1. I have a table named filepaths

  • 0

First of all, I am using Postgres 9.1.

I have a table named filepaths and other tables that have rows that point to the id of their corresponding filepaths. Is there a common design approach for reference counting the filepaths so that when other rows are dropped and there are no longer any references to a particular filepath row, it can be dropped as well?

Example:

    [filepaths]
    1 | c:\windows\system32\test.exe
    2 | c:\windows\calc.exe

    [events_2011_08_30]
    [1][timestamp][other data] [ filepaths = 1]
    [2][timestamp][other data] [ filepaths = 2]

    [events_2011_08_31]
    [1][timestamp][other data] [ filepaths = 1]

So I will be storing data in tables to partition it, and I want to delete old tables when they are older than say 30 days (will still have them archived). In the above example, let’s assume there are only those two events_ tables. If I delete the 2011_08_30, I would desire a way to know that nothing is pointing to filepaths ‘2’ and therefore remove it, but know that a row is still pointing to filepaths ‘1’ and therefore retain it.

Any thoughts, suggestions, etc? I believe some of the strategies I have read, at least for postgres and triggers, still have race conditions about which thread got a lock first on the primary key column and other related issues.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T10:05:39+00:00Added an answer on May 25, 2026 at 10:05 am

    You don’t need reference counting. (you could implement it using triggers, if you really want it)
    What you want is called a foreign key [constraint]

    The simplest way to clean up the filepath table is by using a NOT EXISTS construct, eg

    DELETE FROM filepaths fp
    WHERE NOT EXISTS ( SELECT * FROM events ev where ev.file_id = fp.file_id)
    AND NOT EXISTS (SELECT * FROM events_version_xxx ev where ev.file_id = fp.file_id)
    AND NOT EXISTS (SELECT * FROM events_version_yyy ev where ev.file_id = fp.file_id)
    ...
    ;
    

    This is ugly. But the database model is ugly, too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using jQuery, how do I delete all rows in a table except the first?
First of all, I'm using Windows, just to make that clear. I am using
First of all: I'm at Scala 2.8 I have a slight issue while using
First of all, I shall say that I am using an old version of
I have a number of Eclipse projects that are all using classes from a
First of all (in case this is important) I'm using ActiveState's Perl (v5.8.7 built
First of all, am I the only person using JSONML? And second of all,
First of all, before I begin, I am using VC++ 2008 professional, running an
I've been creating an iPhone App using Core Data. First of all, does it
I'm using a singleton class to save all my settings info. It's first utilized

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.