Re: [SQL] query assistance

2003-11-04 Thread Michael Glaesemann
Hi Jodi, On Wednesday, November 5, 2003, at 12:16 AM, Jodi Kanter wrote: Is there a straight forward way to pull out duplicates in a particular field given a value in another field? For example, I have a table that lists users and study names associated with those users. Each user can have one or

Re: [SQL] Need Help : Query problem

2003-11-19 Thread Michael Glaesemann
On Wednesday, November 19, 2003, at 10:26 AM, Abdul Wahab Dahalan wrote: How do I write a query so that I can get a result as below [ select only a record/s with same kk and kj but different pngk. For example here I've 3 records with same kk=01,kj=01 but diff pngk=a,b,c and 2 records with same kk

Re: [SQL] Crosstable query

2003-12-22 Thread Michael Glaesemann
.4, but you can add it if it's not. Hope this helps. Michael Glaesemann grzm myrealbox com ---(end of broadcast)--- TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]

[SQL] Distributed keys

2003-12-23 Thread Michael Glaesemann
efulness of PostgreSQL without hindering SQL conformance. I'm interested in hearing what others have to say, especially along the lines of implementation. I haven't seen much discussion of distributed keys on the lists (other than Josh Berkus), so perhaps there isn't much inte

Re: [SQL] postgreSQL editors

2003-12-30 Thread Michael Glaesemann
earch patterns), Applescript, FTP, CVS, and shell script support, if those things interest you. I write most of my SQL in it before feeding the file to psql or just copying and pasting the commands into phppgadmin or psql directly. Michael Glaesemann grzm myrealbox com ---

Re: [SQL] Ambiguous error message

2004-01-02 Thread Michael Glaesemann
otocols using (protocolid); If you explain a little more what your query is trying to return, I might be able to help more. Michael Glaesemann grzm myrealbox com ---(end of broadcast)--- TIP 6: Have you searched our list archives? http://archives.postgresql.org

Re: [SQL] sort by on two columns

2004-01-02 Thread Michael Glaesemann
e UNION, I believe. If it's something else, I'm not sure I understand what you're asking. Perhaps you could include a sample of what you're getting, along with what you'd like to see? Michael Glaesemann grzm myrealbox com ---(end of broadcas

Re: [SQL] sort by on two columns

2004-01-02 Thread Michael Glaesemann
online docs: <http://www.postgresql.org/docs/current/static/queries-order.html> It doesn't explicitly give you an example of sorting on more than one column, but the syntax explanation at the top includes it. Does this help? Michael Glaesemann grzm myrealbox com ---

Re: [SQL] COPY command

2004-01-08 Thread Michael Glaesemann
I usually use 'NULL' as NULL, so the line would be foo bar NULL foofoo barbar then use the COPY command with NULL AS 'NULL' Check out the following link for detailed info on the COPY command: <http://www.postgresql.org/docs/current/static/sql-copy.html> HTH Michae

Re: [SQL] Missing data for column

2004-01-09 Thread Michael Glaesemann
quot; Could you include the COPY command you're using, as well as the first couple of lines of the file you're copying from? It's hard to know what the problem is without this. Regards, Michael Glaesemann grzm myrealbox com ---(end of broadcast)

Re: [SQL] Transpose rows to columns

2004-01-12 Thread Michael Glaesemann
have some ideas on how to do this? I'd suggest looking at tablefunc in /contrib. It includes crosstab functionality that you might find useful. I don't think it'll do exactly what you describe here, but something quite similar. Michael Glaesemann grzm myrealbox com --

Re: [SQL] Insert into:Bad date external representation

2004-01-14 Thread Michael Glaesemann
mp c; ERROR: Bad date external representation '' Here's your clue right here: It means the dodate text field in custdo_temp contains data that does not represent a valid date. Check to make sure custdo_temp.dodate is all properly formatted. H

Re: [SQL] sql query with join and parameter in postgresql function

2004-01-16 Thread Michael Glaesemann
x27;m not wrong, a view does not accept any parameter as input... But you can just define the view and select it with a WHERE clause with your parameter, just like a normal table. Would that help? Michael Glaesemann grzm myrealbox com ---(end of broadcast)--

Re: [SQL] Trying to make efficient "all vendors who can provide all items"

