Re: [SQL]

2013-10-08 Thread Andreas Kretschmer
Kaleeswaran Velu v_kal...@yahoo.com wrote: Hi Team, I am using PostgreSQL 9.2.3 in Windows platform. I have created two databases in it. Now I want to refer the tables across the databases. Meaning would like to create Database link. Can anyone guide me on how to create a DB link? You can

Re: [SQL] Primary DB stuck becuase of unavailable standby (synchronized streaming) - please help

2013-04-18 Thread Andreas Kretschmer
Sofer, Yuval yuval_so...@bmc.com wrote: Hi, I am using Postgres DB with stand by database, configured with streaming in synchronized mode (each commit on primary DB waits for commit on secondary DB). Sometimes we suffer from network issues and as consequences, secondary

Re: [SQL] How to reject overlapping timespans?

2013-02-17 Thread Andreas Kretschmer
Andreas maps...@gmx.net hat am 17. Februar 2013 um 18:02 geschrieben: 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

Fwd: Re: [SQL] sql basic question

2012-12-28 Thread Andreas Kretschmer
sorry, only a private replay and not to the list -- Ursprüngliche Nachricht -- Von: Andreas Kretschmer andr...@a-kretschmer.de An: Antonio Parrotta antonioparro...@gmail.com Datum: 28. Dezember 2012 um 15:19 Betreff: Re: [SQL] sql basic question Hi, your question was: What I want

Re: [SQL] sql basic question

2012-12-28 Thread Andreas Kretschmer
| 129007 | 0.63454675634756 |0 *m 19 | 129007 | 0.97897897897654 |0 *M 13 | 129007 | 0.22345364656788 |1 *m 11 | 129007 | 0.86787897897689 |1 *M thanks - Antonio On 28 December 2012 15:19, Andreas Kretschmer andr...@a-kretschmer.dewrote: Hi, your

Re: [SQL] Help with a select statement design

