[SQL] "Truncate [ Table ] name [Cascade]"?

2003-07-19 Thread Andreas
Hi there, Would it be possible to implement some kind of cascading truncate? As far as I understand, the "no truncate if table is referenced" change was introduced to ensure database integrity. However, if the referencing table is truncated, too, there should be no problems as far as foreign k

[SQL] Notation of index

2004-01-07 Thread Andreas
Hi, I'm moving from MySQL to Pg. MySQL lets me create indices like this: CREATE TABLE t ( id INTEGERNOT NULL, numba INTEGER NOT NULL, txtVARCHAR(100) NOT NULL, anosanumba INTEGER NOT NULL , PRIMARY KEY (id), INDEX (numba), UNIQUE (anosanumba) );

[SQL] where to start with this procedure ?

2004-05-19 Thread Andreas
Hi, I know a bit of SQL but not exactly a lot so I ran into this problem. I have tables on the server that get joined in a view. That's OK. Now I need just a couple of records say 10-100 of 30 000 which could easily be filtered by a integer key. As of now I have to pull the whole lot into Access a

Re: [SQL] where to start with this procedure ?

2004-05-20 Thread Andreas
Hi Andrei, Use the Offset and Limit in the SQL query. [...] SELECT select_list FROM table_expression WHERE condition LIMIT 50 OFFSET 1 This query will return 50 elements starting with the 1 elements... so the elemenst from 1 to 10050. That isn't the issue since I only ne

[SQL] Multitable uniqueness ?

2004-05-25 Thread Andreas
Hi folks, Is there a way to have something like this : UNIQUE (table_1.id, table_2.xxx) I got some tables that have a couple of foreign keys. Now I try to minimize those relationships to clean up the mess. :-} We do business fairs. (???) Like c-bit only a few magnitudes smaller. So we have p

Re: [SQL] Multitable uniqueness ?

2004-05-27 Thread Andreas
Jean-Luc Lachance schrieb: Do you really need MANY-TO-MANY between customers and projects? I can see customers owning many projects, but do you really have projects belonging to many customers? In this case yes. projects ( 1, 'x-fair 2003'; 2, 'y-fair 2003'; 3, 'x-fair 2004') customer ( 1,

Re: [SQL] Multitable uniqueness ?

2004-05-27 Thread Andreas
Bruno Wolff III wrote: On Wed, May 26, 2004 at 05:13:14 +0200, Andreas <[EMAIL PROTECTED]> wrote: Is there a way to have something like this : UNIQUE (table_1.id, table_2.xxx) Postgres doesn't support database constraints at this time which is what you would need to do

Re: [SQL] Database backup

2004-10-18 Thread Andreas
sreejith s wrote: How to take Database backup from an application developed in Visual Basic thats running at Windows Client and Database resting at Linux Server. THanx You wrote a similar question some days ago and mentioned that pg_dump wouldn't work on Windows, so I figure you don't want to l

[SQL] How to check date-interval constraints

2006-03-02 Thread Andreas
Hi, I'd like to have a table that looks like this: my_option ( id serial primary key, myvalue double, valid_start timestamp, valid_stop timestamp ); I want to store values that are only valid in a given start-stop-interval so I could find a date-specific value for

[SQL] How update a table within a join efficiently ?

2009-07-10 Thread Andreas
Hi, how would I update a table within a join in a more efficient way? E.g. the folowing case: table_a holds abstract elements. One column represents "priority" which can be based on information of other tables. table_b might hold such details in a column "size" for about 3000 of 8 records o

[SQL] Need magical advice for counting NOTHING

2009-07-22 Thread Andreas
, type3, 7 user2, type1, 11 user2, type3, 17 but I needed also user2, type2, 0 How would I get there ? Regards Andreas -- 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] Need magical advice for counting NOTHING

2009-07-25 Thread Andreas
nha schrieb: Hello, Le 23/07/09 10:23, Glenn Maynard a écrit : 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

[SQL] How fetch multiple rows into one text-field?

2009-07-31 Thread Andreas
sists of a couple of case-infos and should look like case_id, case_name, case_all_log_events Is there a way to do this? regards andreas -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql

[SQL] Howto automatically define collumn names for a function result.