2004-03-09 Thread Michael Glaesemann
SELECT DISTINCT vi1.vendor_id FROM vendors_items vi1 WHERE NOT EXISTS ( SELECT item_id FROM select_items EXCEPT SELECT items FROM vendors_items vi2 WHERE vi1.vendor_id = vi2.vendor_id ) ); Michael Glaesemann grzm myrealbox com On Mar 9, 2004, at 10:37 PM, <[

Re: [SQL] feature request ?

2004-06-23 Thread Michael Glaesemann
IF foo IS NULL THEN ... ELSIF foo THEN ... ELSE ... END IF; Michael Glaesemann grzm myrealbox com ---(end of broadcast)--- TIP 5: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faqs/FAQ.html

Re: [SQL] feature request ?

2004-06-24 Thread Michael Glaesemann
On Jun 24, 2004, at 1:49 PM, sad wrote: On Thursday 24 June 2004 09:32, Michael Glaesemann wrote: Creating a new control structure to do handle this seems odd. However, one could easily have the same effect using a nested if. Using the pl/pgsql ELSIF construct, it's pretty straightforward. I

Re: [SQL] feature request ?

2004-06-24 Thread Michael Glaesemann
lternative" for 3-valued logic afaik. Why should PostgreSQL go beyond what the standard specifies in this hairy area? Three-valued logic is something I strive to stay away from to the best of my ability, as it is far too complicated for my feeble mind. Michael Glaesemann grz

Re: [SQL] surrogate key or not?

2004-07-23 Thread Michael Glaesemann
ed to ensure there is a way to identify each row uniquely. It is quite independent of which columns you may or may not want to search on. If name is not going to be necessarily unique in the table, it isn't a primary key. Michael Glaesemann grzm myrealbox com

Re: [SQL] surrogate key or not?

2004-07-23 Thread Michael Glaesemann
On Jul 23, 2004, at 6:00 PM, Kenneth Gonsalves wrote: On Friday 23 July 2004 03:29 pm, Michael Glaesemann wrote: You appear to be misunderstanding the purpose of a primary key. A primary key is used to ensure there is a way to identify each row uniquely. It is quite independent of which columns

Re: [SQL] Datetime

2004-08-03 Thread Michael Glaesemann
What you want is timestamp(2) or timestamptz(2), I believe. Michael Glaesemann grzm myrealbox com ---(end of broadcast)--- TIP 2: you can get off all lists at once with the unregister command (send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])

Re: [SQL] Datetime

2004-08-03 Thread Michael Glaesemann
e a better choice if one is concerned with compatibility. Michael Glaesemann grzm myrealbox com ---(end of broadcast)--- TIP 5: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faqs/FAQ.html

Re: [SQL] Datetime

2004-08-03 Thread Michael Glaesemann
On Aug 3, 2004, at 8:50 PM, Achilleus Mantzios wrote: O kyrios Michael Glaesemann egrapse stis Aug 3, 2004 : I believe this is incorrect. I believe PostgreSQL uses its own Do you suggest postgresql has any other means of getting time except the time(2) syscall?? timestamp datatype internally

Re: [SQL] Datetime

2004-08-03 Thread Michael Glaesemann
On Aug 4, 2004, at 12:13 AM, Tom Lane wrote: Michael Glaesemann <[EMAIL PROTECTED]> writes: No. I'm just saying that PostgreSQL does not represent or store timestamps as epoch timestamps internally. You're wrong. It's not exactly Unix-like because we use a different epoch date

Re: [SQL] Datetime

2004-08-03 Thread Michael Glaesemann
ation has turned my negative "what it is not" knowledge into the much more positive "what it is", and that's always a good thing. Michael Glaesemann grzm myrealbox com ---(end of broadcast)--- TIP 4: Don't 'kill -9' the postmaster

Re: [SQL] UNIQUE constraint

2004-08-08 Thread Michael Glaesemann
| c ---+---+--- 1 | 2 | 3 1 | 1 | 1 (2 rows) Michael Glaesemann grzm myrealbox com ---(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] casting BOOL to somthng

2004-08-31 Thread Michael Glaesemann
t; test=# select true::text; text -- t (1 row) You can find more information at <http://www.postgresql.org/docs/current/static/sql-createcast.html> Hope this helps! Michael Glaesemann grzm myrealbox com ---(end of broadcast)--- TIP 6: Have you searched our list archives? http://archives.postgresql.org

Re: [SQL] Arbitrary precision arithmatic with pgsql