2012-12-28 Thread Andreas Kretschmer
JORGE MALDONADO jorgemal1...@gmail.com hat am 24. Dezember 2012 um 17:30 geschrieben: I have a record with the following fields: id1, id2, id3, id4, price1, price2, price3, price4 I would like to write a SELECT statement in order to get 4 records: id, price (record that comes from id1 and

Re: [SQL] checking the gaps in intervals

2012-10-06 Thread Andreas Kretschmer
Anton Gavazuk antongava...@gmail.com wrote: Hi dear community, Have probably quite simple task but cannot find the solution, Imagine the table A with 2 columns start and end, data type is date start end 01 dec. 10 dec 11 dec. 13 dec 17 dec. 19 dec . If I

Re: [SQL] checking the gaps in intervals

2012-10-06 Thread Andreas Kretschmer
Andreas Kretschmer akretsch...@spamfence.net wrote: Anton Gavazuk antongava...@gmail.com wrote: Hi dear community, Have probably quite simple task but cannot find the solution, Imagine the table A with 2 columns start and end, data type is date start end 01 dec

Re: [SQL] Reuse temporary calculation results in an SQL update query

2012-09-29 Thread Andreas Kretschmer
Matthias Nagel matthias.h.na...@gmail.com hat am 29. September 2012 um 12:49 geschrieben: Hello, is there any way how one can store the result of a time-consuming calculation if this result is needed more than once in an SQL update query? This solution might be PostgreSQL specific and not

Re: [SQL] [GENERAL] Indexing question

2012-08-14 Thread Andreas Kretschmer
amit sehas cu...@yahoo.com wrote: In SQL, given a table T, with two fields f1, f2, is it possible to create an index such that the same record is indexed in the index, once with field f1 and once with field f2. (I am not looking for a compound index in which the key would look like f1,

Re: [SQL] can this be done with a check expression?

2012-08-02 Thread Andreas Kretschmer
Tom Lane t...@sss.pgh.pa.us wrote: Wayne Cuddy lists-pg...@useunix.net writes: A less bogus way of doing things is to use an EXCLUDE constraint, although that will restrict you to be running PG 9.0 or newer. You also need some way of representing the ranges as indexable objects. In 9.0 or

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

2012-07-11 Thread Andreas Kretschmer
Andreas maps...@gmx.net wrote: 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

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

2012-07-11 Thread Andreas Kretschmer
Andreas Kretschmer akretsch...@spamfence.net wrote: Andreas maps...@gmx.net wrote: 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

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

2012-07-11 Thread Andreas Kretschmer
Marc Mamin m.ma...@intershop.de wrote: Or this one: test=*# create unique index on log((case when state = 0 then 0 when state = 1 then 1 else null end)); CREATE INDEX Now you can insert one '0' and one '1' - value - but no more. Hi, A partial index would do the same,

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

2012-06-22 Thread Andreas Kretschmer
Andreas maps...@gmx.net wrote: Hi, is there a way to limit access for some users only to certain records? e.g. there is a customer table and there are account-managers. Could I limit account-manager #1 so that he only can access customers only acording to a flag? Yea, it's possible.

Re: [SQL] master/detail

2012-05-23 Thread Andreas Kretschmer
Jan Bakuwel jan.baku...@greenpeace.org hat am 21. Mai 2012 um 01:17 geschrieben: Hi, I'm trying to get my head around the following question. As an example take a table with products: productid (pk) name and productprice productpriceid (pk) productid (fk) pricedate price There

Re: [SQL] How change col name during query to use it in where clause

2012-05-04 Thread Andreas Kretschmer
Marcel Ruff m...@marcelruff.info hat am 4. Mai 2012 um 12:25 geschrieben: Hi, is an alias name not usable in the where clause? Exactly. Andreas -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription:

Re: [SQL] Simple way to get missing number

2012-04-24 Thread Andreas Kretschmer
Emi Lu em...@encs.concordia.ca wrote: Good morning, May I know is there a simple sql command which could return missing numbers please? For example, t1(id integer) values= 1, 2, 3 500 select miss_num(id) from t1 ; something like ,[ code ] | test=# select * from

Re: [SQL] Simple way to get missing number

2012-04-24 Thread Andreas Kretschmer
Raj Mathur (राज माथुर) r...@linux-delhi.org wrote: Nice one, but curious about how would this perform if the numbers in question extended into 7 figures or more? mode=David Fetter TIAS (Try It And See) /mode Andreas -- Really, I'm not out to destroy Microsoft. That will just be a

Re: [SQL] getting the OS user name

2012-04-23 Thread Andreas Kretschmer
John Fabiani jo...@jfcomputer.com wrote: Hi, In my app it is possible to login as one name and use a different name to login to postgres. Is it possible to get the actual OS login name using plsql. Since you can login to an remote database server: no. Andreas -- Really, I'm not out

Re: [SQL] foreign key is it a real key

2012-02-13 Thread Andreas Kretschmer
John Fabiani jo...@jfcomputer.com wrote: Hi, I have read a few articles and I'm not sure if it's me or the authors but I do not believe my question was answered. If I have table that has a PK and a FK - will the planner use the FK just same as it would use the PK? IOW's is a FK also

Re: [SQL] ignore unique violation OR check row exists

2012-01-04 Thread Andreas Kretschmer
rverghese ri...@hotmail.com wrote: I want to insert a bunch of records and not do anything if the record already exists. So the 2 options I considered are 1) check if row exists or insert and 2) ignore the unique violation on insert if row exists. Any opinions on whether it is faster to

Re: [SQL] i want small information regarding postgres

2012-01-02 Thread Andreas Kretschmer
vinodh chowdary vinodchowda...@gmail.com wrote: Hi sir, i am using postgres as database for my project. i want to convert postgres data into excel sheet. is there any way to do it? please reply me. This should be possible with ODBC. (But i'm not familiar with it, don't ask me how ...)

Re: [SQL] Problem with tables and columns names

