[GENERAL] disjoint union types

2007-10-09 Thread Sam Mason
Hi, I was after opinions as to the best way to lay tables out to get the effect of a disjoint union type (also known as a tagged union). When I have to do this at the moment, I'm creating a structure like: CREATE TABLE circle ( id SERIAL PRIMARY KEY, radius REAL NOT NULL ); CREATE TABLE

Re: [GENERAL] disjoint union types

2007-10-10 Thread Sam Mason
On Tue, Oct 09, 2007 at 10:30:15AM -0500, Erik Jones wrote: On Oct 9, 2007, at 9:38 AM, Sam Mason wrote: CREATE TABLE circle ( id SERIAL PRIMARY KEY, radius REAL NOT NULL ); CREATE TABLE square ( id SERIAL PRIMARY KEY, sidelen REAL NOT NULL ); CREATE TABLE shapes ( id SERIAL

Re: [GENERAL] disjoint union types

2007-10-10 Thread Sam Mason
On Wed, Oct 10, 2007 at 05:02:36PM +0100, Ian Barber wrote: I wonder if the best way to go would be to use the OO stuff. I don't see how the following is object orientated, but I'm not sure it matters much. If you had a shapes table, that had the various operations you were interested in (say

Re: [GENERAL] disjoint union types

2007-10-12 Thread Sam Mason
On Wed, Oct 10, 2007 at 12:10:10PM -0500, Erik Jones wrote: On Oct 10, 2007, at 11:42 AM, Sam Mason wrote: On Wed, Oct 10, 2007 at 05:02:36PM +0100, Ian Barber wrote: CREATE TABLE shapes ( shape_id serial PRIMARY KEY, area real not null ); CREATE TABLE circle ( radius real not null

Re: [GENERAL] can I define own variables?

2007-10-12 Thread Sam Mason
On Sat, Oct 13, 2007 at 12:18:45AM +0200, Andreas wrote: can I define connection-global variables within a ODBC connection ? You could use a temporary table, keyed on the variable name. Not particularly nice to use, but it works. You can create accessor functions reasonably easily if you want.

Re: [GENERAL] Calculation of per Capita on-the-fly - problems with SQL syntax

2007-10-15 Thread Sam Mason
On Mon, Oct 15, 2007 at 02:08:24PM +0200, Stefan Schwarzer wrote: Just one thing: As my year columns can have as well values like 1970-75, they are not integers, but text fields. Thus, the IN parameter in the WHERE clause doesn't work. Do you have any other idea how ti could work? I'd be

Re: [GENERAL] Convert bytea to Float8

2007-10-15 Thread Sam Mason
On Mon, Oct 15, 2007 at 03:16:40PM -0500, Lee Keel wrote: I am sorry to push this issue, but I have clients waiting on a solution for this. So, does the lack of response mean that I am going to have to find another approach? Or can this conversion be done in ppgsql\perl? This question

Re: [GENERAL] Group By question

2007-10-16 Thread Sam Mason
On Tue, Oct 16, 2007 at 07:46:34AM -0700, Jeff Lanzarotta wrote: Hello, I have a table that looks something like this: SKU Dept Col1 Col2 Col3 --- -- --- --- -- 1112 3 2123 4 32

Re: [GENERAL] Calculation of per Capita on-the-fly - problems with SQL syntax

2007-10-17 Thread Sam Mason
On Wed, Oct 17, 2007 at 08:29:58AM +0200, Stefan Schwarzer wrote: Hmmm Actually, my intention was to get a more excel like output, that is the formatting into year-columns. This eases a lot the PHP/HTML display/loop. Otherwise I would have to start to do some joggling inside PHP to get

Re: [GENERAL] insert continue on error

2007-10-17 Thread Sam Mason
On Tue, Oct 16, 2007 at 03:37:46PM -0400, Tom Hart wrote: I'm trying to migrate our data mine from a MS Access backend to a postgresql backend, and I'm bumping into problems with the conversion. When I've had to do this before, I've tended to create a table with the same columns but all of

Re: [GENERAL] Prepared statement parameters for an 'IN ()' clause

2007-10-17 Thread Sam Mason
On Wed, Oct 17, 2007 at 07:37:15AM -0700, Jason L. Buberel wrote: Can someone point me to an example of creating a prepared statement for a query with an 'IN' clause? The query looks like this: select value from table where state = $1 and city = $2 and zip = $3 and date in ( $4 ); You're

Re: [GENERAL] Array intersection

2007-10-17 Thread Sam Mason
On Wed, Oct 17, 2007 at 10:37:23AM -0500, Josh Trutwin wrote: On Wed, 17 Oct 2007 10:19:43 -0500 Josh Trutwin [EMAIL PROTECTED] wrote: Hi, Is it possible to find the intersection of two array values? a = '{1,2,3}' b = '{2,3,4}' a intersect b = '{2,3}' Assume I need to

Re: [GENERAL] Array intersection

2007-10-17 Thread Sam Mason
On Wed, Oct 17, 2007 at 11:28:31AM -0500, Josh Trutwin wrote: It's inelegant, but I just did this: IF return_empty THEN RETURN '{}'; END IF; humm, why didn't that seem to work for me... ah well. Next version fixes a problem that I didn't test of the inputs being NULL.

Re: [GENERAL] Array intersection

2007-10-17 Thread Sam Mason
On Wed, Oct 17, 2007 at 11:31:51AM -0500, Josh Trutwin wrote: Is the =ANY specific to PG 8.2 or higher? On 8.1.10: It appears (according to [1] and [2]) that you may be able to just remove the '=' to get it working with 8.1.x. i.e. v ANY ('{1,2}') is correct in 8.1.x but in 8.2.x it's v

Re: [GENERAL] Array intersection

2007-10-17 Thread Sam Mason
On Wed, Oct 17, 2007 at 01:00:48PM -0500, Josh Trutwin wrote: Works like a champ on 8.1. Thanks! That's OK, it was a good learning experience. Did you see David Fetter's reply to the original post? He has an interesting alternative. I did, it's much more elegant. I've never seen

Re: [GENERAL] select count() out of memory

2007-10-26 Thread Sam Mason
On Fri, Oct 26, 2007 at 08:26:13AM +0200, Thomas Finneid wrote: Scott Marlowe wrote: It may well be that one big table and partial indexes would do what you want. Did you explore partial indexes against one big table? That can be quite handy. Hmm, interresting, I suppose it could work.

Re: [GENERAL] select count() out of memory

2007-10-26 Thread Sam Mason
On Fri, Oct 26, 2007 at 08:25:09AM +0200, Thomas Finneid wrote: Gregory Stark wrote: Tom's point is that if you have 55k tables then just *finding* the newest child table is fairly expensive. You're accessing a not insignificant-sized index and table of tables. And the situation is worse when

Re: [GENERAL] select count() out of memory

2007-10-26 Thread Sam Mason
On Fri, Oct 26, 2007 at 02:21:39PM +0100, Gregory Stark wrote: Sam Mason [EMAIL PROTECTED] writes: I think the lookup that is being referred to is the fact that if you've got 55k (plus) files in a directory then the filesystem still has to perform a search in the directory to locate

Re: [GENERAL] Securing stored procedures and triggers

2007-10-31 Thread Sam Mason
On Wed, Oct 31, 2007 at 05:18:58PM -0400, mgould wrote: Thanks all. In the open source community there seems to be more talent to hack than in other environments. I think we're just much more honest about what the technology is really capable of. None of us is likely to actually bother

Re: [GENERAL] select random order by random

2007-11-01 Thread Sam Mason
On Thu, Nov 01, 2007 at 04:49:16PM +, Richard Huxton wrote: Gregory Stark wrote: This does strike me as wrong. random() is marked volatile and the planner ought not collapse multiple calls into one. I think I agree with the earlier poster. Surely these two queries should be

Re: [GENERAL] Would an index benefit select ... order by?

2007-11-05 Thread Sam Mason
On Mon, Nov 05, 2007 at 10:09:12AM +0400, rihad wrote: What if it's really a limited select: select * from foo order by created_at desc limit SCREEN_AT_A_TIME; because this is what I meant initially (sorry), would Postgres always use index to get at sorted created_at values, so I don't

Re: [GENERAL] How to temporarily disable a table's FK constraints?

2007-11-05 Thread Sam Mason
On Mon, Nov 05, 2007 at 01:52:54PM -0400, Kynn Jones wrote: BTW, I realize that I can just drop and reinstate constraints, but from the point of view of writing a Perl script to do all this, it would be much easier if I could just disable temporarily all the FK constraints on a table. Do you

[GENERAL] odbcng

2007-11-07 Thread Sam Mason
On Tue, Nov 06, 2007 at 05:48:12PM -0300, Alvaro Herrera wrote: FYI there's another Postgres ODBC driver that is said to have better performance. https://projects.commandprompt.com/public/odbcng (Yes, my company maintains it) Are there any known issues when calling it from VB? I've got a

Re: [GENERAL] Linux v.s. Mac OS-X Performance

2007-11-12 Thread Sam Mason
On Mon, Nov 12, 2007 at 10:14:46AM -0700, Steve Wampler wrote: Also, what kernel are you using with CentOS 5 - a 32-bit (with hugemem to support the 8GB) or a 64-bit? And which was PostgreSQL compiled for? You don't need a 32bit kernel to support 8GB of memory should you? As long as the kernel

Re: [GENERAL] Linux v.s. Mac OS-X Performance

2007-11-12 Thread Sam Mason
On Mon, Nov 12, 2007 at 11:31:59AM -0600, Scott Marlowe wrote: On Nov 12, 2007 11:29 AM, Sam Mason [EMAIL PROTECTED] wrote: You don't need a 32bit kernel to support 8GB of memory should you? As long as the kernel supports PAE that should be enough to make use of it. You only need a 64bit

Re: [GENERAL] Linux v.s. Mac OS-X Performance

2007-11-12 Thread Sam Mason
On Mon, Nov 12, 2007 at 11:46:12AM -0600, Scott Marlowe wrote: On Nov 12, 2007 11:37 AM, Sam Mason [EMAIL PROTECTED] wrote: And what's the performance hit of using native 64bit code? I'd guess similar, moving twice as much data around with each pointer has got to affect things. That's

Re: [GENERAL] Linux v.s. Mac OS-X Performance

2007-11-12 Thread Sam Mason
On Mon, Nov 12, 2007 at 05:02:52PM -0500, Vivek Khera wrote: On Nov 12, 2007, at 12:29 PM, Sam Mason wrote: You only need a 64bit address space when each process wants to see more than ~3GB of RAM. And how exactly do you get that on a 32-bit CPU? I didn't mean to suggest you could. You can

Re: [GENERAL] Chunk Delete

2007-11-15 Thread Sam Mason
On Thu, Nov 15, 2007 at 04:18:27PM +0200, Abraham, Danny wrote: The temporary sequence works perfectly for me. You may want to read my other message and test again. You are well into implementation details here and the trick that was suggested will (with the current version of PG delete the

Re: [GENERAL] Chunk Delete

2007-11-15 Thread Sam Mason
On Thu, Nov 15, 2007 at 09:43:52AM -0500, Andrew Sullivan wrote: On Thu, Nov 15, 2007 at 03:33:04PM +0200, Abraham, Danny wrote: Based on a condition, 2,000,000 records should be deleted daily. Why not use that condition (which I presume is indexed) as the criterion for your delete? I

Re: [GENERAL] Enforcing Join condition

2007-11-15 Thread Sam Mason
On Thu, Nov 15, 2007 at 01:24:04PM +0530, ??? ?? wrote: Is there a way to force join conditions in queries i.e. When a join is made to a table on a particular field, another column should also be checked? CREATE TABLE test (info_type varchar(3), info_reference

Re: [GENERAL] Variable LIMIT and OFFSET in SELECTs

2007-11-15 Thread Sam Mason
On Thu, Nov 15, 2007 at 06:08:20PM +0100, Reg Me Please wrote: Your remarks make a lot of sense. Of course. good! it's interesting to see how things like this fit together. But then why allowing the LIMIT and the OFFSET as coming from function argument evaluations? I believe the query is

Re: [GENERAL] Variable LIMIT and OFFSET in SELECTs

2007-11-15 Thread Sam Mason
On Thu, Nov 15, 2007 at 05:34:43PM +0100, Reg Me Please wrote: Il Thursday 15 November 2007 14:09:16 Trevor Talbot ha scritto: On 11/15/07, Reg Me Please [EMAIL PROTECTED] wrote: In any case, what'd be the benefit for not allowing variables as LIMIT and OFFSET argument? When you can

Re: [GENERAL] Enforcing Join condition

2007-11-15 Thread Sam Mason
On Thu, Nov 15, 2007 at 07:46:46PM +0530, ??? ?? wrote: On Nov 15, 2007 5:52 PM, Sam Mason [EMAIL PROTECTED] wrote: What I tend to do here, is something like: CREATE TABLE test ( type INTEGER, ref1 INTEGER REFERENCES table1 CHECK ((type = 1

Re: [GENERAL] Chunk Delete

2007-11-15 Thread Sam Mason
On Thu, Nov 15, 2007 at 02:46:09PM +0100, Alexander Staubo wrote: On 11/15/07, Abraham, Danny [EMAIL PROTECTED] wrote: With Oracle we do it with: delete ,tname where cond and rownum Y; You could create a temporary sequence: create temporary sequence foo_seq; delete from foos

Re: [GENERAL] Variable LIMIT and OFFSET in SELECTs

2007-11-15 Thread Sam Mason
On Thu, Nov 15, 2007 at 07:28:17PM +, Richard Huxton wrote: Reg Me Please wrote: As Sam says I should be able to put an IMMUTABLE expression into a LIMIT or OFFSET. And under some circumstances (SQL function body) it's true even with VARIABLE expressions like function call arguments.

Re: [GENERAL] getting the number of rows affected by a query

2007-11-16 Thread Sam Mason
On Fri, Nov 16, 2007 at 09:00:46AM +0800, Ow Mun Heng wrote: I'm trying to do some periodic updates from another DB and would like to know the # of updates/inserts/deletes from that job. Humm; it would be nice if you could use the new RETURNING construct that's been introduced in 8.2, i.e.

Re: [GENERAL] Primary Key

2007-11-16 Thread Sam Mason
On Fri, Nov 16, 2007 at 03:50:20PM -0300, Jo??o Paulo Zavanela wrote: How many fields is recomended to create a primary key? I'm thinking to create one with 6 fields, is much? Normally a primary key would just be a single column. When you start going to that many I'd probably have a serial

Re: [GENERAL] Primary Key

2007-11-16 Thread Sam Mason
( Fi Fie Foe Fum, I smell the blood of a religious war ) On Fri, Nov 16, 2007 at 01:03:23PM -0600, Ron Johnson wrote: On 11/16/07 12:54, Sam Mason wrote: On Fri, Nov 16, 2007 at 03:50:20PM -0300, Jo??o Paulo Zavanela wrote: How many fields is recomended to create a primary key? I'm

Re: [GENERAL] field doesn't exist even though I'm sure it does

2007-11-16 Thread Sam Mason
On Fri, Nov 16, 2007 at 03:13:48PM -0500, Tom Hart wrote: column isactive of relation membermailingaddress does not exist Table public.membermailingaddress Column | Type | Modifiers -+--+--- IsActive| boolean | If you

Re: [GENERAL] Primary Key

2007-11-16 Thread Sam Mason
On Fri, Nov 16, 2007 at 12:06:46PM -0800, Joshua D. Drake wrote: When that is needed I do this: create table foo(id serial unique, a text, b text, primary (a,b)); Humm, so the other way around from what I've ended up doing. I'll need to think about the implications of changing things around

Re: [GENERAL] getting the number of rows affected by a query

2007-11-16 Thread Sam Mason
On Fri, Nov 16, 2007 at 12:51:07PM +, Raymond O'Donnell wrote: On 16/11/2007 10:02, Sam Mason wrote: SELECT COUNT(*) FROM ( DELETE FROM foo RETURNING 1) x; I haven't played with this yet, but AFAICS this will simply return the integer value 1. I currently get a syntax error

Re: [GENERAL] unexplainable error

2007-11-16 Thread Sam Mason
On Fri, Nov 16, 2007 at 01:58:21PM +0100, [EMAIL PROTECTED] wrote: Every time, after mass import into the database (it's a development server, so the import updates the database with full dump from the production server) - the first several clicks on the development web site return -

Re: [GENERAL] Variable LIMIT and OFFSET in SELECTs

2007-11-16 Thread Sam Mason
On Fri, Nov 16, 2007 at 01:38:30AM -0500, Tom Lane wrote: Sam Mason [EMAIL PROTECTED] writes: wow, that's kind of fun isn't it. I only thought you could put a constant in there. Maybe I should have had a look in the grammar/tested it first! IIRC, it used to be restricted to a constant

Re: [GENERAL] Common criteria evaluation?

2007-11-16 Thread Sam Mason
On Fri, Nov 16, 2007 at 01:34:40PM -0500, Greg Smith wrote: On Fri, 16 Nov 2007, Sam Mason wrote: Just out of interest, what does EAL level 1 actually test/check for? There's a good summary of this whole process on the relevant Wikipedia pages: http://en.wikipedia.org/wiki

Re: [GENERAL] Common criteria evaluation?

2007-11-16 Thread Sam Mason
On Thu, Nov 15, 2007 at 07:35:52PM -0800, Geoff wrote: I know an older version of PostgreSQL for Linux was evaluated at EAL 1 in Japan. Are there any other versions that are going through this now? Just out of interest, what does EAL level 1 actually test/check for? I'd assume that it was a

Re: [GENERAL] Primary Key

2007-11-16 Thread Sam Mason
On Fri, Nov 16, 2007 at 04:41:42PM -0500, Merlin Moncure wrote: On Nov 16, 2007 3:21 PM, Sam Mason [EMAIL PROTECTED] wrote: On Fri, Nov 16, 2007 at 12:06:46PM -0800, Joshua D. Drake wrote: When that is needed I do this: create table foo(id serial unique, a text, b text, primary (a,b

Re: [GENERAL] Primary Key

2007-11-18 Thread Sam Mason
On Sun, Nov 18, 2007 at 04:19:01AM +, Ron Johnson wrote: If the PK was synthetic and generated by the engine, then a (buggy) app could insert duplicate tolls and the system wouldn't utter a peep. But the customer sure would when he saw the duplicate entries. You'd just need to put a

Re: [GENERAL] GIN: any ordering guarantees for the hits returned?

2007-11-18 Thread Sam Mason
On Sun, Nov 18, 2007 at 09:59:41AM -0800, David Fetter wrote: Ordering is never guaranteed without an ORDER BY, except in the time between a CLUSTER and the first write operation after it. It's my understanding that with the new seqscan piggy-backing in 8.3 even this will go. I'm not sure if

Re: [GENERAL] Timestamp comparison with string in some special cases

2007-11-19 Thread Sam Mason
On Mon, Nov 19, 2007 at 04:52:10PM +0100, Dragan Matic wrote: select * from table where timestamp_column '11/19/2007 15:46:09 PM' Maybe the to_timestamp() function would help you: SELECT to_timestamp('11/19/2007 15:46:09 PM','MM/DD/ HH24:MI:SS') - 2007-11-19 15:46:09+00 That just

Re: [GENERAL] Timestamp comparison with string in some special cases

2007-11-19 Thread Sam Mason
On Mon, Nov 19, 2007 at 06:03:36PM +0100, Dragan Matic wrote: Sam Mason wrote: On Mon, Nov 19, 2007 at 04:52:10PM +0100, Dragan Matic wrote: select * from table where timestamp_column '11/19/2007 15:46:09 PM' Maybe the to_timestamp() function would help you: SELECT

Re: [GENERAL] Primary Key

2007-11-23 Thread Sam Mason
On Fri, Nov 23, 2007 at 12:00:18PM +0100, Csaba Nagy wrote: I'm not sure how it is in the US, but here in Germany I just reused a car plate from the owner it had before me... so now the plate is uniquely associated at most with the car, not the owner... and I'm pretty sure that's not unique

Re: [GENERAL] PL/pgSQL and SETOF

2007-11-30 Thread Sam Mason
On Fri, Nov 30, 2007 at 09:09:28AM -0800, Cultural Sublimation wrote: Postgresql complains that set-valued function called in context that cannot accept a set. Anyway, what am I doing wrong, and what is the simplest way of translating get_items in PL/pgSQL? I would guess you're calling it

Re: [GENERAL] difficulty extracting variable-sized field on triggered row

2007-12-04 Thread Sam Mason
On Tue, Dec 04, 2007 at 10:11:04AM -0600, Glen W. Mabey wrote: Searching for DatumGetTextP from the search text box at the top of www.postgresql.org yields no hits, and a google search on DatumGetTextP does not seem to turnip [sic] any direct documentation on this function. Is there

Re: [GENERAL] aggregate and order by

2007-12-07 Thread Sam Mason
On Thu, Dec 06, 2007 at 02:12:48PM -0600, Matthew Dennis wrote: I want to create an aggregate that will give the average velocity (sum of distance traveled / sum of elapsed time) from position and timestamps. How do you want to handle noisy data? If you want to handle it in any reasonable way

Re: [GENERAL] Q: using generate_series to fill in the blanks

2007-12-07 Thread Sam Mason
On Fri, Dec 07, 2007 at 01:18:13PM +0800, Ow Mun Heng wrote: select i.i as vdt,dcm_evaluation_code as c_id , case when count(vdt_format) = 0 then NULL else count(vdt_format) end as count from generate_series(1,7) i left join footable f on i.i = f.vdt_format and c_id in ('71','48') group by

Re: [GENERAL] How can I insert NULL into column with the type of timestamp?

2007-12-12 Thread Sam Mason
On Tue, Dec 11, 2007 at 10:29:04AM +0800, bookman bookman wrote: So it means that the column with type timestamp cannot accept a NULL .Is there any way I can tansfer this table into postgre?How can i deal with NULL in this case? NULL values are encoded as an unquoted \N by default in PG.

Re: [GENERAL] Efficiency vs. code bloat for SELECT wrappers

2007-12-17 Thread Sam Mason
On Mon, Dec 17, 2007 at 12:49:46PM -0500, Colin Wetherbee wrote: Because I know Perl a whole lot better than SQL, PostgreSQL, and even the Perl DBI, I'm always inclined to wrap the database stuff in a nice little package and forget about it. This method has worked well for me in the past,

Re: [GENERAL] Efficiency vs. code bloat for SELECT wrappers

2007-12-17 Thread Sam Mason
On Mon, Dec 17, 2007 at 01:29:10PM -0500, Ted Byers wrote: I routinely keep my SQL code distinct from my Perl, java or C++ code. When a client program needs to do something with the database, then either a child process executes a script I have written, if the client program doesn't need to

Re: [GENERAL] referential integrity and defaults, DB design or trick

2007-12-20 Thread Sam Mason
On Thu, Dec 20, 2007 at 06:31:47PM +0100, Ivan Sergio Borgonovo wrote: On Thu, 20 Dec 2007 09:55:29 -0600 Erik Jones [EMAIL PROTECTED] wrote: On Dec 20, 2007, at 8:50 AM, Ivan Sergio Borgonovo wrote: On Wed, 19 Dec 2007 17:24:52 +0100 Ivan Sergio Borgonovo [EMAIL PROTECTED] wrote: I've

Re: [GENERAL] Hash Indexes

2008-01-07 Thread Sam Mason
On Tue, Jan 08, 2008 at 01:49:53AM +1100, Naz Gassiep wrote: You could always do something like: CREATE INDEX foo ON table((md5(textcol))); Then it will get used in queries like: SELECT * FROM table WHERE md5(textcol) = md5('text'); That's exactly what I was considering doing, however

Re: [GENERAL] many to one of many modeling question

2008-01-08 Thread Sam Mason
On Mon, Jan 07, 2008 at 02:32:26PM -0500, Kevin Hunter wrote: Something along the lines of CREATE TABLE o_1 ( id SERIAL ... ); CREATE TABLE o_2 ( id SERIAL ... ); CREATE TABLE o_3 ( id SERIAL ... ); CREATE TABLE comments ( id SERIAL, obj_id INTEGER ... FOREIGN KEY (obj_id)

Re: [GENERAL] Getting the count(*) from two tables and two date ranges in same query

2008-01-28 Thread Sam Mason
On Mon, Jan 28, 2008 at 03:11:10PM +0100, H??kan Jacobsson wrote: Resulting in 4 columns in the ResultSet like: count(*)_from_table2_between_fromdate1_and_todate1 = X count(*)_from_table2_between_fromdate2_and_todate2 = Y count(*)_from_table3_between_fromdate1_and_todate1 = Z

[GENERAL] handling of COUNT(record) vs IS NULL

2008-01-28 Thread Sam Mason
Hi, I've just noticed that the handling of COUNT(record) and (record IS NULL) aren't consistent with my understanding of them. If I run the following query: SELECT NULL IS NULL, COUNT( NULL ), (NULL,NULL) IS NULL, COUNT((NULL,NULL)); The IS NULL checks both return TRUE as

Re: [GENERAL] handling of COUNT(record) vs IS NULL

2008-01-28 Thread Sam Mason
On Mon, Jan 28, 2008 at 04:38:01PM -0500, Tom Lane wrote: Sam Mason [EMAIL PROTECTED] writes: I've just noticed that the handling of COUNT(record) and (record IS NULL) aren't consistent with my understanding of them. If I run the following query: SELECT NULL IS NULL

Re: [GENERAL] referencing to computed columns in where clause

2008-01-29 Thread Sam Mason
On Tue, Jan 29, 2008 at 06:04:48PM +0100, Ivan Sergio Borgonovo wrote: select case when (a3) then a*b when (a3) then a+b end as pippo where pippo12; I've tended to do: SELECT * FROM ( SELECT complicated expression AS pippo) x WHERE pippo 12; Sam

Re: [GENERAL] referencing to computed columns in where clause

2008-01-31 Thread Sam Mason
On Tue, Jan 29, 2008 at 06:49:50PM +0100, Ivan Sergio Borgonovo wrote: On Tue, 29 Jan 2008 17:17:39 + Sam Mason [EMAIL PROTECTED] wrote: I've tended to do: SELECT * FROM ( SELECT complicated expression AS pippo) x WHERE pippo 12; It risk to be much harder

Re: [GENERAL] Getting the count(*) from two tables and two date ranges in same query

2008-01-31 Thread Sam Mason
On Wed, Jan 30, 2008 at 09:52:17AM +0100, H??kan Jacobsson wrote: I just realised that issuing the SQL on one table produces the correct count. SELECT sum(case when table2.date between '2007-07-13' and '2007-07-13' then 1 else 0 end) as sumx FROM table2 WHERE id = n; This is working

Re: [GENERAL] How to paste two tables side-by-side?

2008-02-28 Thread Sam Mason
On Wed, Feb 27, 2008 at 07:39:51AM -0500, Kynn Jones wrote: Suppose I have two tables, A and B, with k(A) and k(B) columns respectively, and let's assume to begin with that they have the same number of rows r(A) = r(B) = r. What's the simplest way to produce a table C having r rows and k(A) +

Re: [GENERAL] WAL Log Size

2008-02-28 Thread Sam Mason
On Thu, Feb 28, 2008 at 04:35:44PM -0500, Greg Smith wrote: Courtesy of Simon ( http://archives.postgresql.org/pgsql-general/2007-06/msg00015.php ) you can force 16MB worth of WAL activity that doesn't leave any changes behind with: create table xlog_switch as select '0123456789ABCDE'

Re: [GENERAL] LIMIT Question

2008-02-29 Thread Sam Mason
On Fri, Feb 29, 2008 at 05:28:29PM +0530, Gurjeet Singh wrote: On Fri, Feb 29, 2008 at 3:55 PM, Martijn van Oosterhout [EMAIL PROTECTED] wrote: Except if you have an index on the column you're ordering by. Then the server can really return the first row quickly. Quickly for sure... but I

Re: [GENERAL] ISO something like #if 0 ... #endif for SQL code

2008-03-11 Thread Sam Mason
On Mon, Mar 10, 2008 at 10:50:26AM -0500, Kynn Jones wrote: Hi! When it comes to programming SQL, my newbie approach is to write my code in a file test.sql, which I test from within psql by using my_db= \i /some/path/test.sql ...and (once I'm satisfied with the code) copy and paste it

Re: [GENERAL] FROM + JOIN when more than one table in FROM

2008-03-13 Thread Sam Mason
On Wed, Mar 12, 2008 at 12:48:22PM +0100, Ivan Sergio Borgonovo wrote: On Wed, 12 Mar 2008 11:48:24 +0100 Martijn van Oosterhout [EMAIL PROTECTED] wrote: Perhaps this would owrk: FROM sm inner join st inner join pt inner join pm one of the inner join doesn't have an on relationship.

Re: [GENERAL] postgre vs MySQL

2008-03-14 Thread Sam Mason
On Fri, Mar 14, 2008 at 03:17:27PM +0530, Gurjeet Singh wrote: On Thu, Mar 13, 2008 at 6:06 PM, rrahul [EMAIL PROTECTED] wrote: Thanks to all you wonderful people out their. I don't know if its your love for Postgres or nepothism that makes it look far superior than mysql. I wouldn't

Re: [GENERAL] Using PL/R for predictive analysis of data.

2008-03-14 Thread Sam Mason
On Wed, Mar 12, 2008 at 09:35:24AM -0700, [EMAIL PROTECTED] wrote: In short R appears to have more than enough capability to do the job (from a statistical perspective), however there doesnt seem to be that much discussion on using the PL/R implementation, or for that matter tutorials on using

Re: [GENERAL] [postgis-users] how many min. floating-points?

2008-03-20 Thread Sam Mason
On Thu, Mar 20, 2008 at 02:02:12PM -0400, John Smith wrote: how many min. floating-points must a server hardware support for postgresql+postgis? does postgresql+postgis do much floating-point math to make a difference? can someone give postgresql+postgis application examples that will require

Re: [GENERAL] Make MS Access UPDATE PostGre SQL Table

2008-03-25 Thread Sam Mason
On Mon, Mar 24, 2008 at 07:08:13AM -0600, Pettis, Barry wrote: I'm fairly new to DBMS's and PostGre SQL in particular. Most of my experience is with MS Access. I've created MS Access to retrieve data from PostGre by linking tables and have done so without error. If you've linked the

Re: [GENERAL] select any table

2008-03-26 Thread Sam Mason
On Tue, Mar 25, 2008 at 05:37:00PM -0400, Malinka Rellikwodahs wrote: On Tue, Mar 25, 2008 at 2:54 PM, Joshua D. Drake wrote: On Tue, 25 Mar 2008 13:37:37 -0500 Jon Roberts wrote: It would be a nice enhancement to have a select any table privilege or at least grant

Re: [GENERAL] pgplsql, how to save row variable to a table row

2008-03-26 Thread Sam Mason
On Wed, Mar 26, 2008 at 01:14:07PM +0100, josep porres wrote: I've tried: EXECUTE 'INSERT INTO F2_TEMPFAC SELECT * FROM row_tempf'; I think that: INSERT INTO f2_tempfac SELECT (row_tempf).*; should do what you want. Unless you're doing something very fancy you don't want the execute

Re: [GENERAL] select any table

2008-03-26 Thread Sam Mason
. disallows revoking of access) should be taken out and shot quickly. Any language of reasonable complexity will support some form of information hiding (aka abstraction) and suggesting you can stop this by disallowing revoking of access is just silly. Sam Mason wrote: In ACL (Access Control List

Re: [GENERAL] Survey: renaming/removing script binaries (createdb, createuser...)

2008-03-26 Thread Sam Mason
1. b 2. c 3. d 4. b and c I do most of my admin using SQL these days. my preference would be towards keeping them because they're nice in the beginning. Sam -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription:

Re: [GENERAL] oddly high cost but low actual_time (but not in slony replicants)

2008-03-26 Thread Sam Mason
On Wed, Mar 26, 2008 at 01:23:22PM -0500, Jeff Amiel wrote: explain analyze select * from table_a; Seq Scan on table_a (cost=1.00..10001.02 rows=19 width=103) (actual time=0.007..0.012 rows=19 loops=1) Total runtime: 0.040 ms any ideas? Looks like you've disabled seqscans.

Re: [GENERAL] casting from integer to boolean

2008-03-26 Thread Sam Mason
On Wed, Mar 26, 2008 at 05:28:18PM -0500, Seb wrote: On Wed, 26 Mar 2008 15:11:47 -0700, Richard Broersma [EMAIL PROTECTED] wrote: [...] INSERT INTO my_table (var_bool) VALUES ( CAST( 0 AS BOOLEAN )); or INSERT INTO my_table (var_bool) VALUES (0::BOOLEAN); Thanks Richard. Is there

Re: [GENERAL] Performance of update

2008-03-27 Thread Sam Mason
On Wed, Mar 26, 2008 at 01:26:03PM -0700, Sam wrote: Iam trying to update a database table with approx 45000 rows. Iam not updating all rows at a time. Iam updating 60 rows at a given time for example. and this is happening in a FOR LOOP. A function that has the update statements is called

Re: [GENERAL] returned value from SQL statement

2008-03-27 Thread Sam Mason
On Thu, Mar 27, 2008 at 11:25:18AM +0100, Alain Roger wrote: not really.. but it is true that it can be confusing...sorry :-( the purpose here, it is to solve my problem with a transaction inside a function. hum, I think PG works a little differently than you think. a function is run inside

Re: [GENERAL] dunction issue

2008-03-27 Thread Sam Mason
On Thu, Mar 27, 2008 at 08:43:46PM +0100, Alain Roger wrote: i have a problem solving my function trouble. this function should return an email address stored in a table (tmp_newsletterreg) based on a number (sessions ID). if the session id is not find it should return a string corresponding

Re: [GENERAL] dunction issue

2008-03-27 Thread Sam Mason
On Thu, Mar 27, 2008 at 03:34:49PM -0700, Adrian Klaver wrote: Or a simpler way to do handle my previous suggestion: IF (ret_email IS NULL ) OR (ret_email='') THEN RETURN ('-3') That would be the sane fix, yes. Based on the previous emails from the OP, he seems to be missing a lot of

Re: [GENERAL] dunction issue

2008-03-28 Thread Sam Mason
On Fri, Mar 28, 2008 at 06:43:00PM +0900, Craig Ringer wrote: Alain Roger wrote: I do not agree with you Sam. Stored procedure are safe from hacking (from external access). In that a stored procedure encapsulates a series of data operations, meaning that the client doesn't have to know

Re: [GENERAL] SELECT DISTINCT ON and ORDER BY

2008-03-28 Thread Sam Mason
On Fri, Mar 28, 2008 at 01:12:49PM +0100, Stanislav Raskin wrote: id value order_field 1 10 3 2 12 4 3 10 1 45 8 5 12 2 Hence selecting rows with distinct values, but primarily ordered by order_field, instead of value, which is requires by DISTINCT

Re: [GENERAL] dunction issue

2008-03-28 Thread Sam Mason
On Sat, Mar 29, 2008 at 04:05:15AM +0900, Craig Ringer wrote: Sam Mason wrote: ALTER TABLE tmp_newsletterreg ADD CONSTRAINT simplistic_email_check CHECK lower(trim(both ' ' from email)) LIKE '[EMAIL PROTECTED]'; Just out of interest, what's the lower() function call doing? Absolutely

Re: [GENERAL] Escaping \n

2008-03-28 Thread Sam Mason
On Fri, Mar 28, 2008 at 05:06:10PM -0400, Terry Lee Tucker wrote: HINT: Use the escape string syntax for escapes, e.g., E'\r\n'. The problem is a line like 'UPDATE bill SET notes = 'blah, blah, yea\nmore stuff'; How to I escape the newline embeded in the string? I've tried the advice

Re: [GENERAL] Escaping \n

2008-03-28 Thread Sam Mason
On Fri, Mar 28, 2008 at 05:29:06PM -0400, Terry Lee Tucker wrote: Thanks Sam. No, that is not what I tried. I had tried: UPDATE bill SET notes = 'blah, blah, yeaE'\n'more stuff.' It didn't dawn on me that the E went in front of the whole string! it's always easy when you know how! Thanks for

Re: [GENERAL] Using tables in other PostGreSQL database

2008-04-01 Thread Sam Mason
On Tue, Apr 01, 2008 at 09:12:54AM -0600, Pettis, Barry wrote: I guess the biggest problem is trying to describe something in terms that all can understand. On a forum like this most CONTRIBUTORS those who answer questions speak a language that the typical novice poster doesn't use or

Re: [GENERAL] choosing the right locking mode

2008-04-03 Thread Sam Mason
On Thu, Apr 03, 2008 at 09:44:55PM +0500, rihad wrote: Given this type query: UPDATE bw_pool SET user_id=? WHERE bw_id= (SELECT MIN(bw_id) FROM bw_pool WHERE user_id IS NULL) RETURNING bw_id The idea is to single-threadedly get at the next

Re: [GENERAL] percentile rank query

2008-04-10 Thread Sam Mason
On Thu, Apr 10, 2008 at 05:20:21PM +0100, William Temperley wrote: SELECT count(*) AS frequency, score, SELECT count(uid) FROM scoretable st2 WHERE st2.score = st1.score) - count(*)) + (count(*)/2))::float/(select count(*) from scoretable)) FROM scoretable st1 GROUP BY score ORDER BY

Re: [GENERAL] Post-installation questions

2008-04-12 Thread Sam Mason
On Sat, Apr 12, 2008 at 03:05:41PM +, william wayne wrote: This is a newbie question as I have not used the product before. After installation of PG 8.2 I noticed that I have 2 servers: postgresql database server 8.2 (localhost:5432) and another one differing only in the name (the second

Re: [GENERAL] SQL injection, php and queueing multiple statement

2008-04-12 Thread Sam Mason
On Sat, Apr 12, 2008 at 11:06:42PM +0200, Ivan Sergio Borgonovo wrote: But what about already written code that use pg_query? If you rewrite the database interface then it doesn't matter, the calls to pg_query will end up being calls to prepare/execute underneath so you'll have their protection.

Re: [GENERAL] No Return??

2008-04-13 Thread Sam Mason
On Sun, Apr 13, 2008 at 01:07:26PM -0700, Bob Pawley wrote: When I try it as a whole I get the message control reached end of trigger procedure without RETURN. I've re-indented the code to make it a bit more obvious what's going on in your old version: DECLARE pumpnumber integer; BEGIN

Re: [GENERAL] Storage sizes for dates/times (documentation bug?)

2008-04-15 Thread Sam Mason
On Tue, Apr 15, 2008 at 02:46:14PM +0200, Karsten Hilbert wrote: Of course, the actual time stored in the database in UTC is quite correct - it was indeed 3pm in location B when it was 7am in London. But we need to know the original local time (and also be able to know UTC since we want to

Re: [GENERAL] Storage sizes for dates/times (documentation bug?)

2008-04-15 Thread Sam Mason
On Tue, Apr 15, 2008 at 04:04:20PM +0200, Karsten Hilbert wrote: On Tue, Apr 15, 2008 at 02:31:22PM +0100, Sam Mason wrote: On Tue, Apr 15, 2008 at 02:46:14PM +0200, Karsten Hilbert wrote: Of course, the actual time stored in the database in UTC is quite correct - it was indeed 3pm

Re: [GENERAL] Storage sizes for dates/times (documentation bug?)

2008-04-15 Thread Sam Mason
On Tue, Apr 15, 2008 at 06:48:27AM -0700, Adrian Klaver wrote: On Tuesday 15 April 2008 6:31 am, Sam Mason wrote: My reasoning goes something like this: The WITH and WITHOUT clauses seem to be the opposite of my naive understanding of their purpose. I'd think that if you specify WITH TIME

  1   2   3   4   5   6   7   >