2009-08-27 Thread Andreas
Hi, wouldn't it be great to have functions return "setof something" as result where "something" was determined out of the result of a SELECT within the function? like CREATE OR REPLACE FUNCTION coffee(integer, timestamp, timestamp) RETURNS SETOF AS $BODY$ SELECT staff_id, name, room, COUN

[SQL] Need magic for a moving statistic

2009-10-01 Thread Andreas
Hi, I need some magic for a moving statistic that works on a rather big table starting at a given date within the table up until now. The statistic will count events allways on fridays over periods of 2 weeks before ... biweekly? So I'd like to get a line every 2 weeks for everthing between.

Re: [SQL] SQL moving window averages/statistics

2009-10-01 Thread Andreas
Just 3 points ... 1) don't use "date" as a column name because it's a data type. 2) to_char(current_date, 'MM')||to_char(current_date, 'DD') is equivalent to to_char(current_date, 'MMDD') 3) you should get the same result with ... where icao='KSFO' and (EXTRACT (MONTH from d

Re: [SQL] Need magic for a moving statistic

2009-10-02 Thread Andreas
A. Kretschmer schrieb: [...] Or simpler: test=*# select ((d-'2009-10-02'::date)/14) || '. period' as period, sum(value) from foo group by 1; This is tricky, because you use a text-column to sort but need numerical sorting since there will be more than 0-9 periods. This is still the way

[SQL] Need even more magic. Now for tricky counts.

2009-10-03 Thread Andreas
Hi, there is a vast log-table that collects several state data for objects. (log_id, project_fk, object_fk, state_fk, log_type_fk, created_on::timestamp, ...) log_id is a sequence, project_fk foreign key on a project-table object_fk foreign key on a object-table state_fk can have 10 v

[SQL] constants in 2-column foreign keys or how to design a storage for text-groups ?

2009-12-08 Thread Andreas
Hi, my frontend has a lot of combo- and listboxes where one can chose a textsnippet that represents a key-number which is stored in several tables as foreign-key attributes. Those textsnippets are usually semantically grouped in 2-10 strings that belong together somehow. stupid example: -

Re: [SQL] Re: constants in 2-column foreign keys or how to design a storage for text-groups ?

2009-12-11 Thread Andreas
Jasen Betts schrieb: On 2009-12-09, Andreas wrote: ... stupid example: --- color: red, green, blue size: tiny, little, big, giant structure: hard, soft, floppy How would I solve the rather common text storage issue? have you considered using enumerated types instead

[SQL] How to cascade information like the user roles ?

2010-01-18 Thread Andreas
Hi, I need something like the user-roles of PG to store options of my users. I guess i need a table with roles, options and one that stores the refernces from roles to options. roles (role_id, role_name) option (option_id, option_name) role_has_option (role_fk, option_fk) so far is easy. Now

Re: [SQL] How to cascade information like the user roles ?

2010-01-19 Thread Andreas
Filip Rembiałkowski schrieb: 2010/1/19 Andreas mailto:maps...@gmx.net>> Hi, I need something like the user-roles of PG to store options of my users. I guess i need a table with roles, options and one that stores the refernces from roles to options. roles (r

Re: [SQL] How to cascade information like the user roles ?

2010-01-20 Thread Andreas
Thanks a whole lot and some :) It's great that you actually did a working script. I find it tremendosly easier to learn with a working example than with some links to other documentation which makes or does not make sense. I've got a 8.4 server so both ways work nicely. Is there a way to prev

[SQL] Howto have a unique restraint on UPPER (textfield)

2010-01-30 Thread Andreas
Hi, is there a way to define a unique restraint on UPPER (textfield)? E.g. mytable ( name_id serial PRIMARY KEY, name varchar(255), UNIQUE ( upper (name) ) ) psql throws a syntax error because of the upper() function. I need to prohibit that 2 of strings like cow, Cow, CoW appe

Re: [SQL] Howto have a unique restraint on UPPER (textfield)

2010-01-31 Thread Andreas
Joshua Tolley schrieb: On Sun, Jan 31, 2010 at 03:26:14AM +0100, Andreas wrote: Hi, is there a way to define a unique restraint on UPPER (textfield)? E.g. mytable ( name_id serial PRIMARY KEY, name varchar(255), UNIQUE ( upper (name) ) ) psql throws a syntax error because of the

Re: [SQL] Howto have a unique restraint on UPPER (textfield)

2010-01-31 Thread Andreas
Tom Lane schrieb: Andreas writes: So I had the missconception that UNIQUE (...) within CREATE TABLE (...) was actually just an shorter way to define a unique index which it is not. Well, it is that --- it just doesn't provide access to all the features that CREATE INDEX does.

[SQL] Howto get a group_number like row_number for groups

2010-04-08 Thread Andreas
Hi I'd like to have an alternating colorindex in the output of a query that consecutive rows that are the same within a colum the same number. The query generates a readable output from a log-table and a few others that hold referenced texts. log (log_id int, log_event_fk int, object_fk i

[SQL] How to find broken UTF-8 characters ?

2010-04-25 Thread Andreas
Hi, I regularly have to import from Excel files, that hold rather simple text and number columns. That works. Occasionally there are unwanted special characters at the end of text-columns that Exel and pgAdmin either show as a upward arrow with a short leg on top 90° to the right or others a

Re: [SPAM]-D] [SQL] How to find broken UTF-8 characters ?

2010-04-26 Thread Andreas
Am 26.04.2010 12:12, schrieb silly sad: On 04/26/10 04:12, Andreas wrote: looks like a complete offtopic Not anymore. The bad signs are in the DB now. I'd need some command that filters somehow for inconvertible (Unicode-->local charset) data. How can I find those Unicode charact

Re: [SPAM]-D] [SQL] How to find broken UTF-8 characters ?

