Re: [SQL] intervals

2011-11-03 Thread Michael Glaesemann
NTERVAL; good. > expire := ('10' || ' days')::INTERVAL; bad. Michael Glaesemann grzm seespotcode net -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql

Re: [SQL] " in transaction" can't be killed with pg_cancel_backend(). Is it a bug?

2011-01-04 Thread Michael Glaesemann
ackend. Likely you're looking for pg_terminate_backend(). Michael Glaesemann grzm seespotcode net -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql

Re: [SQL] Table Design for Hierarchical Data

2010-04-06 Thread Michael Glaesemann
all)? I'd say one table for hierarchy and possibly another for the permissions data. > If one table, should the digits be broken into separate columns? Probably not. > Should parent > ids be stored in each node? Only if you use an encoding scheme (such as adjacency list) which requir

Re: [SQL] Problem with the to_timestamp function

2008-01-30 Thread Michael Glaesemann
e the equivalent of PM, rather than designating a time zone. Not that that affects your advice, of course. Michael Glaesemann grzm seespotcode net ---(end of broadcast)--- TIP 4: Have you searched our list archives?

Re: [SQL] extract or date_part on an interval? How many e

2008-01-27 Thread Michael Glaesemann
1 mons 30 days | 20 | f 1987-01-30 | 2008-01-28 | 20 years 11 mons 29 days | 20 | f (6 rows) Michael Glaesemann grzm seespotcode net ---(end of broadcast)--- TIP 2: Don't 'kill -9' the postmaster

Re: [SQL] TIMESTAMP comparison problem

2008-01-22 Thread Michael Glaesemann
o use integer datetimes? I would like to have at least microsecond precision. Well, you can't get better than microsecond precision with timestamps in Postgres. And the only way you can rely on that level of precision is to compile with --enable-integer-datetimes. Michael Glaesemann grzm s

Re: [SQL] EPOCH TIMESTAMP Conversion Problem

2008-01-01 Thread Michael Glaesemann
a future release. Michael Glaesemann grzm seespotcode net ---(end of broadcast)--- TIP 5: don't forget to increase your free space map settings

Re: [SQL] Misnamed field in subquery does not cause error when field name exists in parent query

2007-12-22 Thread Michael Glaesemann
On Dec 22, 2007, at 17:12 , Rick Innis wrote: It may be that SQL is doing exactly as it should, since 'id' is in scope within the subselect, but if that's the case it's a nasty gotcha. Yes, and yes. Michael Glaesemann grzm seespotcode net

Re: [SQL] NULLIF problem

2007-11-29 Thread Michael Glaesemann
;' when it probably means NULL. Michael Glaesemann grzm seespotcode net ---(end of broadcast)--- TIP 2: Don't 'kill -9' the postmaster

Re: [SQL] NULLIF problem

2007-11-27 Thread Michael Glaesemann
y need to handle this is you middleware, or handle the IF THEN explicitly in a function. Maybe CASE would work: CASE WHEN mytime = '' THEN NULL ELSE CAST(mytime AS TIMESTAMP) END Michael Glaesemann grzm seespotcode net ---(end of broadcast)--- TIP 2: Don't 'kill -9' the postmaster

Re: [SQL] dynmic column names inside trigger?

2007-11-23 Thread Michael Glaesemann
text) ... returns NULL Don't confuse RETURNS NULL ON NULL INPUT with the function return value: this is the verbose spelling of STRICT. Michael Glaesemann grzm seespotcode net ---(end of broadcast)--- TIP 9: In versions below 8.0, the pl

Re: [SQL] what's wrong with my date comparison?

2007-10-16 Thread Michael Glaesemann
7-10-31' as date_comparison; arithmetic_comparison | date_comparison ---+- f | t (1 row) Michael Glaesemann grzm seespotcode net ---(end of broadcast)--- TIP 6: explain analyze is your friend

Re: [SQL] Having difficulty writing a "best-fit" query..

2007-10-16 Thread Michael Glaesemann
oundry.org/projects/fulldisjunction/ Michael Glaesemann grzm seespotcode net ---(end of broadcast)--- TIP 2: Don't 'kill -9' the postmaster

