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

2005-04-26 Thread Dan Langille
On 26 Apr 2005 at 14:24, Christoph Haller wrote: > Dan Langille wrote: > > > > 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. In reality, this isn't about books,

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

2005-04-25 Thread Dan Langille
id appears? I'm having trouble constructing the query. I'm not even sure I can do this in one select, but that would be nice. Examples and clues are appreciated. Any ideas? Thank you. -- Dan Langille : http://www.langille.org/ BSDCan - The Technical BSD Conference - http://w

Re: [SQL] UPDATE one table with values from another

2003-10-08 Thread Dan Langille
On Wed, 8 Oct 2003, Josh Berkus wrote: > Dan, > > > UPDATE commit_log_ports_elements X > >SET X.needs_refresh = CLP.needs_refresh, > >X.port_version = CLP.port_version, > >X.port_revision = CLP.port_revision > > FROM commit_log_ports CLP > WHERE X.commit_log_id = CLP.commit_lo

[SQL] UPDATE one table with values from another

2003-10-08 Thread Dan Langille
I know there is a simple solution, but I can't remember what it is. :( I have two similar tables. I want to update the fields from one table to contain the values form the other. The two tables are: laptop.freshports.org=# \d commit_log_ports Table "public.commit_log_ports" Column |

Re: [SQL] Multiple table join

2003-10-06 Thread Dan Langille
able A, B, C where A.Location = B.Location and A.Item_Num = C.Item_Num -- Dan Langille : http://www.langille.org/ ---(end of broadcast)--- TIP 3: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to [EMAIL PROTE

Re: [SQL]

2003-09-29 Thread Dan Langille
Yes it would, by a factor of 5. P.S. but it would not show dates for which there are no logins. The above can return zero rows. The previous example always returns MaxDays rows. -- Dan Langille : http://www.langille.org/ ---(end of broadcast)--

Re: [SQL]

2003-09-29 Thread Dan Langille
users (cost=0.00..446.75 rows=1730 width=8) (actual time=0.87..195.38 rows=110 loops=1) Filter: ((date(lastlogin))::timestamp without time zone > (('now'::text)::date - '3 days'::interval)) Total runtime: 199.33 msec (7 rows) freshports=# T

Re: [SQL] now() in loop statement

2003-09-29 Thread Dan Langille
functions return the start time of the current transaction; their values do not change during the transaction. timeofday() returns the wall clock time and does advance during transactions. -- Dan Langille : http://www.langille.org/ ---(end of

[SQL]

2003-09-28 Thread Dan Langille
Error occurred while executing PL/pgSQL function logincounts WARNING: line 9 at execute statement ERROR: parser: parse error at or near "days" at character 151 thnks -- Dan Langille - http://www.langille.org/ ---(end of broadcast)--- TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]

Re: [SQL]