2010-04-28 Thread Andreas
5:18, schrieb Justin Graf: On 4/26/2010 8:41 AM, Andreas wrote: How can I get rid of them? iconv -c AFAIK iconv would translate on file system level but I would think that messed up a allready messed up Excel workmap even further. I'd be glad to handle csv, too. I would look at a macro/

[SQL] How to find events within a timespan to each other?

2010-07-07 Thread Andreas
1 ... 13:05 242 1 ... 13:06 E.g. the checked event_typ_id may be 3 then the result should be line 19, 21, 23 regards Andreas :) -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref

[SQL] How would I store little key-Nr to text lists?

2010-07-10 Thread Andreas
Hi how would I store little key-Nr to text lists? Like e.g. colors 1 red 2 green 3 blue Maybe I later also need to add 4 yellow? Obviously the numbers are used for foreign keys in data tables and the texts appear in selects. On the other hand users should chose from listboxes in an ap

[SQL] howto delete using a join ?

2010-07-23 Thread Andreas
Hi, is there a way to delete from a table using information from another table to decide if a row should be dropped? In my case there is a log events ( event_id, event_type_fk, ...); event_types ( event_type_id, relevance_level ); Now I'd like to delete all old events with certain relevance

[SQL] Help Need some hindsight

2010-08-04 Thread Andreas
Hi, I need to display log events (again). The log is simply like this log ( log_id serial primary key, create_ts timestamp default localtimestamp, object_id, state_id, ... ) It records the state of objects and when and what happend to to change this state. I'd like to get a list that sh

[SQL] is there a distinct function for comma lists ?

2010-09-07 Thread Andreas
Hi, is there a distinct function for comma separated lists ? I sometimes need to update tables where I got a set of IDs, like: update mytable set someattribute = 42 where mytable.id in ( 1, 2, 3, 5, 7, 11, 3, 6, 13, 13, 3, 11 ... ) So there are double entries in the list but in this case i

[SQL] HowTo divide streetname from house-nr ?

2010-09-22 Thread Andreas
Hi, how could I divide streetnames from housenumbers ? I have to deal with input like this: Parkstreet 42 Parkstr. 42 Casle Avenue 42 Casle Str. 42-47 Casle Str. 54 - 55 probaply even Casle Str. 42-47 a Perhaps one could cut ap the 1st numeric char and regard everything left of it as the st

[SQL] Need magic for inserting in 2 tables