2004-08-31 Thread Michael Glaesemann
power operation for numeric, which I think you'd have to write yourself, possibly leveraging one of the procedural languages (perhaps pl/perl) to access such an operation (as you yourself mentioned). I'm sure you could find an algorithm to port to PL/pgsql as well. Hope this help

Re: [SQL] Arbitrary precision arithmatic with pgsql

2004-08-31 Thread Michael Glaesemann
On Aug 31, 2004, at 9:17 PM, Michael Glaesemann wrote: What you need is a power operation for numeric, which I think you'd have to write yourself, Looking a little closer, there is a pow() function that takes two numeric arguments and returns numeric. <http://www.postgresql.org/docs

Re: [SQL] casting BOOL to somthng

2004-08-31 Thread Michael Glaesemann
. Luckily PostgreSQL provides convenient ways of making user-defined casts. Just my thoughts. Michael Glaesemann grzm myrealbox com ---(end of broadcast)--- TIP 3: if posting/reading through Usenet, please send an appropriate subscribe-nomail c

Re: [SQL] Arbitrary precision arithmatic with pgsql

2004-08-31 Thread Michael Glaesemann
pow(numeric,numeric) function? Would the 100 be cast INT -> NUMERIC? Michael Glaesemann grzm myrealbox com ---(end of broadcast)--- TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]

Re: [SQL] casting BOOL to somthng

2004-08-31 Thread Michael Glaesemann
you don't print *something* you can't see it? Michael Glaesemann grzm myrealbox com ---(end of broadcast)--- TIP 8: explain analyze is your friend

Re: [SQL] casting BOOL to somthng

2004-09-01 Thread Michael Glaesemann
On Sep 1, 2004, at 2:55 PM, sad wrote: On Wednesday 01 September 2004 10:38, Michael Glaesemann wrote: On Sep 1, 2004, at 2:41 PM, sad wrote: On Wednesday 01 September 2004 09:24, Stephan Szabo wrote: There's a fairly accepted convention for integer representations. There's no such conv

Re: [SQL] HOW TO HANDLE ZEROS IN DATE FIELD?

2004-09-10 Thread Michael Glaesemann
00 to NULL, for example. You may be able to do some of this preprocessing in the database itself, first loading the raw data into a temporary table and then transforming it before putting it into the desired table. Michael Glaesemann grzm myrealbox com

Re: [SQL] HOW TO HANDLE ZEROS IN DATE FIELD?

2004-09-11 Thread Michael Glaesemann
ch will be doing these inserts. In that case I would recommend either using temp tables to process the data, or build a middleware app that other client apps would connect to, rather than to the db directly, the goal being to have a single API against which you can code the client apps. Good

Re: [SQL] create unique index schema.index_name on table (column)?

2004-09-11 Thread Michael Glaesemann
On Sep 12, 2004, at 5:42 AM, [EMAIL PROTECTED] wrote: Is the syntax "schema_name.index_name" for create unique index wrong, unsupported or what? I know is doesn't work as postgres kicks me back a syntax error each time (version 7.3.2 & 7.4.5). -sigh- Could you give a full example (including the e

Re: [SQL] create unique index schema.index_name on table (column)?

2004-09-11 Thread Michael Glaesemann
On Sep 12, 2004, at 2:48 PM, Michael Glaesemann wrote: On Sep 12, 2004, at 5:42 AM, [EMAIL PROTECTED] wrote: Is the syntax "schema_name.index_name" for create unique index wrong, unsupported or what? I know is doesn't work as postgres kicks me back a syntax error each time (versio

Re: [SQL] Create interval using column value?

2004-10-24 Thread Michael Glaesemann
g 'build_interval'. Try something like WHERE built_on < current_timestamp - build_interval * INTERVAL '0.001 second'; (btw, current_timestamp is the SQL standard for now() ) Regards, Michael Glaesemann grzm myrealbox com ---(end of broadcast)

Re: [SQL] get sequence value of insert command

2004-11-19 Thread Michael Glaesemann
On Nov 19, 2004, at 5:41 PM, Erik Thiele wrote: now how do i know the id of my newly inserted element? and how can this be done in a completely concurrency safe way? This is a FAQ (4.15.1, among others). See currval() and nextval() in the documentation as well. Michael Glaesemann grzm myrealbox

Re: [SQL] error: cast the timestam expression

