[SQL] using count in other column

2009-07-23 Thread bartjoosen
Hi, I made up a query to make a count for each item for each month/year: SELECT"Artnr_ID", to_char("Date_plan","") AS "Jaar", to_char("Date_plan","MM") AS "Maand", Count("tblArtnrs"."Artikelnr") AS "Monthly_count", "val1","val2","val3" FROM (("tblAnalyses" INNER JOIN "tblStudies" ON "tblAnaly

Re: [SQL] Bit by "commands ignored until end of transaction block" again

2009-07-23 Thread Adrian Klaver
On Thursday 23 July 2009 12:39:23 am Glenn Maynard wrote: > > The ORM on a whole is decent, but there are isolated areas where it's > very braindamaged--this is one of them. They have a stable-release > API-compatibility policy, which I think just gets them stuck with some > really bad decisions

Re: [SQL] Bit by "commands ignored until end of transaction block" again

2009-07-23 Thread Stephen Frost
* Glenn Maynard (gl...@zewt.org) wrote: > > The ORM can't control transactions, can't call functions or can't set > > savepoints? > > It can't write the necessary SQL to say "insert this unless it already > exists", namely: If it can't cleanly handle failure cases like this one, then I think your

Re: [SQL] Need magical advice for counting NOTHING

2009-07-23 Thread Glenn Maynard
On Thu, Jul 23, 2009 at 1:01 AM, Andreas wrote: > SELECT user_name, log_type_fk, COUNT(log_type_fk) > FROM log > JOIN users ON (user_id = user_fk) > WHERE (ts IS BETWEEN  sometime  AND   another) > GROUP BY user_name, log_type_fk > ORDER BY user_name, log_type_fk create table users (user_id intege

Re: [SQL] Bit by "commands ignored until end of transaction block" again

2009-07-23 Thread Richard Huxton
Glenn Maynard wrote: On Thu, Jul 23, 2009 at 2:41 AM, Richard Huxton wrote: Ah [cue light-bulb effect], I think I understand. Your function isn't in the database is it? Surely your application knows if it's issuing BEGIN..COMMIT? I'm writing a Python library call. It has no idea whether the c

Re: [SQL] Double aggregate problem

2009-07-23 Thread David Weilers
Hello, I have the following tables: CREATE TABLE tblvacature ( id serial PRIMARY KEY, account int NOT NULL REFERENCES tblaccount (id) ON DELETE CASCADE, title varchar(128), bedrijfsprofiel text, functieomschrijving text, functieeisen text,

Re: [SQL] Bit by "commands ignored until end of transaction block" again

2009-07-23 Thread Glenn Maynard
On Thu, Jul 23, 2009 at 2:41 AM, Richard Huxton wrote: > Ah [cue light-bulb effect], I think I understand. Your function isn't in the > database is it? Surely your application knows if it's issuing BEGIN..COMMIT? I'm writing a Python library call. It has no idea whether the caller happens to be i

Re: [SQL] Bit by "commands ignored until end of transaction block" again

2009-07-23 Thread Thomas Kellerer
Chris, 23.07.2009 09:06: psql -d dbname .. # select now(); now --- 2009-07-23 17:04:21.406424+10 (1 row) Time: 2.434 ms (csm...@[local]:5432) 17:04:21 [test] # savepoint xyz; ERROR: SAVEPOINT can only be used in transaction blocks (csm...@[local]:5432)

Re: [SQL] Need magical advice for counting NOTHING

2009-07-23 Thread A. Kretschmer
In response to A. Kretschmer : > test=*# select foo.user_name, foo.log_type, sum(case when log_type_fk is > not null then 1 else 0 end) from (select user_id, user_name, > log_type_id, log_type from users cross join log_type) foo full join log > on ((foo.user_id, foo.log_type_id)=(log.user_fk, log.l

Re: [SQL] Bit by "commands ignored until end of transaction block" again

2009-07-23 Thread Chris
Joshua Tolley wrote: On Thu, Jul 23, 2009 at 02:04:53AM -0400, Glenn Maynard wrote: On Thu, Jul 23, 2009 at 1:31 AM, Richard Huxton wrote: - Let me use SAVEPOINT outside of a transaction, You are never outside a transaction. All queries are executed within a transaction. "Transaction block",