2010-10-03 Thread Andreas
Hi, I need to insert a lot of basically blank records into a table to be filled later. Sounds silly but please bear with me. :) projects ( project_id, project_name, ... ) companies ( company_id, ... ) departments ( department_id, department ) staff ( staff_id SERIAL, company_fk, department

Re: [SQL] Need magic for inserting in 2 tables

2010-10-03 Thread Andreas
Am 04.10.2010 01:46, schrieb Scott Marlowe: On Sun, Oct 3, 2010 at 4:14 PM, Andreas wrote: insert into staff ( company_fk, ..., department_fk ) select company_fk, ..., department_fk from departments, companies, company_2_project AS c2p where company_id = c2p.company_fk

Re: [SQL] Need magic for inserting in 2 tables

2010-10-03 Thread Andreas
Am 04.10.2010 02:58, schrieb Scott Marlowe: The same way it would use the output of a select, it's a record set. So it's x rows by y columns. Then where were my insert statements wrong? Please, look this is a simple but complete example and show me my error. create temporary table table_1 (

[SQL] Is there a conditional string-concatenation ?

2010-10-11 Thread Andreas
Hi, Is there a conditional string-concatenation ? I'd like to have an elegant way to connect 2 strings with some 3rd element between only if there really are 2 strings to connect. e.g. MyCat ( 'John', '_', 'Doe' ) --> 'John_Doe' while MyCat ( 'John', '_', '' ) --> 'John' MyCat ( '', '_', 'Doe

[SQL] How to collect text-fields from multiple rows ?

2010-10-15 Thread Andreas
Hi, how can I collect text-fields from multiple rows into one output row? I'd like to do an equivalent to the aggregate function SUM() only for text. The input is a select that shows among other things a numerical column where I would like to group by. The text column of all rows in a group sh

[SQL] insert into table from list or array ?

2010-10-18 Thread Andreas
Hi, is it possible to insert into a table from list or an array ? Suppose there is a set of numbers that might be IDs of tables within the DB. To work with them I'd need a temporary table that just holds a single column with those numbers. Something like create temporary table tmptable as se

Re: [SQL] insert into table from list or array ?

2010-10-18 Thread Andreas
Am 18.10.2010 20:14, schrieb Pavel Stehule: 2010/10/18 Andreas: is it possible to insert into a table from list or an array ? yes, it's possible INSERT INTO tmptab SELECT v FROM unnest(string_to_array('1,2,4,2,1',',')) g(v) Thanks Pavel, though I'm

[SQL] How to search for a part of a number

2010-10-24 Thread Andreas
Hi, I'm wondering if there was a clever way to find parts of a numeric string in another table. There is a table that holds city-codes and city-names. City-code would be the part of a phone number that identifies the city. Over here this code can have 2 - 5 digits. So the table would contain:

Re: [SQL] Sorting router interfaces

2010-11-01 Thread Andreas
Am 01.11.2010 13:15, schrieb Brian Sherwood: I am trying to sort router interface names. The problem is that I am doing a text sort and need to do a numerical sort. What I get instead is the following text ordering: GigabitEthernet1/0/1| 1/0/1 | {1,0,1} GigabitEthernet1/0/10 | 1/

[SQL] unexpected ORDER BY

2010-11-09 Thread Andreas
Hi, I've got an PG 8.4 on a opensuse box running. The DB is unicode german. There is a text column I'd like to order by but as far as I see PG ignores special chars and uses only characters and numbers. E.g. I get : S&T C... S&T E... STP <-- ??? STP A <-- ??? S&T P... S&T R... Can I modify t

[SQL] multi table import from 1 denormalized source table

2010-11-15 Thread Andreas
Hi, I frequently get tables from spreadsheets to import into the DB. Usually it looks like this: A1, A2, A3, A4, B1, B2, B3, with optional C1, C2, D1, D2, ... and there is a 1:n relation between A and B. If provieded the C would be 1:1 to A and D 1:1 to B. Up until now I let a VBA script

[SQL] Howto "insert or update" ?

2010-11-22 Thread Andreas
Hi, is there an elegant way to tell PG : a) Hey PG, look here are e.g. 3 values A, B, c for tableX b) please check if there is a row matching A and B as key in tableX c) if such a row exists, execute an UPDATE on column c else INSERT a new row. Currently I have a trigger function tha

[SQL] need help with some aggregation magic

2011-06-09 Thread Andreas
hi, I have a log-table that stores events of users and projects like this ( user_id integer, project_id integer, ts timestamp, event_type integer ) I need an aggregated list of worktime per user, per project, per day. The users can switch projects during the day so I can't work this out with mi