2003-09-28 Thread Dan Langille
On 28 Sep 2003 at 15:45, Tom Lane wrote: > Dan Langille <[EMAIL PROTECTED]> writes: > > WHERE lastlogin between current_date - interval \''' || > > quote_literal(i - 1) || '' days\' > > AND current_da

Re: [SQL] Removing simliar elements from a set

2003-09-27 Thread Dan Langille
ggested this: SELECT * FROM master WHERE NOT EXISTS ( SELECT * FROM matches WHERE master.pathname LIKE (matches.pathname || '/%')); Cheers. -- Dan Langille : http://www.langille.org/ ---(end of broadcast)--- TIP

[SQL] Removing simliar elements from a set

2003-09-26 Thread Dan Langille
ories specified in MATCHES. My first attempt, which works only if MATCHES contains one item: SELECT * FROM MASTER JOIN MATCHES ON NOT (MASTER.pathname ~ ('^' || MATCHES.pathname || '/.+')); However, if there is more than one row in MATCHES, this will not work. Clues please

Re: [SQL] Backup of multiple tables

2003-09-22 Thread Dan Langille
will buy you a beer should we ever meet. I'm sure others would feel simlarly obliged. -- Dan Langille : http://www.langille.org/ ---(end of broadcast)--- TIP 8: explain analyze is your friend

Re: [SQL] Getting the return type right for SETOF

2003-08-31 Thread Dan Langille
On 30 Aug 2003 at 13:59, Stephan Szabo wrote: > On Sat, 30 Aug 2003, Dan Langille wrote: > > > Hi folks, > > > > I'm playing with SETOF on functions. But I can't get the return type > > correct. What have I missed? A cast? > > > > CREATE

[SQL] Getting the return type right for SETOF

2003-08-30 Thread Dan Langille
r name | text type | text status | text iscategory | boolean isport | boolean -- Dan Langille : http://www.langille.org/ ---(end of broadcast)--- TIP 3: if posting/reading through Usenet, please send an appropriate subscr

[SQL] inet versus text for ip addresses

2003-07-04 Thread Dan Langille
references recount_polls (pollid) on update restrict on delete restrict; It removes a table and the associated primary key, and removed a foreign key from the modified recount_iptopolls table. Comments? -- Dan Langille : http://www.langille.org/ ---(e

Re: [SQL] timestamp with postgresql 7.3

2003-04-04 Thread Dan Langille
Unable to identify a function that satisfies the given > argument types You may need to add explicit typecasts > > And tried various typecasts without any success. > > Any help? I think you need to read the 7.3 documentation and release notes. -- Dan Langille

[SQL] Analyse article

2003-02-27 Thread Dan Langille
ments, etc appreciated. -- Dan Langille : http://www.langille.org/ ---(end of broadcast)--- TIP 6: Have you searched our list archives? http://archives.postgresql.org

Re: [SQL] 7.3 "group by" issue

2003-02-21 Thread Dan Langille
On Fri, 21 Feb 2003, Josh Berkus wrote: > Dan, Chad, > > > I see the distinction you are making. > > > > Maybe Tom or Josh could throw out a better answer, but I think that youve > > called it one thing in your select and tried to group by it using a > > syntaticly different name. > > This looks l

Re: [SQL] 7.3 "group by" issue

2003-02-21 Thread Dan Langille
tch_list_element.watch_list_id WHERE watch_list.user_id = 1 GROUP BY element_id My question: why should it not work? It's referring to the same column as the previous two examples which do work. -- Dan Langille : http://www.langille.org/ ---(end of broadcast)-

Re: [SQL] 7.3 "group by" issue

2003-02-21 Thread Dan Langille
> > heres what it says in the docs > *The ORDER BY clause specifies the sort order: > > *SELECT select_list > * FROM table_expression > * ORDER BY column1 [ASC | DESC] [, column2 [ASC | DESC] ...] > *column1, etc., refer to select list columns. These can be eithe

Re: [SQL] 7.3 "group by" issue

2003-02-21 Thread Dan Langille
element.watch_list_id > WHERE > watch_list.user_id = 1 >GROUP BY watch_list_element.element_id ERROR: Attribute unnamed_join.element_id must be GROUPed or used in an aggregate function -- Dan Langille : http://www.langille.org/ ---(end of broadcast)---

[SQL] 7.3 "group by" issue

2003-02-21 Thread Dan Langille
: Attribute unnamed_join.element_id must be GROUPed or used in an aggregate function Note that in the select the table name is not mentioned but it is in the GROUP BY. To solve the problem, you either have to name the table in both locations or not name it in either location. Why? -- Dan Langille

[SQL] design review, FreshPorts change

2003-01-30 Thread Dan Langille
ase, both technical and user. Cheers -- Dan Langille : http://www.langille.org/ ---(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 get thro

Re: [SQL] Oracle outer join porting question

2003-01-15 Thread Dan Langille
d,sub.operation test-# FROM document doc LEFT OUTER JOIN document_subscription sub test-# ON sub.document_id = doc.id AND sub.user_id = 6; id | title | user_id | operation +---+-+--- 1 | doc1 | | 2 | doc2 | 6 | op2 4 | doc4 | | -- Dan

Re: [SQL] Oracle outer join porting question

2003-01-15 Thread Dan Langille
6 | op2 4 | doc4 | | (4 rows) > > here're also simplified definitions of the two tables used in the query > and some test data: Thanks for supplying the table and data. That makes things much easier. -- Dan Langille : http://www.langille.org/ ---

Re: [SQL] ON DELETE CASCADE

2002-12-12 Thread Dan Langille
On 12 Dec 2002 at 11:01, Tim Perdue wrote: > That command works, but now I think I have 2x as many triggers as I > want. How do I get rid of the original triggers? I had to do something similar and documented it at http://www.freebsddiary.org/postgresql-dropping-constraints.php hth -

[SQL] adding a GROUP BY to an outer join

2002-12-08 Thread Dan Langille
19.78 msec Phew! That's fast! -- Dan Langille : http://www.langille.org/ ---(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 get through to the mailing list cleanly

Re: [SQL] master-detail relationship and count

2002-11-29 Thread Dan Langille
example of an OUTER JOIN but not the master-detail situation which occurs elsewhere in the database. cheers -- Dan Langille : http://www.langille.org/ ---(end of broadcast)--- TIP 5: Have you checked our extensive FAQ? http://www.postgresql.org/users-lounge/docs/faq.html

Re: [SQL] escape single quote in INSERT command

2002-11-26 Thread Dan Langille
= DBI -> connect ( ".."); > $sth = $dbh -> prepare("insert into tab (a,b) values (?,?)"); > $sth -> execute($a , $b ); > $sth -> finish(); > $dbh -> commit(); > $dbh -> disconnect(); IIRC, there is a dbi->quote()

Re: [SQL] subselect instead of a view...

2002-11-26 Thread Dan Langille
On 26 Nov 2002 at 0:29, Tom Lane wrote: > "Dan Langille" <[EMAIL PROTECTED]> writes: > > SELECT E.name, EP.pathname, E.id, EP2.pathname, CL.id > > ... > > and EP2.pathname like EP.pathname || '/%' > > > I am still suspicous of th

Re: [SQL] subselect instead of a view...

2002-11-25 Thread Dan Langille
On 25 Nov 2002 at 22:15, Dan Langille wrote: > I know this can be done better, I just can't figure out how. I keep > thinking of a subselect but I'm totally blocked. It must be bed time. It's odd what reading the paper, relaxing with a book, and then trying to sleep can g

[SQL] subselect instead of a view...

2002-11-25 Thread Dan Langille
ime=0.21..0.23 rows=1 loops=2) -> Seq Scan on element_pathnames ep (cost=0.00..2355.70 rows=119570 width=41) (actual time=0.08..858.74 rows=119570 loops=2) Total runtime: 9464.51 msec Clues please? -- Dan Langille : http://www.langille.org/ ---

Re: [SQL] Trees: maintaining pathnames

2002-11-22 Thread Dan Langille
On 17 Nov 2002 at 11:39, Dan Langille wrote: > My existing tree implementation reflects the files contained on disk. > The full pathname to a particlar file is obtained from the path to the > parent directory. I am now considering putting this information into > a field

Re: [SQL] Trees: maintaining pathnames

2002-11-22 Thread Dan Langille
On 20 Nov 2002 at 15:20, Dan Langille wrote: > On 17 Nov 2002 at 14:51, Josh Berkus wrote: > > > Dan, > > > > > My existing tree implementation reflects the files contained on > > > disk. > > > The > > > full pathname to a particlar file i

Re: [SQL] calculating interval

2002-11-22 Thread Dan Langille
On 22 Nov 2002, praveen vejandla wrote: > Dear All, > > Is there any way in postgresql to calculate the interval between > two times excluding specific days,specific duration. > > Ex: > timestamp1 : 2002-10-01 10:30AM > timestamp2 : 2002-15-01 04:50PM > > suppose if i need the difference between

Re: [SQL] connectby questions

2002-11-22 Thread Dan Langille
On Fri, 22 Nov 2002, Dan Langille wrote: > Here is the actual data for the above nodes: > > freshports=# select * from element where id in (104503, 104504, 104505); >id | name | parent_id | directory_file_f

[SQL] connectby questions

2002-11-21 Thread Dan Langille
I just installed 7.3rc1 and added contrib/tablefunc. I am able to get the example in the README document to work. I am having trouble understanding how to get my real data to behave. The table is: freshports=# \d element Table "public.element" Column

Re: [SQL] Trees: maintaining pathnames

2002-11-20 Thread Dan Langille
e from http://developer.postgresql.org/cvsweb.cgi/pgsql- server/contrib/ltree/ltreetest.sql [2] - My application involves mirroring a file system (directories and files). FWIW, in this instances, files are not renamed, they are deleted and recreated elsewhere. -- Dan Langille : http://www.langille.org/ ---(end of broadcast)--- TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]

Re: [SQL] Trees: maintaining pathnames

2002-11-18 Thread Dan Langille
p > 4 | 1 | home | /home > 5 | 4 | greg | /home/greg > 6 | 5 | etc | /home/greg/etc > (6 rows) > > UPDATE tree SET name='users' WHERE id=4; > > SELECT * FROM mytree ORDER BY id; > > id | parent_id |

[SQL] Trees: maintaining pathnames

2002-11-17 Thread Dan Langille
My existing tree implementation reflects the files contained on disk. The full pathname to a particlar file is obtained from the path to the parent directory. I am now considering putting this information into a field in the table. Attached you will find the pg_dump from my test database (2.4k)

[SQL] using deferred on PK/FK relationships

2002-10-22 Thread Dan Langille
1 test=# insert into master values (2); INSERT 20959596 1 test=# select * from slave; id 1 1 (2 rows) test=# commit; COMMIT test=# select * from slave; id (0 rows) test=# Our hope was that after the commit, slave would retain the original rows. cheers -

Re: [SQL] timestamp

2002-10-07 Thread Dan Langille
On Sun, 6 Oct 2002, Brian Ward wrote: And Brian, since this *is* a mailing list, it would be polite to use a valid email address. I suggest that you either unsubscribe or fix the email address. Mail to [EMAIL PROTECTED] bounces with the message: '550 Invalid recipient: <[EMAIL PROTECTED]>'.

Re: [SQL] timestamp

2002-10-07 Thread Dan Langille
On Sun, 6 Oct 2002, Brian Ward wrote: > How do I create a time stamp column in a table that default to the current > time > when a row is inserted? > I tried putting in now() as the default but I have something wrong > with the syntax or something I think > Any one have an example of a table crea

Re: [SQL] Need some SQL help

2002-10-07 Thread Dan Langille
On Sun, 6 Oct 2002, Brian Ward wrote: > I have a table > id int > statusint > create_dt datetime > > When users log in and out I insert a row into this table throughout the day. > I'm trying though to come up with a querie to tell me and ordering of users > as they report in in the mo

Re: [SQL] Suggestion: md5/crypt functions in sql

2002-10-06 Thread Dan Langille
On Sun, 6 Oct 2002, Joe Conway wrote: > Aasmund Midttun Godal wrote: > > It would be very usefull to have these in sql, so that it is even easier to create >tables with encrypted passwords. > > > > See contrib/pgcrypto See also http://www.freebsddiary.org/postgresql-7.2.php which shows how I in

Re: [SQL] [GENERAL] arrays

2002-09-30 Thread Dan Langille
On 30 Sep 2002 at 12:09, Bruce Momjian wrote: > Dan Langille wrote: > > On 30 Sep 2002 at 8:54, Josh Berkus wrote: > > > > > As such, I'd reccommend one of two approaches for you: > > > > > > 1) Post some of your schema ideas here, and

Re: [SQL] [GENERAL] arrays

2002-09-30 Thread Dan Langille
that he's right about normalizing your data. -- Dan Langille I'm looking for a computer job: http://www.freebsddiary.org/dan_langille.php ---(end of broadcast)--- TIP 3: if posting/reading through Usenet, please send an appropriate subscrib

Re: [SQL] Case Sensitive "WHERE" Clauses?

2002-09-26 Thread Dan Langille
On Thu, 26 Sep 2002, Jordan Reiter wrote: > Are string comparisons in postgresql case sensitive? Yes, AFAIK. I disagree with your comments and recommendations posted at http://www.postgresql.org/idocs/index.php?datatype-character.html because my testing shows that varying text and fixed test co

Re: [SQL] Case Sensitive "WHERE" Clauses?

2002-09-26 Thread Dan Langille
On Thu, 26 Sep 2002, Andrew Perrin wrote: > No, I don't think it's supposed to be case-sensitive. In any case, whether > it's supposed to be or not, it certainly isn't in practice. AFAIK, they are case sensitive by design. It is the right thing to do. ---(end of broadca

Re: [SQL] bulk imports with sequence

2002-08-20 Thread Dan Langille
e the sequence itself. > Currently the only way I can make it work is to grab the next seq > value and insert my own numbers into the file Yes: create sequence mytable_id_seq; alter table mytable alter column id set default nextval('mycolumn_id_seq'::text); -- Dan Langille

Re: [SQL] How to update record in a specified order

2002-08-09 Thread Dan Langille
ifc. What do you mean, "specified order"? My reading of what is required: - sort a given result set according to some criteria - then do something like UPDATE table SET myfield = NEXTVAL - each row in the result set would get a value one more than the previous row --

[SQL] using LIMIT only on primary table

2002-07-27 Thread Dan Langille
dded in commit_date order. Any clues please? thanks -- Dan Langille And yes, I'm looking for a computer job: http://www.freebsddiary.org/dan_langille.php ---(end of broadcast)--- TIP 2: you can get off all lists at once with the unregister com