Re: [SQL] GROUP and ORDER BY

2011-11-08 Thread Tarlika Elisabeth Schmitz
On Tue, 08 Nov 2011 09:57:08 +0530 Robins Tharakan wrote: >On 11/08/2011 02:50 AM, Tarlika Elisabeth Schmitz wrote: >> Hello, >> >> I would like to GROUP the result by one column and ORDER it by >> another: >> >> SELECT >> no, name, similarit

[SQL] GROUP and ORDER BY

2011-11-07 Thread Tarlika Elisabeth Schmitz
sult ordered by similarity. My solution: SELECT * FROM ( SELECT DISTINCT ON (no) no, name, similarity(name, 'Tooneyvara') AS sim FROM vtown WHERE similarity(name, 'Tooneyvara') > 0.4 ORDER BY no, sim DESC ) AS x ORDER BY sim Is that the best way to achieve

[SQL] extract some column/value pairs via hstore

2011-06-13 Thread Tarlika Elisabeth Schmitz
rying(3) NOT NULL, region_fk character varying(3) NOT NULL, id serial NOT NULL, "name" character varying(50) NOT NULL, source character varying(2) NOT NULL ) -- Best Regards, Tarlika Elisabeth Schmitz -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make chang

Re: [SQL] Order of evaluation in triggers for checks on inherited table partitions

2011-05-27 Thread Tarlika Elisabeth Schmitz
On Fri, 27 May 2011 12:28:51 -0700 Kevin Crain wrote: >Is the order of evaluation for the trigger causing this error? Are you aware that triggers are executed in alphabetical order? I simply used RAISE to check the order of execution of my triggers: RAISE NOTICE '% % % %: received %', TG_TABLE

Re: [SQL] extracting location info from string

2011-05-26 Thread Tarlika Elisabeth Schmitz
On Thu, 26 May 2011 10:15:50 +1200 Andrej wrote: >On 26 May 2011 09:13, Tarlika Elisabeth Schmitz > wrote: >> On Wed, 25 May 2011 09:25:48 -0600 >> Rob Sargent wrote: >> >>> >>> >>>On 05/24/2011 10:57 AM, Lew wrote: >>>>

Re: [SQL] extracting location info from string

2011-05-25 Thread Tarlika Elisabeth Schmitz
On Wed, 25 May 2011 09:25:48 -0600 Rob Sargent wrote: > > >On 05/24/2011 10:57 AM, Lew wrote: >> Tarlika Elisabeth Schmitz wrote: >> >>> CREATE TABLE person >>> ( >>> id integer NOT NULL, >>> "name" character varying(2

Re: [SQL] extracting location info from string

2011-05-25 Thread Tarlika Elisabeth Schmitz
On Tue, 24 May 2011 12:57:57 -0400 Lew wrote: >Tarlika Elisabeth Schmitz wrote: >>this was just a TEMPORARY table I created for quick analysis >> of my CSV data (now renamed to temp_person). >Ah, yes, that makes much more sense. Temporary tables such as you >describe can b

Re: [SQL] extracting location info from string

2011-05-23 Thread Tarlika Elisabeth Schmitz
On Mon, 23 May 2011 13:11:24 +1200 Andrej wrote: >On 23 May 2011 10:00, Tarlika Elisabeth Schmitz > wrote: >> On Sun, 22 May 2011 21:05:26 +0100 >> Tarlika Elisabeth Schmitz wrote: >> >>>A column contains location information, which may contain any of the

Re: [SQL] extracting location info from string

2011-05-23 Thread Tarlika Elisabeth Schmitz
er_pkey PRIMARY KEY (id), CONSTRAINT country_person_fk FOREIGN KEY (country) REFERENCES country (id) MATCH SIMPLE ON UPDATE CASCADE ON DELETE RESTRICT, CONSTRAINT county_person_fk FOREIGN KEY (country, county) REFERENCES county (country, code) MATCH SIMPLE ON UPDATE

Re: [SQL] extracting location info from string

2011-05-22 Thread Tarlika Elisabeth Schmitz
On Sun, 22 May 2011 21:05:26 +0100 Tarlika Elisabeth Schmitz wrote: >A column contains location information, which may contain any of the >following: > >1) null >2) country name (e.g. "France") >3) city name, region name (e.g. "Bonn, Nordrhein-Westfalen"

[SQL] extracting location info from string

2011-05-22 Thread Tarlika Elisabeth Schmitz
NULL, "name" character varying(50) NOT NULL, CONSTRAINT region_pkey PRIMARY KEY (country, code), CONSTRAINT country_region_fk FOREIGN KEY (country) REFERENCES country (id) MATCH SIMPLE ON UPDATE CASCADE ON DELETE RESTRICT ) = System: PostgreSQL 8.4 -- Best Re