Re: [SQL] need help with some aggregation magic

2011-06-09 Thread Andreas
an user cannot be in more than one project at the time? If so, can't be overlapping, right? Best, Oliveiros - Original Message - From: "Andreas" To: Sent: Thursday, June 09, 2011 2:43 PM Subject: [SQL] need help with some aggregation magic hi, I have a log-table tha

Re: [SQL] need help with some aggregation magic

2011-06-09 Thread Andreas
Am 09.06.2011 18:20, schrieb Richard Broersma: On Thu, Jun 9, 2011 at 6:43 AM, Andreas wrote: I have a log-table that stores events of users and projects like this ( user_id integer, project_id integer, ts timestamp, event_type integer ) I need an aggregated list of worktime per user, per

[SQL] problem with selecting from a function

2011-06-20 Thread Andreas
Hi, I've got a table with a couple of objects. Primary key object_id. There is a function that fetches some values from another table that relate to an object_id. Like fctX ( 7 ) --> set of typX ... ( 14, 'bla' ), ( 17, 'blu' ), ( 21, 'ble' ), ... The result of the function can have 0 or mo

[SQL] How to remove a set of characters in text-columns ?

2011-06-30 Thread Andreas
Hi, how can I remove a set of characters in text-columns ? Say I'd like to remove { } ( ) ' " , ; . : ! Of course I can chain replace ( replace ( replace ( replace ( ... , '' ) and replace the chars one by one against an empty string ''. There might be a more elegant way. Is there ? rega

Re: [SQL] How to remove a set of characters in text-columns ?

2011-06-30 Thread Andreas
problem. :) my replace...replace... was a wee bit tedious ;) thanks a lot to you, Charlie and Steve :) regards Andreas -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql

[SQL] need magic to shuffle some numbers

2011-08-23 Thread Andreas
Hi, there is a table that has among others a integer primary key "id" and another integer column "prio" as well as an integer "group_id". I'd like to invert the values of the prio-column for one of the groups. The prio numbers start with 3 and there are 1159 different prios in this group. At

[SQL] How can I inherit constraints?

2011-09-06 Thread Andreas
Hi, how would I let a table inherit the constraints of its parent(s) ? It'd be rather cool not having to repeat every foreign key a table inherited from it's parents. -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/

[SQL] Clever way to check overlapping time intervals ?

2011-09-15 Thread Andreas
Hi, is there a clever way to check overlapping time intervals ? An option named n should be taken from date y to y. The same name is ok for another interval. e.g. table : mytab ( d1 date, d2 date, n text, v text ) There should be a constraint to provide no row can have a d1 or d2 within the in

[SQL] insert or update within transaction

2011-09-17 Thread Andreas
Hi, http://www.postgresql.org/docs/current/static/sql-update.html has an example where an either an insert or update is done according if a key already exists. The example is about wines. I did it with numbers. drop table if exists tbl; create table tbl ( key int primary key, val int ); insert

Re: [SQL] Use select and update together

2011-09-17 Thread Andreas
Am 13.09.2011 07:50, schrieb pasman pasmański: In 8.4 this syntax is not implemented. select * from ( update tbl set val = 1 where key in ( 1, 2, 3, 4, 5 ) returning * ) as x wouldn't work even in PG 9.1. So what data structure is coming out of an "update ... returning *" statement? It obvio

[SQL] Howto build a funtion that selects an id or inserts a value

2011-09-23 Thread Andreas
Hi, I'd like to have a function that looks up an id of an item. In case the item doesn't exist in the table yet it should be inserted and the new id should be returned. From the PG docu, I took the merge_db sample and modified it a bit. This works but I'm wondering if INSERT part could be tune

[SQL] Better way to check more than 1 value NOT IN (...)

2011-09-24 Thread Andreas
Hi, I've got to check if 2 values are not in a set that is dynamically calculated by a function. The query looks like select some_id, from . where 10 is not in ( select x from my_function (some_id)) and 20 is not in ( select x from my_function (some_id)) Is there a efficiency

[SQL] how to calculate differences of timestamps?

2011-09-26 Thread Andreas
How could I calculate differences of timestamps in a log-table? Table log ( user_id integer, login boolean, ts timestamp ) So login = true would be a login-event and login = false a logout. Is there a way to find the matching login/logout to calculate the difference? Or is there a better tabl

