Re: [SQL] alter column type from boolean to char with default

2006-08-02 Thread Rod Taylor
On Wed, 2006-08-02 at 09:19 -0400, Tom Lane wrote: > "Markus Bertheau" <[EMAIL PROTECTED]> writes: > > I basically want to change a boolean column to char. The boolean > > column has a default of true. The char column should have 'f' for > > false and 't' for true. I think that an SQL statement lik

Re: [SQL] Alternative to Select in table check constraint

2006-07-01 Thread Rod Taylor
On Fri, 2006-06-30 at 18:41 -0700, Richard Broersma Jr wrote: > > > CHECK ( 1 = ALL ( SELECT COUNT(STATUS) > > > FROM BADGES > > > WHERE STATUS = 'A' > > > GROUP BY EMPNO)) > > > > From t

Re: [SQL] sessions and prepared statements

2006-06-16 Thread Rod Taylor
On Fri, 2006-06-16 at 08:27 -0400, John DeSoi wrote: > On Jun 15, 2006, at 11:49 AM, chester c young wrote: > > > in PHP for example, where there are multiple sessions and which you > > get is random: > > > > how do you know if the session you're in has prepared a particular > > statement? > >

Re: [SQL] SQL Technique Question

2006-06-15 Thread Rod Taylor
On Thu, 2006-06-15 at 13:59 -0700, [EMAIL PROTECTED] wrote: > i frequently join certain tables together in various > tables. > is it a good practice to leave this included in the > queries, as is, or should i factor it out somehow? if > i should factor it, how do i do so? Future proofing selects

Re: [SQL] Efficient Searching of Large Text Fields

2006-06-13 Thread Rod Taylor
On Tue, 2006-06-13 at 15:30 -0500, Aaron Bono wrote: > In another post on a different topic, Rod Taylor said the following: > > "A\tcat in the\nhat" might be stored as ARRAY['A', 'cat', 'in', 'the', > 'hat']. >

Re: [SQL] COPY to table with array columns (Longish)

2006-06-12 Thread Rod Taylor
On Mon, 2006-06-12 at 21:58 -0500, Aaron Bono wrote: > I agree with Tom. Personally I cannot think of a time I would use an > array column over a child table. Maybe someone can enlighten me on > when an array column would be a good choice. Arrays are a good choice when the data comes naturally s

Re: [SQL] Am I crazy or is this SQL not possible

2006-06-01 Thread Rod Taylor
On Thu, 2006-06-01 at 14:13 -0400, Yasir Malik wrote: > > What I would like to do is simply get the last date_sent and it's > > status for every broadcast. I can't do a GROUP BY because I can't put > > an aggregate on the status column. > > > > SELECT MAX(date_sent), status > > FROM broadcast_hist

Re: [SQL] Table design question

2006-06-01 Thread Rod Taylor
> So I'm designing a table and I'm looking for an appropriate key. The > natural key is a string from a few characters up to a maximum of > perhaps 100. Joe gets quite fierce about avoiding the use of a serial > id column as a key. The string is unique in the table and fits the > criteria for a key

Re: [SQL] Find min and max values across two columns?

2006-03-24 Thread Rod Taylor
On Fri, 2006-03-24 at 16:20 -0500, Tom Lane wrote: > Rod Taylor <[EMAIL PROTECTED]> writes: > > The reason for the subselect is to prevent multiple calculations of > > individual column aggregates. I believe it *may* be calculated multiple > > times otherwise t

Re: [SQL] Find min and max values across two columns?

2006-03-24 Thread Rod Taylor
On Fri, 2006-03-24 at 15:19 -0500, Amos Hayes wrote: > Hello. I've recently begun to use PostgreSQL in earnest (working with > data as opposed to just having clever applications tuck it away in > there) and have hit a wall with something. > > I'm trying to build a query that among other things

Re: [SQL] have you feel anything when you read this ?

2006-03-20 Thread Rod Taylor
On Mon, 2006-03-20 at 17:53 +0300, Eugene E. wrote: > I wrote: > > >> the problem is: you'll get this four byte sequence '\000' _instead_ > >> of NUL-byte anyway. > > You wrote: > > > Your client library should take care of escaping and de-escaping. > > We both agree as you see. > > Then i

Re: [SQL] Permission to Select

2006-03-13 Thread Rod Taylor
On Mon, 2006-03-13 at 10:46 -0400, Alvaro Herrera wrote: > Rod Taylor wrote: > > > By allowing the user a where clause you grant them select privileges. > > You will find that delete works the same way. > > > > This is one of those times when per column permiss

Re: [SQL] Permission to Select

2006-03-13 Thread Rod Taylor
On Mon, 2006-03-13 at 12:51 +0300, Eugene E. wrote: > Hi all > the serious problem with permissions is encountered > > NOTE: the following example is really useful but there is no room to > describe it's use. > > > db=# CREATE USER u; > db=# CREATE TABLE t (i int, a text); > db=# REVOKE all ON

Re: [SQL] Is there any way to stop triggers from cycling?

2006-03-08 Thread Rod Taylor
> I'm experimenting with a set of triggers to automagically maintain > ltrees-organized tables. I almost have it working, except for a pesky > problem with re-ordering groups. > Currently I'm doing this by only cascade-updating the row adjacent to the > one I'm moving. However, this is resul

Re: [SQL] indexing for left join

2006-01-19 Thread Rod Taylor
> Sequential despite the indices? Or is this because the tables of my test > DB are virtually empty? This is it. PostgreSQL changes strategies with data load. Performance testing must be done on an approximation of the real data (both values and size). -- ---(end of br

Re: [SQL] DEFAULT Constraint based on table type?

2005-11-28 Thread Rod Taylor
On Mon, 2005-11-28 at 14:22 -0600, Announce wrote: > Lets say I have the following tables. > > CREATE TABLE animals(id primary key, name varchar, type varchar); > CREATE TABLE dogs (breed varchar)INHERITS (animals); > CREATE TABLE birds (bool hasFeathers) INHERITS (animals); r=# alter

Re: [SQL] Foreign key to 2 tables problem

2005-11-22 Thread Rod Taylor
On Tue, 2005-11-22 at 16:24 +0100, Joost Kraaijeveld wrote: > Hi, > > Is there a way to create a foreign key to 2 tables: e.g. a bankaccount > table that has a column "owner", that must point to a record in either > the customer or the supplier table? No. What you need is an owner table that cust

Re: [SQL] time

2005-11-10 Thread Rod Taylor
On Thu, 2005-11-10 at 11:21 -0700, Michael Fuhr wrote: > On Thu, Nov 10, 2005 at 01:11:27PM -0500, Rod Taylor wrote: > > rbt=# select cast(now() - date_trunc('day', now()) as time); > > time > > - > > 13:10:42.495579 > > (1 ro

Re: [SQL] time

2005-11-10 Thread Rod Taylor
On Thu, 2005-11-10 at 09:03 -0600, Judith Altamirano Figueroa wrote: > Hello everybody!!!, I'd like to know if there another way to get the > time from a timestamp type, because in earliest versions I just get > the time like time(fecha) and now this returns an error, thanks in > advanced!!! r

Re: [SQL] How to join several selects

2005-08-24 Thread Rod Taylor
On Wed, 2005-08-24 at 15:46 +0200, Josep Sanmartí wrote: > Hello, > I have a 'big' problem: > I have the following table users(name, start_time, end_time), a new row > is set whenever a user logs into a server. I want to know how many > users have logged in EVERYDAY between 2 different dates. Th

Re: [SQL] Make COUNT(*) Faster?

2005-07-08 Thread Rod Taylor
On Fri, 2005-07-08 at 17:34 +0200, Dawid Kuroczko wrote: > On 7/8/05, Rod Taylor <[EMAIL PROTECTED]> wrote: > > Create 2 sequences, one for counting tuple additions and one for > > counting tuple deletions. > > > > When you INSERT a tuple, bump the

Re: [SQL] Make COUNT(*) Faster?

2005-07-08 Thread Rod Taylor
> So, leave COUNT(*) alone. But it would be very handy to have a > way to get an approximate table size that is more accurate than is > provided by a pg_class.reltuples that is only updated on vacuums. Create 2 sequences, one for counting tuple additions and one for counting tuple deletions. Whe

Re: [SQL] ENUM like data type

2005-06-29 Thread Rod Taylor
On Wed, 2005-06-29 at 10:21 -0300, Martín Marqués wrote: > El Mié 29 Jun 2005 09:40, KÖPFERL Robert escribió: > > > > | > > |I personally think that the ENUM data type is for databases > > |that are not well > > |designed. So, if you see the need for ENUM, that means you > > |need to re-think

Re: [SQL] empty view, replace view, column type change?

2005-06-23 Thread Rod Taylor
On Thu, 2005-06-23 at 22:27 +0200, Markus Bertheau wrote: > Dnia 23-06-2005, czw o godzinie 16:19 -0400, Rod Taylor napisał(a): > > > The data types are different, as one has the timestamp to (6) decimal > > places after seconds. > > That's strange. I explicitly spec

Re: [SQL] empty view, replace view, column type change?

2005-06-23 Thread Rod Taylor
On Thu, 2005-06-23 at 22:03 +0200, Markus Bertheau wrote: > Hi, > > it seems to me that the following should work but it fails: > > CREATE VIEW co AS SELECT LOCALTIMESTAMP::TIMESTAMP AS ov WHERE FALSE; > CREATE TABLE link (ov TIMESTAMP); > CREATE OR REPLACE VIEW co AS SELECT ov FROM link; The da

Re: [SQL] ORDER BY handling mixed integer and varchar values

2005-05-16 Thread Rod Taylor
> Is there any elegent query you folks can think of that combines the > two so I can one query that has alpha sorting on alpha categories and > numeric sorting on numeric values that are in the same column?? select * from r order by (case when col ~ '^[0-9]+$' THEN lpad(col, 10, '0') else col end)

Re: [SQL] SQL subquery (count distinct) - Any Ideas?

2005-04-18 Thread Rod Taylor
On Wed, 2005-04-13 at 18:28 +0100, Matt Fulford wrote: > I'm trying to write a query to return the number of different customers > called on a single day. The database has a table called 'user', a table > called 'caller_session' which references a 'user' record, and a table called > 'call' whic

Re: [SQL] Getting the output of a function used in a where clause

2005-04-18 Thread Rod Taylor
On Tue, 2005-04-12 at 23:08 -0700, Bill Lawrence wrote: > Thanks, > > Unfortunately, I think that solution requires the distance calculation to be > executed twice for each record in the table. There are ~70K records in the > table. Is the postgres query optimizer smart enough to only perform the

Re: [SQL] About "Alter table... alter column.. TYPE ... "

2005-04-18 Thread Rod Taylor
> To alter table column from varchar(32) to date. "Alter table" command > does not seem to work: > > alter table test alter column col type date ; > ERROR: column "col1" cannot be cast to type "date" Alter table will not automatically throw away information. That is, in cases where it believes

Re: [SQL] getting count for a specific querry

2005-04-08 Thread Rod Taylor
> > select * from mytable where somecondition AND uniquecol>? > > ORDER by uniquecol limit 50 OFFSET 50; > > > where the ? is placeholder for last value returned by last query. > > Uh, you don't want the OFFSET there do you? But otherwise, yeah, > this is a popular solutio

Re: [SQL] Newbie wonder...

2005-03-14 Thread Rod Taylor
On Mon, 2005-03-14 at 10:02 +0100, PFC wrote: > If you want to add a SERIAL field to an existing table, create a > sequence > and then create an integer field with default nextval(seq) and postgres > will fill it automatically. The order in which it will fill it is not > guaranteed tho

Re: [SQL] replacing mysql enum

2004-12-11 Thread Rod Taylor
On Sat, 2004-12-11 at 07:47 -0800, Stephan Szabo wrote: > On Sat, 11 Dec 2004, Ian Barwick wrote: > > > (Oddly enough, putting the NULL in the CHECK constraint seems > > to make the constraint worthless: > > test=> create table consttest (field varchar(2) check (field in > > (null, 'a','b','c')))

Re: [SQL] Doubt :- Image_Insert

2004-11-22 Thread Rod Taylor
On Mon, 2004-11-22 at 15:09 +0100, Jerome Alet wrote: > Hi, > > On Mon, Nov 22, 2004 at 08:54:20AM -0500, Rod Taylor wrote: > > On Mon, 2004-11-22 at 19:11 +0530, sreejith s wrote: > > > Hello friends I have a doubt, > > > Is it possible to insert image

Re: [SQL] Doubt :- Image_Insert

2004-11-22 Thread Rod Taylor
On Mon, 2004-11-22 at 19:11 +0530, sreejith s wrote: > Hello friends I have a doubt, > Is it possible to insert images into a postgres db. What is its > datatype. Is its possible to insert jpeg images. or v have to store > the path into the db. Pls reply. its urgent. Use bytea for a datatype. Post

Re: [SQL] tree structure photo gallery date quiery

2004-11-16 Thread Rod Taylor
On Tue, 2004-11-16 at 11:29 +, Gary Stainburn wrote: > > How would I go about creating a view to show a) the number of photos > in > a gallery and b) the timestamp of the most recent addition for a > gallery, so that it interrogates all sub-galleries? There isn't a very simple answer to tha

Re: [SQL] Reuse previously calculated column in sql query?

2004-10-20 Thread Rod Taylor
On Wed, 2004-10-20 at 08:50, Philippe Lang wrote: > Hello, > > Is it possible to reuse a previously calculated column in a following > column, like: SELECT col1 , col2 , col2 * 0.75 AS col3 FROM (SELECT foo.val1 AS col1 , long_calculation(foo.val1) AS col2 FROM

Re: [SQL] COUNT(*) to find records which have a certain number of

2004-09-20 Thread Rod Taylor
On Mon, 2004-09-20 at 12:19, T E Schmitz wrote: > I figured it eventually. (The only thing I don't know is where to put > the ORDER BY.) Try this: SELECT brand_name, model_name FROM (SELECT ... INTERSECT SELECT ...) AS t ORDER BY ... ---

Re: [SQL] multi column foreign key for implicitly unique columns

2004-08-18 Thread Rod Taylor
On Wed, 2004-08-18 at 12:27, Jan Wieck wrote: > On 8/18/2004 12:18 PM, Tom Lane wrote: > > > Richard Huxton <[EMAIL PROTECTED]> writes: > >> * Allow multiple unique constraints to share an index where one is a > >> superset of the others' columns. > > > >> That way you can mark it unique without

Re: [SQL] multi column foreign key for implicitly unique columns

2004-08-18 Thread Rod Taylor
> However, Bruce, this should be on the TODO list: > > * Allow foreign key to reference a superset of the columns >covered by a unique constraint on the referenced table. It would probably be more beneficial to be able to create a unique constraint without requiring the fields be ind

Re: [SQL] reply to setting

2004-08-11 Thread Rod Taylor
> > faster than ones sent through the lists. It is also possible that the direct > > replies might be handled differently by the recipient (e.g. a filter may put > > them in different folders). > > This is very true. In fact, I get mildly annoyed when people *don't* > include the direct reply to

Re: [SQL] Displaying two tables side by side

2004-08-11 Thread Rod Taylor
Depending on the size of your structures, something like the below may be significantly faster than the subselect alternative, and more reliable than the ctid alternative. CREATE TYPE result_info AS (a integer, b integer, c integer, d integer); CREATE OR REPLACE FUNCTION parallelselect() RETURNS

Re: [SQL] Exception handling from trigger

2004-08-09 Thread Rod Taylor
> Is this way of handling exceptions possible in postgres ? > If so, what is the normal way to handle this exceptions, from a > plpgsql/trigger(rule??) perspective ? 8.0 should allow you to do this. 7.4 you need to perform your own checks and catch whether they succeed or fail.

Re: [SQL] Make a column case insensitive

2004-08-08 Thread Rod Taylor
On Fri, 2004-08-06 at 11:29, Gordon Ross wrote: > Is it possible to make a column case insensitive, without having to pepper your > SELECTs with lots of lower() function calls (and forgetting to do it at times !) You could make yourself a set returning function to do this job -- but that is proba

Re: [SQL] surrogate key or not?

2004-07-21 Thread Rod Taylor
> All three of these implementation issues are, at least in theory, > surmountable. For example, Sybase overcame problems (1) and (3) by creating > an automated, system-controlled hash key based on the table's real key. This > was a solution endorsed by E.F. Codd in the mid-90's when he came

Re: [SQL] date_format in postresql

2004-07-21 Thread Rod Taylor
Which version of PostgreSQL are you using? select version(); > On Tue, 20 Jul 2004 22:39:38 -0400, Rod Taylor <[EMAIL PROTECTED]> wrote: > > On Tue, 2004-07-20 at 20:55, azah azah wrote: > > > Hi, > > > I want convert from mysql to postresql, > &

Re: [SQL] date_format in postresql

2004-07-20 Thread Rod Taylor
On Tue, 2004-07-20 at 20:55, azah azah wrote: > Hi, > I want convert from mysql to postresql, > in mysql, query to database using the code as below: > > date_format(submittime, "%W %M %e, %Y - %r") to_char(submittime, 'format string') http://www.postgresql.org/docs/7.4/static/functions-formattin

Re: [SQL] Query plan discrepancies

2004-07-16 Thread Rod Taylor
Have you run ANALYZE recently? Please send back EXPLAIN ANALYZE for the below query. > EXPLAIN from DB 2 (doesn't come back): >QUERY PLAN >

Re: [SQL] Constraint->function dependency and dump in 7.3

2004-07-13 Thread Rod Taylor
On Tue, 2004-07-13 at 13:42, SZŰCS Gábor wrote: > Dear Rod, > > Thanks. It'll be a pain to have two versions between the prod and devel > servers, but I'll forward this info to the chief. You can make this part easier on yourself. Dump the structure from production and migrate it to devel (fix t

Re: [SQL] Constraint->function dependency and dump in 7.3

2004-07-13 Thread Rod Taylor
> Checked, and So do you say, this problem persists in dbs dumped from 7.4 to > 7.4 too? i.e. upgrading to 7.4 (which we tested for quite some time now) > won't help? There may have been some minor fiddling to make it easier, but I wouldn't call it fixed by any means. > trying dump confirmed thi

Re: [SQL] Constraint->function dependency and dump in 7.3

2004-07-12 Thread Rod Taylor
On Mon, 2004-07-12 at 08:29, SZŰCS Gábor wrote: > Dear Fellow Countymen, > > I fear none of your answers are acceptable for me. Also, from Csaba's > answer, this sounds to me more like a bug in pg_dump v7.3. It is a bug (or a missing feature) that should be solved with v7.5 for restoring to 7.5 o

Re: [SQL] Queries across multiple database

2004-06-30 Thread Rod Taylor
On Wed, 2004-06-30 at 18:54, Garth Thompson wrote: > I am in the process of migrating the databases for an application from mysql > to postgres. The application is uses several different databases. From > what I have read, postgres still does not support queries across multiple > databases. If t

Re: [SQL] Last insert id

2004-06-15 Thread Rod Taylor
On Tue, 2004-06-15 at 03:05, Andrei Bintintan wrote: > "Is it safe to use "select max(table1_id) from table1" after the insert?" > > Yes it is safe, but ONLY if you use it inside a transaction.(BEGIN/COMMIT). No, this is not safe outside of the serializable isolation. rbt=# begin; BEGIN rbt=# se

Re: [SQL] most efficient way to manage ordering

2004-06-01 Thread Rod Taylor
> Ideally, I'd like to figure out a single SQL query that can be run > afterwards to clean up the dsply_order to make sure that each number occurs > only one time and that there are no gaps. Well... by far the easiest way to approach this is not to clean up the gaps. Removing gaps will only make t

Re: [SQL] Procedure failing after upgrade

2004-05-05 Thread Rod Taylor
On Tue, 2004-05-04 at 09:32, patkins wrote: > All, > > I just upgraded to the latest version from 7.2.x and now a procedure is failing. > > Please tell me what I'm doing wrong! Please include the actual error message produced. That said, I'm getting an interesting error. It appears as if the int

Re: [SQL] Check a value in array

2004-04-29 Thread Rod Taylor
On Thu, 2004-04-29 at 13:37, Marco Lazzeri wrote: > Hi all. > > I have to check if a value is in an array. > > I've got a date array in a table and I would like to perform queries > like: > > SELECT * FROM table WHERE date IN dates_array; If you're using 7.4 or later, try: SELECT * FRO

Re: [SQL] problem with slow select

2004-04-26 Thread Rod Taylor
On Wed, 2004-04-21 at 11:00, francescosaf wrote: > hi > > I have two tables: Please send results of EXPLAIN ANALYZE for the query in question. Thanks ---(end of broadcast)--- TIP 3: if posting/reading through Usenet, please send an appropriate

Re: [SQL] Server Side C programming Environment Set up

2004-04-22 Thread Rod Taylor
On Thu, 2004-04-22 at 10:11, Peter Eisentraut wrote: > Am Donnerstag, 22. April 2004 15:58 schrieb Rod Taylor: > > > make install-all-headers > > > > > > It's explained in the installation instructions. > > > > That doesn't happen on most

Re: [SQL] Server Side C programming Environment Set up

2004-04-22 Thread Rod Taylor
On Thu, 2004-04-22 at 01:18, Peter Eisentraut wrote: > Kemin Zhou wrote: > > IN chapter 33 Extending SQL > > 33.7.5 Writing Code > > when run pg_config --includedir-server > > I got /usr/local/pgsql/include/server but my machine does have this > > directory > > make install-all-headers > > It's

Re: [SQL] Can someone tell me why this statement is failing?

2004-04-20 Thread Rod Taylor
> Can anyone tell me why this SQL statement is not > matching with the row from the table below? I think > I'm going mad! Indeed. The row is NOT in that range. 1082377320 is > 1082375100 not <= it ---(end of broadcast)--- TIP 3: if posting/reading

Re: [SQL] SQL challenge--top 10 for each key value?

2004-04-09 Thread Rod Taylor
On Fri, 2004-04-09 at 18:43, Greg Stark wrote: > Josh Berkus <[EMAIL PROTECTED]> writes: > > > Rod, > > > > > Something along the lines of the below would accomplish what you want > > > according to spec. ROW_NUMBER() is a spec defined function. (6.10 of > > > SQL200N) > > > > Great leaping litt

Re: [SQL] SQL challenge--top 10 for each key value?

2004-04-08 Thread Rod Taylor
On Thu, 2004-04-08 at 19:33, Greg Stark wrote: > Jeff Boes <[EMAIL PROTECTED]> writes: > > > I headed off in the direction of groups of SELECTs and UNIONs, and quit when I > > got to something like four levels of "SELECT ... AS FOO" ... > > four? wimp, that's nothing! > > ok, seriously I think t

Re: [SQL] partial unique constraint

2004-04-06 Thread Rod Taylor
On Tue, 2004-04-06 at 10:29, Robert Treat wrote: > Trying to come up with the proper syntax to meet the following criteria: > > create table foo (bar integer, baz boolean UNIQUE (bar, baz = true)); Tt takes 2 steps. CREATE TABLE ... CREATE UNIQUE INDEX ... (bar) WHERE baz = true;

Re: [SQL] Newbie Query question

2004-03-26 Thread Rod Taylor
> However, this query does not give me the result I expected. It appears that > the database engine first calculates the cartesian product of the tables A > and B and then evaluates the query. Hence, I get multiple matches for Yup.. WHERE filters the results of the join. > Is there any way to do

Re: [SQL] Compiling pl/pgsql functions

2004-02-20 Thread Rod Taylor
logic, or lack thereof, but accounting needs to use both sets of information to do their work. Otherwise, having each group relegated to their own schema with semi-public views is a nice way to pass information from department to department for small companies. Sure beats the spreadsheets on the centr

Re: [SQL] Inserting NULL into Integer column

2004-02-18 Thread Rod Taylor
> Note that the ' marks aren't part of the string, they are the delimiter of > the string, and I always run every server with magic_quotes_gpc on. > > anything else? :-) Good point. I looked at the single quotes of the second line and somehow the DEFAULT got quoted as well ;) -

Re: [SQL] Inserting NULL into Integer column

2004-02-18 Thread Rod Taylor
> and then you can foreach across the input: > > foreach($fields as $f){ > if (!$_POST[$f]){ > $_POST[$f]='DEFAULT'; > } else { > $_POST[$f] = "'".$_POST[$f]."'"; > } > } Default in quotes isn't going to work, and please tell me you escape those things with pg_escape_string() at som

Re: [SQL] ORDER BY TIMESTAMP_column ASC, NULL first

2004-02-15 Thread Rod Taylor
On Thu, 2004-02-12 at 05:06, Fredrik Wendt wrote: > Hi! > > I read posts telling me that NULL values are considered greater than > non-null values. Fine. Is there a way to explicitly reverse this? ORDER BY column IS NOT NULL, column ASC; ---(end of broadcast)

Re: [SQL] 7.4 - FK constraint performance

2004-02-15 Thread Rod Taylor
. Statistics list the 10 most common values (all of them). Given this, would it not be reasonable to assume that 239 is a recent addition (if there at all) to the table and not very common? -- Rod Taylor Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL PGP Key: http://www.rbt.

Re: [SQL] 7.4 - FK constraint performance

2004-02-15 Thread Rod Taylor
On Thu, 2004-02-12 at 23:25, Tom Lane wrote: > Rod Taylor <[EMAIL PROTECTED]> writes: > > Statistics say there are 10 values. Statistics list the 10 most common > > values (all of them). Given this, would it not be reasonable to assume > > that 239 is a recent additi

Re: [SQL] 7.4 - FK constraint performance

2004-02-15 Thread Rod Taylor
Most of the queries are going to be for the other values (in which case you've wasted an index scan) which is minor, but in the event there is a single 239 you're still taking a big hit. That is an awful lot of work to handle the non-existant case only. -- Rod Taylor Build

Re: [SQL] column alias and group by/having/order

2004-02-13 Thread Rod Taylor
> select val1+val2 as val > from some_table > group by val having val>1; > ERROR: Attribute "val" not found > > Is it a bug or a feature? It's a mis-feature that group by accepts aliases of the select list. Having is proper. ---(end of broadcast)--

Re: [SQL] Sometimes referential integrity seems not to work

2004-02-02 Thread Rod Taylor
> TRUNCATE cannot be used inside of a transaction, and since 7.3 it checks > for foreign keys. So I guess Enio is getting but ignoring the error In 7.4 truncate is transaction safe. ---(end of broadcast)--- TIP 1: subscribe and unsubscribe comma

Re: [SQL] rules and return values question

2003-11-28 Thread Rod Taylor
> tables but it introduces too much overhead. In any case, we need the return > value (or an exception) from the function but there does not seem a way to > return it. Can't you use erreport() to return an exception message? ---(end of broadcast)-

Re: [SQL] Multicolum index and primary key

2003-11-17 Thread Rod Taylor
> Suppose by example that one have a table1 with a primary key over three > field (a, b, c): .. > are the indexes over (a) and (a, b) redundant (and so useless)? Yes, they are redundant not not necessarily useless. In short, an index with 3 keys will be larger than an index with 1 key, as such

Re: [SQL] transaction processing after error in statement

2003-11-10 Thread Rod Taylor
> Although i am not aware of the roots of this discussion but would like > to > comment at this point . > > When we work with sequences an aborted transaction does have > a permanent effect on the last value of sequence. Is this behaviour > not a violation of above defination of transaction ? I

Re: [SQL] transaction processing after error in statement

2003-11-10 Thread Rod Taylor
> be recovered either. When committing a transaction the effects of all > operations that did not fail will be made permanent. This is how > transaction processing is described in the literature. I would be interested in reading that (URLs please) as I didn't see anything in the spec that was inte

Re: [SQL] DateDiff in PostgreSQL

2003-11-07 Thread Rod Taylor
> ie, a function that returns difference of two dates(timestamp) in days > or months or year.. > > The - operator for timestamp retuns the intervel in days only. rbt=# select extract('days' from current_timestamp - '2003-01-01'::timestamp); date_part --- 310 (1 row)

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

2003-11-02 Thread Rod Taylor
On Sun, 2003-11-02 at 19:42, Mark Stosberg wrote: > 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 ali

Re: [SQL] Table versions

2003-10-29 Thread Rod Taylor
> What I did next, is put a trigger on pg_attribute that should, in theory, > on insert and update, fire up a function that will increment a version System tables do not use the same process for row insertion / updates as the rest of the system. You're trigger will rarely be fired. signature.asc

Re: [SQL] naming conventions constraint

2003-10-24 Thread Rod Taylor
rbt=# create table bob_is(your_uncle integer, constraint "bob_is#your_uncle" check(true)); CREATE TABLE rbt=# \d bob_is Table "public.bob_is" Column | Type | Modifiers +-+--- your_uncle | integer | Check constraints: "bob_is#your_uncle" CHECK true Yo

Re: [SQL] see a current query

2003-10-22 Thread Rod Taylor
On Wed, 2003-10-22 at 05:26, sad wrote: > Hello > > i'am logged in as superuser (pgsql) > trying to > SELECT * FROM pg_stat_activity; > and seeing NULLs instead of current_query column& You need to change the stats settings in postgresql.conf. By default the current query is not enabled as it d

Re: [SQL] How can I produce the following desired result?

2003-10-14 Thread Rod Taylor
On Tue, 2003-10-14 at 22:09, aicean wrote: > How can I produce the following desired result? I'm not sure I understand the problem, but you might want to try a subselect in the FROM. SELECT FROM table JOIN (SELECT goodid FROM table WHERE ) AS tab USING (good

Re: [SQL] [PERFORM] sql performance and cache

2003-10-14 Thread Rod Taylor
> > Perhaps you are confusing it with the MySQL query cache? > Is there plan on developing one (query cache)? For the most part, prepared queries and cursors give you a greater advantage due to their versatility -- both of which we do have. In the cases where an actual cache is useful, the clien

Re: [SQL] Creating Index

2003-10-01 Thread Rod Taylor
>-> Seq Scan on table1 (cost=0.00..20.00 rows=1000 width=0) (actual Run VACUUM ANALYZE, then repost your EXPLAIN ANALYZE results please. signature.asc Description: This is a digitally signed message part

Re: [SQL] A simple way to Create type ...?

2003-09-16 Thread Rod Taylor
> I guess, ideally it'd be > create type AddressType AS varchar(50) ; > but it does not work. Only one keyword off. SQL calls this a domain. They're limited in 7.3, but much improved (not yet perfect) for 7.4. http://www.postgresql.org/docs/7.3/interactive/sql-createdomain.html signature.asc

Re: [SQL] Q: select query

2003-09-13 Thread Rod Taylor
> in other words, all but the first row of a group. Interesting question. The below should work and be quick so long as there is a UNIQUE(col1, col2) constraint. SELECT col1 , col2 FROM j WHERE col2 != (SELECT col2 FROM j AS jsub WHERE col1 = j.col1

Re: [SQL] MINUS & ROWNUM in PostGres

2003-09-09 Thread Rod Taylor
> The problem is we are using PostGres 7.1.In this version REPLACE() is not > available. It sounded like you were just starting to work on the change over. I highly suggest upgrading to 7.3 at the very least, 7.4 if you're going to be a few months prior to going to production. A ton of good work

Re: [SQL] MINUS & ROWNUM in PostGres

2003-09-08 Thread Rod Taylor
On Mon, 2003-09-08 at 09:44, Jomon Skariah wrote: > Hi, > > Do we have any replacement for REPLACE() of Oracle in PostGres? What does replace() do? String replacement? http://www.postgresql.org/docs/7.3/interactive/functions-string.html replace(string text, from text, to text) signature.asc

Re: [SQL] SQL subqueries newbie help

2003-09-07 Thread Rod Taylor
On Sun, 2003-09-07 at 07:42, Alexei Chetroi wrote: > On Sat, Sep 06, 2003 at 01:21:36PM -0400, Rod Taylor wrote: > > > I'd like to write a query which returns following information regarding > > > each item: item, date of very first event, very last event. > > &g

Re: [SQL] SQL subqueries newbie help

2003-09-06 Thread Rod Taylor
> I'd like to write a query which returns following information regarding > each item: item, date of very first event, very last event. > Is this possible? I think I can write several SELECT queries and > procces them by an application or possibly write some procedure, but > what is better soluti

Re: [SQL] Porting from Oracl to Postgres

2003-09-05 Thread Rod Taylor
On Fri, 2003-09-05 at 00:24, Jomon Skariah wrote: > > Hi, > > Thanks for your replys. > > We are facing another problem now. > > we need to find an alternative for Oracle's ADD_MONTHS in PostGres.. Guessing based on the name that it adds a quantity of months to a timestamp. How about an SQL I

Re: [SQL] MINUS & ROWNUM in PostGres

2003-09-04 Thread Rod Taylor
> 1)Do we have a replacement in PostGres for MINUS operator of Oracle . I believe MINUS is non-standard word for EXCEPT, correct? > 2 Also I need to find an alternative for ROWNUM in oracle.. If you are looking for a unique identifier, try using the OID. signature.asc Descript

Re: [SQL] "SELECT IN" Still Broken in 7.4b

2003-08-22 Thread Rod Taylor
> What is measured by the \timing option? The figures reported > are slightly larger than those loged when the log_duration parameter > is true. The time of the psql client. It will include round trip activity including network overhead. signature.asc Description: This is a digitally sign

Re: [SQL] "SELECT IN" Still Broken in 7.4b

2003-08-20 Thread Rod Taylor
On Wed, 2003-08-20 at 17:41, Stephan Szabo wrote: > On Wed, 20 Aug 2003, Rod Taylor wrote: > > > > Thanks, Stephan. I was really hoping that the IN(valuelist) was going to > > > be changed at the same time, because it really is unusable for anything > > >

Re: [SQL] "SELECT IN" Still Broken in 7.4b

2003-08-20 Thread Rod Taylor
Ensure your IN list is unique. You might find better times by through an indexed temp table. On Wed, 2003-08-20 at 16:32, Mike Winter wrote: > I'm sure many on this list are sick of hearing about this problem, but it > was on the fix list for 7.4, but doesn't appear to have been changed. > > You

Re: [SQL] "SELECT IN" Still Broken in 7.4b

2003-08-20 Thread Rod Taylor
> Thanks, Stephan. I was really hoping that the IN(valuelist) was going to > be changed at the same time, because it really is unusable for anything > over a couple of thousand values. Changed to do what? I suppose that the ability to combine several index scans via a bitmap would help to linear

Re: [SQL] Reverse pattern match.

2003-08-18 Thread Rod Taylor
On Mon, 2003-08-18 at 03:05, Moonstruck wrote: > I want to create a table of regular expression patterns (for assessing > phone numbers), something like: > CREATE TABLE CallType ( pattern varchar primary key, > typevarchar, > rateint4); > INS

Re: [SQL] Do it exist?

2003-08-16 Thread Rod Taylor
> In another language I would do: > find first Order where Order.Order_num = "". > if avaialble Order then it_exists = true. > > In PostgreSQL ?: > SELECT DISTINCT Order_num from Order_header where Order_num = ''; > > Is this close? If so, how to raise flage that row exists? >

Re: [SQL] Why table has drop, but the foreign key still there?

2003-08-14 Thread Rod Taylor
> insert into state (state_code,state) values ('GU','Guam'); > drop table whitepage; > delete from state where state_code = 'GU'; > ERROR: Relation "whitepage" does not exist Old version of PostgreSQL? Effort went into cleaning up inter-object dependencies in 7.3. I don't recall having that pa

Re: [SQL] Insert a description while creating a table

2003-08-14 Thread Rod Taylor
On Wed, 2003-08-13 at 07:56, [EMAIL PROTECTED] wrote: > Hi, > > I want to insert descriptions at the columns of my tables but without > using the command COMMENT ON. I want to do it together with the table > creation. Is that possible? > > I wanna do something like this: > > create table test

  1   2   >