2011-12-19 Thread Andreas Kretschmer
Gabriel Filipiak gabriel.filip...@gmail.com wrote: Hi, so I am working on PostgreSQL 9.1.2 on x86_64-unknown-linux-gnu, compiled by gcc (Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2, 64-bit. It seems that i can't give a table name for example testTable it has to be test_table, because I can't

Re: [SQL] Column ... does not exist (view + union)

2011-12-17 Thread Andreas Kretschmer
Stefan Weiss krewech...@gmail.com wrote: - running this query - SELECT name FROM dossier_contact_v WHERE dossier_id = 56993 AND ctype = 234 UNION SELECT name FROM dossier_contact_v WHERE dossier_id = -1 AND ctype = -1 ORDER BY

Re: [SQL] conditional FROM

2011-12-10 Thread Andreas Kretschmer
Richard Klingler rich...@klingler.net wrote: Good day... I'm trying to build a query for PGSQL 9.1 where a table has two references with only one being used depending of the type of entry.. For example, the table has following simplified structure: portid primary key

Re: [SQL] conditional FROM

2011-12-10 Thread Andreas Kretschmer
Richard Klingler rich...@klingler.net wrote: This seems to do the trick... select arp.ip, arp.mac, arp.port2time, arp.time, arp.hostname, arp.vlan from arp, port, node where arp.arp2port = port.portid and port.name = 'Fa1/0/1' and port.port2node = node.nodeid and

Re: [SQL] Number timestamped rows

2011-11-02 Thread Andreas Kretschmer
Jan Peters peters...@gmx.at wrote: Dear all, maybe a stupid question, but: I have a table that is ordered like this: user_id|timestamp|event 1 |0:1 |event_a 1 |0:2 |event_b 2 |0:1 |event_b 2 |0:3 |event_c 2 |0:4 |event_b 3 |0:1

Re: [SQL] Problem with DROP ROLE

2011-10-25 Thread Andreas Kretschmer
You can't do that in THAT way, but you can use dynamic SQL:   test=# select * from drop_role ;    t  foobar (1 row) test=*# do $$ declare r text; begin for r in select t from drop_role loop execute 'drop role ' || quote_ident(r) || ';'; end loop; end; $$language plpgsql;   DO     

Re: [SQL] postgres sql help

2011-10-16 Thread Andreas Kretschmer
James Bond coolof...@hotmail.com wrote: hi, i am fairly new in postgresql, so if anyone can help me would be great if i simply do: select ver_no from version order by ver_no the result will be something like this: .1.3.1 .1.3.2.5. .1.4.1.7.12 .1.4.11.14.7. .1.4.3.109.1.

Re: [SQL] Group by on Date

2011-10-16 Thread Andreas Kretschmer
maya.more meena...@gmail.com wrote: I have a table with Date and unit column. . I want to find sum of unit column considering 3 days each User will specify start and enddate Eg DateUnit 10/1/2011 1 10/2/2011 2 10/3/2011 3 10/4/2011 4 10/5/2011 4

Re: [SQL] Clever way to check overlapping time intervals ?

2011-09-15 Thread Andreas Kretschmer
Andreas maps...@gmx.net wrote: 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

Re: [SQL] Subselects not allowed?

2011-06-12 Thread Andreas Kretschmer
, and Andreas Kretschmer. You guys are great. And even better, in the first comment to the blog post, I was advised about the SETVAL() function which does exactly what I wanted in the first place. Yeah, right! Andreas -- Really, I'm not out to destroy Microsoft. That will just be a completely

Re: [SQL] Subselects not allowed?

2011-06-11 Thread Andreas Kretschmer
into m max(i) from foo; execute 'create sequence seq_foo start with ' || m; end; $$; DO Time: 1,115 ms test=*# \ds seq_foo; List of relations Schema | Name | Type | Owner +-+--+ public | seq_foo | sequence | kretschmer (1 row) test=*# select

Re: [SQL] How to realize ROW_NUMBER() in 8.3?

2011-05-03 Thread Andreas Kretschmer
Emi Lu em...@encs.concordia.ca wrote: Thank you for the info. I found a simple way: == [1] create SEQUENCE tmp start 7820; [2] insert into desti_table_name select nextval('tmp'), c1, c2... ... cN from t1 left join t2... ... tn where

Re: [SQL] concatenate question

2010-12-11 Thread Andreas Kretschmer
Tony Capobianco tcapobia...@prospectiv.com wrote: Here's my table: plsql_dw=# \d tmpsv_parent_master Table staging.tmpsv_parent_master Why won't this work? plsql_dw=# select memberid || addeddate from tmpsv_parent_master limit 10; ERROR: operator does not exist: numeric ||

Re: [SQL] force view column varchar(32) to varchar(128)

2010-11-19 Thread Andreas Kretschmer
Emi Lu em...@encs.concordia.ca wrote: Hello, Is there a way to force the view column change from varhcar(32) to varchar(128)? No, you have to recreate the view ... Andreas -- Really, I'm not out to destroy Microsoft. That will just be a completely unintentional side effect.

Re: [SQL] obtaining difference between minimum value and next in size

2010-11-17 Thread Andreas Kretschmer
John Lister john.lister...@kickstone.com wrote: Hi, I was wondering if it is possible to do this with a single query rather than iterate over all of the rows in an application: I have a table which for brevity looks like: create table offers { integer id; integer product_id;

Re: [SQL] Duplicate rows

2010-08-10 Thread Andreas Kretschmer
Edward W. Rouse ero...@comsquared.com wrote: Is there any way to remove a duplicate row from a table? Not my db but I have to work with it. On version 7.4 right now. How to select the right records? You can try to use the ctid-column, see my simple example: test=# select * from dups ; i

Re: [SQL] Duplicate rows

2010-08-10 Thread A. Kretschmer
In response to Edward W. Rouse : Solved. Because this is a 7.4 version and we used with oids by default, I can use the oids instead of the ctid to remove the duplicates. Yeah, that's right ;-) Regards, Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr

Re: [SQL] Help Need some hindsight

2010-08-04 Thread A. Kretschmer
see, the where-condition contains a timestamp that isn't in the table, it's after the id=3. Maybe there are other, better solutions... HTH, Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: - Header) GnuPG: 0x31720C99, 1006 CCB4 A326 1D42 6431 2EB0 389D

Re: [SQL] grouping subsets

2010-07-22 Thread A. Kretschmer
, checking if the 2nd column is different from the previous. With plain SQL it's maybe possible too, but i don't know how ... Regards, Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: - Header) GnuPG: 0x31720C99, 1006 CCB4 A326 1D42 6431 2EB0 389D 1DC2 3172