[SQL] Question on imports with foreign keys

2011-12-07 Thread Andreas
Hi, suppose you need to import a csv with standard ciolums like name, adress, phone, ... and some additional text columns that need to be split off into referenced tables. Those lookup-tables will only be needed for a project with limited life time so I create a schema that might be called "

Re: [SQL] Question on imports with foreign keys

2011-12-08 Thread Andreas
Am 08.12.2011 09:39, schrieb Emre Hasegeli: On Thu, 08 Dec 2011 08:48:51 +0200, Andreas wrote: How is the easiest way to to find the customer.id of the new customers so I can insert the projectinfos? It is easy to select rows not related with another table. One of the following queries

[SQL] Is there a way to remove every character but numbers?

2012-02-05 Thread Andreas
Hi, I need to clean up a text column so that it just contains numbers or the "+" sign if it is the first character of the string. Well, it is needed to normalise up a phone number column. So it'd be great if the "+" could be transformed in "00" in the same step. -- Sent via pgsql-sql mailing

[SQL] need help with import

2012-02-15 Thread Andreas
Hi I get CSV files to import. Th structure is like this. main part, sub part Could be like this A, a1 A, a2 A, a3 B, b1 B, b2 The database has a table for main_part and one for sub_part. The relation needs to be n:m so there is a relation table that holds ( main_id, sub_id ). The 2 primary key

Re: [SQL] need help with import

2012-02-15 Thread Andreas
Am 16.02.2012 02:13, schrieb David Johnston: -Original Message- From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org] On Behalf Of Andreas Sent: Wednesday, February 15, 2012 8:03 PM To: pgsql-sql@postgresql.org Subject: [SQL] need help with import Hi I get CSV

[SQL] How to split up phone numbers?

2012-02-20 Thread Andreas
Hi, is there a way to split up phone numbers? I know that's a tricky topic and it depends on the national phone number format. I'm especially interested in a solution for Germany, Swizerland and Austria. I've got everything in a phone number column that makes hardly sense like: +49432156780 004

[SQL] syntax of joins

2012-04-06 Thread Andreas
hi, is there a disadvantage to write a join as select * froma, b where a.id = b.a_id; over select * froma join b on a.id = b.a_id; -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql

[SQL] How to group by similarity?

2012-04-24 Thread Andreas
Hi, I'm trying to get an idea about pg_trgrm. I created a GIST index on a text column in a table. Now I can filter the table with similarity(). How would I group the table so that it shows groups that have similarity () > x ? Lets say the table looks like this: id, txt 1, aa1 2, bb1 3,

[SQL] generic crosstab ?

2012-04-24 Thread Andreas
Hi, is there a generic solution to dump the result of a query as a crosstab, when I can't know how many columns I will need? E.g. I get something like this: id, x 1, a 1, b 1, c 2, l 2, m and I'd like to see it as: id, x1, x2, x3, . xn 1, a, b, c,null, null 2,

Re: [SQL] generic crosstab ?

2012-04-24 Thread Andreas
Am 24.04.2012 22:08, schrieb Samuel Gendler: On Tue, Apr 24, 2012 at 1:01 PM, Andreas <mailto:maps...@gmx.net>> wrote: Hi, is there a generic solution to dump the result of a query as a crosstab, when I can't know how many columns I will need? E.g. I get somet

Re: [SQL] generic crosstab ?

2012-04-24 Thread Andreas
Am 25.04.2012 00:04, schrieb Joe Conway: On 04/24/2012 02:42 PM, David Johnston wrote: You must specify the output record structure: SELECT crosstab(text, text) AS ( col1_name col1_type [, colN_name colN_type]* ) Whether this relates to the “materialization node” message you are receiving I ha

[SQL] Need help in grouping records

2012-05-19 Thread Andreas
Hi, I'm trying to fight against double entries in tables. I got as far as I can find similar records with trigram string matching. If I do this with a table compared to itself I get something like this: id_a, id_b 3, 5 3, 7 5, 3 5, 7 7, 3 7, 5 11, 13 13, 11 so the records with t

Re: [SQL] Need help in grouping records