Re: [SQL] Optimize querry sql

2007-09-15 Thread Michael Glaesemann
#x27;re mine :). I haven't measured it, but there might actually be (a very small bit of) overhead in calling CURRENT_TIMESTAMP and CURRENT_DATE as they're converted to now(), so that's one potential reason not to use them. Michael Glaesemann grzm seespotc

Re: [SQL] How to influence the planner

2007-08-31 Thread Michael Glaesemann
;re running which include bug and security fixes. Even better, upgrade to 8.2.4, as there may very well be performance improvements in 8.2 which help you. You could look through the 8.2 release notes to see if any might apply. Hope this helps. Michael Glaesemann grzm seespotcode net --

Re: [SQL] How to influence the planner

2007-08-31 Thread Michael Glaesemann
right up their alley. Hope this gets you started on the right track. Michael Glaesemann grzm seespotcode net ---(end of broadcast)--- TIP 5: don't forget to increase your free space map settings

Re: [SQL] date problems

2007-08-30 Thread Michael Glaesemann
; Enter data to be copied followed by a newline. End with a backslash and a period on a line by itself. >> 27/08/2007 >> \. Since the datestyle was changed, we can now input '27/08/2007'. test=# select * from dates; a_date ---- 2007-08-30 2007-08-

Re: [SQL] fetch first rows of grouped data

2007-08-28 Thread Michael Glaesemann
ink of a way to return more than one row per "distinct on condition". I'd be interested to hear if you've thought of a way to use DISTINCT ON in this situation. Michael Glaesemann grzm seespotcode net ---(end of broadcast)--

Re: [SQL] fetch first rows of grouped data

2007-08-27 Thread Michael Glaesemann
On Aug 27, 2007, at 13:12 , Michael Glaesemann wrote: select city, event, event_date, ( select count(event) from events i where i.city = o.city and i.event_date < o.event_date and event_date > current_date -- make sure they're future events Thi

Re: [SQL] fetch first rows of grouped data

2007-08-27 Thread Michael Glaesemann
future events having nearness_rank <= 1; Note that this can potentially show more than 2 events if the most recent upcoming events "tie" (have the same event_date). Michael Glaesemann grzm seespotcode net ---(end of broadcast)--- TIP 6: explain analyze is your friend

Re: [SQL] SELECT syntax synopsis: column_definition?

2007-08-21 Thread Michael Glaesemann
On Aug 21, 2007, at 18:04 , Michael Glaesemann wrote: So the *form* is right, but I don't know of an example that works. CREATE TABLE foos ( foo text PRIMARY KEY , title text NOT NULL ); INSERT INTO foos (foo, title) values ('foo', 'the great') , ('ba

Re: [SQL] SELECT syntax synopsis: column_definition?

2007-08-21 Thread Michael Glaesemann
10) as a(s text); But not quite, as this raises an error :) ERROR: a column definition list is only allowed for functions returning "record" So the *form* is right, but I don't know of an example that works. You've got me curious now, too! Mich

Re: [SQL] Join question

2007-08-21 Thread Michael Glaesemann
ded to proceed with the query, which can be useful when comparing alternatives, so you can compare using DISTINCT ON with your own query using max. Hope this helps. Michael Glaesemann grzm seespotcode net ---(end of broadcast)-

Re: [SQL] [GENERAL] Join query help

2007-08-20 Thread Michael Glaesemann
On Aug 20, 2007, at 20:33 , novice wrote: Many many thanks for all the advice =) Glad to help. Good luck! Michael Glaesemann grzm seespotcode net ---(end of broadcast)--- TIP 6: explain analyze is your friend

Re: [SQL] [GENERAL] Join query help

2007-08-20 Thread Michael Glaesemann
On Aug 20, 2007, at 20:27 , Michael Glaesemann wrote: Note: record_id is in integer, yet you're quoting the value ('1'). This causes the server to cast the text value to an integer. Here it's not going to cause much of a problem, just a couple CPU cycles. In ta