2005-01-28 Thread Michael Glaesemann
text HINT: You will need to rewrite or cast the expression." Both dates are of type timesamp! Could you post the output to \d xyz and \d comments from psql? Michael Glaesemann grzm myrealbox com ---(end of broadcast)--- TIP 6: Have

Re: [SQL] pg primary key bug?

2005-02-03 Thread Michael Glaesemann
gth(constname) as constname_length from a_constants_str; Here's another one which would show if PostgreSQL is treating them equally: select constname, count(constname) from a_constants_str; The results of these queries might shed some light on the issue. Hope this helps. Michael Glae

Re: [SQL] Determining Rank

2005-02-03 Thread Michael Glaesemann
marties" has a bunch of things like this in it. I've found it quite helpful. Hope this helps. Michael Glaesemann grzm myrealbox com create table items ( item text not null , qty integer not null ) without oids; insert into items (item, qty) values ('foo', 1); insert

Re: [SQL] definative way to place secs from epoc into timestamp

2005-03-02 Thread Michael Glaesemann
esn't help you now, but it'll be there in the future. Michael Glaesemann grzm myrealbox com ---(end of broadcast)--- TIP 7: don't forget to increase your free space map settings

Re: [SQL] definative way to place secs from epoc into timestamp

2005-03-03 Thread Michael Glaesemann
aterial hard to get my head around myself :). Since I went through it, I thought I'd share it with the list. Regards, Michael Glaesemann grzm myrealbox com test=# create table ts2int (ts2int_id serial not null unique , ts timestamp without time zone default current_timestamp , tstz

Re: [SQL] Query issue/8.0.1/Serendipity

2005-03-08 Thread Michael Glaesemann
if e.timestamp is >= 1110241185 it's definitely going to be <= 1112335200 Hope this helps. I find white space helps me read my own SQL much more easily. Michael Glaesemann grzm myrealbox com ---(end of broadcast)--- TIP 3: if posting/read

Re: [SQL] Query issue/8.0.1/Serendipity

2005-03-08 Thread Michael Glaesemann
On Mar 8, 2005, at 21:28, Larry Rosenman wrote: On Tuesday 08 March 2005 06:21 am, Michael Glaesemann wrote: Larry, Restating your SQL in a more reader-friendly form: [snip] This is from an error page (and machine generated to boot :) ) Regardless if it's machine-generated or not, I&#x

Re: [SQL] 'true'::TEXT::BOOLEAN

2005-06-03 Thread Michael Glaesemann
); text2bool --- t (1 row) test=# select text2bool('false'); text2bool --- f (1 row) Just an idea. Michael Glaesemann grzm myrealbox com ---(end of broadcast)--- TIP 4: Don't 'kill -9' the postmaster

Re: [SQL] 'true'::TEXT::BOOLEAN

2005-06-03 Thread Michael Glaesemann
ype type_source on (castsource = type_source.oid) join pg_type type_target on (casttarget = type_target.oid) where type_target.typname = 'bool' or type_source.typname = 'bool' order by type_source.typname; source | target ----+---- (0 rows) This is in v8.0.3 Michael G

Re: [despammed] [SQL] rejecting characters in a field

2005-06-09 Thread Michael Glaesemann
*/^#'. How do i do this? With a RULE or a TRIGGER. Or a CHECK constraint on the column. Michael Glaesemann grzm myrealbox com ---(end of broadcast)--- TIP 8: explain analyze is your friend

Re: [SQL] Permission denied for language pltclu

2005-06-10 Thread Michael Glaesemann
/docs/8.0/interactive/pltcl.html Hope this helps. Michael Glaesemann grzm myrealbox com ---(end of broadcast)--- TIP 7: don't forget to increase your free space map settings

Re: [SQL] Permission denied for language pltclu

2005-06-10 Thread Michael Glaesemann
. Now how to change permission of that user to be able to create this function? Make sure the user creating the function is a PostgreSQL superuser. Michael Glaesemann grzm myrealbox com ---(end of broadcast)--- TIP 2: you can get off all lists a

Re: [GENERAL] [SQL] Permission denied for language pltclu

2005-06-10 Thread Michael Glaesemann
superuser should be able to create such a function, regardless of whether they created the database or not. Michael Glaesemann grzm myrealbox com ---(end of broadcast)--- TIP 5: Have you checked our extensive FAQ? http

Re: [GENERAL] [SQL] Permission denied for language pltclu

