Re: [SQL] sessions and prepared statements

2006-06-16 Thread PFC
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? and/or how do you get a list of prepared statements? last, is there any after login trigger that one could use to prepare

Re: [SQL] Efficient Searching of Large Text Fields

2006-06-13 Thread PFC
2. What functions or libraries are available to make such searching easy to implement well? the tsearch2 module does that, and has a substantial advantage over a solution you might reimplement : it's already done (and it works). Try it... ---(end of

Re: [SQL] Most efficient way to hard-sort records

2006-05-07 Thread PFC
Is it possible to do this : CREATE TABLE sorted (order_no SERIAL PRIMARY KEY, other columns...) INSERT INTO sorted (columns) SELECT * FROM main_table INNER JOIN key_table ON main_table.id = key_table.main_table_id WHERE key = 'param' ORDER BY value SELECT The SERIAL will

Re: [SQL] Most efficient way to hard-sort records

2006-05-07 Thread PFC
Another version along that line ? # create sequence counterseq start 1; -- (set/reset whenever a counter is needed) # select main_table.*, nextval('counterseq') as position2 into sorted_main_table from main_table, keytable where main_table.id = keytable.main_table_id order by

Re: [SQL] Expressing a result set as an array (and vice versa)?

2006-03-27 Thread PFC
SELECT array_accum( DISTINCT list_id ) FROM bookmarks; array_accum --- {1,2,3,4,5,7} Couldn't you just use array()? Yes, you can do this : SELECT ARRAY( SELECT something with one column ); However, array_accum() as an aggregate is more interesting because you can

Re: [SQL] Expressing a result set as an array (and vice versa)?

