pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: ogjunk-pgjedan@yahoo.com
To: pgsql-sql@postgresql.org
Subject: Need help: Find dirty rows, Update, Delete SQL
Date: Sat, 18 Feb 2006 09:41:58 -0800 (PST)
Message-ID: <20060218174158.74971.qmail@web50312.mail.yahoo.com> (raw)

Hello,

I need a bit of help with some SQL.
I have two tables, call them Page and Bookmark.
Each row in Page can have many Bookmarks pointing to it, and
they are joined via a FK (Page.id = Bookmark.page_id).

Page has a 'url' column: Page.url, which has a unique index on it.

My Page.url column got a little dirty, and I need to clean it up,
and that's what I need help with.

Here is an example of dirtiness:

Page:

id=1 url = 'http://example.com/';
id=2 url = 'http://example.com/#';     -- dirty
id=3 url = 'http://example.com/#foo';  -- dirty

The last two rows are dirty.  Normally I normalize URLs before
inserting them, but these got in, and now I need to clean them.

The problem is that rows in Bookmark table may point to dirty
rows in Page, so I can't just remove the dirty rows, and I can't
just update 'url' column in Page to 'http://example.com/';,
because that column is unique.

Is there some fancy SQL that I can use them to find the dirty
rows in page (... where url like '%#%') and then find rows in
Bookmark table that point to them, then point those rows to
good rows in Page (e.g. id=1 row above), and finally remove the
dirty rows from Page?

Any help would be greatly appreciated.

I'm using Pg 8.0.3

Thanks,
Otis






view thread (3+ messages)  latest in thread

Message-ID: <20060218174158.74971.qmail@web50312.mail.yahoo.com>
Permalink:  ../20060218174158.74971.qmail@web50312.mail.yahoo.com/
Also on:    postgresql.org/message-id/20060218174158.74971.qmail@web50312.mail.yahoo.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: ogjunk-pgjedan@yahoo.com
  Subject: Re: Need help: Find dirty rows, Update, Delete SQL
  In-Reply-To: <20060218174158.74971.qmail@web50312.mail.yahoo.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox