Re: [despammed] [SQL] session-wide autocommit off

2004-11-30 Thread Andreas Kretschmer
OCOMMIT \set AUTOCOMMIT FALSE begin; But this works only one transaction. regards, Andreas -- Andreas Kretschmer(Kontakt: siehe Header) Tel. NL Heynitz: 035242/47212 GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net ===Schollglas Untern

Re: [despammed] [SQL] sum query

2004-12-04 Thread Andreas Kretschmer
select id, sum(summe) from (select id, sum(quantity) as summe from tbl3 where order_id in (select order_id from tbl2 where closed = false) group by id union select id,0 from tbl1 group by id) as x group by x.id order by x.id; and this result: id | sum --+- AB12 | 15 CD34 | 5

Re: [despammed] [SQL] question about index

2004-12-16 Thread Andreas Kretschmer
average. > > should I create an index to speedup the counts or not ? Yes. Andreas -- Andreas Kretschmer(Kontakt: siehe Header) Tel. NL Heynitz: 035242/47212 GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net ===Schollglas Unternehmensgruppe=== -

Re: [despammed] [SQL] sql can i substitute

2004-12-17 Thread Andreas Kretschmer
d' test-# when fruit = 2 then 'bad' test-# when fruit = 3 then 'rotten' end from fruit; name | fruit | case +---+ Apple | 1 | good Banana | 2 | bad Cherry | 3 | rotten (3 Zeilen) Please read http://www.postgresql.org/docs/7.4/interactive

Re: [despammed] [SQL] sql can i substitute

2004-12-17 Thread Andreas Kretschmer
and 'rotten' under the column 'fruit'? Yes, simple: test=# select name, case test-# when fruit = 1 then 'good' test-# when fruit = 2 then 'bad' test-# when fruit = 3 then 'rotten' end as fruit from fruit; name | fruit ----+---- Apple

Re: [SQL] [despammed] question about index

2004-12-16 Thread Andreas Kretschmer
am 16.12.2004, um 8:10:25 -0600 mailte Bruno Wolff III folgendes: > On Thu, Dec 16, 2004 at 12:01:39 +0100, > Andreas Kretschmer <[EMAIL PROTECTED]> wrote: > > > > > > considering that almost 70% of the rows will be with 'VALUE1', 20% > > > w

Re: [despammed] [SQL] private table

2005-01-26 Thread Andreas Kretschmer
am 26.01.2005, um 10:13:52 +0200 mailte Din Adrian folgendes: > Hello, > I am want to use a private table in postgresql(every client to see his own > data). > Is this possible? How can I do it! Why? You can create different users and/or different databases. Regards, Andreas

Re: [despammed] [SQL] Accessing objects over db-borders

2005-02-04 Thread Andreas Kretschmer
rently the context on DB bbb? Yes, take a look at dblink (contrib-package) Andreas -- Andreas Kretschmer(Kontakt: siehe Header) Heynitz: 035242/47212, D1: 0160/7141639 GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net ===Schollglas Unternehmensgruppe=== --

Re: [despammed] [SQL] SQL error: function round(double precision, integer) does not exist

2005-02-28 Thread Andreas Kretschmer
atches(smiles,smarts))::numeric,2) Regards, Andreas -- Andreas Kretschmer(Kontakt: siehe Header) Heynitz: 035242/47212, D1: 0160/7141639 GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net ===Schollglas Unternehmensgruppe=== ---(end of broadcast)

Re: [despammed] [SQL] How do I do this?

2005-03-23 Thread Andreas Kretschmer
linux-gnu, compiled by GCC i386-linux-gcc (GCC) 3.3.5 (Debian 1:3.3.5-5) (1 Zeile) Regards, Andreas -- Andreas Kretschmer(Kontakt: siehe Header) Heynitz: 035242/47212, D1: 0160/7141639 GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net ===Schollglas Unternehmensgruppe=== --

Re: [despammed] [SQL] Crosstab function

2005-04-06 Thread Andreas Kretschmer
am 06.04.2005, um 13:55:35 +0700 mailte bandeng folgendes: > hello guys, > > I want to use crosstab function but that function it doesnt exist. my > version is 7.3 so how do i get the tablefunc.sql from postgre contrib? apt-get install postgresql-contrib Regards, Andreas

Re: [despammed] [SQL] How do I connect with something like JDBCManager to Postgres on Fedora Linux