2006-03-24 Thread PFC
CREATE OR REPLACE FUNCTION foreach( liste INTEGER[] ) RETURNS SETOF INTEGER AS $$ DECLARE i INTEGER; BEGIN FOR i IN 1..icount(liste) LOOP RETURN NEXT liste[i]; END LOOP; END; $$ LANGUAGE plpgsql; CREATE AGGREGATE array_accum ( sfunc = array_append, basetype = anyelement,

Re: [SQL] Update counter when row SELECT'd ... ?

2006-03-21 Thread PFC
On Tue, 21 Mar 2006 04:33:22 +0100, Daniel CAUNE [EMAIL PROTECTED] wrote: I have a simple table: name, url, counter I want to be able to do: SELECT * FROM table ORDER BY counter limit 5; But, I want counter to be incremented by 1 *if* the row is included in that 5 ... so that those 5

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

2006-03-20 Thread PFC
have you feel anything when you read this ? Business as usual... It's more fun to grep crash on this page, which gets about 27 results... ---(end of broadcast)--- TIP 2: Don't 'kill -9' the postmaster

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

2006-03-20 Thread PFC
the problem is: you'll get this four byte sequence '\000' _instead_ of NUL-byte anyway. http://www.postgresql.org/docs/8.1/interactive/datatype-binary.html says : A binary string is a sequence of octets (or bytes). Binary strings are distinguished from character strings by two

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

2006-03-20 Thread PFC
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 am asking: WHY should a client take care of de-escaping ? Why not to get his

Re: [SQL] PostgreSQL Handling of Special Characters

2006-03-19 Thread PFC
My Database uses SQL_ASCII encoding. I just received an email with all accented characters destroyed. UNICODE should be the default for anything in 2006. ---(end of broadcast)--- TIP 6: explain analyze is your friend

Re: [SQL] Permission to Select

2006-03-13 Thread PFC
What information can be retrieved from a structure by being able to update all rows? Write a plpgsql function snoop(x) which inserts x into a table 'log' created by you, and also returns x. UPDATE users SET password=snoop(password). Read log table. Done. If you

Re: [SQL] connectby documentation

2006-03-13 Thread PFC
7.4?! Huh... Is there any sources.list a bit more updated? Where can I download PostgreSQL contrib modules. The documentation 8.1 doesn't help so much. Where can I find more documentation on available contrib. modules? gentoo automatically compiles and installs the contribs (you just

Re: [SQL] input from a external text file......!

2006-03-11 Thread PFC
inside psql, type : \i filename On Sat, 11 Mar 2006 11:29:20 +0100, AKHILESH GUPTA [EMAIL PROTECTED] wrote: Hi All.! I just want to know one thing that is it possible with PGSQL that, if I want to insert and execute a query from a external text file instead of giving it at

Re: [SQL] How can I selet rows which have 2 columns values cross equal?

2006-03-10 Thread PFC
What are your conditions on a and b ? Can a be equal to b on a row ? If so, do you want this row ? If you want to avoid duplicates, I suggest first removing them, then adding a constraint CHECK( ab ) for instance. Then, from you r application (or in an ON INSERT trigger), swap a and b if

Re: [HACKERS] [SQL] Interval subtracting

2006-03-08 Thread PFC
For same reasons, i.e. a need for precision, I find it hard to accept the idea of mixing positive and negative units in the same interval. The plus or minus sign should be outside of the interval. The interval data type is really useful. I see no reason to restrict its usefulness with an

Re: [SQL] 'locking' the SELECTs based on indices...

2006-02-23 Thread PFC
I lock just that particular row, which is no good. I need to have all the codes for the service 1 locked, so if it happens that two users send the very same code, one has to fail. Therefore, from within plpgsql I first do: I'm a bit tired tonight so I'll simplify your example :

Re: [SQL] 'locking' the SELECTs based on indices...

2006-02-23 Thread PFC
Now, If some other user want's his prize, when checking his code, if he sends code for some other service then service 1, that's ok. If he's sends code for the service 1 the PERFORM will wait untill I'm finished with previous user. Sorry for the double post. If the rows in your

Re: [SQL] How to implement Microsoft Access boolean (YESNO)

2006-01-24 Thread PFC
On Tue, 24 Jan 2006 06:03:48 +0100, Greg Stark [EMAIL PROTECTED] wrote: Tom Lane [EMAIL PROTECTED] writes: Greg Stark [EMAIL PROTECTED] writes: Jesper K. Pedersen [EMAIL PROTECTED] writes: Having checked the I/O format it seems that MS Access exports the values of a YESNO field as 0 and 1

Re: [SQL] Help with simple query

2005-12-28 Thread PFC
If you want the latest by user, you can cheat a bit and use the fact that the id's are incrementing, thus ordering by the id is about the same as ordering by the date field. I know it can be inexact in some corner cases, but it's a good approximation, and very useful in practice : SELECT

Re: [SQL] automatic update or insert

2005-10-25 Thread PFC
In a system of mine i need to insert records into table [tbStat], and if the records exist i need to update them instead and increase a column [cQuantity] for every update. I.e. the first insert sets cQuantity to 1, and for every other run cQuantity is increased. Currently i have implemented

Re: [SQL] PostgreSQL help

2005-08-29 Thread PFC
Check your database encoding, client encoding, and the encoding you use in your file. If your database is UNICODE, pgadmin will convert accordingly, but your file has to be in the right encoding. On Mon, 29 Aug 2005 12:27:41 +0200, Shavonne Marietta Wijesinghe [EMAIL PROTECTED] wrote:

Re: [SQL] insert into / select from / serial problem

2005-08-15 Thread PFC
On Wed, 10 Aug 2005 05:03:47 +0200, tgh002 [EMAIL PROTECTED] wrote: I am using a insert statement like: INSERT INTO newtable SELECT field1, field2 FROM anothertable newtable structure is: serial, varchar, varchar What syntax do I use to insert the serial field? Ive tried something like:

Re: [SQL] [SQL] Caracter é

2005-08-06 Thread PFC
Hello, This is probably a character encoding issue ; try issuing a SET client_encoding TO whatever encoding you're using ; it is possible that your connection through PHP defaults to SQL_ASCII in which é is illegal (mine did). Or, check your browser, form etc. encoding to make

Re: [SQL] sum but not grouped by?

2005-08-05 Thread PFC
On Fri, 05 Aug 2005 19:53:14 +0200, Henry Ortega [EMAIL PROTECTED] wrote: Is it possible at all to do this without any joins or subselect? I don't think so. You could always hide them in a view... ---(end of broadcast)--- TIP

Re: [SQL] Counting Row

2005-07-24 Thread PFC
I'd suggest : - first getting the 'order fields' value for the ticket you want : SELECT field_order FROM mytable WHERE condition AND identifier=the_one_you're_looking_for ORDER BY field_order DESC LIMIT 1 - then counting all the tickets up to this order : SELECT count(*) FROM mytable WHERE

Re: [SQL] Create trigger for auto update function

2005-07-18 Thread PFC
CREATE TRIGGER triger_users_pass_md5 AFTER INSERT OR UPDATE ON hoy EXECUTE PROCEDURE update_pass(integer); Try : FOR EACH ROW EXECUTE ---(end of broadcast)--- TIP 1: if posting/reading through Usenet, please send an appropriate

Re: [SQL] two sums in one query

2005-07-08 Thread PFC
SELECT SUM( CASE WHEN COALESCE( DEBIT , 0 ) 0 THEN COALESCE( AMOUNT , 0 ) ELSE 0 END ) AS DEBIT_AMT , SUM( CASE WHEN COALESCE( CREDIT , 0 ) 0 THEN COALESCE( AMOUNT , 0 ) ELSE 0 END ) AS CREDIT_AMT FROM TABLE NAME I don't know if it will use indexes (bitmapped OR indexes in 8.1 ?)...

Re: [SQL] two sums in one query

2005-07-08 Thread PFC
SELECT (SELECT sum(amount) FROM table WHERE debit=X) AS debit, (SELECT sum(amount) FROM table WHERE credit=x) AS credit; If most of the records are credits or debits you don't want to do this. A single sequential scan through the table will be the best plan. I thought that debit = source

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

2005-07-08 Thread PFC
which wouldn't have helped.) If true, I can handle that parsing myself easily enough without exposing RelationGetNumberOfBlocks. Is there a way to get EXPLAIN results in a non-text-formatted way for easier use ? I'm asking, because it seems the feature set grows by the minute in

Re: [SQL] Clustering problem

2005-07-08 Thread PFC
Is it even possible to cluster a table based on the clustering scheme (which is not the link_id ...) from the master table? Can you gurus think of a better strategy? :) (Please??) :) You can create a functional index on a function which returns the desired order by looking in the main