[SQL] Trigger: update if record exists

2011-05-09 Thread Tarlika Elisabeth Schmitz
I wrote a trigger function to convert inserts into updates if the record exists already. - I am not using rules because the table is populated via COPY. - I am employing a two-stage process (PERFORM, then UPDATE) because the update trigger might decide not to update after all, and therefore FOUND

Re: [SQL] data import via COPY, Rules + Triggers

2011-05-07 Thread Tarlika Elisabeth Schmitz
On Wed, 4 May 2011 23:48:04 +0100 Tarlika Elisabeth Schmitz wrote: >I have got a database that needs to be populated, first with historical >data, then on a daily basis.[...] >Once imported, data will neither be modified nor deleted. > >Data come in denormalized CSV formats. [

Re: [SQL] data import via COPY, Rules + Triggers

2011-05-07 Thread Tarlika Elisabeth Schmitz
ame; >if not found then >insert into manager(name) values (NEW.manager_name); >select into id_manager CURRVAL('manager_id_seq'); >end if; >INSERT INTO athlete (... manager_fk...) VALUES ( ... id_manager...); > >good luck! > > >On Thu, May 5, 2011

[SQL] check constraint bug?

2011-05-05 Thread Tarlika Elisabeth Schmitz
this to: ALTER TABLE horse ADD CONSTRAINT val_horse_stats CHECK (sex != 'f') OR (stats IS NULL)); -- Best Regards, Tarlika Elisabeth Schmitz -- 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] data import via COPY, Rules + Triggers

2011-05-05 Thread Tarlika Elisabeth Schmitz
Thank you for your help, Sergey. That certainly works. I was wondering whether the manager.id could maybe be obtained via INSERT ... RETURNING? -- Best Regards, Tarlika Elisabeth Schmitz On Thu, 5 May 2011 08:45:32 +0300 sergey kapustin wrote: >Try using (select id from manager wh

[SQL] data import via COPY, Rules + Triggers

2011-05-04 Thread Tarlika Elisabeth Schmitz
manager_fk, _received) VALUES (NEW.id, NEW.name, NEW.dad_id, NEW.sponsor_id, ?, NEW._received); ) System: PostgreSQL 8.3 no of users: 1 -- Best Regards, Tarlika Elisabeth Schmitz -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make chang

Re: [SQL] data import: 12-hour time w/o AM/PM

2011-02-08 Thread Tarlika Elisabeth Schmitz
On Tue, 8 Feb 2011 18:38:44 - "Oliveiros d'Azevedo Cristina" wrote: >- Original Message - >From: "Tarlika Elisabeth Schmitz" >To: >Sent: Tuesday, February 08, 2011 6:14 PM >Subject: [SQL] data import: 12-hour time w/o AM/PM > > >I

Re: [SQL] data import: 12-hour time w/o AM/PM

2011-02-08 Thread Tarlika Elisabeth Schmitz
On Wed, 9 Feb 2011 08:21:47 +1300 Andrej wrote: >On 9 February 2011 07:14, Tarlika Elisabeth Schmitz > wrote: >> From the date and time I want to create a timestamp. >> I know that >> - the events take place during the day, say between 10:30 and 22:30 >> - it&#

[SQL] data import: 12-hour time w/o AM/PM

2011-02-08 Thread Tarlika Elisabeth Schmitz
g the day, say between 10:30 and 22:30 - it's always a set of events at one location spaced about 30min apart - the imported data are chained (have a link to previous/next event) Have you got any idea how I could tackle this problem -- Best Regards, Tarlika Elisabeth Schmitz -- Se

Re: [SQL] psql -f COPY from STDIN

2010-11-13 Thread Tarlika Elisabeth Schmitz
On Sat, 13 Nov 2010 12:01:35 + Tarlika Elisabeth Schmitz wrote: >I'd like the store the COPY command in a separate file without >specifying an input file name. I want to feed it the data from the >shell script that calls psql "STDIN: All rows are read from the same sou

Re: [SQL] psql -f COPY from STDIN

2010-11-13 Thread Tarlika Elisabeth Schmitz
On Fri, 12 Nov 2010 22:22:11 -0500 Tom Lane wrote: >Tarlika Elisabeth Schmitz writes: >> The following command works fine when pasing it to psql via the -c >> option: > >> cat event.csv | \ >> psql -c "COPY (event_id, event_name) FROM STDIN DELIMITER AS &#