Re: [SQL] [GENERAL] Join query help

2007-08-20 Thread Michael Glaesemann
--- + 2007, 29 |1 | 2 | 1 2007, 30 |2 | 8 | 6 (2 rows) Michael Glaesemann grzm seespotcode net ---(end of broadcast)

Re: [SQL] Join query help

2007-08-20 Thread Michael Glaesemann
ation_count ---+--+--- +-------- 2007, 29 |2 | 6 | 4 2007, 30 |1 | 4 | 3 (2 rows) I've got data bel

Re: [SQL] SUPERUSER vs CREATEUSER causes foul 'code smell'

2007-08-16 Thread Michael Glaesemann
you using?) Michael Glaesemann grzm seespotcode net ---(end of broadcast)--- TIP 2: Don't 'kill -9' the postmaster

Re: [SQL] Problem with phone list.

2007-08-15 Thread Michael Glaesemann
with the same phone number has the same duration, which is also the max). If you add a DISTINCT (and ORDER BY) to the subquery, you could get distinct numbers, but potentially miss information. Michael Glaesemann grzm seespotcode net ---(end of broadcast)---

Re: [SQL] Getting pk of the most recent row, in a group by

2007-08-13 Thread Michael Glaesemann
UP BY type ) type_counts USING (type); Michael Glaesemann grzm seespotcode net ---(end of broadcast)--- TIP 5: don't forget to increase your free space map settings

Re: [SQL] populate value of column

2007-08-07 Thread Michael Glaesemann
explain the result you want? (And in the future, please post actual DDL and statements.) Michael Glaesemann grzm seespotcode net ---(end of broadcast)--- TIP 5: don't forget to increase your free space map settings

Re: [SQL] Adding NOT NULL columns in PostgreSQL 7.4?

2007-08-07 Thread Michael Glaesemann
round in 7.4, this should work: * Add the column (without the NOT NULL constraint) * UPDATE the table with the values you want in the new column * Add the NOT NULL constraint to the column. You should be able to wrap this all in a transaction if so desired. Hope this helps. Michael G

Re: [SQL] Using function like where clause

2007-08-06 Thread Michael Glaesemann
rom table where field_test = 'mydatum' Probably not. What have you tried? What does the documentation say? A couple of minutes in psql would probably be faster than sending an email to the list. Michael Glaesemann grzm seespotcode net ---(end of broadcast)--

Re: [SQL] Increment a sequence by more than one

2007-08-03 Thread Michael Glaesemann
ld be interleaved in this case. This might not be an issue, of course. Michael Glaesemann grzm seespotcode net ---(end of broadcast)--- TIP 4: Have you searched our list archives? http://archives.postgresql.org

Re: [SQL] Increment a sequence by more than one

2007-08-03 Thread Michael Glaesemann
rwise). Regarding Michael's suggestion - I tried messing around with LOCK and similar commands but they're only allowed to run against TABLES not SEQUENCES - too bad - that would have been perfect. Yeah, I thought that might be the case. Michael Glaesemann grzm seespotcode net ---(end of broadcast)--- TIP 3: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faq

Re: [SQL] Increment a sequence by more than one

