Re: [SQL]

2013-10-08 Thread Andreas Kretschmer
Kaleeswaran Velu 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 use db_link, see

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

2013-04-18 Thread Andreas Kretschmer
Sofer, Yuval 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 machine > is no

Re: [SQL] How to reject overlapping timespans?

2013-02-17 Thread Andreas Kretschmer
Andreas 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 reject a

Re: [SQL] Help with a select statement design

2012-12-28 Thread Andreas Kretschmer
JORGE MALDONADO 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 price 1) > id,

Re: [SQL] sql basic question

2012-12-28 Thread Andreas Kretschmer
gt; 12 | 23434 | 0.88764543364566 |0 *M > 33 | 23434 | 0.23235478697988 |1 *m/M > 14 | 129007 | 0.63454675634756 |0 *m > 19 | 129007 | 0.97897897897654 |0 *M > 13 | 129007 | 0.22345364656788 | 1 *m > 11 | 129007 | 0.867878

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 An: Antonio Parrotta Datum: 28. Dezember 2012 um 15:19 Betreff: Re: [SQL] sql basic question Hi, your question was: "What I want to achieve is a result table with min an

Re: [SQL] checking the gaps in intervals

2012-10-06 Thread Andreas Kretschmer
Andreas Kretschmer wrote: > Anton Gavazuk 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

Re: [SQL] checking the gaps in intervals

2012-10-06 Thread Andreas Kretschmer
Anton Gavazuk 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 have inter

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

2012-09-29 Thread Andreas Kretschmer
Thomas Kellerer hat am 29. September 2012 um 16:13 geschrieben: > Matthias Nagel wrote on 29.09.2012 12:49: > > 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

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

2012-09-29 Thread Andreas Kretschmer
Matthias Nagel 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 standard SQL compliant.

Re: [SQL] matching a timestamp field

2012-09-22 Thread Andreas Kretschmer
BACHELART PIERRE (CIS/SCC) wrote: > Hello, > > > > > > Why is my sql below accepted in 8.1.19 and refused in 8.4.9 ??? > > Welcome to psql 8.1.19, the PostgreSQL interactive terminal. > > ansroc=# select * from s12hwdb where record ~'2012-09-20' limit 5; > > > psql (8.4.9) > > > ERR

Re: [SQL] [GENERAL] Indexing question

2012-08-14 Thread Andreas Kretschmer
amit sehas 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 f2>, instead the

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

2012-08-02 Thread Andreas Kretschmer
Tom Lane wrote: > Wayne Cuddy 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 9.1, probably the best way is to use c

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

2012-07-11 Thread Andreas Kretschmer
Marc Mamin 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] Prevent double entries ... no simple unique index

2012-07-11 Thread Andreas Kretschmer
Andreas Kretschmer wrote: > Andreas 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, accept

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

2012-07-11 Thread Andreas Kretschmer
Andreas 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 object X

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

2012-06-22 Thread Andreas Kretschmer
Andreas 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. Write funct

Re: [SQL] master/detail

2012-05-23 Thread Andreas Kretschmer
Jan Bakuwel 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 are multipl

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

2012-05-04 Thread Andreas Kretschmer
Marcel Ruff 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: http://www.postgresql.org/mailpref/pgsql-sql

Re: [SQL] Simple way to get missing number

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

Re: [SQL] Simple way to get missing number

2012-04-24 Thread Andreas Kretschmer
Emi Lu 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 emi_lu ; |

Re: [SQL] getting the OS user name

2012-04-23 Thread Andreas Kretschmer
John Fabiani 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 to destroy Micros

Re: [SQL] how to concatenate in PostgreSQL

2012-03-24 Thread Andreas Kretschmer
Rehan Saleem wrote: > hi , > how can we concatinate these lines and execute sql command > >set sql = 'select user,username, firstname ' > set sql += ' lastname, cardno from table1 where userid=' + 5 sql = sql || ' bla fasel'; || is the concat - Operator. Andreas -- Really, I

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