2005-06-10 Thread Michael Glaesemann
On Jun 10, 2005, at 7:26 PM, Michael Glaesemann wrote: On Jun 10, 2005, at 6:51 PM, Dinesh Pandey wrote: Actually this problem occurs when the function is being created by the user who has not created the current database. Solution: The database must be created by the user who is

Re: [SQL] UPDATEABLE VIEWS ... Examples?

2005-06-20 Thread Michael Glaesemann
issue with materialized views is to make sure it's always up-to-date with the evaluation of the view. Michael Glaesemann grzm myrealbox com ---(end of broadcast)--- TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]

Re: [SQL] customising serial type

2005-06-21 Thread Michael Glaesemann
ql.org/docs/8.0/interactive/sql-createsequence.html http://www.postgresql.org/docs/8.0/interactive/sql-altersequence.html Michael Glaesemann grzm myrealbox com ---(end of broadcast)--- TIP 9: In versions below 8.0, the planner will ignore your desire to

Re: [SQL] Create connection with Oracle database from Postgres plpgsql function

2005-07-05 Thread Michael Glaesemann
On Jul 5, 2005, at 6:40 PM, Dinesh Pandey wrote: How can we create connection with Oracle database from Postgres plpgsql function and execute some oracle stored procedure? I don't think it's possible with plpgsql. Try DBI-link. <http://pgfoundry.org/projects/dbi-link/> Mi

Re: [SQL] Generating a range of integers in a query

2005-07-13 Thread Michael Glaesemann
this table as a subquery. Any ideas? Take a look at generate_series(), available in v8.0 and above. http://www.postgresql.org/docs/8.0/interactive/functions-srf.html Michael Glaesemann grzm myrealbox com ---(end of broadcast)--- TIP 9: In

Re: [SQL] diary constraints

2005-08-23 Thread Michael Glaesemann
s (by George Essig, I believe): Developing Time-Oriented Database Applications in SQL by Richard T. Snodgrass The book is out of print, but the author has made the PDF available on his website at: http://www.cs.arizona.edu/people/rts/tdbbook.pdf Hope this helps! Michael Glaesemann grzm myre

Re: [SQL] How to join several selects

2005-08-24 Thread Michael Glaesemann
AS num_of_users FROM users WHERE start_time BETWEEN startDate + 1 AND startDate + 2 And of course, using EXPLAIN ANALYZE will help decide which is more performant. Michael Glaesemann grzm myrealbox com ---(end of broadcast)--- TIP 4: Have you searched our list archives? http://archives.postgresql.org

Re: [SQL] Tidying values on variable instantiation

2005-08-25 Thread Michael Glaesemann
can understand your motivation, I personally think this kind of operation is best left in the application layer (which includes such insert functions) rather than the DDL. Just my ¥2. Michael Glaesemann grzm myrealbox com ---(end of broadcast)--- TIP 6: explain analyze is your friend

Re: [SQL] a "catch all" type ... such a thing?

2005-09-08 Thread Michael Glaesemann
ook in the archives will provide more info. Michael Glaesemann grzm myrealbox com ---(end of broadcast)--- TIP 3: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faq

Re: [SQL] Age in days

2005-09-12 Thread Michael Glaesemann
On Sep 10, 2005, at 1:04 AM, Mark A. Strivens wrote: select date_trunc('day',age(now(),dateofbirth)) from people My questions is, is there any way to convert that figure into an age expressed as a number days only? Try select current_date - dateofbirth from people; Michael

Re: [SQL] changing a column's position in table, how do you do that

2005-09-28 Thread Michael Glaesemann
lexibility. Changing a few SQL statements to return (or insert) the columns how you want them is much easier than changing the underlying table structure and having to make sure *all* of your queries then fit the new table structure. Michael Glaesemann grzm myrealbox com --

Re: [SQL] Update timestamp on update