2005-04-22 Thread Andreas Kretschmer
he pg_hba.conf. Read this about -i and TCPIP_SOCKET and edit this to enable access via tcp/ip. Andreas -- Andreas Kretschmer(Kontakt: siehe Header) Heynitz: 035242/47212, D1: 0160/7141639 GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net ===Schollglas Unternehmensgruppe=== --

Re: [despammed] [SQL] Insert psql commands inside a script

2005-04-22 Thread Andreas Kretschmer
a file for > the sql instructions but right on the same line. I use very short psql > commands and would like to do it all with 1 file. echo "select bla from fasel" | psql -U database You can also use here documents, shell-variables and so on. Regards, Andreas -- Andreas Kre

[SQL] how many tuples on a cursor?

2005-05-02 Thread Andreas Kretschmer
i'm using 7.4.6. Is there now a way to get the total number of rows in a CURSOR? Andreas -- Andreas Kretschmer(Kontakt: siehe Header) Heynitz: 035242/47212, D1: 0160/7141639 GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net ===Schollglas Unternehmensgruppe=== -

Re: [despammed] [SQL] Query two database at once

2005-05-02 Thread Andreas Kretschmer
trib on dblink. You should look in the archiv of the list, Tom Lane and other people described the way with dblink in the past. Andreas -- Andreas Kretschmer(Kontakt: siehe Header) Heynitz: 035242/47212, D1: 0160/7141639 GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net ===Schollglas

Re: [despammed] [SQL] accessing multiple database

2005-05-04 Thread Andreas Kretschmer
erent db site. Tq in > advance. 1. write your own client thats connect to several databases 2. use dblink, this is part of the contrib-distribution Andreas -- Andreas Kretschmer(Kontakt: siehe Header) Heynitz: 035242/47212, D1: 0160/7141639 GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp

Re: [despammed] [SQL] Balance Calculation

2005-05-22 Thread Andreas Kretschmer
his should solve your perfomance-problem. Regards, Andreas -- Andreas Kretschmer(Kontakt: siehe Header) Heynitz: 035242/47212, D1: 0160/7141639 GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net ===Schollglas Unternehmensgruppe=== ---

Re: [despammed] [SQL] Balance Calculation

2005-05-22 Thread Andreas Kretschmer
am 22.05.2005, um 10:17:53 +0200 mailte Andreas Kretschmer folgendes: > > can you help me how to fix them. > > Can I using function to fix them (how?) > > It is possible to create a extra table for the balance and a trigger for > insert/update that calculates the balance

Re: [despammed] [SQL] need date clarification

2005-05-23 Thread Andreas Kretschmer
ENT_DATE; date 2005-05-23 (1 Zeile) Regards, Andreas -- Andreas Kretschmer(Kontakt: siehe Header) Heynitz: 035242/47212, D1: 0160/7141639 GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net ===Schollglas Unternehmensgruppe=== --

Re: [despammed] Re: [SQL] Need clarification

2005-05-23 Thread Andreas Kretschmer
0 2005-05-23 (2 Zeilen) test=# select * from datediff where CURRENT_DATE - start > 10; start 1966-08-30 (1 Zeile) test=# select * from datediff where CURRENT_DATE - start < 10; start 2005-05-23 (1 Zeile) Btw.: please no TOFU, read http://en.wikipedia.org/wi

Re: [despammed] [SQL] Duplicated records

2005-05-24 Thread Andreas Kretschmer
am 24.05.2005, um 17:59:31 -0300 mailte [EMAIL PROTECTED] folgendes: > Hi. > How can I delete the duplicated records with "DELETE FROM TABLE WHERE..." > clause?? Please read http://www.gtsm.com/oscon2003/deletetid.html Its a very good article about this problem. Regards,

Re: [despammed] Re: [SQL] Duplicated records

2005-05-25 Thread Andreas Kretschmer
=# insert into blub values (1, 'x'); | INSERT 970706 1 | test_db=# insert into blub values (1, 'y'); | FEHLER: duplizierter Schlüssel verletzt Unique-Constraint >>blub_pkey<< ` In other words: if there a primary key on the first row, you cannot insert duplicates.

Re: [despammed] [SQL] rejecting characters in a field

2005-06-09 Thread Andreas Kretschmer
h a RULE or a TRIGGER. Regards, Andreas -- Andreas Kretschmer(Kontakt: siehe Header) Heynitz: 035242/47212, D1: 0160/7141639 GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net ===Schollglas Unternehmensgruppe=== ---(end of broadcast)---