2012-05-20 Thread Andreas
Am 20.05.2012 05:04, schrieb Jasen Betts: On 2012-05-19, Andreas wrote: Hi, I'm trying to fight against double entries in tables. I got as far as I can find similar records with trigram string matching. If I do this with a table compared to itself I get something like this: id_a, id_b 3

[SQL] Select every first/last record of a partition?

2012-05-21 Thread Andreas
Hi, suppose a table that has records with some ID and a timestamp. id,ts 3,2012/01/03 5,2012/01/05 7,2012/01/07 3,2012/02/03 3,2012/01/05 5,2012/03/01 7,2012/04/04 to fetch every last row of those IDs I do: select id, ts from ( select id, ts, row_number(

[SQL] Is there a similarity-function that minds national charsets?

2012-06-20 Thread Andreas
Hi, Is there a similarity-function that minds national charsets? Over here we've got some special cases that screw up the results on similarity(). Our characters: ä, ö, ü, ß could as well be written as: ae, oe, ue, ss e.g. select similarity ( 'Müller', 'Mueller' ) results to: 0.363636 In

[SQL] How to limit access only to certain records?

2012-06-22 Thread Andreas
, account_manager_id ). Could I let the database control that account-manager #1 can only see customers who are assigned to him in the cu_am-relation? For now I do this in the front-end but this is easily circumvented for anyone who has a clue and uses some other client like psql. Regards Andreas -- Sent

[SQL] How to solve the old bool attributes vs pivoting issue?

2012-06-27 Thread Andreas
Hi I do keep a table of objects ... let's say companies. I need to collect flags that express yes / no / don't know. TRUE / FALSE / NULL would do. Solution 1: I have a boolean column for every flag within the companies-table. Whenever I need an additional flag I'll add another column. This

[SQL] Prevent double entries ... no simple unique index

2012-07-11 Thread Andreas
Hi, I've got a log-table that records events regarding other objects. Those events have a state that shows the progress of further work on this event. They can be open, accepted or rejected. I don't want to be able to insert addition events regarding an object X as long there is an open or a

Re: [SQL] Prevent double entries ... no simple unique index

2012-07-12 Thread Andreas
Am 12.07.2012 07:14, schrieb Andreas Kretschmer: Marc Mamin wrote: A partial index would do the same, but requires less space: create unique index on log(state) WHERE state IN (0,1); OK, nice :) What if I have those states in a 3rd table? So I can see a state-history of when a state

[SQL] join against a function-result fails

2012-07-27 Thread Andreas
Hi, I have a table with user ids and names. Another table describes some rights of those users and still another one describes who inherits rights from who. A function all_rights ( user_id ) calculates all rights of a user recursively and gives back a table with all userright_ids this user di

[SQL] Need help with a special JOIN

2012-09-29 Thread Andreas
Hi, asume I've got 2 tables objects ( id int, name text ) attributes ( object_id int, value int ) attributes has a default entry with object_id = 0 and some other where another value should be used. e.g. objects ( 1, 'A' ), ( 2, 'B' ), ( 3, 'C' ) attributes ( 0, 42

[SQL] rolling statistic probaply a window function?

2012-10-14 Thread Andreas
I have a rather big log table that collects events for objects and the change of their states. Say an object can have state 0-9. Every now and then an event happens that gets logged as: ( event TIMESTAMP, object_id INTEGER, state_id INTEGER ) Now I need to get a history of the last 12 weeks tha

[SQL] need some magic with generate_series()

2013-01-22 Thread Andreas
Hi I need a series of month numbers like 201212, 201301 MM to join other sources against it. I've got a table that describes projects: projects ( id INT, project TEXT, startdate DATE ) and some others that log events events( project_id INT, createdate DATE, ...) to show some statistics I

Re: [SQL] need some magic with generate_series()

2013-01-22 Thread Andreas
0101'::date, '1 month'::interval) m; On Tue, Jan 22, 2013 at 3:49 PM, jan zimmek wrote: hi andreas, this might give you an idea how to generate series of dates (or other datatypes): select g, (current_date + (g||' month')::interval)::date from generate_series(1,12) g;

Re: [SQL] need some magic with generate_series()

2013-01-22 Thread Andreas
der by 1, 2; Am 23.01.2013 01:08, schrieb Alexander Gataric: I would create a common table expression with the series from Filip and left join to the table you need to report on. - Reply message - From: "Andreas" To: "Filip Rembiałkowski" Cc: "jan zimmek&qu