Re: [SQL] UUID for Postgresql 8.4

2010-07-21 Thread A. Kretschmer
In response to Trinath Somanchi : Hi All, I have a column in my Postgresql database tables which need UUID. Is there any function in Pgsql for UUID generation. Please help me in this regard. http://www.postgresql.org/docs/8.4/static/uuid-ossp.html Andreas -- Andreas Kretschmer Kontakt

Re: [SQL] How to Get Column Names from the Table

2010-07-07 Thread A. Kretschmer
In response to venkat : Dear All,    How to get Column Names from Table in PostgreSQL. select column_name from information_schema.columns where table_name = 'your_table'; Regards, Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: - Header) GnuPG

Re: [SQL] error on line 1 trying to execute a script using psql

2010-06-21 Thread A. Kretschmer
to configure your editor not to save the BOM or chop off the first three bytes yourself (with tail, sed, Perl Co.). Additional error: you can't do a COMMIT inside a function. Regards, Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: - Header) GnuPG: 0x31720C99

Re: [SQL] is there a tutorial on window functions?

2010-06-11 Thread Andreas Kretschmer
John jo...@jfcomputer.com wrote: Hi, I'd like to learn the use of window functions and did not find a tutorial using google (postgres window function tutorial). I'm hoping someone has a link. My link-collection: http://delicious.com/akretschmer/windowing and

Re: [SQL] sum an alias