2007-08-03 Thread Michael Glaesemann
mance to ignore transactions, so this may not be possible (though perhaps that's just values returned via the nextval function). Hope this gives you some additional ideas on how to handle this. Michael Glaesemann grzm seespotcode net ---(end of broadcast)--

Re: [SQL] [NOVICE] alter table table add column

2007-07-30 Thread Michael Glaesemann
And, I want to add the field name age with type integer after lastname OR before the address field. How to I do that? Can't without dumping the database, altering the schema in the dump, and reloading. But why does it matter? Just call the columns in the order you want. Michael Glaese

Re: [SQL] increment the primary key value without using sequences

2007-07-29 Thread Michael Glaesemann
issues. Michael Glaesemann grzm seespotcode net ---(end of broadcast)--- TIP 2: Don't 'kill -9' the postmaster

Re: [SQL] group by range of values

2007-07-27 Thread Michael Glaesemann
ades GROUP BY birth_decade ORDER BY birth_decade; birth_decade |avg --+ 1940 | 69500. 1950 | 55333. 1960 | 53000. 1970 | 40333. (4 rows) Hope this gives you some options.

Re: [SQL] Using escape strings in an insert statement.

2007-07-03 Thread Michael Glaesemann
On Jul 3, 2007, at 10:49 , Erik Jones wrote: On Jul 2, 2007, at 6:11 PM, Michael Glaesemann wrote: On Jul 2, 2007, at 17:45 , Paul Lambert wrote: tester=# insert into testing (test_text) values ('abcE'\\'123'); This should be INSERT INTO testing (test_text) value

Re: [SQL] Using escape strings in an insert statement.

2007-07-02 Thread Michael Glaesemann
On Jul 2, 2007, at 18:26 , Paul Lambert wrote: Looks like it's a toss-up between turning standard_conforming_strings on or turning escape_string_warning off, both seem to have the same effect in not giving the error anymore. A warning is not an error :) Michael Glaesemann

Re: [SQL] Using escape strings in an insert statement.

2007-07-02 Thread Michael Glaesemann
out. With standard_conforming_strings on (i.e., follow the SQL spec), the backslash is just a backslash character. Which one is the correct syntax and how can I make it not return anything other than a successful insert? Depends on the setting of standard_conforming_strings. Michael Glaese

Re: [SQL] yet another simple SQL question

2007-06-26 Thread Michael Glaesemann
erhaps John could have phrased his email differently, but I think he was trying to help Joshua. Michael Glaesemann grzm seespotcode net ---(end of broadcast)--- TIP 6: explain analyze is your friend

Re: [SQL] NO DATA FOUND Exception

2007-06-25 Thread Michael Glaesemann
SELECT prefix FROM WHERE prefix IN (). Another way to do this might be to not use a function at all, but a query along the lines of SELECT prefix FROM WHERE p_line LIKE prefix || '%'; Hope this helps. Michael Glaesemann grzm seespotcode net

Re: [SQL] join problem

2007-06-19 Thread Michael Glaesemann
[Please don't top post as it makes the discussion more difficult to follow, and please reply to the list so that others may benefit from and participate in the discussion.] On Jun 19, 2007, at 14:17 , A. R. Van Hook wrote: Michael Glaesemann wrote: On Jun 13, 2007, at 8:19 , A. R

Re: [SQL] [GENERAL] Setting Variable - (Correct)

2007-06-18 Thread Michael Glaesemann
ate) RETURNS date IMMUTABLE LANGUAGE sql AS $_$ select date_trunc('year', $1)::date $_$; CREATE FUNCTION truc_years_ago(date, integer) RETURNS date IMMUTABLE LANGUAGE sql AS $_$ select date_trunc('year', $1 - $2 * INTERVAL '1 year')::date $_$: Note that foo::date is Pos

Re: [SQL] [GENERAL] Setting Variable - (Correct)

2007-06-18 Thread Michael Glaesemann
production_hours of each month of the current year, and I need to return too the average of the 3 past years, can I do all in only one query or I need to do a UNION with another query? Glad you found it helpful. What have you tried so far? Michael Glaesemann grzm seespotcode net

Re: [SQL] [GENERAL] Setting Variable - (Correct)

2007-06-18 Thread Michael Glaesemann
On Jun 18, 2007, at 10:17 , Michael Glaesemann wrote: Looking over your function, I'm a little confused about what you're trying to do. I'm guessing the (final) result you're trying to get is the number of hours lost for each product per area per month for the thre

Re: [SQL] [GENERAL] Setting Variable - (Correct)

2007-06-18 Thread Michael Glaesemann
(YEAR FROM START_DATE) = EXTRACT(YEAR FROM END_DATE)+3 LOOP will only be true for a limited number of months, not over the whole three-year range. The idea of three years has no real meaning in the query after this point. Anyway, hope this helps. Michael Glaesemann grzm seespotcode net ---(end of broadcast)--- TIP 4: Have you searched our list archives? http://archives.postgresql.org

Re: [SQL] Setting variable

2007-06-18 Thread Michael Glaesemann
hours_temp" line 10 at assignment Note that the error is at line 10. You've only shown lines 1 through 7 of the function body, so you haven't actually shown us where the error is. Michael Glaesemann grzm seespotcode net ---(end of broadcast)-

Re: [SQL] join problem

2007-06-13 Thread Michael Glaesemann
ems doesn't have a cusid column, you can use USING (cusid) and USING (ivid) rather than ON (cai.cusid = v.cusid) and ON (v.ivid = i.ivid), which has the nice property of outputing only one join column rather than one column for each table, (i.e., only one cusid column rather than o

Re: [SQL] subtract a day from the NOW function

2007-06-07 Thread Michael Glaesemann
1 day 01:00:00 It is a bit tricky. Datetime math is inherently so. select timestamptz '2007-11-04' + interval '1 day 01:00:00'; ?column? 2007-11-05 01:00:00-08 What PostgreSQL is doing behind the scenes is incrementing the date

Re: [SQL] subtract a day from the NOW function

2007-06-07 Thread Michael Glaesemann
text_values; Is this what you would expect? What's the advantage to using to_char? Michael Glaesemann grzm seespotcode net ---(end of broadcast)--- TIP 2: Don't 'kill -9' the postmaster

Re: [SQL] subtract a day from the NOW function

2007-06-07 Thread Michael Glaesemann
amptz |?column? + 2007-11-04 00:00:00-05 | 2007-11-05 00:00:00-06 (1 row) test=# show time zone; TimeZone US/Central (1 row) Note how the UTC offset changes across the daylight saving time change. Michael Glaesemann

Re: [SQL] subtract a day from the NOW function

2007-06-07 Thread Michael Glaesemann
me_timestamp, 'MMDD') > to_char((now() - interval '1 day'), 'MMDD'); I'd never use to_char to compare dates. The built-in comparison operators work just fine. Michael Glaesemann grzm seespotcode net ---(end of broadcast)--- TIP 4: Have you searched our list archives? http://archives.postgresql.org