[SQL] psql -f COPY from STDIN

2010-11-12 Thread Tarlika Elisabeth Schmitz
PY (event_id, event_name) FROM STDIN DELIMITER AS ',' NULL AS '' cat event.csv | psql -f event.sql What's the problem? Many thanks in advance. -- Best Regards, Tarlika Elisabeth Schmitz -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes t

Re: [SQL] identifying duplicates in table with redundancies

2010-09-29 Thread Tarlika Elisabeth Schmitz
On Wed, 29 Sep 2010 10:40:03 +0200 Andreas Schmitz wrote: > On 09/28/2010 10:36 PM, Tarlika Elisabeth Schmitz wrote: >> On Tue, 28 Sep 2010 11:34:31 +0100 >> "Oliveiros d'Azevedo Cristina" >> wrote: >> >>> - Original Message - >

Re: [SQL] identifying duplicates in table with redundancies

2010-09-28 Thread Tarlika Elisabeth Schmitz
On Tue, 28 Sep 2010 11:34:31 +0100 "Oliveiros d'Azevedo Cristina" wrote: >- Original Message - >From: "Tarlika Elisabeth Schmitz" >To: >Sent: Monday, September 27, 2010 5:54 PM >Subject: Re: [SQL] identifying duplicates in table with redundan

Re: [SQL] identifying duplicates in table with redundancies

2010-09-27 Thread Tarlika Elisabeth Schmitz
d","trainer_name" >>> FROM student >>> ) x >>> GROUP BY "trainer_name"-- the field you want to test for >>> duplicates >>> HAVING (COUNT(*) > 1) >>> ) z >>> NATURAL JOIN student y What indices would

Re: [SQL] identifying duplicates in table with redundancies

2010-09-24 Thread Tarlika Elisabeth Schmitz
get quite upset about it! It took me a while to get my head round your outer query with the NATURAL JOIN between the student table and the nested query results. I have done table joins before but this solution would not have sprung to mind. -- Many thanks, Tarlika Elisabeth Schmitz -- Sent vi

Re: [SQL] identifying duplicates in table with redundancies

2010-09-24 Thread Tarlika Elisabeth Schmitz
Dear Oliveiros, Thank you for taking the time to help. On Fri, 24 Sep 2010 11:22:21 +0100 "Oliveiros d'Azevedo Cristina" wrote: >- Original Message - >From: "Tarlika Elisabeth Schmitz" >To: >Sent: Thursday, September 23, 2010 10:39 PM >Subjec

[SQL] identifying duplicates in table with redundancies

2010-09-23 Thread Tarlika Elisabeth Schmitz
(trainer_id,trainer_name) trainer_id as id, trainer_name as name from student ) as trainer group by trainer.id having count (trainer.name) > 1 ) ) as y order by trainer_id -- Best Regards, Tarlika Elisabeth Schmitz -- Sent via pgsql-

Re: [SQL] JOIN and aggregate problem

2009-02-23 Thread Tarlika Elisabeth Schmitz
On Mon, 23 Feb 2009 15:44:05 + Richard Huxton wrote: > Tarlika Elisabeth Schmitz wrote: > > On Fri, 20 Feb 2009 19:06:48 + > > Richard Huxton wrote: > >> try something like: > >> > >> SELECT t1.d, t1.s, t1.c, count(*) > >> FROM t1 &g

Re: [SQL] JOIN and aggregate problem

2009-02-23 Thread Tarlika Elisabeth Schmitz
.d >AND t1.s = t2.s >AND t1.c = t2.c >AND t2.x = TRUE > GROUP BY t1.d, t1.s, t1.c,t2.x; > > [...] > > On Fri, Feb 20, 2009 at 12:04 PM, Tarlika Elisabeth Schmitz > wrote: > > I have 2 tables T1 and T2 > > > > T1 has the columns: D, S, C.

Re: [SQL] JOIN and aggregate problem

2009-02-23 Thread Tarlika Elisabeth Schmitz
On Fri, 20 Feb 2009 19:06:48 + Richard Huxton wrote: > Tarlika Elisabeth Schmitz wrote: > > I have 2 tables T1 and T2 > > > > T1 has the columns: D, S, C. The combination of D,S,C is unique. > > T2 has the columns: D, S, C, and boolean X. The combination

Re: [SQL] JOIN and aggregate problem

2009-02-23 Thread Tarlika Elisabeth Schmitz
On Fri, 20 Feb 2009 11:15:09 -0800 (PST) Stephan Szabo wrote: > On Fri, 20 Feb 2009, Tarlika Elisabeth Schmitz wrote: > > > I have 2 tables T1 and T2 > > > > T1 has the columns: D, S, C. The combination of D,S,C is unique. > > T2 has the columns: D, S, C, and boole

