Re: [SQL] Can I read the data without commit

2012-03-23 Thread Tim Landscheidt
John Fabiani wrote: > Yes I understand - but I want to know is it possible? Can I read the data I > just inserted without a commit. > [...] Are you talking about a web application? Then no, you'll have to code that yourself. Tim -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)

Re: [SQL] How to split up phone numbers?

2012-02-21 Thread Tim Landscheidt
(anonymous) wrote: > is there a way to split up phone numbers? > I know that's a tricky topic and it depends on the national > phone number format. > I'm especially interested in a solution for Germany, Swizerland and Austria. > I've got everything in a phone number column that makes hardly sense

Re: [SQL] time interval math

2012-02-08 Thread Tim Landscheidt
"Edward W. Rouse" wrote: > Hehe, thanks, I played around and ended up with this: > round(SUM(extract('epoch' from (time_out - time_in > I will have to do the division outside of the query, but that's really a > minor issue. You can always use subqueries. > Knowing the total i

Re: [SQL] Getting a list of a table's attributes that are sortable sorted by uniqueness

2012-01-26 Thread Tim Landscheidt
I wrote: > I frequently use pg_dump to dump databases and compare them > with diff. To get rid of most "false positives", I'd like > to patch pg_dump to sort the table so that its dumped order > isn't changed more than necessary by insertions & Co. > So I'm looking for a query that will return

Re: [SQL] Token separation

2012-01-16 Thread Tim Landscheidt
Tom Lane wrote: >> [ "0x13" is lexed as "0" then "x13" ] >> Is this behaviour really conforming to the standard? > Well, it's pretty much the universal behavior of flex-based lexers, > anyway. A token ends when the next character can no longer sensibly > be added to it. I know, but - off the

[SQL] Token separation

2012-01-15 Thread Tim Landscheidt
Hi, I just tried to input a hexadecimal number in PostgreSQL (8.4) and was rather surprised by the result: | tim=# SELECT 0x13; | x13 | - |0 | (1 Zeile) | tim=# SELECT 0abc; | abc | - |0 | (1 Zeile) | tim=# The documentation says: | A token can be a key word, an identifier,

Re: [SQL] Fwd: i want small information regarding postgres

2012-01-12 Thread Tim Landscheidt
Alvaro Herrera wrote: >> would someone with the appropriate authority please unsubscribe this >> person's email address from this list so we don't all get a bounce message >> after every email we send to the list? Thanks. > Just did it. In the future, please email sysadm...@postgresql.org with

Re: [SQL] lo_import

2012-01-03 Thread Tim Landscheidt
MaurĂ­cio Cruz wrote: > I'm trying to use lo_import to import a file into my > database, if I execute from postgres runing in my local > machine > it works perfectly, but if I do it in the postgres runing in > the server, it says "No such file or directory" > I Guess postgres only see file on the

[SQL] Getting a list of a table's attributes that are sortable sorted by uniqueness

2011-12-29 Thread Tim Landscheidt
Hi, I frequently use pg_dump to dump databases and compare them with diff. To get rid of most "false positives", I'd like to patch pg_dump to sort the table so that its dumped order isn't changed more than necessary by insertions & Co. So I'm looking for a query that will return a list of a ta

Re: [SQL] postgres sql help

2011-10-17 Thread Tim Landscheidt
Harald Fuchs 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.

Re: [SQL] how to calculate differences of timestamps?

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

Re: [SQL] Passing function parameters to regexp_replace

2011-09-17 Thread Tim Landscheidt
Leif Biberg Kristensen wrote: > On Saturday 17. September 2011 19.07.03 Tim Landscheidt wrote: >> Leif Biberg Kristensen wrote: >> > UPDATE sources SET source_text = regexp_replace(source_text, >> > E'n="(.*?)$1(.*?)"', E'n="\\1$2\\2&

Re: [SQL] Passing function parameters to regexp_replace

2011-09-17 Thread Tim Landscheidt
Leif Biberg Kristensen wrote: >> UPDATE sources SET source_text = regexp_replace(source_text, >> E'n="(.*?)$1(.*?)"', E'n="\\1$2\\2"', 'g') where source_text like >> '%n="%$2%">%'; > Sorry, I pasted a literal replacement, and substituted the parameters by hand. > The expression should of course

Re: [SQL] Window function sort order help

2011-09-16 Thread Tim Landscheidt
Dianna Harter wrote: > Having trouble getting a window function to sort correctly. > Given this data > consumer_id | move_date | history_timestamp > -++ >12345| 2008-01-05 | 2007-12-11 06:02:26.842171 >12345| 2008-02-29 |

Re: [SQL] Add one column to another

2011-08-25 Thread Tim Landscheidt
(anonymous) wrote: > I have to deal with a table which contains: > first_name > surname > email1 > email2 > ... and I would like to create a view which combines both email columns thus: > first_name > surname > email > It looks simple but I can't think of an obvious query. Try: | SELECT firs

Re: [SQL] need magic to shuffle some numbers

2011-08-24 Thread Tim Landscheidt
(anonymous) wrote: > there is a table that has among others a integer primary key > "id" and another integer column "prio" as well as an integer > "group_id". > I'd like to invert the values of the prio-column for one of the groups. > The prio numbers start with 3 and there are 1159 different > p

Re: [SQL] Confused about writing this stored procedure/method.

2011-08-24 Thread Tim Landscheidt
(anonymous) wrote: > [...] > I intend pass the number of the month(say 1 for January , 2 for February > etc>) as the parameter to this method and return a number that corresponds > to the index of the month in the new order , say I pass 8 for August , I > return 11 , in order to get the index of

Re: [SQL] Help with regexp-query

2011-08-02 Thread Tim Landscheidt
Johann Spies wrote: > I am struggling a bit to do the following type of update in a table. > I want the content of a field updated like this: > Original: > '0894396e-16bf-4e63-aa52-97fe7031eec9||50a6b47c-f69c-414d-bcb6-14bbe403de5f|||' > After update: > '|0894396e-16bf-4e63-aa52-97fe7031e

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

2011-06-30 Thread Tim Landscheidt
(anonymous) wrote: > how can I remove a set of characters in text-columns ? > Say I'd like to remove { } ( ) ' " , ; . : ! > Of course I can chain replace ( replace ( replace ( replace > ( ... , '' ) and replace the chars one by one against > an empty string ''. > There might be a more elega

Re: [SQL] Duplicates Processing

2010-10-08 Thread Tim Landscheidt
Gary Chambers wrote: > I've been provided a CSV file of parts that contains duplicates of > properties (e.g. resistors have a wattage, tolerance, and temperature > coefficient property) of those parts that differ by a manufacturer > part number. What I'd like to do is to process this file and, u

Re: [SQL] Aggregates (last/first) not behaving

2010-07-22 Thread Tim Landscheidt
Wes Devauld wrote: > I believe I lost the flavour of what I'm doing when I constructed this > example. I'm not interested in the timepoint as much as the value that is > attached to it. I need to be able to find the last chronological record for > a given day. > I can get the value for which I

Re: [SQL] grouping subsets

2010-07-22 Thread Tim Landscheidt
Rainer Stengele wrote: > yes, the date is always incremented - but anyway the date > column is not really the point! Actually the first tow > columns are relevant. I want them gouped together as > indicated, adding up column 1 in the blocks with identical > second column, but not adding up over a

Re: [SQL] grouping subsets

2010-07-22 Thread Tim Landscheidt
Richard Huxton wrote: >>> What I want to get is the values grouped by "subset", where a subset is a >>> set of rows with identical column until the colum changes. >>> Is there a way to get >>> | 2 | B | >>> | 4 | C | >>> | 4 | B | >>> | 3 | D | >>> by SQL only? >> I think, the problem is that

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

2010-07-07 Thread Tim Landscheidt
(anonymous) wrote: > is there a way to find events in a log that happen within a > certain timespan to each other? > Log is like this > event_idinteger not null default 0 primary key > event_type_idinteger not null default > user_idinteger not null default

Re: [SQL] How to select text field as interger

2010-06-29 Thread Tim Landscheidt
Jerrel Kemper wrote: > My table consist off the following fields > CREATE TABLE test > ( > id bigserial NOT NULL, > name character varying(100), >CONSTRAINT logs_pkey PRIMARY KEY (log_id) > ) > with value : > IDName > 1 001 > 201 > 3 1 > 411 > Select

Re: [SQL] enforcing constraints across multiple tables

2010-06-25 Thread Tim Landscheidt
Andrew Geery wrote: > [...] > My questions are: > (A) Is there a way to check (2) above using a constraint and not a trigger? > (B) Is there an easier way to solve this problem? Does the complicated > nature of the solution make the design poor? > (C) Should I not worry about this constraint at

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

2010-06-21 Thread Tim Landscheidt
Steven Dahlin wrote: > I am attempting to generate a temporary function to execute some dml with > the following script: > create or replace function setuplicense() returns integer as $$ > declare > hwcustid integer := 0; > retvalinteger := 0; > begin > insert into license.customer >

Re: [SQL] what does this do

2010-06-10 Thread Tim Landscheidt
Richard Broersma wrote: >>> I have a piece of python code that excutes a SQL statement: >>> apitempCur.execute("select * from jfcs_balancedue('%s') f(enrolleeid >>> varchar, >>> course_cost decimal, paid_amt decimal)" % (enrollIds,)); >>> The "enrollids" is a list of primary keys and the "jfcs

Re: [SQL] what does this do

2010-06-10 Thread Tim Landscheidt
John wrote: > I have a piece of python code that excutes a SQL statement: > apitempCur.execute("select * from jfcs_balancedue('%s') f(enrolleeid varchar, > course_cost decimal, paid_amt decimal)" % (enrollIds,)); > The "enrollids" is a list of primary keys and the "jfcs_balancedue" is a user >

Re: [SQL] Extending Regular Expression bounds limit of 255.

2010-05-29 Thread Tim Landscheidt
Jasen Betts wrote: >> It looks like most of our tools are using the Perl version of regular >> expressions with an upper limit of a bound being 32766. Is there any way to >> change this in PG? Or can I change from POSIX to Perl? > perhaps you can do something in pl-perl? > posix regular expre

Re: [SQL] inner join and limit

2010-05-26 Thread Tim Landscheidt
Michele Petrazzo - Unipex wrote: > I have two table that are so represented: > t1: > id int primary key > ... other > t2: > id int primary key > t1id int fk(t1.id) > somedate date > ... other > data t1: > 1 | abcde > 2 | fghi > data t2: > 1 | 1 | 2010-05-23 > 2 | 1 | 2010-05-24 > 3 | 1 | 2010-

Re: [SQL] safely exchanging primary keys?

2010-05-24 Thread Tim Landscheidt
Louis-David Mitterrand wrote: >> > you use something simple like (untested): >> > >> > | UPDATE cabin_type >> > | SET id_cabin_type = >> > | CASE >> > | WHEN id_cabin_type = id1 THEN >> > | id2 >> > | ELSE >> > | id1 >> > | END >> > | WHERE id_cabin_type IN

Re: [SQL] safely exchanging primary keys?

2010-05-24 Thread Tim Landscheidt
Louis-David Mitterrand wrote: > I have this function which swaps primary keys for cabin_types (so that > id_cabin_type ordering reflects natural data ordering): > CREATE OR REPLACE FUNCTION swap_cabin_types(id1 integer, id2 integer) > RETURNS integer > AS $$ > declare

Re: [SQL] How to get CURRENT_DATE in a pl/pgSQL function

2010-05-19 Thread Tim Landscheidt
Brian Modra wrote: >>> It works using 'now' and I assume that since curtime is >>> of type DATE that the assignment casts the return automatically >>> to type DATE. Thank you for the ideas. >>> [...] >> What's wrong with Pavel's correct and to-the-point answer? > No need actually to cast... jus

Re: [SQL] How to get CURRENT_DATE in a pl/pgSQL function

2010-05-18 Thread Tim Landscheidt
Kenneth Marshall wrote: > It works using 'now' and I assume that since curtime is > of type DATE that the assignment casts the return automatically > to type DATE. Thank you for the ideas. > [...] What's wrong with Pavel's correct and to-the-point answer? Tim -- Sent via pgsql-sql mailing li

Re: [SQL] import ignoring duplicates

2010-05-16 Thread Tim Landscheidt
Mark Fenbers wrote: > I am using psql's \copy command to add records to a database > from a file. The file has over 100,000 lines. > Occasionally, there is a duplicate, and the import ceases > and an internal rollback is performed. In other words, no > data is imported even if the first error o

Re: [SQL] regexp_replace and search/replace values stored in table

2010-04-27 Thread Tim Landscheidt
Leif Biberg Kristensen wrote: > [...] > So far, so good. But when I try to do the actual expansion, I'm stumped. > pgslekt=> select regexp_replace((select source_text from sources where > source_id=23091), (select quote_literal(short_link) from short_links where > link_type = 'sk'), (select quot

Re: [SQL] How to max() make null as biggest value?

2010-04-20 Thread Tim Landscheidt
Feixiong Li wrote: > I am newbie for sql, I have a problem when using max() > function, I need get null when there are null in the value > list, or return the largest value as usual, who can do > this? > i.e. max([1,2,3,4,5]) => 5 > max([1,2,3,4,5,null]) => null You can cheat a bit: | tim=#

Re: [SQL] UNION or LEFT JOIN?

2010-02-16 Thread Tim Landscheidt
Louis-David Mitterrand wrote: > Here is the basic schema: > -->id_ship>--- > || > [SHIP]->id_ship->[CABIN]->id_cabin->[PRICE]<-id_cruise<-[CRUISE] > It's a database of cruise prices. > Each

Re: [SQL] Can i force deletion of dependent rows?

2010-02-13 Thread Tim Landscheidt
Shruthi A wrote: > Thanks people, but the trigger doesnt really solve my problem. You see, > there is actually a CHAIN of dependencies where B references A, C references > B, D and E reference C and so on... So if i start writing triggers for all > these, there'll be a huge process to follow.

Re: [SQL] Can i force deletion of dependent rows?

2010-02-12 Thread Tim Landscheidt
Shruthi A wrote: > I have 2 tables (A and B) where the table B has a foreign key reference to > table A. Like this: > create table A (x int primary key); > create table B (y int primary key, z int references A (x) ); > As you can see, i've not specified any further 'on delete' clause to the >

Re: [SQL] complex join question

2010-02-12 Thread Tim Landscheidt
Louis-David Mitterrand wrote: > Here is my schema: > cruise_line -> ship(id_line) -> cruise_type(id_ship) -> cruise(id_cruise_type) > -> price(id_cruise, id_currency) <- currency (USD,GBP,EUR,CAD) > (a 'cruise' is a 'cruise_type' + a date) > I am trying to display a count of cruise's for

Re: [SQL] Proper case function

2009-12-31 Thread Tim Landscheidt
Michael Gould wrote: > Based on what I read it wouldn't handle cases where the result should be > MacDonald from macdonald. There are other cases such as the sentence below > ('it''s crazy! i couldn''t believe kate mcdonald, leo dicaprio, (terrence) > trent d''arby (circa the 80''s), and jada

Re: [SQL] loading a file into a field

2009-12-31 Thread Tim Landscheidt
Brian Sherwood wrote: > I am looking to play around with the postgres XML functions, but can't > seem to find a way to load my data. > I have a number of XML files: file1.xml, file2.xml, etc All files > follow the same xml format (DTD?) > I would like to create the following table: > CREA

Re: [SQL] Lag and lead window functions order by weirdness

2009-10-18 Thread Tim Landscheidt
Thom Brown wrote: > [...] > Having a look around, it looks as if Postgres might be misbehaving. > According to this page, > http://my.safaribooksonline.com/0596004818/sqlnut2-CHP-4-SECT-3, the ORDER > BY in the window function's clause shouldn't be having this ordering effect: > "Furthermore, t

Re: [SQL] FW: simple? query

2009-08-18 Thread Tim Landscheidt
Jan Verheyden wrote: > Thanks for the suggestion, the only problem is, if primary key is used then > each row should be unique what is not true; since I have a column > 'registered' what only can be 1 or 0... > [...] I have no idea what you are trying to say. Tim -- Sent via pgsql-sql mail

Re: [SQL] simple? query

2009-08-14 Thread Tim Landscheidt
"Relyea, Mike" wrote: >> The goal is, where uid not equals to 'janvleuven10' a new >> record should be inserted with the uid, and registered=0 > So if a record is found you want to update it and if a record isn't > found you want to insert it. I think you'll probably want to use > plpgsql http:

Re: [SQL] mail alert

2009-08-13 Thread Tim Landscheidt
Alvaro Herrera wrote: >> > It's on Windows >> I'd go with notify and a listener written in C using c-client to send >> emails, but only because I've used those before. > I wouldn't write it in C but rather Perl or Python, but whatever suits > your fancy should work (Visual Basic anyone?). The

Re: [SQL] Tweak sql result set... ?

2009-07-30 Thread Tim Landscheidt
(anonymous) wrote: >> > Any ideas on how to achieve this? I would like to let the original sql >> > code stay original. I can prepare postgres before executing the sql if >> > this makes it easier to acheive the goal >> Have a look at CREATE RULE. > Ok, you mean I could create a rule for the tab

Re: [SQL] Tweak sql result set... ?

2009-07-28 Thread Tim Landscheidt
(anonymous) wrote: > I have a problem where I want to tweak a simple select in an > "unobtrusive way". Imagine I have the following select statement: > "SELECT name FROM customer LIMIT 1" and I get a normal result set from > this. But, could I,maybe by defining some other function or similar, > ch

[SQL] Comparing a string against an XPath result set

2009-07-16 Thread Tim Landscheidt
Hi, I'm trying to check whether a given string is part of an XPath result set. I have encountered some performance prob- lems in the process, but before I track those down further, I'd like to see if I've chosen the right path to begin with: | SELECT * FROM $TABLE | WHERE $COLUMN = ANY((xpath($