[SQL] Obscure behavior of ORDER BY

2011-03-23 Thread Tambet Matiisen
Hi everyone! I recently noticed obscure behavior of ORDER BY. Consider this example: select email from ( select '@'::text as email union all select '.'::text as email ) a order by email; The result is: email --- . @ (2 rows) This is all normal - I expect, that dot is smaller than

Re: [SQL] Function or Field?

2005-05-03 Thread Tambet Matiisen
Hi. What is the better way to store the last record for a translation??? I.E: The data for the last product vendding. What is better: a) Create a field in product table and create a Trigger (before insert or update into vendding table) to alter this field. b) Create a view or

Re: [SQL] Function to either return one or all records

2005-04-21 Thread Tambet Matiisen
-Original Message- From: Tom Lane [mailto:[EMAIL PROTECTED] Sent: Thursday, April 21, 2005 12:06 AM To: Tambet Matiisen Cc: KPFERL Robert; pgsql-sql@postgresql.org Subject: Re: [SQL] Function to either return one or all records Tambet Matiisen [EMAIL PROTECTED] writes

Re: [SQL] Function to either return one or all records

2005-04-20 Thread Tambet Matiisen
CREATE OR REPLACE FUNCTION getval(integer) RETURNS SETOF id_val_tbl AS $BODY$ select * from id_bal_tbl where ( $1 is null )or (id=$1 ); $BODY$ LANGUAGE 'sql' VOLATILE SECURITY DEFINER; It works fine, however an index is never used (if just one record is requested). The column id

Re: [SQL] Flattening query result into columns

2005-03-23 Thread Tambet Matiisen
The problem in linked article could be solved with custom aggregate in PostgreSQL: create or replace function concat(text, text) returns text immutable language sql as ' select case when $1 = then $2 else $1 || '' '' || $2 end '; drop aggregate concat(text) cascade; create aggregate

Re: [SQL] How to force subquery scan?

2005-03-17 Thread Tambet Matiisen
-Original Message- From: Tom Lane [mailto:[EMAIL PROTECTED] Sent: Wednesday, March 16, 2005 5:42 PM To: Tambet Matiisen Cc: [EMAIL PROTECTED]; pgsql-sql@postgresql.org Subject: Re: [SQL] How to force subquery scan? Tambet Matiisen [EMAIL PROTECTED] writes: It seems

Re: [SQL] How to force subquery scan?

2005-03-16 Thread Tambet Matiisen
... Does this do better: SELECT prodid, avg(prodcost) as average_cost, sum(prodcost * salesamount) as cost_total FROM ( SELECT p.product_id as prodid, product_cost(s.product_id, s.date) as prodcost, s.amount as salesamount FROM products p LEFT JOIN sales s

Re: [SQL] Parameterized views proposition

2005-03-16 Thread Tambet Matiisen
Tambet Matiisen [EMAIL PROTECTED] writes: How tough it would be to implement CREATE VIEW xxx PARAMETERS (yyy) AS zzz; as CREATE TYPE xxx; CREATE FUNCTION xxx(yyy) RETURNING SETOF xxx LANGUAGE sql AS 'zzz'; What's the point? It'd be nonstandard anyway, so just use

Re: [SQL] Parameterized views proposition

2005-03-15 Thread Tambet Matiisen
... I wonder if it could be possible to improve CREATE VIEW syntax by adding parameters? Something like this: CREATE VIEW product_sales(date,date) AS select p.product_id, coalesce(sum(s.amount), 0) from product p left join sales s on p.product_id = s.product_id and s.date between $1

[SQL] How to force subquery scan?

2005-03-15 Thread Tambet Matiisen
Another (possibly design?) problem of mine. I have a function product_cost(product_id, date), which does simple SELECT call. I declared it as STABLE, hoping that multiple invocations of the same function are replaced with one. Query is something like this: SELECT p.product_id,

[SQL] Parameterized views proposition

2005-03-12 Thread Tambet Matiisen
Hi there! We use views in our applications a lot, in fact we prefer to have least sql at client side. All queries are written as select * from view, whenever possible. But there are queries, which are impossible to express as views. Especially if you would like to put a filter on right side of

Re: [SQL] Parameterized views proposition

2005-03-12 Thread Tambet Matiisen
-Original Message- From: PFC [mailto:[EMAIL PROTECTED] Sent: Saturday, March 12, 2005 2:08 PM To: Tambet Matiisen; pgsql-sql@postgresql.org Subject: Re: [SQL] Parameterized views proposition What about using PREPARE ? ---(end of broadcast

Re: [SQL] good style?

2003-02-21 Thread Tambet Matiisen
-Original Message- From: Rafal Kedziorski [mailto:[EMAIL PROTECTED] Sent: Friday, February 21, 2003 3:30 PM To: [EMAIL PROTECTED] Subject: [SQL] good style? hi, I have 8 tables and this query: select u.users_id, m.name as mandant_name, u.login_name, u.password,

Re: [SQL] Function executing twice

2003-01-30 Thread Tambet Matiisen
I think you should first check your application logic, for example print something out just before calling the function. Then you can easily see, if the problem is in PostgreSQL or in your application. I once had similar problem, when I used function as argument to COALESCE. COALESCE is

Re: [SQL] calling function from rule

2003-01-24 Thread Tambet Matiisen
-Original Message- From: Tom Lane [mailto:[EMAIL PROTECTED]] Sent: Thursday, January 23, 2003 7:01 PM To: Tambet Matiisen Cc: [EMAIL PROTECTED] Subject: Re: [SQL] calling function from rule Tambet Matiisen [EMAIL PROTECTED] writes: Try 7.3, we changed the rules about

[SQL] calling function from rule

2003-01-23 Thread Tambet Matiisen
I have a view and update rule on it, which updates another table. Now I would like to call a function, after update of the table is done. Also the function must be called in the same transaction as update. I tried to define an additional update rule on the view, but doing a SELECT in update

Re: [SQL] calling function from rule

2003-01-23 Thread Tambet Matiisen
Tambet Matiisen [EMAIL PROTECTED] writes: I have a view and update rule on it, which updates another table. Now I would like to call a function, after update of the table is done. Also the function must be called in the same transaction as update. I tried to define an additional

Re: [SQL] full join in view

2003-01-15 Thread Tambet Matiisen
If you need only not null-kdt_id and dor_id, then just change your joins into inner joins. The whole idea is to show expected expenses (in koostude_detailid) even if they were actually not spent (the same material is not listed in dokumentide_read). And also show actual expenses (in

Re: [SQL] Oracle outer join porting question

2003-01-15 Thread Tambet Matiisen
-Original Message- From: Marko Asplund [mailto:[EMAIL PROTECTED]] Sent: Wednesday, January 15, 2003 4:31 PM To: [EMAIL PROTECTED] Subject: [SQL] Oracle outer join porting question i'm trying to port an existing application from Oracle8i to PostgreSQL but i'm having

Re: [SQL] full join in view

2003-01-14 Thread Tambet Matiisen
Can you add some sql examples - table index definition, view definition? If your view doesn't contain other views or sub-selects, postgres should use indexes. Tomasz Myrta You are right. After disabling seq_scan, it uses indexes just as you described. Unfortunately my view happens

Re: [SQL] full join in view

2003-01-14 Thread Tambet Matiisen
To: Tambet Matiisen Cc: [EMAIL PROTECTED] Subject: Re: [SQL] full join in view Tambet Matiisen wrote: You are right. After disabling seq_scan, it uses indexes just as you described. Unfortunately my view happens to use subquery: Don't disable seq_scan - sometimes it is better than

[SQL] full join in view

2003-01-08 Thread Tambet Matiisen
I'm making a report in Crystal Reports, which makes use of full join. As Crystal Reports does not support full join natively, I created a view which contains the join and based my report on that view. The report has also a parameter to filter only subset of rows from view. My problem is, that

Re: [SQL] Sorry, to many clients already

2003-01-07 Thread Tambet Matiisen
When I'm trying to connect I have this error message: Something unusual has occured to cause the driver to fail.Please report this exception: java.sql.SQLException: Sorry, to many clients already. I also met this error yesterday. Default PostgreSQL limit for incoming connections is

Re: [SQL] Grant execute on functions; related objects permissions ?

2003-01-06 Thread Tambet Matiisen
In PostgreSQL 7.3 you have option to execute function with owner's rights or caller's rights. Default is caller's rights (as it was before 7.3), you probably want owner's rights. See development version of docs: http://developer.postgresql.org/docs/postgres/sql-createfunction.html btw, views