[SQL] JOIN and aggregate problem

2009-02-20 Thread Tarlika Elisabeth Schmitz
combinations in T2 where X = true. There might be no matching pair in T2 or there might be match but X is false. How can I express this? -- Best Regards, Tarlika Elisabeth Schmitz -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http

Re: [SQL] exclude part of result

2008-06-27 Thread Tarlika Elisabeth Schmitz
not exists (select a,b,c, from navigation t2 where t2.a = > t1.a and t2.b = t1.b and t2.c = t1.c) Many thanks - there seems to be half a dozen ways of achieving the desired result! > > --- On Thu, 6/26/08, Tarlika Elisabeth Schmitz > <[EMAIL PROTECTED]> wrote: From: Tarlika Elisa

Re: [SQL] exclude part of result

2008-06-27 Thread Tarlika Elisabeth Schmitz
On Fri, 27 Jun 2008 11:33:07 +0200 Harald Fuchs <[EMAIL PROTECTED]> wrote: > In article <[EMAIL PROTECTED]>, > Tarlika Elisabeth Schmitz <[EMAIL PROTECTED]> writes: > > > PRODUCT table : > > > A B C > > 100 200 300 > > 100 200 301 > >

Re: [SQL] exclude part of result

2008-06-26 Thread Tarlika Elisabeth Schmitz
t of the product and item table > with this statement: 'select a,b,c, count()from product LEFT > JOIN item on' > > > > P.M. > > --- On Thu 06/26, Tarlika Elisabeth Schmitz < > [EMAIL PROTECTED] > wrote: > > From: Tarlika Elisabeth Schmit

[SQL] exclude part of result

2008-06-26 Thread Tarlika Elisabeth Schmitz
om above result. How can I achieve this? -- Best Regards, Tarlika Elisabeth Schmitz A: Because it breaks the logical sequence of discussion Q: Why is top posting bad? -- 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] 3 SELECTs rolled into 1 ?

2008-06-04 Thread Tarlika Elisabeth Schmitz
On Wed, 4 Jun 2008 09:55:46 +0200 "A. Kretschmer" <[EMAIL PROTECTED]> wrote: > am Wed, dem 04.06.2008, um 8:41:29 +0100 mailte Tarlika Elisabeth > Schmitz folgendes: > > I have 3 similar SELECTs. I am wondering whether they could be > > rolled into one?

[SQL] 3 SELECTs rolled into 1 ?

2008-06-04 Thread Tarlika Elisabeth Schmitz
|| section.id as x FROM item LEFT JOIN product ON ... LEFT JOIN department ON ... LEFT JOIN section ON ... SELECT item.id department.id as x FROM item LEFT JOIN product ON ... LEFT JOIN department ON ... -- Best Regards, Tarlika Elisabeth Schmitz A: Because it breaks the logical

[SQL] UPDATE with table join

2008-05-27 Thread Tarlika Elisabeth Schmitz
s this the most efficient way of doing this? Is there a limit to the number of results that IN can cope with? This needs to run on Postgres 7.4. -- Best Regards, Tarlika Elisabeth Schmitz A: Because it breaks the logical sequence of discussion Q: Why is top posting bad? -- Sent via pgsql-s

Re: [SQL] extracting words

2008-04-24 Thread Tarlika Elisabeth Schmitz
On Wed, 23 Apr 2008 07:18:44 +0200 "A. Kretschmer" <[EMAIL PROTECTED]> wrote: > am Tue, dem 22.04.2008, um 22:25:04 +0100 mailte Tarlika Elisabeth > Schmitz folgendes: > > TABLE product: product_pk, product_name, department_fk > > TABLE produc

Re: [SQL] extracting words

2008-04-23 Thread Tarlika Elisabeth Schmitz
On Wed, 23 Apr 2008 09:13:03 -0400 Alvaro Herrera <[EMAIL PROTECTED]> wrote: > Tarlika Elisabeth Schmitz wrote: > > > I need to extract the words from department_name and product_name > > (words are separated by spaces) and get something like: > > > > 1 ca

[SQL] extracting words

2008-04-22 Thread Tarlika Elisabeth Schmitz
cakes 1 desserts 1 apple 1 crumble 2 cakes 2 desserts 2 cheese 2 cake 3 starters 3 soups 3 french 3 onion 3 soup Would it be more sensible to produce a table join and split the result into keywords programmatically? -- Best Regards, Tarlika Elisabeth Schmitz A: Because it breaks the