[SQL] Peer-review requested of soft-delete scheme

2013-04-16 Thread Mark Stosberg
Hello, I'm working on designing a soft-delete scheme for our key entity-- there are 17 other tables that reference our key table via RI. Let's call the table "foo". I understand there are a couple common design patterns for soft-deletes: 1. Use a trigger to move the rows to a "tombstone table".

Re: [SQL] Need help revoking access WHERE state = 'deleted'

2013-02-28 Thread Mark Stosberg
On 02/28/2013 02:08 PM, Tom Lane wrote: > Mark Stosberg writes: >> # Explicitly grant access to the view. >> db=> grant select on entities_not_deleted to myuser; >> GRANT > >> # Try again to use the view. Still fails >> db=> SELECT 1 FROM entities_

Re: [SQL] Need help revoking access WHERE state = 'deleted'

2013-02-28 Thread Mark Stosberg
On 02/28/2013 01:02 PM, Ben Morrow wrote: > Quoth m...@summersault.com (Mark Stosberg): >> >> We are working on a project to start storing some data as "soft deleted" >> (WHERE state = 'deleted') instead of hard-deleting it. >> >> To make su

[SQL] Need help revoking access WHERE state = 'deleted'

2013-02-28 Thread Mark Stosberg
We are working on a project to start storing some data as "soft deleted" (WHERE state = 'deleted') instead of hard-deleting it. To make sure that we never accidentally expose the deleted rows through the application, I had the idea to use a view and permissions for this purpose. I thought I coul

[SQL] recommended data model for a search?

2011-02-15 Thread Mark Stosberg
We have an application that manages RSS feeds for searches. Our first attempt at modeling this was to create a table for the searches with the standard integer primary key generated from a sequence, and then have one column per search key. Each row should represent a unique search. When a new se

[SQL] Best practices for geo-spatial city name searches?

2009-02-24 Thread Mark Stosberg
primary key, and a zipcode as an additional column. Then, by joining on the zipcodes table, the coordinates for a city could be found. Is there any other way I should be considering data modelling to support searches on zipcodes and cities? Thanks! Mark -- . . . . . . . . . . . .

[SQL] Re: Best practice for long-lived journal tables: bigint or recycling IDs?

2008-07-09 Thread Mark Stosberg
> > > 3. Deal with wraparound by ensuring that the applications behave sanely > > > > Wrap-around? > > > > Exceeding the max size of "int" looks more like a brick wall than > > wrap-around to me: > > > > insert into t values (2147483648); > > ERROR: integer out of range > > Hmm, you can a

[SQL] Re: Best practice for long-lived journal tables: bigint or recycling IDs?

2008-07-08 Thread Mark Stosberg
On Tue, 8 Jul 2008 17:20:13 -0400 Alvaro Herrera <[EMAIL PROTECTED]> wrote: > Mark Stosberg wrote: > > > > Hello, > > > > I have some tables that continually collect statistics, and then over time > > are > > pruned as the stats are aggregated in

[SQL] Best practice for long-lived journal tables: bigint or recycling IDs?

2008-07-08 Thread Mark Stosberg
manent storage. Both options have some appeal for me. What have others done? Mark -- . . . . . . . . . . . . . . . . . . . . . . . . . . . Mark StosbergPrincipal Developer [EMAIL PROTECTED] Summersault, LLC 765-939-9301 ext 202 database driven websit

Re: [SQL] Egroupware infolog query slow (includes query plan)

2008-07-06 Thread Mark Stosberg
I should have mentioned in the last post that PostgreSQL 8.2.9 is in use. I could upgrade to 8.3.x if that is expected to help performance in this case. Mark On Sun, 2008-07-06 at 16:23 -0400, Mark Stosberg wrote: > Hello, > > I could use some help figuring out how to speed u

[SQL] Egroupware infolog query slow (includes query plan)

2008-07-06 Thread Mark Stosberg
Hello, I could use some help figuring out how to speed up a query. Below is the SQL and query plan for a common SELECT done by the open source eGroupware project. Now that there are about 16,000 rows in egw_infolog and 32,000 in egw_infolog_extra, the below query takes about 6 minutes to finish

