[SQL] sub query and AS

2012-05-23 Thread Ferruccio Zamuner
Hi, I like PostgreSQL for many reasons, one of them is the possibility to use sub query everywhere. Now I've found where it doesn't support them. I would like to use a AS (sub query) form. This is an example: First the subquery: select substr(descr, 7, length(descr)-8) from (select string

Re: [SQL] To having or not to having?

2011-10-23 Thread Ferruccio Zamuner
On 10/23/11 23:12, I wrote: Hello, I'm rusty with SQL and I've started to practice it again but I'm falling on this issue. I've found first solution using WINDOWING: SELECT d.pintime, d.a_id, d.c_id, d.value, d.id, d.sincedate, d.todate, d.description, d.genre FROM (SELECT pintime,a_

[SQL] To having or not to having?

2011-10-23 Thread Ferruccio Zamuner
Hello, I'm rusty with SQL and I've started to practice it again but I'm falling on this issue. The problem: Extracting rows from 'b' table trapping min() of a calculated value "days" on 'a' table and a parameter. SELECT b.*, $1::date-a.sincedate AS "days" FROM b, a WHERE pintime

[SQL] PostgreSQL array, recursion and more

2010-11-17 Thread Ferruccio Zamuner
MESH Data Tree: example: Hallux;A01.378.610.250.300.792.380 where: A01 is Body Regions A01.378 is Extremities A01.378.610 is Lower Extremity A01.378.610.250 is Foot A01.378.610.250.300 is Forefoot, Human A01.378.610.250.300.792 is Toes CREATE OR REPLACE FUNCTION mesh_split(text) RETURNS text[]

[SQL] PL/SQL trouble

2002-11-26 Thread Ferruccio Zamuner
Hi, I really don't understand following PostgreSQL 7.2.3 behaviour: $ psql mydb mydb=> CREATE FUNCTION MONDAY(timestamp) RETURNS DATE AS ' DECLARE var1 date; BEGIN select into var1 to_date($1::date-(case when extract(DOW from timestamp $1) = 0 then 6 else (extract(DOW from timestamp $1)-1)

[SQL] Multicolumn primary keys and multicolumn foreign keys

2001-01-28 Thread Ferruccio Zamuner
Hi, I've found a trouble and I've tried to avoid it without success: --- create table companies ( id serial not null primary key, firm_name text not null, activity text ); create table customers ( id int not null references companies, seller_id int not nul

[SQL] date infinity

2001-01-01 Thread Ferruccio Zamuner
Hi, I've not found, as reported into postgresql docs, 'infinity': create temp table subscriptions ( id int references people, expire date default 'infinity'); ERROR: Unrecognized date external representation 'infinity' Is there someone that knows the new costant name? >From PostgreSQL d

[SQL] resetting serials and sequences

2001-01-01 Thread Ferruccio Zamuner
Hi, #create temp table a ( id serial primary key, name text not null); #insert into a (name) values ('Tom'); #insert into a (name) values ('Fer'); #insert into a (name) values ('Mario'); #select * from a; id | name +--- 1 | Tom 2 | Fer 3 | Mario (3 rows) OK. Now

[SQL] Unable to identify an ordering operator

2000-12-31 Thread Ferruccio Zamuner
Hello, select persons.name,firm.name,persons.tel from persons,work,firm where (persons.table_owner=0) and (work.id_firm=firm.id and work.id_person=persons.id) union select persons.name,firm.name,persons.tel from persons,work,firm wh

[SQL] Permission and users

2000-10-24 Thread Ferruccio Zamuner
Hi, PostgreSQL superuser (named A) create two different users: B: able to create db C: able to create db B creates db B_DB C creates db C_DB C is able to add tables at C_DB as well as at B_DB. B is able to add tables at B_DB as well ad at C_DB. How can I limit C to operate only to C_DB and B o