Re: [SQL] [despammed] rejecting characters in a field

2005-06-09 Thread Andreas Kretschmer
am 09.06.2005, um 3:29:15 -0500 mailte Bruno Wolff III folgendes: > On Thu, Jun 09, 2005 at 09:18:09 +0200, > Andreas Kretschmer <[EMAIL PROTECTED]> wrote: > > am 09.06.2005, um 12:36:31 +0530 mailte Kenneth Gonsalves folgendes: > > > hi > > > i have a tab

Re: [despammed] [SQL] substr or char_length problem

2005-06-17 Thread Andreas Kretschmer
195 > > > Select * from tbl_xxx where > tbl_xxx.A2=substr('196895588454554545454',0,char_length(tbl_xxx.A2)+1); Perhaps because char_length() returns NULL and this is a invalid value for substr(). Use coalesce(): ... substr('196895588454554545454',0,coalesce(ch

Re: [despammed] [SQL] info

2005-06-20 Thread Andreas Kretschmer
am 20.06.2005, um 11:45:55 +0200 mailte Luca Rasconi folgendes: > I need to know if somebody read this mail. Yes, i read it ;-) Regards, Andreas -- Andreas Kretschmer(Kontakt: siehe Header) Heynitz: 035242/47212, D1: 0160/7141639 GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.

Re: [despammed] Re: [SQL] 'show full processlist' in postgres?

2005-07-01 Thread Andreas Kretschmer
- > 7349453 | admintool |5436 | 100 | admintool | | > 7349454 | postgres |5437 |1 | postgres | | > (2 rows) > > But 'current_query' is still always empty... B-( enable stats_command_string in your postgresql.conf Re

Re: [SQL] BirthDay SQL Issue

2005-10-05 Thread Andreas Kretschmer
brett <[EMAIL PROTECTED]> schrieb: > Hi there > > This is my first posting here, please forgive me if I make any > mistakes here. > > Ok > > I have the structure > > {CLIENTS} = Client ID, First Name, Surname, DOB, Address, Home Phone > No, Mobile Phone No > > As one relation / table (There

Re: [SQL] sql function

2005-10-14 Thread Andreas Kretschmer
Shavonne Marietta Wijesinghe <[EMAIL PROTECTED]> schrieb: > I have 2 schemas "operativo" and "autore" and they both have a table "PECDT00" > > i want to create a function with the following sql command (using the > programme > pgadmin 3) in pgadmin 3 there is a small wizard to fill when u creat

Re: [SQL] How to speed up the database query?

2005-10-27 Thread Andreas Kretschmer
Abdul Wahab Dahalan <[EMAIL PROTECTED]> schrieb: > Hi everyone! > > I'm looking for solution to speed up the database query, means that to > get resultset as quicker as we can. 09:41 < akretschmer> ??tuning 09:41 < rtfm_please> For information about tuning 09:41 < rtfm_please> see http://www.pow

Re: [SQL] serial in output

2005-11-04 Thread Andreas Kretschmer
alessandra de gregorio <[EMAIL PROTECTED]> schrieb: > Hi, > > What function should I use to get a serial number, together with my results, > from a query? > > Ex. Of output I want: > > 1 ooo pp ij > 2 hou joo iu > 3 bhi ft yh > > Basically, I would l

Re: [SQL] Create Public Schema

2005-11-20 Thread Andreas Kretschmer
[EMAIL PROTECTED] <[EMAIL PROTECTED]> schrieb: > Hello all, > > I'm trying to create a schema that contains the default tables, functions, > etc. of the public schema. Using pgAdmin, when I create a schema, it is blank 1. make a dump from the public-schema 2. edit the dump and change 'public' t

Re: [SQL] Is it possible to redirect an update/insert/delete to a different table?

2005-11-20 Thread Andreas Kretschmer
Andy Ballingall <[EMAIL PROTECTED]> schrieb: > Hello Peter, > > I'm glad it's possible, but I can't see how from the documentation. > > Say if I have a table called 'apples' and a table called 'pears'. > > What would the rule look like that would remap all updates on apples so that > they were

Re: [SQL] Is it possible to redirect an update/insert/delete to a different table?

2005-11-20 Thread Andreas Kretschmer
Andy Ballingall <[EMAIL PROTECTED]> schrieb: > Hello Jaime, > > I'm still not quite clear. > > Say I have a number of different updates on a table 'apples' in my code, > including: > > UPDATE apples set pips=6 and color='yellow' where id=3; > UPDATE apples set size=10 where id=6; > > What woul

Re: [SQL] Is it possible to redirect an update/insert/delete to a different table?

2005-11-20 Thread Andreas Kretschmer
Andy Ballingall <[EMAIL PROTECTED]> schrieb: > Hi Andreas, > > The rule you've given only works for an update which changes the name. > > If I do another update which changed the colour instead of the name, that > rule wouldn't do the right thing. Right. > Instead, I'm looking for something w

Re: [SQL] How to change database owner in PostgreSQL 7.4?

2005-11-26 Thread Andreas Kretschmer
frank church <[EMAIL PROTECTED]> schrieb: > Hi guys, > > What is the command change database owner in PostgreSQL 7.4? ALTER DATABASE foo OWNER TO blob; In general: start psql and type '\h alter database', and, more general, '\h' and '\?' HTH, Andreas -- Really, I'm not out to destroy Micros

Re: [SQL] MAX, MIN and arrays

2005-11-27 Thread Andreas Kretschmer
Colton A Smith <[EMAIL PROTECTED]> schrieb: > Hi: > >Let's say I have a table with a column of one-dimensional arrays. What > exactly is returned when the database is queried for a maximum from that > particular column? The array was the greatest average value? Let's say What du you exp

Re: [SQL] SQL Statement Help needed

2005-12-04 Thread Andreas Kretschmer
Michael Avila <[EMAIL PROTECTED]> schrieb: > I am not much of a SQL guru so I am having trouble trying to figure out how > to format a SQL statement. > > I have a table with members named members. Each member has only 1 record. > Then I have a table with member telephone numbers in it name > memb

Re: [SQL] question with times and intervals

2006-01-26 Thread Andreas Kretschmer
Richard Huxton schrieb: > Now (upper_time - lower_time) is the interval you want and summing them > will give you your answer. > > Any help? Yes, thanks. But, i remember a little function that i wrote in the past: http://a-kretschmer.de/tools/time_intersect.sql And now i have a solution (i h

Re: [SQL] alter table

2006-02-15 Thread Andreas Kretschmer
Maciej Piekielniak <[EMAIL PROTECTED]> schrieb: > Hello , > > How can i modify few fields with alter? > > ALTER TABLE fv_wystawione > ALTER id_fv SET DEFAULT nextval('id_fv_seq'::text), > ALTER imie SET DEFAULT ''; test=# create table xyz (id int not null); CREATE TABLE test=# create sequ

Re: [SQL] alter table

2006-02-15 Thread Andreas Kretschmer
Maciej Piekielniak <[EMAIL PROTECTED]> schrieb: > Hello Andreas, > > Wednesday, February 15, 2006, 7:54:28 PM, you wrote: > AK> test=# alter table xyz alter column id set default nextval('xyz_seq'), > alter column foo set default ''; > > PGAdmin-SQL: > > alter table xyz alter column id set def

Re: [SQL] newbie question

2006-03-03 Thread Andreas Kretschmer
ivan marchesini <[EMAIL PROTECTED]> schrieb: > Dear users.. > I have fastly created a table in a postgresql database.. > some columns where edited by hand (columns A, B, C), and some others > (columns D, E, F) have been calculated as a result of mathematical > equation (where the factors are the A

Re: [SQL] input from a external text file......!

2006-03-11 Thread Andreas Kretschmer
AKHILESH GUPTA <[EMAIL PROTECTED]> schrieb: > Hi All.! > I just want to know one thing that is it possible with PGSQL that, > if I want to insert and execute a query from a external text file instead of > giving it at the pgsql prompt? in psql, try simple "\i your_file.sql" to execute the

Re: [SQL] Merging rows into one result?

2006-03-11 Thread Andreas Kretschmer
Jesper K. Pedersen <[EMAIL PROTECTED]> schrieb: > Is it possible to use SQL to merge data into one result? > > A theorethical example to explain: > > tbl_test ( > id integer, > information varchar(25)) > > id | information > ---+-- > 1 | Yo > 2 | Go away > 1 | Stay put > 3 |

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.

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] 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] 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] 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: > 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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 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] 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] 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
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] 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] [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] 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] 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] 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] 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] 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

  1   2   >