Re: [SQL] getting back autonumber just inserted

2005-07-07 Thread PFC
That's a different issue than whether currval() is subject to interference from other transactions. And just wait until PostgreSQL 8.1 comes out and people start using lastval() -- then it could get *really* confusing which sequence value you're getting. What happens if an INSERT trigger

Re: [SQL] getting back autonumber just inserted

2005-07-07 Thread PFC
Do you mean with lastval()? Here's what happens: Hm, interesting, you mean the return value of lastval() also depends if you set your constraints to deferred or immediate ? I wond ---(end of broadcast)--- TIP 6: Have you searched our

Re: [SQL] getting back autonumber just inserted

2005-07-07 Thread PFC
What happens if an INSERT trigger inserts something into another table which also has a sequence ? Using what, lastval()? The app will get very confused, because it'll get the value from the sequence used in the trigger. Using currval there is no problem, but you already

Re: [SQL] Unique primary index?

2005-06-28 Thread PFC
index is... an index ! UNIQUE is an index which won't allow duplicate values (except for NULLS) PRIMARY KEY is exactly like UNIQUE NOT NULL, with the bonus that the database knows this column is the primary key so you can use stuff like NATURAL JOIN without telling which column you want to

Re: [SQL] people who buy A, also buy C, D, E

2005-06-26 Thread PFC
The goal of my query is: given a book, what did other people who bought this book also buy? I plan the list the 5 most popular such books. You can use the table listing ordered products directly, for example : table ordered_products: order_id, product_id, quantity SELECT

[SQL] assorted problems with intarray and other GiST contribs.

2005-06-26 Thread PFC
Hello ! I'm using postgresql 8.0.1-r2 on gentoo linux. So, here are the problems : * int_array_aggregate crashes SELECT int_array_aggregate(id) FROM (SELECT id FROM shop.products LIMIT X) as foo; This one