2010-06-03 Thread A. Kretschmer
by page_count_pdate; ERROR: aggregate function calls cannot be nested LINE 3: MAX(page_count_count) as day_max, sum(MAX(page_count_cou... Can you provide the correct table definition? Regards, Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: - Header) GnuPG: 0x31720C99

Re: [SQL] Rules and sequences

2010-05-27 Thread A. Kretschmer
a simple AFTER trigger instead. There are a ready solution: http://andreas.scherbaum.la/blog/archives/100-Log-Table-Changes-in-PostgreSQL-with-tablelog.html Regards, Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: - Header) GnuPG: 0x31720C99, 1006 CCB4 A326

Re: [SQL] Check set of date intervals

2010-05-27 Thread A. Kretschmer
additional contrib module from Jeff Davis, described here: http://thoughts.j-davis.com/2010/03/09/temporal-postgresql-roadmap/ Regards, Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: - Header) GnuPG: 0x31720C99, 1006 CCB4 A326 1D42 6431 2EB0 389D 1DC2

Re: [SQL] Check set of date intervals

2010-05-27 Thread A. Kretschmer
In response to A. Kretschmer : please, suggest an idea how to implement this in SQL without writing a procedure. There are a really nice additional contrib module from Jeff Davis, described here: http://thoughts.j-davis.com/2010/03/09/temporal-postgresql-roadmap/ short example

Re: [SQL] Check set of date intervals

2010-05-27 Thread A. Kretschmer
| 8 10 |13 (3 rows) Maybe that's the way you have to go ... Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: - Header) GnuPG: 0x31720C99, 1006 CCB4 A326 1D42 6431 2EB0 389D 1DC2 3172 0C99 -- Sent via pgsql-sql mailing

Re: [SQL] Question about slow queries...

2010-05-27 Thread A. Kretschmer
between 8.1 and 8.4 ... Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: - Header) GnuPG: 0x31720C99, 1006 CCB4 A326 1D42 6431 2EB0 389D 1DC2 3172 0C99 -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription

Re: [SQL] Need a help in regexp

2010-05-06 Thread A. Kretschmer
1 2 3 (3 Zeilen) Regards, Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: - Header) GnuPG: 0x31720C99, 1006 CCB4 A326 1D42 6431 2EB0 389D 1DC2 3172 0C99 -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your

Re: [SQL] INSERT INTO...RETURNING vs SELECT

2010-04-05 Thread Andreas Kretschmer
Cliff Wells cl...@develix.com wrote: As far as I can see, INSERT INTO...RETURNING is semantically equivalent to SELECT...FROM with a side-effect, so it seems this construct should work. Can someone shed some light? Well, at the moment you can't reuse the RETURNING-values, you have to wait

Re: [SQL] SQL syntax rowcount value as an extra column in the result set

2010-03-26 Thread A. Kretschmer
PostgreSQL 8.4.2 on x86_64-pc-linux-gnu, compiled by GCC gcc-4.3.real (Debian 4.3.2-1.1) 4.3.2, 64-bit (1 row) test=*# Regards, Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150

Re: [SQL] Help me with this multi-table query

2010-03-26 Thread A. Kretschmer
| count +-+--- 1 | 3 | 1 2 | 2 | 2 3 | 1 | 3 (3 rows) Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: - Header) GnuPG: 0x31720C99, 1006 CCB4 A326 1D42 6431 2EB0 389D 1DC2 3172 0C99 -- Sent via pgsql

Re: [SQL] window function to sort times series data?

2010-03-24 Thread A. Kretschmer
by id_price,created_on ; id_price | price | created_on --+---+- 1 |12 | 2010-02-01 00:00:00 1 | 8 | 2010-03-01 00:00:00 (2 rows) That's okay for you? Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639

Re: [SQL] window function to sort times series data?

2010-03-24 Thread A. Kretschmer
In response to Louis-David Mitterrand : On Wed, Mar 24, 2010 at 03:29:36PM +0100, A. Kretschmer wrote: In response to Louis-David Mitterrand : Hi, I have time series data: price(id_price int, price int, created_on timestamp) I'd like to select the latest price before, say