2012-02-13 Thread Andreas Kretschmer
John Fabiani 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 an index use

Re: [SQL] sql query problem

2012-01-17 Thread Andreas Kretschmer
Alok Thakur wrote: > Dear, > > I am trying to provide you as much details as possible. > > answer` ( > `id` int(10) NOT NULL AUTO_INCREMENT, > `question_id` int(10) NOT NULL, > `user_id` int(10) NOT NULL, > `answer` int(10) NOT NULL, -> > `status` tinyint(1) NOT NULL, --> Status wil

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

2012-01-04 Thread Andreas Kretschmer
rverghese 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 INSERT and then ca

Re: [SQL] i want small information regarding postgres

2012-01-02 Thread Andreas Kretschmer
vinodh chowdary 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 ...) Andreas -- Really

Re: [SQL] Problem with tables and columns names

2011-12-19 Thread Andreas Kretschmer
Gabriel Filipiak 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 access it via psql is t

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

2011-12-17 Thread Andreas Kretschmer
Stefan Weiss 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 ctype; > >

Re: [SQL] conditional FROM

2011-12-10 Thread Andreas Kretschmer
Richard Klingler 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 node.name like 'no

Re: [SQL] conditional FROM

2011-12-10 Thread Andreas Kretschmer
Richard Klingler 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 > port2no

Re: [SQL] Number timestamped rows

2011-11-02 Thread Andreas Kretschmer
Jan Peters 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 |even

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      "Bric

Re: [SQL] Group by on Date

2011-10-16 Thread Andreas Kretschmer
maya.more 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 > 10/6/

Re: [SQL] postgres sql help

2011-10-16 Thread Andreas Kretschmer
James Bond 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. > .1.4.8.66. >

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

2011-09-15 Thread Andreas Kretschmer
Andreas 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 row can

Re: [SQL] Subselects not allowed?

2011-06-12 Thread Andreas Kretschmer
Leif Biberg Kristensen wrote: > On Saturday 11. June 2011 22.09.09 Leif Biberg Kristensen wrote: > > I've written a blog post which I hope may be helpful to others in a similar > > situation: > > > > <http://solumslekt.org/blog/?p=321> > > > >

Re: [SQL] Subselects not allowed?

2011-06-11 Thread Andreas Kretschmer
Leif Biberg Kristensen wrote: > Can anybody tell me why this doesn't work? > > pgslekt=> CREATE SEQUENCE sources_source_id_seq START WITH (SELECT > MAX(source_id) FROM sources); > ERROR: syntax error at or near "(" > LINE 1: CREATE SEQUENCE sources_source_id_seq START WITH (SELECT MAX... >

Re: [SQL] unnest in SELECT

2011-05-20 Thread Andreas Kretschmer
Karl Koster wrote: > I have a couple of questions regarding unnest. > > 1) If I issue a select statement "select unnest(vector1) as v from > some_table", I cannot seem to use the column alias v in a WHERE or > HAVING clause. I can use it in an ORDER BY or GROUP by clause. Is this > the way

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

2011-05-03 Thread Andreas Kretschmer
Emi Lu 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 ... ... > > Jus

Re: [SQL] Table name as a variable in SELECT query

2010-12-18 Thread Andreas Kretschmer
Andrey Fokin wrote: > Hi, > please advise is possible in SELECT query use variable as a table name? > > I would like to have for example something like: > > CREATE OR REPLACE FUNCTION test_name (tb varchar) RETURNS int AS $$ > > DECLARE > > .. > > BEGIN >

Re: [SQL] concatenate question

2010-12-11 Thread Andreas Kretschmer
Tony Capobianco 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 || timestamp withou

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

2010-11-19 Thread Andreas Kretschmer
Emi Lu 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. (Li

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

2010-11-17 Thread Andreas Kretschmer
John Lister 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; > double price; > } > > wh

Re: [SQL] Duplicate rows

2010-08-10 Thread Andreas Kretschmer
Edward W. Rouse 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 --- 1 1 1 2 2

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

2010-06-11 Thread Andreas Kretschmer
John 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 http://delicious.com/akretschmer/cte Andre

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

2010-04-05 Thread Andreas Kretschmer
Cliff Wells 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 for 9.1, writeabl

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

2010-03-24 Thread Andreas Kretschmer
A. Kretschmer 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 | 2010-03-26 1 |13 | 2010-

Re: [SQL] Drop all constraints

2010-03-06 Thread Andreas Kretschmer
Gianvito Pio 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 think, you can cha

Re: [SQL] Triggers on system tables

2010-03-03 Thread Andreas Kretschmer
Gianvito Pio 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. (Linus Torvalds) "If

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] short-cutting if sum()>constant

2009-12-22 Thread Andreas Kretschmer
msi77 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. (L

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

2009-07-30 Thread Andreas Kretschmer
Emi Lu 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 > CAD | Ca

Re: [SQL] how to set the value to the column

2009-04-16 Thread Andreas Kretschmer
DM wrote: > Hi All, > > I have a table test with columns name and value > > test table > name > value > > It has around 500 rows. > > I added a new column id to the table, > > Table test > id, > name, > value > > I am not sure how to insert numbers to my column id (1-500). You can cr

Re: [SQL] counts of groupings by date year-month

2009-02-27 Thread Andreas Kretschmer
Carol Cheung wrote: > Hi, > I have a table called temp > > access_date | active | status > -++ > 2009-02-01 | t | 15 > 2009-02-01 | f | 16 > 2009-02-02 | f | 17 > 2009-02-01 | t | 17 > 2009-02-02 | f | 21 > 2009-

Re: [SQL] Seeking for the fore-part of the key

2009-01-11 Thread Andreas Kretschmer
Havasvölgyi Ottó schrieb: > Hi, > > Let's assume I have a table (called tbl) with a column 'name' and an index on > it. > How to optimally find records whose name column begins with - say - "Pre"? > I know it can be done with LIKE (WHERE name LIKE 'Pre%'), but will this use > the > index mentio

Re: [SQL] adding "order by" to a "group by" query

2008-12-06 Thread Andreas Kretschmer
Scott Marlowe <[EMAIL PROTECTED]> schrieb: > >> You can use a subquery like my example: > >> > >> test=*# select i, comma(t) from (select distinct i,t from foo) bar group > >> by i; > >> i | comma > >> ---+- > >> 1 | a, b, c > >> (1 row) > >> > >> Time: 0.554 ms > >> test=*# select i, c

Re: [SQL] adding "order by" to a "group by" query

2008-12-06 Thread Andreas Kretschmer
Louis-David Mitterrand <[EMAIL PROTECTED]> schrieb: > > But if I append this > >order by pt.type_fr = 'comédien'; > > I get this error: > > ERROR: column "pt.type_fr" must appear in the GROUP BY clause or be > used in an aggregate function > > It seems I am using pt.type_fr in

Re: [SQL] EXECUTE query INTO problem

2008-11-25 Thread Andreas Kretschmer
Tk421 <[EMAIL PROTECTED]> schrieb: >I've got a problem with a function: It receives two parameters, the > first, the table name, and the second, a where condition. The function > looks like this: > >DECLARE > cod bigint; > query TEXT; > >BEGIN > query = 'SELECT co

Re: [SQL] Select function with set return type

2008-08-18 Thread Andreas Kretschmer
Nacef LABIDI <[EMAIL PROTECTED]> schrieb: > Hi all, > > I am writing some functions with retrun type as a SETOF of a datatype that I > have defined. How can I test them with a select statement. > Doing select my_function(); return set valued function called in context that > cannot accept a set

Re: [SQL] using calculated column in where-clause

2008-06-17 Thread Andreas Kretschmer
Patrick Scharrenberg <[EMAIL PROTECTED]> schrieb: > Something like this > select a, b , a*b as c from ta where c=2; > > But postgresql complains, that column "c" does not exist. > > Do I have to repeat the calculation (which might be even more complex yes. Andreas -- Really, I'm not out to de

Re: [SQL] merge timestamps to intervals

2008-05-12 Thread Andreas Kretschmer
Patrick Scharrenberg <[EMAIL PROTECTED]> schrieb: > Hi! > > I have a table where I repeatingly log the status of some service, which > looks something like this: > > < timestamp, status > > > > I'd like to merge this information to intervals where the service was up > or down. > >

Re: [SQL] Concatenation through SQL

2007-12-21 Thread Andreas Kretschmer
Philippe Lang <[EMAIL PROTECTED]> schrieb: 2 ways: * You can use something like this: test=*# select * from a; id | val +- 1 | foo 2 | bar (2 rows) test=*# select array_to_string(array(select val from a), ', '); array_to_string - foo, bar (1 row) * comma-aggrega

Re: [SQL] INSERT INTO relational tables

2007-12-07 Thread Andreas Kretschmer
Stefan Scheidegger <[EMAIL PROTECTED]> schrieb: > An example to explain my Problem: Lets say I have a table containing > information about the customer (name, address, ...) and about his > order (pieces, product-name, price). Because one customer can order > several products I split the table into

Re: [SQL] execute system command from storage procedure

2007-12-06 Thread Andreas Kretschmer
Sabin Coanda <[EMAIL PROTECTED]> schrieb: > Hi there, > > Is it possible to execute a system command from a function ? (e.g. bash ) Yes, of course, but you need an untrusted language like pl/perlU oder plsh. http://plsh.projects.postgresql.org/ Andreas -- Really, I'm not out to destroy Micros

Re: [SQL] Removing whitespace using regexp_replace

2007-10-28 Thread Andreas Kretschmer
Thomas Kellerer <[EMAIL PROTECTED]> schrieb: > Andreas Kretschmer wrote on 28.10.2007 12:42: > >>I have a column with the datatype "text" that may contain leading > >>whitespace (tabs, spaces newlines, ...) and I would like to remove them > >>all

Re: [SQL] Removing whitespace using regexp_replace

2007-10-28 Thread Andreas Kretschmer
Thomas Kellerer <[EMAIL PROTECTED]> schrieb: > Hi, > > I have a column with the datatype "text" that may contain leading > whitespace (tabs, spaces newlines, ...) and I would like to remove them all > (ideally leading and trailing). You can use trim() for that: select 'x' || trim(both '\t' fr

Re: [PERFORM] [SQL] two queryes in a single tablescan

2007-10-20 Thread Andreas Kretschmer
Markus Schaber <[EMAIL PROTECTED]> schrieb: > > is there any way to get both results in a single query, > > eventually through stored procedure? > > The retrieved [count(*),A] ; [count(*),B)] data couldnt fit > > on a single table, of course. > > > > The main goal would be to get multiple results

Re: [SQL] What SQL is running against my DB?

2007-10-04 Thread Andreas Kretschmer
Tore Lukashaugen <[EMAIL PROTECTED]> schrieb: > Hello all, > > I have an application running against my postgres 8.2 database (on Windows > Vista) for which I do not have access to the source code. > > I would like to know what SQL statements are being executed by the > application. Is there a

Re: [SQL] Format intervall as hours/minutes etc

2007-09-16 Thread Andreas Kretschmer
Andreas Joseph Krogh <[EMAIL PROTECTED]> schrieb: > Hi all. Any hint on how to format this interval as number of hour/seconds etc? > select age('2007-09-22 17:00'::timestamp, '2000-02-20 18:00'::timestamp); > age > --- > 7 years 7 mons 1 day 23:00:00 You

Re: [SQL] Counting all rows

2007-06-23 Thread Andreas Kretschmer
Stefan Arentz <[EMAIL PROTECTED]> schrieb: > I need to get statistics from a bunch of tables. Simply the number of > records in them. > > The query plan looks like this: > > => explain select count(id) from stuff; > QUERY PLAN > ---

Re: [SQL] joining a table whose name is stored in the primary record

2007-06-17 Thread Andreas Kretschmer
John Gunther <[EMAIL PROTECTED]> schrieb: > I've tried everything I can think of here to join records when the join > table varies and is named in the primary record, but to no avail. Here's an > example with all non-essentials stripped out. > > I have 3 tables: > > create table zip ( > id se

Re: [SQL] show index from [table]

2007-06-08 Thread Andreas Kretschmer
Stefan Zweig <[EMAIL PROTECTED]> schrieb: > hi list, > > currently i am switching from mysql to pgsql, so i am a bit new to > postgres' syntax. You are welcome. > > at the moment i am looking in postgres for something which is similar > to SHOW INDEX FROM [table] in mysql. unfortunately i coul

Re: [SQL] plpgsql function question

2007-04-03 Thread Andreas Kretschmer
Karthikeyan Sundaram <[EMAIL PROTECTED]> schrieb: > > Hi, > > I am having a requirement here. > > 1) I need to write a plpgsql function where it takes the input > parameter of a structure of a table. Because? To build this table? You can pass an ascii-text

Re: [SQL] union with count?

2007-03-28 Thread Andreas Kretschmer
Gerardo Herzig <[EMAIL PROTECTED]> schrieb: > Thanks! But now i have another problem related with count(): > > select page_id, word, word_position, count(page_id) from (select * from > search_word('word1', 'table1') union search_word('word2', 'table2')) foo > group by page_id; > > and gives me

Re: [SQL] ordering by multiple columns

2007-03-14 Thread Andreas Kretschmer
Pablo Barrón <[EMAIL PROTECTED]> schrieb: > > Hi! > > I'm trying to order a list in which the first parameter to order is a > specific > field, and the second should vary depending on a specific condition. More > explicit, I would like to do something like: > > - ORDER BY a.column1, [b.colu

Re: [SQL] how to use a date range in a join

2007-03-12 Thread Andreas Kretschmer
chester c young <[EMAIL PROTECTED]> schrieb: > trying to do something like > > select d.day, >c.name > from [dates between day1 and day2] d > left join c.some_table; > > but cannot figure out what to put into the brackets. Perhaps something like this: test=# select curre

Re: [SQL] Inc

2007-03-06 Thread Andreas Kretschmer
Richard Broersma Jr <[EMAIL PROTECTED]> schrieb: > --- Ezequias Rodrigues da Rocha <[EMAIL PROTECTED]> wrote: > > > Thank you but I must inc an specific row. How to do that ? > > > > Does, > > UPDATE your_table > SET your_row = your_row +1 > WHERE your_pkey = ; > > not do what you need? I th

Re: [SQL] Inc

2007-03-06 Thread Andreas Kretschmer
Ezequias Rodrigues da Rocha <[EMAIL PROTECTED]> schrieb: > Thank you but I must inc an specific row. How to do that ? Read the answer again. Please, no silly TOFU (german synonym for text above, fullquote below). > >> For example. I have a table with a field that on each update it > >> incremen

Re: [SQL] sub-limiting a query

2007-02-17 Thread Andreas Kretschmer
Louis-David Mitterrand <[EMAIL PROTECTED]> schrieb: > ballet,etc.) and I am looking for a select that can return the 10 last > entered shows AND at most 2 of each type. Is that possible in one query? A similar question i found in the archive and there are a couple of answers: (for the second par

Re: [SQL] [ADMIN] Deadlock on transaction

2007-02-12 Thread Andreas Kretschmer
Ezequias Rodrigues da Rocha <[EMAIL PROTECTED]> schrieb: > I mean really deadlock. Other transactions can't access the database until the > main transaction is complete. A question: That's not true. > > PostgreSQL doesn't permit multiple transactions concurrently ? Why not? Show us a complete

Re: [SQL] Changing point for commas and commas for point

2007-01-21 Thread Andreas Kretschmer
Ezequias Rodrigues da Rocha <[EMAIL PROTECTED]> schrieb: > Hi list, > > Here in my country (Brazil) we have the decimal simbol as ' , ' (commas) and > thousand separator as ' . ' (point) > > Here my sql uses: to_char(sum(My_column), '0D00') > > Is there any way to make this happens ? I t

Re: [SQL] consistent random order

2006-11-29 Thread Andreas Kretschmer
Jeff Herrin <[EMAIL PROTECTED]> schrieb: > I am returning results ordered randomly using 'order by random()'. My issue > has > to do with page numbers in our web application. When I hit the 2nd page and > retrieve results with an offset, ordering by random() isn't really what I want > since I wil

Re: [SQL] select into

2006-11-24 Thread Andreas Kretschmer
Adrian Klaver <[EMAIL PROTECTED]> schrieb: > On Thursday 23 November 2006 08:45 pm, Tom Lane wrote: > > Mulham freshcode <[EMAIL PROTECTED]> writes: > > > execute sql_str1 into svc_data_rec ; > > > > > > svc_data_rec is a RECORD, which is supposed to be dynamic. > > > > This should work --- in PG

Re: [SQL] select into

2006-11-22 Thread Andreas Kretschmer
Richard Broersma Jr <[EMAIL PROTECTED]> schrieb: > > Hi guys, > > > >Am new to sql scripting so this might be a stupid question. Am getting > > an error while trying > > to do the following > > > > SELECT INTO svc_data_rec * from svc_tbl_name where 'uid' = sub_id; > > > > where svc_data_

Re: [SQL] drop a check

2006-11-13 Thread Andreas Kretschmer
ivan marchesini <[EMAIL PROTECTED]> schrieb: > . > or it depend on the fact I'm using postgres 7.4.13 > many thanks... Maybe, the information-schema can be different in different versions. Andreas -- Really, I'm not out to destroy Microsoft. That will just be a completely unintentional sid

Re: [SQL] drop a check

2006-11-13 Thread Andreas Kretschmer
ivan marchesini <[EMAIL PROTECTED]> schrieb: > Dear all... > I have created a check constraint without giving it a name.. > now I have a check named "$25" in my table that I need to drop or > modify!!! > How can I do??? Can you see the name with \d within psql? An example: test=# create table

Re: [SQL] [GENERAL] Any documatation about porting from Oracle to PostgreSQL

2006-10-17 Thread Andreas Kretschmer
Felix Zhang <[EMAIL PROTECTED]> schrieb: > Hi all, > > I'm a newbie of PostgreSQL. I'm searching materials about porting from Oracle > to PostgreSQL. > Anyone can share with me some good documatations? http://techdocs.postgresql.org/#convertfrom Andreas -- Really, I'm not out to destroy Micr

Re: [SQL] [GENERAL] How to split a table?

2006-10-17 Thread Andreas Kretschmer
Felix Zhang <[EMAIL PROTECTED]> schrieb: > Hi, > > I want to split a table to 2 small tables. The 1st one contains 60% records > which are randomly selected from the source table. > How to do it? Why do you want to do this? Andreas -- Really, I'm not out to destroy Microsoft. That will just

Re: [SQL] Substitute a Character

2006-09-06 Thread Andreas Kretschmer
Judith <[EMAIL PROTECTED]> schrieb: > Hello everybody!! I have a field type text with folios like this: > A98526 > > but I want to change de A for a 0 like this: 098526, exists a way to do > this in a query??? Perhaps something like this: test=# select regexp_replace('A98526', '

Re: [SQL] Mac Address

2006-09-03 Thread Andreas Kretschmer
Ezequias Rodrigues da Rocha <[EMAIL PROTECTED]> schrieb: > Hi list, > > It is possible to retrieve the MAC Address of a computer using a Postgresql > function like others: In the same subnet? Then you can use untrusted languages such as plperlu or plsh to retrieve the MAC for a IP. (arp -a ip)

Re: [SQL] i have a problem of privilages

2006-07-04 Thread Andreas Kretschmer
MJ Santhosh <[EMAIL PROTECTED]> schrieb: > I am not an expert in postgres, may this work for you. > > REVOKE INSERT,UPDATE,DELETE ON ALL from PUBLIC; IIRC, you cant REVOKE ... ON ALL, you need a table-name instead ALL. But, you can create a script for all tables: http://people.planetpostgresql

Re: [SQL] Multi-column index not used, new flipped column index is

2006-05-11 Thread Andreas Kretschmer
[EMAIL PROTECTED] <[EMAIL PROTECTED]> schrieb: > Hi Andreas and Markus, > > Bitmap indices sound like a good reason to go from 8.0 to 8.1. Is 8.2 > around the corner, by any chance? IIRC in autumn/winter. If it is finish ;-) > > I searched PG docs to see if I need to do something special to c

Re: [SQL] Multi-column index not used, new flipped column index is

2006-05-10 Thread Andreas Kretschmer
Markus Schaber <[EMAIL PROTECTED]> schrieb: > Bitmap Index Scans can be your solution, but AFAIK they were invented in > 8.1. Right. > > For bitmap index scans, you have one index on fkColumnOne and one on > fkColumnTwo, and the query planner knows to combine them when both > columns are given i

Re: [SQL] Looking for some help with cascading updates...

2006-04-18 Thread Andreas Kretschmer
Mark True <[EMAIL PROTECTED]> schrieb: > Next silly question, how do you get your database to like plpgsql... - createlang on the command line - create language plpgsql; (in psql) > > I do CREATE LANGUAGE 'plpgsql' and it says it is not defined? Strange... > > --Mark > > > On 4/18/06, AA

Re: [SQL] Looking for some help with cascading updates...

2006-04-18 Thread Andreas Kretschmer
Mark True <[EMAIL PROTECTED]> schrieb: > I guess I should have clarified. I am having trouble figuring out how to > construct the IF statement to see if that item exists in the foreign table > something like: > > count=select count(*) from table; > > if count=0 { > insert fkey into myOtherTable

Re: [SQL] Looking for some help with cascading updates...

2006-04-18 Thread Andreas Kretschmer
Mark True <[EMAIL PROTECTED]> schrieb: > > Here is the question: > > I have a situation where I need to create triggers to cascade an insert > operation to many tables to maintain foreign key constraints. > > So at a high level > > INSERT INTO myTable (Name, Address, Zip) VALUES ('Mark', '3 D

Re: [SQL] on select rule

2006-04-14 Thread Andreas Kretschmer
Sergey Levchenko <[EMAIL PROTECTED]> schrieb: > http://www.postgresql.org/docs/8.1/interactive/sql-createtrigger.htmlSELECT > does not modify any rows so you can not create SELECT triggers.Rules > and views are more appropriate in such cases. On 4/14/06, A. Oh yes, i'm sorry. Andreas -- Reall

Re: [SQL] regarding join

2006-03-24 Thread Andreas Kretschmer
AKHILESH GUPTA <[EMAIL PROTECTED]> schrieb: > hi all, > below I have created two tables in pgsql with field name as 'name' and 'id' as > their datatype 'varchar(15)' and 'integer'. > i want the output as:-> ... a UNION of this 2 tables: test=# select * from test1 union select * from test3 orde

Re: [SQL] how to get the size of array?

2006-03-14 Thread Andreas Kretschmer
Emi Lu <[EMAIL PROTECTED]> schrieb: > Hello, > > Is there a way that I can get the size of one array ? Yes: http://www.postgresql.org/docs/8.1/interactive/functions-array.html HTH, Andreas -- Really, I'm not out to destroy Microsoft. That will just be a completely unintentional side effect.

  1   2   >