Re: [SQL] assorted problems with intarray and other GiST contribs.

2005-06-26 Thread PFC
Thanks for the quick response ! * int_array_aggregate crashes I don't remember this function :) You mean it's not part of intarray contrib ? I thought so ! Sorry ! Then who's responsible for maintenance of it ? int4 nlevel(ltree) -

Re: [SQL] Dynamic PL/pgSQL

2005-06-19 Thread PFC
Within a PL/pgSQL function this would be easy, but I need to store the complete initialization script in a text file and execute it as a whole. In your scritp, put a CREATE FUNCTION and then call it and drop it ;) ---(end of

Re: [SQL] SELECT very slow

2005-06-16 Thread PFC
If autocommit is on (or fetch size is zero) then the driver will build the whole result set before returning to the caller. Sure, but that is not your problem : even building the whole result set should not take longer than a few seconds (I gave you test timings in a previous

Re: [SQL] SELECT very slow

2005-06-15 Thread PFC
It's not the program or Java. The same program takes about 20 seconds with Firebird and the exactly same data. Hm, that's still very slow (it should do it in a couple seconds like my PC does... maybe the problem is common to postgres and firebird ?) Try eliminating disk IO by writing a

Re: [SQL] SELECT very slow

2005-06-14 Thread PFC
The problem is, that a SELECT * FROM foobar; takes ages (roughly 3 minutes) to return the first row. I played around with the fetchSize() to disable the result set caching in the Java program first (before I tried psql) but that did not change anything. Hello, Yours seemed

Re: [SQL] getting details about integrity constraint violation

2005-06-03 Thread PFC
The error fields facility in the FE/BE protocol could be extended in that direction, and I think there's already been some discussion about it; but no one has stepped up with a concrete proposal, much less volunteered to do the work ... Um, if changing the protocol is a bother, you could

Re: [SQL] Sum() rows

2005-05-31 Thread PFC
The simplest would be to create a stored procedure like this : declare row as TB1%rowtype, and ret as (id integer, value numeric, subtot numeric) then : ret.subtot = 0 FOR row IN SELECT * FROM TB1 ORDER BY id DO ret.id = row.id ret.value = row.value ret.subtot =

Re: [SQL] Duplicated records

2005-05-24 Thread PFC
How can I delete the duplicated records with DELETE FROM TABLE WHERE... clause?? The problem is becouse I have imported data from Dbase (dbf) file, and this function have not built the Constraint (unique, primary key, ...), and this function is usually executed. If you have no primary

Re: [SQL] Changed to: how to solve the get next 100 records problem

2005-05-18 Thread PFC
The only strange thing is that without the 3rd order by, the order is wrong. I didn't expect it because each select is created ordered. Is it expected that UNION mixes it all up? (using postgre 7.4.1) That's because UNION removes duplicates, which it will probably doing using a hash

Re: [SQL] Turning column into *sorted* array?

2005-05-18 Thread PFC
SELECT array_accum(x) FROM (SELECT * FROM some_view ORDER BY x) AS tmp; If you're using integers, you could use the int_array_accum or something from the intarray module which is a lot faster. I believe intarray also has a function for sorting integer arrays... BTW, the best alternative (in

Re: [SQL] Does Postgresql have a similar pseudo-column ROWNUM as

2005-05-17 Thread PFC
your subsequent selects are select ... from tab WHERE skeyskey_last OR (skey=skey_last AND pkeypkey_last) ORDER BY skey,pkey LIMIT 100 OFFSET 100; why offset ? you should be able to use the skey, pkey values of the last row on the

Re: [SQL] choosing index to use

2005-05-16 Thread PFC
Try indexing on client, time instead of time, client... putting the equality condition on the first column of the index can make it faster. Else, analyze, increase your stats, etc... On Mon, 16 May 2005 13:39:40 +0200, Ilya A. Kovalenko [EMAIL PROTECTED] wrote: Greetings, How can I

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

2005-05-16 Thread PFC
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?? solution 1 (fast) make a separate column which contains the integer value (updated via a

Re: [SQL] sub-selects

2005-05-16 Thread PFC
SELECT foo.*, npoints( foo.g ) FROM (SELECT a, (select b from c where d = e limit 1) AS g FROM f WHERE isValid( g )) AS foo ? ---(end of broadcast)--- TIP 3: if posting/reading through Usenet, please send an appropriate subscribe-nomail

Re: [SQL] Significance of Database Encoding

2005-05-15 Thread PFC
+--+ | #31169;#12399;#12460;#12521;#12473; +--+ You say it displays correctly in xterm (ie. you didn't see these in your

Re: [SQL] Significance of Database Encoding

2005-05-15 Thread PFC
$ iconv -f US-ASCII -t UTF-8 test.sql out.sql iconv: illegal input sequence at position 114500 Any ideas how the job can be accomplised reliably. Also my database may contain data in multiple encodings like WINDOWS-1251 and WINDOWS-1256 in various places as data has been inserted by different

Re: [SQL] interesting SQL puzzle - concatenating column with itself.

2005-05-10 Thread PFC
BTW the concatenation function you suggest works nicely except that as you noted, it concatenates in an unpredictable order, so I'm now trying to solve that problem. memo_id | sequence | memo_text --- 666 | 1| The quick 666 | 2|

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

2005-04-19 Thread PFC
Thanks Tom and Rod. There are indeed several additional conditions on the real query which prune the search space (I formulate a quick search box and filter on Lat/Lon's within the box). Since my user interface limits the search to a 30 mile radius, there are at most 81 results (in New York

Re: [SQL] Very low performance on table with only 298 rows

2005-04-14 Thread PFC
nbeweb= EXPLAIN ANALYZE select count(*) from onp_web_index; Total runtime: 179748.993 ms WOW. It's possible your table is bloated. What version of PG are you using ? VACUUM FULL ANALYZE VERBOSE onp_web_index if it solves your problem, good, else post the

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

2005-04-11 Thread PFC
try: SELECT zipcode, zipdist($lat1d,$lon1d,lat,long) as distance from zipcodes where distance = $dist;; OR you could use a gist index with a geometric datatype to get it a lot faster. On Sat, 09 Apr 2005 03:43:39 +0200, Bill Lawrence [EMAIL PROTECTED] wrote: HI, Im a newbie so please bear

Re: [SQL] getting count for a specific querry

2005-04-08 Thread PFC
Since it is a count of matched condition records I may not have a way around. What you could do is cache the search results (just caching the id's of the rows to display is enough and uses little space) in a cache table, numbering them with your sort order using a temporary sequence, so that

Re: [SQL] getting count for a specific querry

2005-04-08 Thread PFC
Please run this disk throughput test on your system : http://boutiquenumerique.com/pf/multi_io.py It just spawns N threads which will write a lot of data simultaneously to the disk, then measures the total time. Same for read. Modify the parameters in the source... it's set to generate

Re: [SQL] Query history file

2005-04-03 Thread PFC
~/.psql_history is everything you typed in psql On Sat, 02 Apr 2005 01:42:05 +0200, Mauro Bertoli [EMAIL PROTECTED] wrote: Hi, I've installed a Postgres 8.0. There's a history file with all executed queries? Thanks! ___ Nuovo Yahoo! Messenger: E' molto pi

Re: [SQL] How to store directory like structures?

2005-04-03 Thread PFC
On gentoo (at least on my box) it's installed by default in 8.0, I believe it was installed by default, too, on 7.4.X On Sun, 03 Apr 2005 19:26:03 +0200, Axel Straschil [EMAIL PROTECTED] wrote: Hello! I found, http://www.sai.msu.su/~megera/postgres/gist/ltree/ which seems what's a problem

Re: [SQL] How to store directory like structures?

2005-04-03 Thread PFC
Use the ltree datatype ! It's made specifically for this purpose. http://www.sai.msu.su/~megera/postgres/gist/ On Sun, 03 Apr 2005 12:13:48 +0200, Axel Straschil [EMAIL PROTECTED] wrote: Hello! I want to store some structure like: CREATE TABLE node ( nodeid

Re: [SQL] a very big table

2005-04-03 Thread PFC
I'd suggest modifying your query generator to make it smarter : FROM pubblicita LEFT OUTER JOIN materiali ON (pubblicita.codice_materiale=materiali.codice_materiale) LEFT OUTER JOIN inserzionisti ON (pubblicita.codice_inserzionista=inserzionisti.codice_inserzionista) (snip) WHERE

Re: [SQL] How to store directory like structures?

2005-04-03 Thread PFC
you need to load ltree into your database ! psql yourdb ltree.sql use 'locate ltree.sql' to find if ltree is installed Yeah, I remember now having to do that, but the binary module definitely was here without having to do anything besides emerge postgresql : [EMAIL PROTECTED] peufeu $ locate

Re: [SQL] can you change an FK constraint from NOT DEFERRABLE to DEFERRABLE

2005-03-30 Thread PFC
Checks the docs on ALTER TABLE ... ALTER CONSTRAINT ... On Wed, 30 Mar 2005 11:07:32 +0200, [EMAIL PROTECTED] wrote: Hello. Is it possible to change an FK constraint from NOT DEFERRABLE (the default) to DEFERRABLE without dropping and re-creating it? One idea that came up was to create a

Re: [SQL] New record position

2005-03-30 Thread PFC
Why it? I can't undestand why the new record location was change. Shouldn't it apper at the LAST record??? What need I do?? Thank you. The SQL spec specifies that if you don't use ORDER BY, well, the records come out in any order they want. Actually it's the order they are on disk, which

Re: [SQL] Query performance problem

2005-03-18 Thread PFC
DEFAULT applies to INSERTs, NOT NULL applies to UPDATEs too. In MySQL it applies to both (ie. if you UPDATE to an invalid value, it sets it to 'something'). NOT NULL without default is useful when you want to be sure you'll never forget to put a value in that column, when there is no

Re: [SQL] best way to swap two records (computer details)

2005-03-18 Thread PFC
My question is what's the best way to swap settings between the two computer records and swap any software installed? Ideally I'd like it in the form of a function where I can pass the two p_id's and return a boolean reflecting success (true) or fail (false). I'd say something like that

Re: [SQL] Query performance problem

2005-03-17 Thread PFC
Can anyone tell me why does the following code chokes ... literally - this works almost invisbly under mysql - pg takes more than an hour even on a very small 30 record database. - You should really use 8.0 - How much time toes it takes without the INSERT/UPDATES ? -

Re: [SQL] Query performance problem

2005-03-17 Thread PFC
although may be not relevant to your question, as i have noticed this before with mysql 'sql', what is the point of having a NOT NULL field that defaults to 0? the whole idea of a NOT NULL field is to have the value filled in compulsorily and having a default of 0 or '' defeats the purpose Well

Re: [SQL] Generic Function

2005-03-16 Thread PFC
Look in the plpgsql docs on EXECUTE. But for something that simple, why don't you just generate a query ? ---(end of broadcast)--- TIP 3: if posting/reading through Usenet, please send an appropriate subscribe-nomail

Re: [SQL] select multiple immediate values, but in multiple rows

2005-03-15 Thread PFC
You need a function like this : CREATE OR REPLACE FUNCTION array_srf( integer[] ) RETURNS SETOF integer LANGUAGE PLPGSQL etc... AS $$ DECLARE _data ALIAS FOR $1; _i INTEGER; BEGIN FOR _i IN 1..icount(_data) LOOP RETURN NEXT _data[_i];

Re: [SQL] group by before and after date

2005-03-14 Thread PFC
I have 2 tables 1 has a date field and component need by that date and the other has all the upcoming orders. I am trying to build a query that will give me the Date and ComponentNeed and also how many components have been ordered before that date and how many after. PostGreSQL is telling me

Re: [SQL] Newbie wonder...

2005-03-14 Thread PFC
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 though ! However, you might also like to de-dupe your data

Re: [SQL] Parameterized views proposition

2005-03-12 Thread PFC
What about using PREPARE ? ---(end of broadcast)--- TIP 9: the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match

Re: [SQL] Links between rows in a table

2005-03-07 Thread PFC
The trouble with this approach is that for some ways of using this data you will need to worry about the ordering of of the values. Tradeoffs, always tradeoffs... It depends on the application. Note also that it eliminates duplicates ; moreover without such a condition, any relation A-B could

Re: [SQL] Links between rows in a table

2005-03-06 Thread PFC
It would probably be better to always have either both or neither of the symmetric relationships in the table. You could make a set of triggers to enforce this. Because your relation is symmetric, you should not name them user and friend. The duplication is useless if you add a constraint :

Re: [SQL] Postgres performance

2005-03-06 Thread PFC
Really ? In my experience this is a sure way to get inconsistencies slowly creeping into your database, and you also get a load of funky concurrency issues. Yes, you are rigth... my insert/update are very simple and without problems and so I think to use 'foreign key' coded to

Re: [SQL] Postgres performance

2005-03-05 Thread PFC
No, I haven't foreign keys in the older version, in that new I've it... however I manage relations from app code (PHP)... Really ? In my experience this is a sure way to get inconsistencies slowly creeping into your database, and you also get a load of funky concurrency issues. doesn't

Re: [SQL] Simple delete takes hours

2005-03-04 Thread PFC
Every time a row is removed from pwd_name, the ON DELETE CASCADE trigger will look in pwd_name_rev if there is a row to delete... Does it have an index on pwd_name_rev( rev_of ) ? If not you'll get a full table scan for every row deleted in pwd_name... On Thu, 03 Mar 2005 22:44:58 +0100,

Re: [SQL] Postgres performance

2005-03-02 Thread PFC
The reason PostgreSQL is slower is because it (and by extension the team behind it) cares about your data. Sure, postgres is (a bit but not much) slower for a simple query like SELECT * FROM one table WHERE id=some number, and postgres is a lot slower for UPDATES (although I heard that it's

Re: [SQL] More efficient OR

2005-02-16 Thread PFC
You sound like you don't like the performance you get with OR or IN, from this I deduce that you have a very large list of values to OR from. These make huge queries which are not necessarily very fast ; also they are un-preparable by their very nature (ie. the planner has to look at each

Re: [SQL] Relation in tables

2005-02-16 Thread PFC
Hello all... I am starting in Postgresql... And I have a question: I am developing a DB system to manage products, but the products may be separated by departaments (with its respectives coluns)... Like: CREATE TABLE products( id serial primary key, desc valchar(100), ... ); Okay, but

Re: [SQL] Matching a column against values in code

2005-02-16 Thread PFC
This has been discussed a few hours ago on the mailing list on the subject '[SQL] More efficient OR' On Fri, 11 Feb 2005 10:12:52 -0600, Tim [EMAIL PROTECTED] wrote: Hello all. I sometimes find myself needing an SQL query that will return all the rows of a table in which one column equals

Re: [SQL] Order of columns in a table important in a stored procedure?

2005-02-16 Thread PFC
French verb saisir : here, to enter data in a system by typing it. noun saisie : the action of doing so. It has other meanings : Saisir : - (commonly) to grab or get hold of something swiftly - (sometimes) to understand something - (lawspeak) that is also what the Oracle layers

Re: UPDATE TRIGGER on view WAS: Re: [SQL] Relation in tables

2005-02-16 Thread PFC
And all this time I thought that you couldn't write to a view. You can't. But you can make it seem so you can. You can create an ON UPDATE/INSERT trigger on a view which intercepts the UPDATE/INSERT to the view (which would otherwise fail) and do whatever you want with it,

Re: [SQL] triggers

2005-02-14 Thread PFC
update trigger working on same table??? If an UPDATE trigger does an update on its own table, it can trigger itself and explode... ---(end of broadcast)--- TIP 3: if posting/reading through Usenet, please send an appropriate

Re: [SQL] How to iterate through arrays?

2005-02-09 Thread PFC
- use TEXT instead of CHAR (what is CHAR without (n) ?) - inintialize your array with '{}' because it is created as NULL if you just declare it without setting it to an empty array. Hi there, I'm trying to iterate through arrays in PL/PGSQL: DECLARE update_query

Re: [SQL] the best way to get the first record from each group

2005-02-07 Thread PFC
I don't really gr0k your field names so I'll use an easier example : CREATE TABLE groups ( group_id SERIAL PRIMARY KEY, group_name TEXT NULL ) WITHOUT OIDS; CREATE TABLE people ( user_id SERIAL PRIMARY KEY, group_id INTEGER NOT NULL REFERENCES groups(group_id), score INTEGER NOT NULL )

Re: [SQL] Determining Rank

2005-02-04 Thread PFC
Michael, That's an excellent solution, but on my table, the explain plan sucks and the query time is over 3 minutes when implemented. Is there a simple way to get a row_num without using a temporary sequence? Thanks for your help. -Don Make your query a set returning function which iterates

Re: [SQL] PL/PgSQL - returning multiple columns ...

2005-02-03 Thread PFC
On Thu, 3 Feb 2005 12:48:11 -0400 (AST), Marc G. Fournier [EMAIL PROTECTED] wrote: Perfect, worked like a charm ... but the RETURNS still needs to be a SETOF, other then that, I'm 'away to the races' ... thanks :) No SETOF necessary : CREATE TYPE mytype AS ( number INTEGER, blah TEXT );

Re: [SQL] MSSQL versus Postgres timing

2005-02-01 Thread PFC
CREATE OR REPLACE VIEW viwassoclist AS SELECT a.clientnum, a.associateid, a.associatenum, a.lastname, a.firstname, jt.value AS jobtitle, l.name AS location, l.locationid AS mainlocationid, l.divisionid, l.regionid, l.districtid, (a.lastname::text || ', '::text) || a.firstname::text AS

Re: [SQL] plpgsql select into with multiple target variables

2005-01-28 Thread PFC
Try removing the comma after varz SELECT into varx, vary, varz, colx, coly, colz, FROM I've tried parens and various other things but no luck. John DeSoi, Ph.D. http://pgedit.com/ Power Tools for PostgreSQL ---(end of broadcast)---

Re: [SQL] testing/predicting optimization using indexes

2005-01-26 Thread PFC
I'm quite happy with the speedup in 3, but puzzled over the slowdown in 2. Could you provide : - SELECT count(*) FROM structure; = NRows - SELECT avg(length(smiles)) FROM structure; Then VACUUM FULL ANALYZE structure Redo your timings and this

Re: [SQL] testing/predicting optimization using indexes

2005-01-26 Thread PFC
Finally, I built the table with all the additional columns created during the initial creation of the table. The original speed was obtained! Quite strange ! Did you vacuum full ? analyze ? Did you set a default value for the columns ? mmm maybe it's not the fact of adding the columns,

Re: [SQL] How do I ... SQL question

2005-01-17 Thread PFC
Return only four rows beginning at second row: SELECT count(*) AS count, name, year FROM a GROUP BY name, year ORDER BY count DESC, name ASC LIMIT 4 OFFSET 1; count name year --- -- -- 3 joe2004 s,e,e 2 bob2003 w,e 2 kim2003 s,s 2 sue

Re: [SQL] SQL design question: null vs. boolean values

2005-01-16 Thread PFC
create table xyz ( field_foo char(1) check (field_foo in 'y', 'n'), foo_detail varchar(255), check ( case when field_foo='y' and foo_detail is null then false else true end ) ); A simpler check would be : CHECK( (field_foo = 'y' AND foo_detail

Re: [SQL] SQL Query Performance tips

2005-01-15 Thread PFC
If I understand well a person has all the free weapons which have a level = to his own level, and of course all the weapons he bought. 1) get da weapons One query can only use one index. Bad for you ! Let's split the free and non-free weapons. 1a) free weapons

Re: [SQL] assign the row count of a query to a variable

2005-01-14 Thread PFC
var := count(*) from T; or : SELECT INTO var count(*) from T; ---(end of broadcast)--- TIP 3: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to [EMAIL PROTECTED] so that your message can

Re: [SQL] Column with recycled sequence value

2005-01-13 Thread PFC
You could update all the fields which use this sequence number. You say you have a lot of activity so you must have mahy holes in your sequence, probably of the possible 2^32 values, only a fes millions are used. You can do the following : - Take down the database, back it up, and

  1   2   >