Re: [SQL] window function to sort times series data?

2010-03-24 Thread Andreas Kretschmer
A. Kretschmer andreas.kretsch...@schollglas.com wrote: Well, and now i'm using 8.4 windowing-functions: test=*# select * from price order by price_id, d; price_id | price | d --+---+ 1 |10 | 2010-03-12 1 |11 | 2010-03-19 1 |12

Re: [SQL] ALTER TYPE my_enum AS ENUM ADD ('label10')

2010-03-23 Thread A. Kretschmer
-- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: - Header) GnuPG: 0x31720C99, 1006 CCB4 A326 1D42 6431 2EB0 389D 1DC2 3172 0C99 -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref

Re: [SQL] ALTER TYPE my_enum AS ENUM ADD ('label10')

2010-03-22 Thread A. Kretschmer
things. Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: - Header) GnuPG: 0x31720C99, 1006 CCB4 A326 1D42 6431 2EB0 389D 1DC2 3172 0C99 -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http

Re: [SQL] Postgresql format for ISO8601

2010-03-17 Thread A. Kretschmer
thing, to_char() should be the solution. For instance: test=# select to_char(now(), '-MM-DDThh:mm TZ'); to_char -- 2010-03-17T08:03 CET If this isn't correct, please show an example for the correct format, okay? Regards, Andreas -- Andreas Kretschmer Kontakt

Re: [SQL] Drop all constraints

2010-03-06 Thread Andreas Kretschmer
Gianvito Pio pio.gianv...@gmail.com wrote: Hi all, is there a way to drop all constraints of a table? I found this workaround in the manual: CREATE TABLE temp AS SELECT * FROM distributors; DROP TABLE distributors; CREATE TABLE distributors AS SELECT * FROM temp; DROP TABLE temp; I

Re: [SQL] Triggers on system tables

2010-03-03 Thread Andreas Kretschmer
Gianvito Pio pio.gianv...@gmail.com wrote: Hi all, is there a way (also strange) to define a trigger on a system table (for example on pg_class)? No. Andreas -- Really, I'm not out to destroy Microsoft. That will just be a completely unintentional side effect.

Re: [SQL] what exactly is a query structure?

2010-02-26 Thread A. Kretschmer
In response to silly sad : my own wild guess: string constant '*' is of type unknown Maybe. Add a explicit cast, for instance '*'::text Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: - Header) GnuPG: 0x31720C99, 1006 CCB4 A326 1D42 6431 2EB0 389D

Re: [SQL] what exactly is a query structure?

2010-02-25 Thread A. Kretschmer
Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: - Header) GnuPG: 0x31720C99, 1006 CCB4 A326 1D42 6431 2EB0 389D 1DC2 3172 0C99 -- 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] join with an array

2010-02-24 Thread A. Kretschmer
=*# select array_agg(a.id), v from a join b on (b.id in (select a.id from a)) group by a.v; array_agg | v ---+--- {1,2,3,4,1,2,3,4} | 1 {6,5,5,6} | 2 (2 rows) Question: you are 'pif' in the irc-channel? Regards, Andreas -- Andreas Kretschmer Kontakt: Heynitz

Re: [SQL] [NOVICE] combine SQL SELECT statements into one

2010-02-01 Thread A. Kretschmer
when modified = '2010-01-01' then model else null end as count3 from inventory) foo ; count | count | count ---+---+--- 2 | 2 | 4 (1 row) Regards, Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: - Header) GnuPG: 0x31720C99, 1006 CCB4

Re: [SQL] selecting rows tagged with a but not b

2010-02-01 Thread Andreas Kretschmer
8q5tmky...@sneakemail.com 8q5tmky...@sneakemail.com wrote: Hi, I have a two tables: article articleID, name, content tags articleID, tag I want to find all articles that are tagged with a but not b how do I do this? select a.* from article left join tags t on

Re: [SQL] Using || operator to fold multiple columns into one

2009-12-23 Thread A. Kretschmer
that, use coalesce(column,'') to change NULL to ''. Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: - Header) GnuPG: 0x31720C99, 1006 CCB4 A326 1D42 6431 2EB0 389D 1DC2 3172 0C99 -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make