Re: [SQL] GROUP BY on a column which might exist in one of two tables

2008-06-25 Thread Mark Stosberg
On Wed, 2008-06-25 at 14:20 +, Greg Sabino Mullane wrote: > -BEGIN PGP SIGNED MESSAGE- > Hash: RIPEMD160 > > > > Where the totals are "counts" of the the rows in the hits and views > > tables. There should be no rows for partners without hits or views. > > How about something like th

Re: [SQL] GROUP BY on a column which might exist in one of two tables

2008-06-25 Thread Mark Stosberg
> select > coalesce(h.partner_id, v.partner_id) as partner_id, > coalesce(v.count, 0) as total_views, > coalesce(h.count, 0) as total_hits > from > (select partner_id, count(*) from hits group by partner_id) as h > full outer join > (select partner_id, count(*) from views g

[SQL] GROUP BY on a column which might exist in one of two tables

2008-06-25 Thread Mark Stosberg
Hello, I could use some help figuring out a complex "GROUP BY". As a setup, let's say I have two tables which stores a single "hit" or "view" in a row hits hit_id partner_id views view_id partner_id There is of course a "partners" table with a "partner_id" column. My target result is

[SQL] INSERT ... SELECT FROM .... FOR UPDATE?

2006-07-14 Thread Mark Stosberg
Hello, This is a re-phrasing of question I asked recently, inquiring about a an approach I'm considering. My query is: > INSERT into item_hit_log (item_id, hit_date, hit_count) >SELECT item_id, CURRENT_DATE + CAST('1 day' AS interval), 0 > FROM items where item_state = 'available';

[SQL] Avoiding RI failure with INSERT ... SELECT FROM

2006-07-12 Thread Mark Stosberg
Hello! I got an unexpected SQL failure last night, and want to see how to prevent it in the future. This is with 8.1.3. I have a couple of insert statements that run in a transaction block, initializing rows that will be used the next day: INSERT into item_hit_log SELECT item_id, CURRENT_DAT

Re: [SQL] A tricky sql-query...

2003-11-02 Thread Mark Stosberg
On 2003-10-22, Timo <[EMAIL PROTECTED]> wrote: > > You can't have any recursion in an pure sql-query, can you? It depends on how you think of recursion, I'd say. You join on the same table a number of times, by giving it a different alias each time. You have to manually specify (or generate with

Re: [SQL] recursive sql (using the sort_key method)

2003-09-06 Thread Mark Stosberg
In article <[EMAIL PROTECTED]>, <[EMAIL PROTECTED]> wrote: > > can anyone recommend a good reference source for doing recursive sql on > postgresql? i want to do something similar to a BOM expansion. (i.e. i need > to traverse a self-referencing table that stores a tree structure and answer > a qu

Re: [SQL] how to refer to tables in another database( or schema)

2002-08-25 Thread Mark Stosberg
On Mon, 19 Aug 2002, Stephan Szabo wrote: > On Mon, 19 Aug 2002, Jiaqing wrote: > > > Hello, > > I'm still new here and new to PostgreSQL, I'd like to know that after I > > have created two databases on my site, such as one is called backend, and > > another one is called admin, how do I refer(qu

Re: [SQL] Separating data sets in a table

2002-08-25 Thread Mark Stosberg
On Sun, 25 Aug 2002, Andreas Tille wrote: > On Sat, 24 Aug 2002, Mark Stosberg wrote: > > > On Thu, 22 Aug 2002, Andreas Tille wrote: > > > Hello, > > > > > > I want to solve the following problem: > > > > > > CREATE TABLE

Re: [SQL] Event recurrence - in database or in application code ????

2002-08-21 Thread Mark Stosberg
On 21 Aug 2002, Robert Treat wrote: > On Tue, 2002-08-20 at 22:15, Mark Stosberg wrote: > > > > Hello Darrin, > > > > > > > I've been happy with this solution. I think the Perl turned out to be > > fairly easy to understand and maintain, the SQL

Re: [SQL] Event recurrence - in database or in application code ????

2002-08-20 Thread Mark Stosberg
Hello Darrin, I recently implemented what I would consider the "hard part" of a solution to this using Perl and Postgres. My solution handles multi-day events and recurring events, including events that are both multi-day and recurring. Here's an overview of how I did it: A table called "calend

Re: [SQL] need assistance with multi-row matching expression

2002-08-19 Thread Mark Stosberg
On Mon, 19 Aug 2002, Nick Fankhauser wrote: > > This may not be the best way, but I couldn't resist taking a shot at it... Thanks for the response Nick. If only I knew I was going to get a response from a block away, I would have just come down to say hi. :) I had an "a ha" moment about this ov

[SQL] need assistance with multi-row matching expression

2002-08-19 Thread Mark Stosberg
Hello, I'm using Postgres 7.1 and have been enjoying the upgraded "sub-select" support in this release versus older versions. At the moment, I'm stuck with a SQL issue that I haven't run into before. I need to select the data for all the "parks" that match some search criteria. The parks are s

Re: [SQL] Re: Help!!! Trying to "SELECT" and get a tree structure back.

2001-08-16 Thread Mark Stosberg
--CELKO-- wrote: > > >> The table causing my headache: > > CREATE TABLE app_components > (idNUMERIC(7) NOT NULL PRIMARY KEY, > name VARCHAR(100) NOT NULL, > description VARCHAR(500) NULL, > parent_id NUMERIC(7) NULL >REFERENCES app_components(id) >

Re: [SQL] About table column names.

2001-06-07 Thread Mark Stosberg
David BOURIAUD wrote: > > Hi the list ! > As far as I know, column names for a table can't contain any space, > tabs, and other sort of "exotic" characters. In fact, I know you can have at least spaces in your column names, like this: mark=> create table t ("column one" text); CREATE Just put

[SQL] behavior of ' = NULL' vs. MySQL vs. Standards

2001-06-06 Thread Mark Stosberg
Hello, I'm a long time Postgres user who uses MySQL when I have to. I recently ran into an issue with MySQL where this construct didn't do what I expect: WHERE date_column = NULL I expected it to work like "date_column IS NULL" like it does it Postgres 7.0.2, but instead it returned an empty r

[SQL] creating tables that are visible across databases

2001-04-20 Thread Mark Stosberg
Hello, I'd like to create some tables that would visible across databases, much like the postgres system tables. These would be for "static" data, such as state and country codes, and geo-spatial data. I couldn't find this mentioned in the docs, but unless this feature of the system tables is

Re: [SQL] Client/Server Security question

2001-04-20 Thread Mark Stosberg
Lonnie Cumberland wrote: > > Hello All, > > We are developing an application that will allow our websites to talk to our > database. > > In the interest of security, I am wondering if it is possible to turn off some > of the functions in the SQL command list such that a user can only communicat

Re: [SQL] function to format floats as money? (removing space padding)

2001-04-19 Thread Mark Stosberg
Now that I've figured out that numeric is good for storing money, and that I can format with like this: to_char(price, '9,999,999.99') as price Then I discovered that sometimes this returns leading spaces I don't want. I can get rid of them like this: trim(to_char(price, '9,999,999.99')) as pr

Re: [SQL] function to format floats as money?

2001-04-17 Thread Mark Stosberg
Peter Eisentraut wrote: > > Mark Stosberg writes: > > > I'm curious to know if there is a function available in Postgres 7.0.3 > > (or 7.1) that will format a float style number as "money". I understand > > that the money type is going away in the

[SQL] function to format floats as money?

2001-04-17 Thread Mark Stosberg
Hello, I'm curious to know if there is a function available in Postgres 7.0.3 (or 7.1) that will format a float style number as "money". I understand that the money type is going away in the future, so using a float type that is sometimes formatted like money seems like a good alternative. So

[SQL] a select statement that sometimes joins

2001-04-10 Thread Mark Stosberg
Here's a situation I've run into more than once with SQL: I want to select all the rows in a table that match a criteria, where one of the criteria is possibly having a related entry in a second table. For my example, lets say I have table named 'messages' and another named 'message_attachment