Re: [SQL] subtract a day from the NOW function

2007-06-07 Thread Michael Glaesemann
--- t (1 row) You could also use the age function: SELECT age(CURRENT_TIMESTAMP) < INTERVAL '1 day'; SELECT age(CURRENT_TIMESTAMP) < INTERVAL '1 day'; ?column? -- t (1 row) Hope that helps. Michael Glaesemann grzm seespotcode net ---(end of broadcast)--- TIP 2: Don't 'kill -9' the postmaster

Re: [SQL] [GENERAL] CREATE RULE with WHERE clause

2007-06-05 Thread Michael Glaesemann
n this case. I believe you'd have to implement two views: CREATE VIEW rule_role_sul AS SELECT field1, field2 FROM t2 WHERE roles = 'role_sul'; CREATE VIEW rule_role_norte AS SELECT field3, field4 FROM t2 WHERE roles = 'role_norte'; Hope this helps. Michael Glaesemann

Re: [SQL] [GENERAL] Inserting a path into Database

2007-06-04 Thread Michael Glaesemann
onforming_strings in postgresql.conf so \ will be treated literally: http://www.postgresql.org/docs/8.2/interactive/runtime-config- compatible.html#GUC-STANDARD-CONFORMING-STRINGS Michael Glaesemann grzm seespotcode net ---(end of broadcast)---

Re: [SQL] current_date / datetime stuff

2007-06-04 Thread Michael Glaesemann
On Jun 4, 2007, at 10:59 , Michael Glaesemann wrote: On Jun 4, 2007, at 10:27 , Andrew Sullivan wrote: On Mon, Jun 04, 2007 at 10:04:37AM -0500, Joshua wrote: that will return the date of the first Monday of the month? I guess you need to write a function to do this. I suppose you could

Re: [SQL] current_date / datetime stuff

2007-06-04 Thread Michael Glaesemann
_dow($1, 1); $_$; select first_monday(current_date); first_monday -- 2007-06-04 (1 row) select first_monday('2007-04-01'); first_monday -- 2007-04-02 (1 row) Michael Glaesemann grzm seespotcode net ---(end of broadcast)--