Re: [SQL] short-cutting if sum()constant

2009-12-22 Thread A. Kretschmer
(primary key) and a column for the sum of qty. And you need a TRIGGER: update this table for every insert, update and delete on your table t. Now you can ask _this_ new table if the sum(qty) your constant, this should work very fast. Just an idea... Andreas -- Andreas Kretschmer Kontakt: Heynitz

Re: [SQL] short-cutting if sum()constant

2009-12-22 Thread Andreas Kretschmer
msi77 ms...@yandex.ru wrote: Does PG support CTE? Since 8.4 yes. You can try it. Sorry, but i don't know how a CTE can help in this case, can you explain that? Andreas -- Really, I'm not out to destroy Microsoft. That will just be a completely unintentional side effect.

Re: [SQL] SQL state 58P01 triggered by a database script execution

2009-12-09 Thread A. Kretschmer
/pageinspect: No such file or directory   SQL state :58P01 Pageinspect is a contrib-modul, so i think, you should install that. But i don't know if this available for 8.2. Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: - Header) GnuPG: 0x31720C99, 1006 CCB4

Re: [SQL] SQL state 58P01 triggered by a database script execution

2009-12-09 Thread A. Kretschmer
that function later... Regards, Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: - Header) GnuPG: 0x31720C99, 1006 CCB4 A326 1D42 6431 2EB0 389D 1DC2 3172 0C99 -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription

Re: [SQL] Profiling tool for postgres under win32

2009-11-26 Thread A. Kretschmer
system ? Set log_min_duration to a propper value and analyse your slow queries. Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: - Header) GnuPG: 0x31720C99, 1006 CCB4 A326 1D42 6431 2EB0 389D 1DC2 3172 0C99 -- Sent via pgsql-sql mailing list (pgsql-sql

Re: [SQL] report generation from table.

2009-10-21 Thread A. Kretschmer
Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: - Header) -- 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] select result into string's array

2009-10-09 Thread A. Kretschmer
-- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: - Header) -- 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] right join problem

2009-10-02 Thread A. Kretschmer
rows. Maybe i don't understand you, can you show a simple example with data? Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: - Header) -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http

Re: [SQL] Need magic for a moving statistic

2009-10-02 Thread A. Kretschmer
In response to 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

Re: [SQL] right join problem

2009-10-01 Thread A. Kretschmer
) group by m.id, s.id; id | id | sum ++- 1 | 1 | 6 (1 row) test=*# select m.id, s.id, sum(s.value) from master m left join slave s on (m.id=s.id) group by m.id, s.id; id | id | sum ++- 1 | 1 | 6 2 || (2 rows) Andreas -- Andreas Kretschmer Kontakt

Re: [SQL] selecting latest record

2009-09-22 Thread A. Kretschmer
(4 rows) test=*# select distinct on (id_product) id_product, price from price order by id_product, datum desc; id_product | price +--- 1 |12 2 | 8 (2 rows) Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr

Re: [SQL] ordered by join? ranked aggregate? how to?

2009-09-15 Thread A. Kretschmer
slave AS s ON (m.id = s.master_id) GROUP BY m.id ) foo order by 1,2 ) bar group by 1; id | array_agg +--- 1 | {3,5,7} 2 | {NULL} (2 rows) Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: - Header) -- Sent via pgsql-sql mailing list

Re: [SQL] ordered by join? ranked aggregate? how to?

2009-09-15 Thread A. Kretschmer
| {3,5,7} 2 | {NULL} (2 rows) Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: - Header) -- 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] Question

2009-09-03 Thread A. Kretschmer
nextval() for this sequence. Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: - Header) GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription

Re: [SQL] Min and max element of an array column

2009-09-02 Thread A. Kretschmer
: CREATE OR REPLACE FUNCTION unnest(ANYARRAY) RETURNS SETOF ANYELEMENT LANGUAGE SQL AS $$SELECT $1[i] FROM generate_series(array_lower($1,1),array_upper($1,1)) i;$$; (with Thx to David Fetter) Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: - Header) GnuPG-ID