2005-10-12 Thread Michael Glaesemann
dencies, so it should be relatively easy for people to install it if they want. (IIRC, there's even been discussion in the past of whether or not PL/pgSQL should be installed by default.) Michael Glaesemann grzm myrealbox com ---(end of broadcast)--

Re: [SQL] Query information needed

2005-10-18 Thread Michael Glaesemann
duration from cdr; Then I'd select from this view using aggregates: select callhour, avg(duration) as avg_duration from cdr where src = 601 group by callhour; You could write it This should help you with the simple case of just hourly averages. For averages on any given

Re: [SQL] Problem -Postgre sql

2005-10-18 Thread Michael Glaesemann
t sounds like it might be similar to either COALESCE or the IS NULL expression. These pages might help you: COALESCE http://www.postgresql.org/docs/8.0/interactive/functions- conditional.html#AEN12056 IS NULL http://www.postgresql.org/docs/8.0/interactive/functions-comparison.html Hope this helps.

Re: [SQL] query to file

2005-10-18 Thread Michael Glaesemann
o/file.txt For more psql goodness, take a look at: http://www.postgresql.org/docs/8.0/interactive/app-psql.html Hope this helps! Michael Glaesemann grzm myrealbox com ---(end of broadcast)--- TIP 5: don't forget to increase your free space map settings

Re: [SQL] Problem -Postgre sql

2005-10-18 Thread Michael Glaesemann
and work on columns directly. http://www.postgresql.org/docs/8.0/interactive/functions-aggregate.html I suggest you take some time to look at the docs. They're quite extensive and helpful. http://www.postgresql.org/docs/8.0/interactive/index.html Michael Glaesemann grzm myrealbox com I'm not quit

Re: [SQL] SQL language

2005-10-24 Thread Michael Glaesemann
SQL as 'select true;'; CREATE FUNCTION test=# select test_true(); test_true --- t (1 row) If you want to install other procedural languages, perhaps the documentation can help. http://www.postgresql.org/docs/8.0/interactive/xplang.html#XPLANG- INSTALL Hope this helps

Re: [SQL] Article on Oracle & MySQL in E-week

2005-10-24 Thread Michael Glaesemann
article? http://www.eweek.com/article2/0,1895,1876702,00.asp I skimmed it, but didn't see any mention of PostgreSQL. Perhaps I missed it, or perhaps you mean another article? Michael Glaesemann grzm myrealbox com ---(end of broadcast)--- TIP 4: H

Re: [SQL] date question

2005-11-03 Thread Michael Glaesemann
ime zone - integer How can drop a day to now()?? You can try a couple of different things: one is to use CURRENT_DATE - 1 instead of now() -1. Another would be to cast now() to date, e.g., now()::date - 1. Hope this helps. Michael Glaesemann grzm myrealbox com --

Re: [SQL] Design question: Scalability and tens of thousands of tables?

2005-11-03 Thread Michael Glaesemann
that may help you accomplish this: OSCON 2004 presentation: Flexible Data Acquisition and Analysis Joe's an active member of the PostgreSQL community and there's a lot of good stuff there. Hope this helps. Michael Glaesemann grzm myrealbox com ---(e

Re: [SQL] DISTINCT ON

2005-11-18 Thread Michael Glaesemann
oided when possible, stating that aggregations and sub-queries should be used instead... How would this be done in this scenario? Something like: select max(date), id from observation group by vector_id, obs_type; Do test to see which is better in your situation. Michael Glaesemann grzm myr

Re: [SQL] DISTINCT ON

2005-11-18 Thread Michael Glaesemann
-Original Message- From: Michael Glaesemann [mailto:[EMAIL PROTECTED] Sent: Saturday, 19 November 2005 12:28 p.m. On Nov 19, 2005, at 7:49 , Jeremy Palmer wrote: SELECT DISTINCT ON (vector_id, obs_type) id FROM observation ORDER BY vector_id, obs_type, date

Re: [SQL] dow question

2005-12-07 Thread Michael Glaesemann
it is merely my fantasy. ;-) Will to_char() do what you want? Something like test=# select to_char(current_date, 'Day -MM-DD'); to_char -- Thursday 2005-12-08 (1 row) http://www.postgresql.org/docs/current/interactive/functions- formatting.html

Re: [SQL] ORDER BY does not work as expected with multiple joins

2006-01-13 Thread Michael Glaesemann
er by some_date; some_date | name1 | name2 +---+--- 2006-01-01 | John | Jane 2006-01-03 | John | Sam 2006-01-05 | Jane | John (3 rows) Hope this helps. Michael Glaesemann grzm myrealbox com -- DDL create table table1 ( id1 integer not null , id2 integer not null

Re: [SQL] ORDER BY does not work as expected with multiple joins

2006-01-13 Thread Michael Glaesemann
a relational construct. You can always use EXPLAIN ANALYZE to compare query plans. It can be very useful to see how your query is executed by the planner. Michael Glaesemann grzm myrealbox com ---(end of broadcast)--- TIP 4:

Re: [SQL] ORDER BY does not work as expected with multiple joins

2006-01-13 Thread Michael Glaesemann
On Jan 14, 2006, at 0:45 , Michael Glaesemann wrote: On Jan 14, 2006, at 0:22 , Adam Rosi-Kessel wrote: id1 will always have a value but id2 can be NULL. So should I do a left JOIN on id2 but a plain JOIN on id1? Is there a disadvantage to using a left JOIN where it is not necessary

Re: [SQL] psql client: technique for applying default values to :variables?

2006-01-14 Thread Michael Glaesemann
he command line, BUT have it default to a value inside the SQL script if not present on the command line. You could write a wrapper script that would accept a command line argument and load the file with the appropriate SET statement prepended. Michael Glaesemann grzm myr

Re: [SQL] Characters that needs escape characters when inserting to database

2006-01-16 Thread Michael Glaesemann
://www.postgresql.org/docs/current/interactive/sql- syntax.html#SQL-SYNTAX-STRINGS Michael Glaesemann grzm myrealbox com ---(end of broadcast)--- TIP 4: Have you searched our list archives? http://archives.postgresql.org

Re: [SQL] Matching several rows

2006-01-17 Thread Michael Glaesemann
from "URIGHTS" where "RIGHT" = 10 ) as right_10 using ("ID") Simple is in the eye of the beholder. You might want to compare the EXPLAIN ANALYZE output to see if there are any significant differences between these queries. Michael Glaesemann grzm myrealbox com ---(end of broadcast)--- TIP 3: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faq

Re: [SQL] bug with if ... then ... clause in views

2006-01-18 Thread Michael Glaesemann
n a table). As an aside, you need to double-quote identifiers if you want them to be case-sensitive: otherwise they'll be down-cased. Hope this helps. Michael Glaesemann grzm myrealbox com ---(end of broadcast)--- TIP 6: explain analyze is your friend

Re: [SQL] Still struggling with history tables

2006-01-18 Thread Michael Glaesemann
more theoretical information, "Temporal Data and the Relational Model" by CJ Date, Hugh Darwen, and Nikos Lorentzos.[2] Michael Glaesemann grzm myrealbox com [1](http://www.cs.arizona.edu/people/rts/tdbbook.pdf) [2](http://www.amazon.com/gp/product/1558608559/) ---

Re: [SQL] Matching several rows

2006-01-18 Thread Michael Glaesemann
clause Find below the query plans for the variations we've seen (as well as DDL statements): Michael Glaesemann grzm myrealbox com create table urights ( id integer not null , uright integer not null ); copy urights (id, uright) from stdin; 20 1 20 2 20 5 20

Re: [SQL] Matching several rows

2006-01-18 Thread Michael Glaesemann
.038 rows=5 loops=1) Filter: ((uright = 2) OR (uright = 5) OR (uright = 10)) Total runtime: 0.386 ms (6 rows) Michael Glaesemann grzm myrealbox com ---(end of broadcast)--- TIP 1: if posting/reading through Usenet, please send an

Re: [SQL] stored procedures for complex SELECTs

2006-01-18 Thread Michael Glaesemann
NALYZE or run some other benchmark to see if there's a performance difference. Then you'll know for sure—and have numbers to back it up. Michael Glaesemann grzm myrealbox com ---(end of broadcast)--- TIP 2: Don't 'kill -9' the postmaster

Re: [SQL] Error calling self-made plpgsql function "function XYZ(bigint) does not exist"

2006-01-19 Thread Michael Glaesemann
n name and argument types. You may need to add explicit type casts. If you double-quote your function name (or any identifier) when you create it, you'll need to double-quote them when you call the function as well. Try: select * from "InventGroups_GetAllParents"(0::int8)

Re: [SQL] Error calling self-made plpgsql function "function XYZ(bigint) does not exist"

2006-01-19 Thread Michael Glaesemann
-> mysuperfield MySuperField -> mysuperfield mysuperfield -> mysuperfield "MYSUPERFIELD" -> MYSUPERFIELD "MySuperField" -> "MySuperField" "mysuperfield" -> mysuperfield Michael Glaesemann grzm myrealbox com ---(en

Re: [SQL] alter table

2006-02-15 Thread Michael Glaesemann
; ALTER TABLE fv_wystawione ALTER id_fv SET DEFAULT nextval ('id_fv_seq'::text); ALTER TABLE fv_wystawione ALTER imie SET DEFAULT ''; commit; Michael Glaesemann grzm myrealbox com ---(end of broadcast)--- TIP 6: explain analyze is your friend

Re: [SQL] restircting rows

2006-02-22 Thread Michael Glaesemann
://www.postgresql.org/docs/8.1/interactive/sql-select.html#SQL-LIMIT Michael Glaesemann grzm myrealbox com ---(end of broadcast)--- TIP 3: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faq

Re: [SQL] pg reserved words

2006-02-28 Thread Michael Glaesemann
ractive/sql-keywords- appendix.html I see FREEZE right between FREE and FROM. It's not an SQL keyword, but it is used in PostgreSQL withe VACUUM command. http://www.postgresql.org/docs/current/interactive/sql-vacuum.html Hope this helps. Michael Glaesemann grzm myrealbox com -

Re: [SQL] How to check date-interval constraints

2006-03-02 Thread Michael Glaesemann
her than just CREATE TRIGGER to apply the constraints you're looking for, as often you'll need to wrap a multi-statement update in a transaction to ensure integrity. Michael Glaesemann grzm myrealbox com ---(end of broadcast)--- TIP 3:

Re: [SQL] Check/unique constraint question

2006-03-05 Thread Michael Glaesemann
2 | 5 | f 3 | 5 | t 4 | 6 | f 5 | 6 | t (5 rows) insert into foo (id, active) values (5, true); ERROR: duplicate key violates unique constraint "foo_partial_idx" Michael Glaesemann grzm myrealbox com ---(end of broadcast)-

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

2006-03-10 Thread Michael Glaesemann
st t2 on (t1.a = t2.b and t1.b = t2.a) where t1.a < t2.a; t1_id | t2_id ---+--- 4 | 7 1 | 2 (2 rows) Hope this helps! Michael Glaesemann grzm myrealbox com ---(end of broadcast)--- TIP 1: if posting/reading through Use

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

2006-03-11 Thread Michael Glaesemann
On Mar 11, 2006, at 16:46 , Michael Glaesemann wrote: select t1.id as t1_id, t2.id as t2_id from test t1 join test t2 on (t1.a = t2.b and t1.b = t2.a) where t1.a < t2.a; t1_id | t2_id ---+--- 4 | 7 1 | 2 (2 rows) Just a follow-up (mostly to myself): I'

Re: [SQL] Ask a PostgreSql question (about select )

2006-03-12 Thread Michael Glaesemann
p me one PostgreSQL Statement, Thanks in Oracle select rownum,groupid,qty from abc --- --- 1 a5 3 2 a2 4 3 a3 5 4 5 . . . in PostgreSql How to wirte Statement ( Rownum -> change ??) [EMAIL PROTECTED] Michael Glaesemann grzm myrealbox com -

Re: [SQL] Using a parameter in Interval

2006-03-21 Thread Michael Glaesemann
e generally recommended way is something like: test=# select '4'::integer * interval '1 week'; ?column? -- 28 days (1 row) or the more SQL compliant: test=# select cast('4' as integer) * interval '1 week'; ?column? -- 28 days (

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

2006-04-04 Thread Michael Glaesemann
one to obtain results in binary format. ... Hope this helps. Michael Glaesemann grzm myrealbox com ---(end of broadcast)--- TIP 5: don't forget to increase your free space map settings

Re: [SQL] Modeling trees with Nested Sets and Nested Intervals

2006-04-09 Thread Michael Glaesemann
On Apr 7, 2006, at 16:28 , Daniel Browning wrote: * Static Hierarchies and Binary Fractions in PostgreSQL, by Michael Glaesemann http://www.grzm.com/fornow/archives/2004/07/10/static_hierarchies This is the most complete out-of-the-box solution I've found. I wrote up Tropashko

Re: [SQL] ORDER BY question

2006-05-10 Thread Michael Glaesemann
something like: SELECT * FROM table ORDER BY "ID", "Name"; Hope this helps. Michael Glaesemann grzm seespotcode net ---(end of broadcast)--- TIP 3: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faq

Re: [SQL] timestamp query doesn't use an index ...

2006-05-20 Thread Michael Glaesemann
g., rows expected/actual 33110/94798). Does running ANALYZE help? Michael Glaesemann grzm seespotcode net ---(end of broadcast)--- TIP 1: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to [EMAIL PROTE

  1   2   >