Re: [SQL] Temporal Table Relations and Referential Integrity

2007-05-14 Thread Michael Glaesemann
scussion and critique of the draft. I would be happy to elaborate on what I mean by Temporal Referential-Integrity (RFI) if my questions are unclear. I'm not sure what *you* mean by Temporal Referential-Integrity, but I hope the links I've provided help a bit. Mic

Re: [SQL] Error: Input string was not in a correct format

2007-05-07 Thread Michael Glaesemann
-CONFIG-LOGGING-WHAT Check out the log_statement paramenter (and possibly others). You might also have some logging options within .NET, but as I'm unfamiliar with the framework, I really can't help you there. Michael Glaesemann grzm seespotcode net ---(end of

Re: [SQL] Question on interval

2007-04-20 Thread Michael Glaesemann
#x27;1 second'; You could also create a view that would present the integer column as an interval if you don't want to alter the table itself. Does this help? Michael Glaesemann grzm seespotcode net ---(end of broadcast)---

Re: [SQL] "for SELECT DISTINCT, ORDER BY expressions must appear in select list" - is that the standart or a limitation of postgresql?

2007-02-15 Thread Michael Glaesemann
TINCT clause. Though I suspect Richard is right that ORDER BY takes place after DISTINCT. (My cursory attempt at parsing the SQL 2003 draft failed me.) On further thought, I bet SELECT DISTINCT name FROM test ORDER BY name, number fails with a different error, one directly supporting Richard's

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

2007-02-13 Thread Michael Glaesemann
t I haven't seen yet: Michael Glaesemann grzm seespotcode net ---(end of broadcast)--- TIP 6: explain analyze is your friend

Re: [SQL] implementing (something like) UNIQUE constraint using PL/pgSQL

2007-01-27 Thread Michael Glaesemann
pthread, but this sounds like a special case of the SQL queues I saw on Greg Sabino Mullane's blog: http://people.planetpostgresql.org/greg/index.php?/archives/89- Implementing-a-queue-in-SQL-Postgres-version.html Perhaps you could tweak that to serve your needs. Mic

Re: [SQL] TPCH Benchmark query result invalid

2006-12-12 Thread Michael Glaesemann
x27;ll get around to doing something about it, but now I've at least written it down on my personal todo. Michael Glaesemann grzm seespotcode net ---(end of broadcast)--- TIP 9: In versions below 8.0, the planner will ignore your des

Re: [SQL] subquery abnormal behavior

2006-12-10 Thread Michael Glaesemann
T 0 3 test=# select a from myt1 where a in (select a from myt3); a --- 2 (1 row) It looks like PostgreSQL treats it as a natural join like select a from myt1 natural join myt3; Hope this helps. Michael Glaesemann grzm seespotcode net ---(end of

Re: [SQL] null values in non-nullable column

2006-12-04 Thread Michael Glaesemann
a domain constraint. And yet, if it does not, then an outer join with a NOT NULL domain column on the nullable side is just invalid. Very interesting. Thanks for the explanation. I should dig into the spec more. Michael Glaesemann grzm seespotcode net

Re: [SQL] null values in non-nullable column

2006-12-04 Thread Michael Glaesemann
E AS. "discarding domain-ness" would mean considering the results as their base type, and rechecking the domain would be checked when inserting into the table. Just trying to fit my head around this. Michael Glaesemann grzm seespotcode net ---(end of broa

Re: [HACKERS] timestamp subtraction (was Re: [SQL] formatting intervals with to_char)

2006-10-05 Thread Michael Glaesemann
e it is in the cycle, perhaps the change in behavior should come in 8.3. Michael Glaesemann grzm seespotcode net ---(end of broadcast)--- TIP 4: Have you searched our list archives? http://archives.postgresql.org

Re: [SQL] SQL92 compliance

2006-08-22 Thread Michael Glaesemann
er. 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] primary keys as TEXT

2006-07-28 Thread Michael Glaesemann
requirements. What are your requirements? What profiling have you done to see where your performance bottlenecks may be? Michael Glaesemann grzm seespotcode net ---(end of broadcast)--- TIP 3: Have you checked our extensive FAQ? http

Re: [SQL] Unexpected SQL error for UPDATE

2006-07-12 Thread Michael Glaesemann
u can put together a reproducible test case, it may help someone else be able to figure out what's going on. Michael Glaesemann grzm seespotcode net ---(end of broadcast)--- TIP 9: In versions below 8.0, the planner will ignore your

Re: [SQL] Atomar SQL Statement

2006-07-07 Thread Michael Glaesemann
l address field. I should definitely know better than to make assumption. Sorry, Johann, for not addressing your complete email, but rather just a portion of it. Michael Glaesemann grzm seespotcode net ---(end of broadcast)--- TIP 6: exp

Re: [SQL] How to get list of days between two dates?

2006-07-07 Thread Michael Glaesemann
| Third Event 2006-05-05 | Third Event 2006-05-07 | Fourth Event (8 rows) Michael Glaesemann grzm seespotcode net ---(end of broadcast)--- TIP 2: Don't 'kill -9' the postmaster

Re: [SQL] Atomar SQL Statement

2006-07-07 Thread Michael Glaesemann
t the FAQ entries on SERIAL: http://www.postgresql.org/docs/faqs.FAQ.html#item4.11.2 Hope this helps. Michael Glaesemann grzm seespotcode net ---(end of broadcast)--- TIP 9: In versions below 8.0, the planner will ignore your desire to choo

Re: [SQL] Update from join

2006-07-07 Thread Michael Glaesemann
e the ud_stock number with the same value. However, depending on your table size and the indexes you have on the tables, it might perform better with the IS NULL condition. Hope this helps. Michael Glaesemann grzm seespotcode net ---(end of broadcast)

Re: [SQL] Constraint UNIQUE on a column not case sensitive

2006-07-01 Thread Michael Glaesemann
On Jul 1, 2006, at 22:47 , Daniel CAUNE wrote: The idea is to have an index on that column, in a not case sensitive form, i.e. lower(MyColumn). I think you're really close. Try CREATE UNIQUE INDEX ci_mycolumn_idx ON mytable(lower(mycolumn)); Does that do what you're looking for

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

2006-06-30 Thread Michael Glaesemann
://www.postgresql.org/docs/8.1/interactive/indexes-partial.html Hope this helps. Michael Glaesemann grzm seespotcode net ---(end of broadcast)--- TIP 4: Have you searched our list archives? http://archives.postgresql.org

Re: [SQL] Views and query planner

2006-06-30 Thread Michael Glaesemann
On Jun 30, 2006, at 21:35 , Mario Splivalo wrote: Is postgres going to make one query plan, or each view has it own query plan? Have you taken a look at the EXPLAIN ANALYZE output of the queries? You can see exactly which plan PostgreSQL will use. Michael Glaesemann grzm seespotcode

Re: [SQL] SQL Technique Question

2006-06-15 Thread Michael Glaesemann
answer: benchmark and compare. EXPLAIN ANALYZE is your friend. For example, compare the EXPLAIN ANALYZE output using the view and using the whole, explicit query. You'll learn a lot that will only help you write better queries. Michael Glaesemann grzm sees

Re: [SQL] SQL Technique Question

2006-06-15 Thread Michael Glaesemann
more columns to the target list. So your original query, using this view, would look like: SELECT inspect_result_pass FROM t_inspect_join_view WHERE product_number = '7214118000' AND inspect_result_timestamp > '2006-01-01' AND inspect_result_timestamp < '2006-

Re: [SQL] Join issue

2006-06-06 Thread Michael Glaesemann
, it may make the overall query more tractable by encapsulating portions of it using views. Michael Glaesemann grzm seespotcode net ---(end of broadcast)--- TIP 4: Have you searched our list archives? http://archives.postgresql.org

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

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] 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] 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] 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] 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] 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] 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] 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 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] 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] 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] 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] 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] 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] 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

  1   2   >