Re: [SQL] Selecting values from comma separated string

2009-08-26 Thread A. Kretschmer
; end; The variable sql contains the whole query, and then execute that. HTH, Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: - Header) GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net -- Sent via pgsql-sql mailing list (pgsql-sql

Re: [SQL] Ask About SQL

2009-08-19 Thread A. Kretschmer
by field1, field2; field1 | field2 | field3 ++ x1 | y1 | 5 x1 | y3 | 4 x2 | y1 | 2 x2 | y3 | 4 (4 rows) Regards, Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: - Header) GnuPG-ID

Re: [SQL] Import (.CVS File) to postgreSql

2009-08-10 Thread A. Kretschmer
In response to Premila Devi : Dear All, I like to import (.CVS File) to postgreSql.Could anyone help me. May I know, what the requirement. You can use the COPY-command for that, see the doc. Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr

Re: [SQL] two records per row from query

2009-08-06 Thread A. Kretschmer
show/explain, which rows in your example contains now the values for the new row? Regards, Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: - Header) GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net -- Sent via pgsql-sql mailing list

Re: [SQL] two records per row from query

2009-08-05 Thread A. Kretschmer
| 2102 5 | 2009-03-01 | 2009-03-01 | 2103 | 2103 (3 rows) Hope that helps... Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: - Header) GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net -- Sent via pgsql-sql mailing

Re: [SQL] Show CAS, USD first; the left ordered by currency name

2009-07-30 Thread Andreas Kretschmer
Emi Lu em...@encs.concordia.ca wrote: Good morning, I have a currency table (code, description). Example values: ADF | Andorran Franc ... ... ANG | NL Antillian Guilder AON | Angolan New Kwanza AUD | Australian Dollar AWG | Aruban Florin BBD | Barbados Dollar USD | US Dollar

Re: [SQL] Need magical advice for counting NOTHING

2009-07-23 Thread A. Kretschmer
Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: - Header) GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net -- 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-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

Re: [SQL] uniqueness constraint with NULLs

2009-06-29 Thread A. Kretschmer
')); CREATE INDEX test=*# insert into bobtest (a, b) values (1, 4); INSERT 0 1 test=*# insert into bobtest (a, b, c) values (1, 4, NULL); ERROR: duplicate key value violates unique constraint idx_bobtest test=!# Regards, Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639

Re: [SQL] uniqueness constraint with NULLs

2009-06-29 Thread A. Kretschmer
In response to Robert Edwards : A. Kretschmer wrote: In response to Robert Edwards : Can anyone suggest a way that I can impose uniqueness on a and b when c is NULL? Sure, use a functional index: test=# create table bobtest (a int, b int, c int); CREATE TABLE test=*# create unique

Re: [SQL] uniqueness constraint with NULLs

2009-06-29 Thread A. Kretschmer
In response to Leo Mannhart : On Mon, 2009-06-29 at 17:08 +1000, Robert Edwards wrote: A. Kretschmer wrote: In response to Robert Edwards : Can anyone suggest a way that I can impose uniqueness on a and b when c is NULL? Sure, use a functional index: test=# create table

Re: [SQL] Avoiding will create implicit index NOTICE

2009-06-11 Thread A. Kretschmer
bla CREATE TABLE test=*# rollback; ROLLBACK test=# set client_min_messages='warning'; SET test=*# create table bla(id int primary key); CREATE TABLE test=*# Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: - Header) GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA

Re: [SQL] dynamic columns in a query

2009-06-11 Thread A. Kretschmer
you. Other solution: write a function in plpgsql and build a string that contains your query, and EXECUTE that string. Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: - Header) GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net -- Sent

Re: [SQL] complex column definition in query

2009-06-03 Thread A. Kretschmer
, Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: - Header) GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org

Re: [SQL] Creation of file from postgresql function

2009-06-03 Thread A. Kretschmer
-- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: - Header) GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref

  1   2   3   4   5   >