Re: [SQL] Re: [SQL] need some magic with generate_series()

2013-01-23 Thread Andreas
xpression with the series from Filip and left join to the table you need to report on. Sent from my smartphone - Reply message - From: "Andreas" To: "Filip Rembiałkowski" Cc: "jan zimmek" , Subject: [SQL] need some magic with generate_series() Date: Tue

[SQL] How to access multicolumn function results?

2013-01-23 Thread Andreas
Hi I've got functions that return a TABLE. If I call it with constant parameters like: SELECT * FROM some_fct( 42 ); I get a table with column names as the result as intended. When I rather call it with the parameter coming from another table I get a set of records where I don't know how to a

[SQL] How to reject overlapping timespans?

2013-02-17 Thread Andreas
Hi, I need to store data that has a valid timespan with start and enddate. objects ( id, name, ... ) object_data ( object_id referencs objects(id), startdate, enddate, ... ) nothing special, yet How can I have PG reject a data record where the new start- or enddate lies between the start- or

Re: [SQL] How to reject overlapping timespans?

2013-02-17 Thread Andreas
Am 17.02.2013 19:20, schrieb Andreas Kretschmer: Andreas hat am 17. Februar 2013 um 18:02 geschrieben: I need to store data that has a valid timespan with start and enddate. objects ( id, name, ... ) object_data ( object_id referencs objects(id), startdate, enddate, ... ) nothing special

[SQL] I need to fill up a sparse table in an view

2013-03-02 Thread Andreas
Hi, I need to fill up a sparse table in an view. The table holds some numbers relating months and objects. The month is an integer in the format MM. To make it more convenient to manage this table I decidet to let a value be good till the next entry. E.g. if there is an entry in january and

[SQL] How to split an array-column?

2013-03-18 Thread Andreas
Hi, I've got a table to import from csv that has an array-column like: import ( id, array_col, ... ) Those arrays look like ( 42, ";4941;4931;4932", ... ) They can have 0 or any number of elements separated by ; So I'd need a result like this: 42, 4941 42, 4931 42, 4932 How would I get this?

Re: [SQL] How to split an array-column?

2013-03-18 Thread Andreas
rray_col) from table Venky Kandaswamy Principal Engineer, Adchemy Inc. 925-200-7124 From: pgsql-sql-ow...@postgresql.org [pgsql-sql-ow...@postgresql.org] on behalf of Andreas [maps...@gmx.net] Sent: Monday, March 18, 2013 12

[SQL] monthly statistics

2013-07-08 Thread Andreas
Hi, I need to show a moving statistic of states of objects for every month since beginning of 2013. There are tables like objects ( id integer, name text ); state ( id integer, state text ); 10=A, 20=B ... 60=F history ( object_id integer, state_id, ts timestamp ); Every event that

[SQL] Funny date-sorting task

2007-05-12 Thread Andreas
Hi, I've got a stack of tasks to show in a list. Every task has a timestamp X that may be NULL or a date. It contains the date when this tasks should be done. Sometimes it has date and the time-part, too. The list should be like this: 1) X sometime today should come first in ascending ti

[SQL] percentages of a column

2007-06-29 Thread Andreas
Hi, There is a Select that calculates some SUMs of objects. I'd like to show a list of counts and percentages of this counts based on the sum of all counts. Is that possible in a SELECT statement? Example: Fruit Count % -- Bananas 5 10%

[SQL] List of FKeys ?

2007-08-26 Thread Andreas
elete" options of the relation. Regards Andreas ---(end of broadcast)--- TIP 2: Don't 'kill -9' the postmaster

[SQL] design of tables for sparse data

2007-11-09 Thread Andreas
illable 3) b) Or it is availlable but no one has chosen it in 2007. --> attends_to.in_year Regards Andreas ---(end of broadcast)--- TIP 5: don't forget to increase your free space map settings

Re: [SQL] design of tables for sparse data

2007-11-12 Thread Andreas
Fernando Hevia schrieb: --- Andreas Wrote: --- ... MY QUESTIONS: Your questions have a strong "home-work" look. Yes but I didn't want to bother everyone with my project's details. It's more like a CRM. Up until now I just tried to manage somehow with the s

  1   2   3   4   5   >