Re: [SQL] unique key problem on update

2013-09-20 Thread Thomas Kellerer
Gary Stainburn wrote on 20.09.2013 18:30: You need to define the primary key as deferrable: create table skills_pages ( sp_idserial not null, sp_sequence integer not null, sp_title character varying(80), sp_narative text, primary key (sp_id) deferrable ); Cheers.

Re: [SQL] unique key problem on update

2013-09-20 Thread Thomas Kellerer
Gary Stainburn wrote on 20.09.2013 18:07: I want to add a new page after page 2 so I try to increase the sequence number of each row from page 3 onwards to make space in the sequence for the new record. However, I get duplicate key errors when I try. Can anyone suggest how I get round this.

Re: [SQL] Unquoted column names fold to lower case

2013-07-03 Thread Thomas Kellerer
Theodore Petrosky, 03.07.2013 15:41: sorry, but you misunderstand. this is the correct behavior of SQL. It is part of the specification to do this. Not quite. The SQL standard requires folding to uppercase. -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make

Re: [SQL] Unquoted column names fold to lower case

2013-07-03 Thread Thomas Kellerer
Dev Kumkar wrote on 03.07.2013 17:50: Note that adding quotes for aliases will be blessed by PostgreSQL and then those will be folded to upper case BUT this adds up to lot of changes in the SQL layer. I wonder why you need that. I never had the requirement for that. Which driver/interface do

Re: [SQL] Advice with an insert query

2013-06-07 Thread Thomas Kellerer
JORGE MALDONADO, 07.06.2013 15:58: I need to insert records into a table where one value is fixed and 2 values come from a SELECT query, something like the following example: INSERT INTO table1 fld1, fld2, fl3 VALUES value1, (SELECT fldx, fldy FROM table2) Is this valid? Respectfully,

Re: [SQL] check for overlapping time intervals

2013-04-22 Thread Thomas Kellerer
Wolfgang Meiners, 22.04.2013 12:19: Is there a simpler way to check for overlapping timeintervals? I ask this question, because i have more similar tables with similar layout and would have to write similar functions again and again. Do you have the possibility to upgrade to 9.2? The range

Re: [SQL] Using Ltree For Hierarchical Structures

2013-02-26 Thread Thomas Kellerer
Don Parris wrote on 24.02.2013 23:20: With many thanks to Misa and others who helped out with my question about working with hierarchical data, I have now written a blog post on how I implemented the ltree module to solve my problem.

Re: [SQL] Split a string to rows?

2013-01-07 Thread Thomas Kellerer
Emi Lu wrote on 07.01.2013 21:16: Thanks a lot! I just noticed that my postgresql is 8.3(unnest function is not there by default). Is there a way that I could download and load only this function from somewhere? Are you aware that 8.3 will be de-suppported as of next month? You should

[SQL] Using regexp_matches in the WHERE clause

2012-11-27 Thread Thomas Kellerer
Hi, I stumbled over this question on Stackoverflow http://stackoverflow.com/questions/13564369/postgresql-using-column-data-as-pattern-for-regexp-match And my initial reaction was, that this should be possible using regexp_matches. So I tried: SELECT * FROM some_table WHERE

Re: [SQL] Using regexp_matches in the WHERE clause

2012-11-27 Thread Thomas Kellerer
So I tried: SELECT * FROM some_table WHERE regexp_matches(somecol, 'foobar') is not null; However that resulted in: ERROR: argument of WHERE must not return a set Hmm, even though an array is not a set I can partly see what the problem is (although given the really cool array

Re: [SQL] Using regexp_matches in the WHERE clause

2012-11-27 Thread Thomas Kellerer
Pavel Stehule, 27.11.2012 13:26: My question is: why I cannot use regexp_matches() in the WHERE clause, even when the result is clearly an integer value? use a ~ operator instead So that means, regexp_matches cannot be used as an expression in the WHERE clause? Regards Thomas --

Re: [SQL] Fun with Dates

2012-10-29 Thread Thomas Kellerer
Mark Fenbers wrote on 29.10.2012 23:38: Greetings, I want to be able to select all data going back to the beginning of the current month. The following portion of an SQL does NOT work, but more or less describes what I want... ... WHERE obstime = NOW() - INTERVAL (SELECT EXTRACT (DAY FROM

Re: [SQL] [noob] How to optimize this double pivot query?

2012-10-02 Thread Thomas Kellerer
Robert Buck, 02.10.2012 03:13: So as you can probably glean, the tables store performance metric data. The reason I chose to use k-v is simply to avoid having to create an additional column every time a new metric type come along. So those were the two options I thought of, straight k-v and

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

2012-10-01 Thread Thomas Kellerer
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 be PostgreSQL specific and not standard SQL compliant. Here is an example of what

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

2012-09-29 Thread Thomas Kellerer
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 be PostgreSQL specific and not standard SQL compliant. Here is an example of what

Re: [SQL] DELETE using an outer join

2012-07-20 Thread Thomas Kellerer
Tom Lane, 19.07.2012 16:52: If you're using a reasonably recent version of PG, replacing the NOT IN by a NOT EXISTS test should also help. Thanks. I wasn't aware of that (and the NOT EXISTS does indeed produce the same plan as the OUTER JOIN solution) Now I was wondering if a DELETE

Re: [SQL] DELETE using an outer join

2012-07-20 Thread Thomas Kellerer
Sergey Konoplev, 20.07.2012 10:21: On Thu, Jul 19, 2012 at 6:52 PM, Tom Lane t...@sss.pgh.pa.us wrote: Now I was wondering if a DELETE statement could be rewritten with the same strategy: Not at the moment. There have been discussions of allowing the same table name to be respecified in

[SQL] DELETE using an outer join

2012-07-19 Thread Thomas Kellerer
Hi, (this is not a real world problem, just something I'm playing around with). Lately I had some queries of the form: select t.* from some_table t where t.id not in (select some_id from some_other_table); I could improve the performance of them drastically by changing the NOT NULL

Re: [SQL] left outer join only select newest record

2012-05-23 Thread Thomas Kellerer
Gary Stainburn, 23.05.2012 11:47: Here is a select to show the problem. There is one stock record and two tax records. What I'm looking for is how I can return only the second tax record, the one with the highest ud_id select s_stock_no, s_regno, s_vin, s_created, ud_id, ud_handover_date from

Re: [SQL] Finding Max Value in a Row

2012-05-11 Thread Thomas Kellerer
Carlos Mennens wrote on 11.05.2012 21:03: I have a problem in SQL I don't know how to solve and while I'm sure there are 100+ ways to do this in ANSI SQL, I'm trying to find the most cleanest / efficient way. I have a table called 'users' and the field 'users_id' is listed as the PRIMARY KEY. I

Re: [SQL] Finding Max Value in a Row

2012-05-11 Thread Thomas Kellerer
Carlos Mennens wrote on 11.05.2012 21:30: Thanks for all the help thus far everyone! I sadly didn't create/design the table and would love to create a SEQUENCE on that particular field but not sure how unless I DROP the table and create from scratch. Currently the data TYPE on the primary key

Re: [SQL] Finding Max Value in a Row

2012-05-11 Thread Thomas Kellerer
Carlos Mennens wrote on 11.05.2012 21:50: On Fri, May 11, 2012 at 3:44 PM, Thomas Kellererspam_ea...@gmx.net wrote: Use this: alter table users alter column users_id type integer using to_number(users_id, '9'); (Adjust the '9' to the length of the char column) When you wrote

Re: [SQL] Finding Max Value in a Row

2012-05-11 Thread Thomas Kellerer
Carlos Mennens wrote on 11.05.2012 21:53: Very good question and asked by myself to the original SQL author and he explained while he didn't use the most efficient data types, he used ones he felt would be more transparent across a multitude of RDBMS vendors. So the answer is no, it would not

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

2012-05-04 Thread Thomas Kellerer
Marcel Ruff, 04.05.2012 12:25: Hi, is an alias name not usable in the where clause? select EXTRACT(day from enddate::TIMESTAMP - old_enddate::TIMESTAMP) AS TAGE from account_h where TAGE5; ERROR: column tage does not exist LINE 1: ... TAGE5 ... You need to wrap the query: select * from (

Re: [SQL] UPDATE Multiple Records At Once?

2012-04-11 Thread Thomas Kellerer
Carlos Mennens wrote on 11.04.2012 19:50: I'm trying to update a customer record in a table however I need to change several values (cust_address, cust_contact, cust_email). My question is how do I properly format this into one single command? forza=# SELECT cust_id, cust_name, cust_address,

Re: [SQL] Concurrent Reindex on Primary Key for large table

2012-02-08 Thread Thomas Kellerer
rverghese wrote on 08.02.2012 19:07: I have a large table with about 60 million rows, everyday I add 3-4 million, remove 3-4 million and update 1-2 million. I have a script that reindexes concurrently a couple of times a week, since I see significant bloat. I have autovac on and the settings are

Re: [SQL] UPDATE COMPATIBILITY

2012-01-17 Thread Thomas Kellerer
Gera Mel Handumon, 17.01.2012 07:31: What version of postgresql that the update compatibility below will be implemented? UPDATE COMPATIBILITY UPDATE accounts SET (contact_last_name, contact_first_name) = (SELECT last_name, first_name FROM salesmen WHERE salesmen.id =

Re: [SQL] UPDATE COMPATIBILITY

2012-01-17 Thread Thomas Kellerer
Adrian Klaver, 17.01.2012 16:19: You need to rewrite it to: UPDATE accounts SET contact_last_name = s.last_name, contact_first_name = s.first_name FROM salesmen s WHERE s.id = accounts.sales_id For completeness, you could also do: UPDATE accounts SET

[SQL] Re: Current transaction is aborted, commands ignored until end of transaction block

2011-12-30 Thread Thomas Kellerer
Marcin Mirosław wrote on 30.12.2011 12:07: Would be nice to have an option in PostgreSQL something along the lines of: 'abort-transaction-on-constraint-violation = false' That option is called MySQL with MyISAM tables. Not true. Oracle and others (I believe at least DB2) behave such

Re: [SQL] avoid the creating the type for setof

2011-12-30 Thread Thomas Kellerer
John Fabiani wrote on 30.12.2011 15:26: Hi, I recall somewhere I saw a simple plpgsql function that returned a table with more than one record that did not use a defined type or a temp table ( at least I think I did). Is it possible to create such a function that will return more than one

Re: [SQL] ORACLE PROCEDURE TO POSTGRES FUNCTION -ERROR IN THE OVER PART

2011-11-11 Thread Thomas Kellerer
Manu T, 07.11.2011 08:18: I am using this query in the procedure and i error is throwing as mentioned below.and i want to convert the same oracle query into Postgresql. ERROR-- *ERROR: syntax error at or near OVER LINE 1: ...heme_id,d.value, d.dr_cr_flg , d.rule_id , RANK() OVER (part... ^

Re: [SQL] how to temporally disable foreign key constraint check

2011-10-21 Thread Thomas Kellerer
Emi Lu wrote on 21.10.2011 15:36: Good morning, Is there a way to temporally disabled foreign key constraints something like SET FOREIGN_KEY_CHECKS=0 When population is done, will set FOREIGN_KEY_CHECKS=1 Thanks a lot! Emi You can define the FKs as DEFERRABLE INITIALLY IMMEDIATE. Then at

Re: [SQL] new user on mac

2011-10-20 Thread Thomas Kellerer
Scott Swank, 18.10.2011 23:47: I have a postgres 9.1 database up running, no problem. Purely in terms of writing sql (ddl, dml pg/plsql), what tools are recommended? Coming from an Oracle world, I'm thinking of toad, sql developer, etc. 1. psql text editor of choice (if so, which one?) 2.

Re: [SQL] using the aggregate function max()

2011-09-23 Thread Thomas Kellerer
John Fabiani, 23.09.2011 04:49: I need to find the max(date) of a field but I need that value later in my query. If I select max(x.date_field) as special_date from (select date_field) from table where ...)x I get one row and column. But now I want to use that field in the rest of the query

[SQL] Combining several CTEs with a recursive CTE

2011-09-20 Thread Thomas Kellerer
Hello all, this is more a just curious question, rather than a real world problem. We can combine several CTEs into a single select using something like this: WITH cte_1 as ( select ), cte_2 as ( select ... where id (select some_col from cte_1) ) select * from cte_2; But this

Re: [SQL] Combining several CTEs with a recursive CTE

2011-09-20 Thread Thomas Kellerer
David Johnston, 20.09.2011 16:15: I'm just wondering if this is intended behavioury, simply not (yet) implemented or even invalid according to the standard? I didn't find any reference that it's not allowed in the manual. Regards Thomas Try sticking the recursive keyword after the with if

Re: [SQL] Window function sort order help

2011-09-14 Thread Thomas Kellerer
Nicoletta Maia, 14.09.2011 10:30: SELECT `X`.`consumer_id`, `X`.`move_date` , `X`.`history_timestamp` , MIN( `Y`.`history_timestamp` ) AS `start_time` FROM `Table` AS `X` JOIN `Table` AS `Y` ON `X`.`consumer_id` = `Y`.`consumer_id`

Re: [SQL] to_char() accepting invalid dates?

2011-07-20 Thread Thomas Kellerer
Bruce Momjian, 20.07.2011 03:03: Well, to_char() is based on Oracle's to_char(). How does Oracle handle such a date? Oracle throws an error for the above example: SQL select to_date('20110231', 'MMDD') from dual; select to_date('20110231', 'MMDD') from dual * ERROR

Re: [SQL] to_char() accepting invalid dates?

2011-07-19 Thread Thomas Kellerer
Bruce Momjian, 19.07.2011 00:02: postgres= select to_date('20110231', 'mmdd'); to_date 2011-03-03 (1 row) is there a way to have to_date() raise an exception in such a case? it's possible the odd behaviour you get is required by some standard. That would be

[SQL] to_char() accepting invalid dates?

2011-07-18 Thread Thomas Kellerer
Hi, I just noticed that to_char() will accept invalid dates such as 2011-02-31 and adjust them accordingly: postgres= select to_date('20110231', 'mmdd'); to_date 2011-03-03 (1 row) is there a way to have to_date() raise an exception in such a case? Regards Thomas --

Re: [SQL] to_char() accepting invalid dates?

2011-07-18 Thread Thomas Kellerer
Jasen Betts wrote on 18.07.2011 11:23: postgres= select to_date('20110231', 'mmdd'); to_date 2011-03-03 (1 row) is there a way to have to_date() raise an exception in such a case? it's possible the odd behaviour you get is required by some standard. That would be

Re: [SQL] newbie question * compare integer in a where IN statement

2011-07-13 Thread Thomas Kellerer
Jose Ig Mendez, 13.07.2011 09:36: Hi everybody, I'm trying to compare in a sentence like this (using PostGres 8.3) : select * from myTable where id_integer IN ('1,2,3,4') I want to get the records which key id_integer is 1 or 2 or 3 or 4. the type od my id, of course, is integer. I've

Re: [SQL] Function to total reset a schema

2011-05-29 Thread Thomas Kellerer
Surfing wrote on 29.05.2011 09:38: Hi all, I need to write a function that totally empty a schema. So I have written a TRUNCATE statement for each table and set to 0 each sequence. Btw, it could be good to execute a vacuum statement on each table, but from within the function this is not

Re: [SQL] ordering by date for each ID

2011-05-12 Thread Thomas Kellerer
Nguyen,Diep T wrote on 12.05.2011 03:59: Each ID can have different number of score counts. My goal is to add column order, which shows the order of the values in column date in descendant order for each property. The expected output will look like this: id | date |

[SQL] Specifying column level collations

2011-05-07 Thread Thomas Kellerer
Hi, I'm playing around with 9.1beta1 and would like to create a table where one column has a non-default collation. But whatever I try, I can't find the correct name that I have to use. My database is initialized as follows: postgres=# select version(); version

Re: [SQL] Specifying column level collations

2011-05-07 Thread Thomas Kellerer
Guillaume Lelarge wrote on 07.05.2011 14:02: create table foo (bar text collate fr_FR) -- collation fr_FR for encoding UTF8 does not exist create table foo (bar text collate fr_FR.1252) -- collation fr_FR for encoding UTF8 does not exist create table foo (bar text collate fr_FR.UTF8) --

Re: [SQL] Specifying column level collations

2011-05-07 Thread Thomas Kellerer
Tom Lane wrote on 07.05.2011 18:48: Thomas Kellererspam_ea...@gmx.net writes: My database is initialized as follows: postgres=# select version(); version PostgreSQL 9.1beta1, compiled by Visual

Re: [SQL] Oracle Equivalent queries in Postgres

2011-02-16 Thread Thomas Kellerer
Pavel Stehule, 16.02.2011 11:50: Try to use a standardized information_schema instead - these views are same on PostgreSQL and Oracle. Unfortunately they are not the same: Oracle does not support INFORMATION_SCHEMA Regards Thomas -- Sent via pgsql-sql mailing list

Re: [SQL] Oracle Equivalent queries in Postgres

2011-02-16 Thread Thomas Kellerer
Pavel Stehule, 16.02.2011 12:20: Unfortunately they are not the same: Oracle does not support INFORMATION_SCHEMA sorry, I expected so all mature databases support it. Yes, this is really hard to understand. I would assume creating the INFORMATION_SCHEMA views based on the existing Oracle

Re: [SQL] how to get row number in select query

2011-01-27 Thread Thomas Kellerer
Piotr Czekalski, 27.01.2011 16:21: Gentelmen, I follow this thread and I don't exactly get an idea of yours, but isn't is as simple as (example: table web.files contains one column named fileurl ): select row_number() over(), X.fileurl from (select fileurl from web.files order by fileurl) X

Re: [SQL] sqlplus reporting equivalent in postgres?

2010-12-11 Thread Thomas Kellerer
Samuel Gendler wrote on 11.12.2010 04:23: psql - not as advanced, doesn't have all the features SQL*Plus has. On the other hand, it is at least capable of command history and readline support. Hmm, for me SQL*Plus does support command history, but this is getting off-topic now...

Re: [SQL] Insert row in 1.10.1 and 1.10.3

2010-11-26 Thread Thomas Kellerer
ndias, 26.11.2010 17:22: When doing a insert row with less columns mentioned in into table(col1, col2, col3,... than the columns that exist on the table, on 1.10.1 it returns an error saying INSERT has more expressions than target columns (the error is translated so maybe the text is not exactly

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

2010-10-16 Thread Thomas Kellerer
Andreas wrote on 16.10.2010 05:23: Hi, how can I collect text-fields from multiple rows into one output row? I'd like to do an equivalent to the aggregate function SUM() only for text. The input is a select that shows among other things a numerical column where I would like to group by. The

Re: [SQL] Create Datefield from 3 fields

2010-10-06 Thread Thomas Kellerer
Andreas Forø Tollefsen, 06.10.2010 13:11: Hi. I am trying to create a datefield using YEAR, MONTH and DAY fields of type integer. I tried this query, but it did not give good results: select to_date(gwsyear::text || gwsmonth::text || gwsday::text, '-MM-DD') FROM cshapes You are missing

Re: [SQL] sql disaster - subquery error but delete continues

2010-09-10 Thread Thomas Kellerer
Greg Caulton, 10.09.2010 11:46: delete from form_record_details where form_record_id in (select form_record_id from forms where form_id= 40003656) Seems fine at 1am. However the subquery has a typo in it - there is no form_record_id in the forms table But rather than psql throwing an

Re: [SQL] how to escape _ in select

2010-07-29 Thread Thomas Kellerer
Wes James, 28.07.2010 19:35: I'm trying to do this: select * from table where field::text ilike '%\_%'; but it doesn't work. How do you escape the _ and $ chars? The docs say to use \, but that isn't working. ( http://www.postgresql.org/docs/8.3/static/functions-matching.html ) The text

Re: [SQL] subtract two dates to get the number of days

2010-07-15 Thread Thomas Kellerer
Jean-David Beyer, 14.07.2010 19:05: I just looked them up in my data definitions. Dates are _stored_ as type DATE NOT NULL Very good ;) Yes, if the data happen to be stored at all. But when a program generates the dates dynamically and wants to produce queries from them, it is easier to use

Re: [SQL] subtract two dates to get the number of days

2010-07-14 Thread Thomas Kellerer
Jean-David Beyer wrote on 14.07.2010 14:37: My dates are of the form -mm-dd and such. Storing a date as a string is never a good idea. And I want to do things like adding or subtracting days, months, or years to it or from it. Also the logical comparisons. Which is all a piece of cake

Re: [SQL] subtract two dates to get the number of days

2010-07-13 Thread Thomas Kellerer
Campbell, Lance, 13.07.2010 16:58: I want to subtract to dates to know the number of days different. Example: 01/02/2010 - 01/01/2010 = 1 day 08/01/2010 - 07/31/2010 = 1 day How do I do this? SELECT DATE '2010-02-01' - DATE '2010-01-01'; SELECT DATE '2010-08-01' - DATE '2010-07-31';

Re: [SQL] Cant execute the query

2010-07-08 Thread Thomas Kellerer
Srikanth Kata wrote on 02.07.2010 14:24: When i am executing this query, i am facing the select s.*,a.actid,a.phone,d.domid,d.domname,d.domno,a.actno,a.actname,p.descr as svcdescr from vwsubsmin s inner join packages p on s.svcno=p.pkgno inner join account a on a.actno=s.actno inner join

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

2010-06-11 Thread Thomas Kellerer
John, 11.06.2010 16:17: 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. There is one in the manual: http://www.postgresql.org/docs/current/static/tutorial-window.html Thomas --

Re: [SQL] How to get localized to_char(DATE) output

2010-05-06 Thread Thomas Kellerer
Tom Lane, 06.05.2010 00:51: Thomas Kellererspam_ea...@gmx.net writes: I'm trying to get the output of the to_char(date, text) method in German but I can't get it to work: I think you need 'TMMon' to get a localized month name. regards, tom lane Ah! Silly me. Now

Re: [SQL] How to get localized to_char(DATE) output

2010-05-06 Thread Thomas Kellerer
Jasen Betts, 06.05.2010 11:57: The manual says the value for lc_time is OS dependent and indeed set lc_time = 'German' does not work on Solaris. Is there a way to get a list of allowed values for lc_time for a specific installation? man -k locale would be my starting point (for anything

[SQL] How to get localized to_char(DATE) output

2010-05-05 Thread Thomas Kellerer
Hi, I'm trying to get the output of the to_char(date, text) method in German but I can't get it to work: My understanding is, that I need to set lc_time for the session in order to change the language used by to_char(), but this does not seem to work for me: postgres= select version();

[SQL] Problem with function returning a result set

2010-04-08 Thread Thomas Kellerer
Hi, I'm playing around with functions returning result sets, and I have a problem with the following function: -- Create sample data CREATE TABLE employee (id integer, first_name varchar(50), last_name varchar(50)); INSERT INTO employee values (1, 'Arthur', 'Dent'); INSERT INTO employee

Re: [SQL] Problem with function returning a result set

2010-04-08 Thread Thomas Kellerer
Tom Lane, 08.04.2010 10:59: Thomas Kellererspam_ea...@gmx.net writes: CREATE OR REPLACE FUNCTION get_employees(name_pattern varchar) RETURNS TABLE(id integer, full_name text) AS $$ BEGIN RETURN QUERY SELECT id, first_name||' '||last_name FROM employee WHERE last_name

Re: [SQL] count function alternative in postgres

2010-04-06 Thread Thomas Kellerer
junaidmalik14 wrote on 03.04.2010 14:58: Is there any alternative of mysql function COUNT(DISTINCT expr,[expr...]) in postgres. We get error if we write count like this count(distinct profile.id, profile.name, profile.age) but it works well in mysql. Reference url is given below

Re: [SQL] SQL Developer accessing PostgreSQL

2010-03-31 Thread Thomas Kellerer
Snyder, James, 29.03.2010 18:33: Hello, Is there a way to configure Oracle’s SQL Developer to access a PostgreSQL database? Thanks,Jim As others have pointed out, it's not possible. The Postgres Wiki contains a list of GUI Tools that work with Postgres:

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

2010-03-30 Thread Thomas Kellerer
Snyder, James, 29.03.2010 18:25: Thanks for all the dialog on this subject. My version was derived from the postgreSQL's .jar file (specifically named postgresql-8.4-701.jdbc4.jar) that I'm using. When I do the following: select version() I get the following: PostgreSQL 8.3.6 Then you

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

2010-03-26 Thread Thomas Kellerer
Jayadevan M, 26.03.2010 07:56: Thank you for setting that right. Apologies for not checking version. The orginal poster stated that he is using 8.4, so that solution will work for him. Thomas -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your

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

2010-03-25 Thread Thomas Kellerer
Snyder, James wrote on 25.03.2010 22:33: I’m using PostgreSQL (8.4.701) There is no such version. The current version is 8.4.3 On a side note, Oracle allows the following syntax to achieve the above: select count(*) over () as ROWCOUNT , first_name from people The same syntax will work

Re: [SQL] 8.4.1 distinct query WITHOUT order by

2009-12-21 Thread Thomas Kellerer
Gary Chambers wrote on 21.12.2009 23:15: The current maintainer is unsure about being able to do the right thing and recompile the code after fixing the query. Why not simply add the necessary GROUP BY? Thomas -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to

Re: [SQL] pg_get_functiondef and overloaded functions

2009-10-30 Thread Thomas Kellerer
Tom Lane wrote on 30.10.2009 05:44: select pg_get_functiondef('foo(int)'::regproc) select pg_get_functiondef('foo(int4)'::regproc) select pg_get_functiondef('foo(integer)'::regproc) but each time I get the error: function foo(integer) does not exist What am I missing? You need to use

Re: [SQL] Using information_schema to find about function parameters?

2009-10-29 Thread Thomas Kellerer
Mario Splivalo, 29.10.2009 17:51: I looked at the information_schema.routines, to get information about the functions in the database, but there doesn't seem to be a way to extract the parameters information about functions? Where would I seek for such information? They are stored as an array

[SQL] pg_get_functiondef and overloaded functions

2009-10-29 Thread Thomas Kellerer
Hi, I'm playing around with the new pg_get_functiondef() function but I can't get it to work when I need to specify the argument list. select pg_get_functiondef('foo'::regproc) works without problems. However if I have e.g. foo(int) and foo(int, int) I can't get this to work. I tried

Re: [SQL] Common table expression - parsing questions

2009-10-04 Thread Thomas Kellerer
the6campbells wrote on 29.09.2009 04:54: 2. Do you intend to remove the requirement to include the recursive keyword - as other vendors allow The standard *requires* the keyword. As far as I can tell there are two DBMS that require it (Postgres, Firebird) and two that don't (SQL Server and

Re: [SQL] CHECK constraint on multiple tables

2009-09-14 Thread Thomas Kellerer
Mario Splivalo wrote on 14.09.2009 16:20: Have you considered refactoring so there's only one table? Unfortunately I can't do that, due to the object-relational-mapper-wrapper-mambo-jumbo. You could still refactor that into one single table, then create two updateable views with the names

Re: [SQL] mysql code questions

2009-08-12 Thread Thomas Kellerer
Ray Stell wrote on 12.08.2009 20:19: http://www.brentozar.com/archive/2009/04/getting-the-most-recent-record/ How this works? What is ttNewer? What is a clustered primary key in mysql? That article talks about SQL Server not MySQL. select tt.* FROM TestTable tt LEFT OUTER JOIN TestTable

Re: [SQL] Bit by commands ignored until end of transaction block again

2009-07-23 Thread Thomas Kellerer
Chris, 23.07.2009 09:06: psql -d dbname .. # select now(); now --- 2009-07-23 17:04:21.406424+10 (1 row) Time: 2.434 ms (csm...@[local]:5432) 17:04:21 [test] # savepoint xyz; ERROR: SAVEPOINT can only be used in transaction blocks

Re: [SQL] WITH RECURSION output ordering with trees

2009-07-10 Thread Thomas Kellerer
Philippe Lang, 10.07.2009 11:10: Hi, I'm playing with the new WITH RECURSIVE feature of 8.4. I'm trying to figure out how to use it with trees. Here is the test code I use: I'd like to perform a real recursion, and show the tree structure in a more appopriate way, like this: Any idea how to

Re: [SQL] it's not NULL, then what is it?

2009-06-30 Thread Thomas Kellerer
Steve Crawford wrote on 01.07.2009 00:39: canon=# select count(maf) from gallo.sds_seq_reg_shw canon-# where maf ISNULL; I believe count will only count not-null Correct SELECT count(some_col) FROM some_table; is the same as SELECT count(*) FROM some_table WHERE some_col IS NOT NULL;

Re: [SQL] Comparing two tables of different database

2009-04-29 Thread Thomas Kellerer
Nicholas I, 29.04.2009 08:39: Hi, can anybody me suggest me, how to compare two tables of different database. Do you want to compare the data or the structure of the two tables? Thomas -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription:

Re: [SQL] Permanent alias for postgresql table

2009-03-12 Thread Thomas Kellerer
Marco Lechner, 12.03.2009 13:59: Hi list, I'm searching for a way to create permanent alias for tablenames in postgresql. We are storing various versions of a routable network in postgresql (postgis, pgrouting) and access a certain version with a bunch of php-skripts. We like to use aliases for

Re: [SQL] Permanent alias for postgresql table

2009-03-12 Thread Thomas Kellerer
Marco Lechner, 12.03.2009 15:26: Hi Mina, thanks for your answer. I thought about that, but don't views decrease performance, because they are calculated on access? I'm not sure what you mean with calculated. A view is just a SQL query. There is no difference in executing the SQL query

Re: [SQL] store pdf files

2008-12-09 Thread Thomas Kellerer
ivan marchesini wrote on 09.12.2008 11:11: Hi to all... I need to create a db that contain link to some pdf files.. At the moment these are simple links (to the files that are stored into the file system) storing paths into a column of a dbf table... I need to manage this data considering that

Re: [SQL] fast insert-if-key-not-already-there

2008-08-04 Thread Thomas Kellerer
Patrick Scharrenberg, 04.08.2008 17:51: Hi! I have to do much inserts into a database where the key most often is already there. My current approach is to query for the key (ip-address), and if the result is null I do the insert. For every IP-Address I need the ip_addr_id from the same table.

[SQL] xpath_table

2008-05-15 Thread Thomas Kellerer
Hi, I am using xpath_table to convert elements from an XML column to rows. Now according to http://www.postgresql.org/docs/8.3/static/xml2.html this function will be removed in a future version. That chapter also claims that the new XML syntax covers the functionality of the xml2 module,

Re: [SQL] Protection from SQL injection

2008-04-26 Thread Thomas Kellerer
Thomas Mueller wrote on 26.04.2008 18:32: Literals can still be used when using query tools, or in applications considered 'safe'. I fail to see how the backend could distinguish between a query sent by a query tool and a query sent by an application. Thomas -- Sent via pgsql-sql mailing

Re: [SQL] After updating dataset the record goes to the end of the dataset

2008-04-22 Thread Thomas Kellerer
Nacef LABIDI, 22.04.2008 11:54: Hi all, I am using Postgres in a Delphi application through ODBC. I am having an issue with updating records. When I create a dataset to get the records in a table then after I update one of these records and then refresh the dataset, the record goes to the

[SQL] Having a mental block with (self) outer joins

2008-04-21 Thread Thomas Kellerer
Hi, I'm playing around with putting a hierarchy of items into the database. But for some reason I'm having a mental block understanding the following: I have a table category with id and parent_id implementing the typical adjacency model. To get the first two levels of the hierarchy I use:

Re: [SQL] Having a mental block with (self) outer joins

2008-04-21 Thread Thomas Kellerer
hubert depesz lubaczewski, 21.04.2008 16:05: ROOT, 1, NULL CHILD1, 2, 1 CHILD2, 3, 1 I would have expected the following result: ROOT, NULL ROOT, CHILD1 ROOT, CHILD2 but the row with (ROOT,NULL) is not returned. why would you expect it? the columns are: parent and child (on your output).

Re: [SQL] Columns view? (Finding column names for a table)

2008-02-06 Thread Thomas Kellerer
Steve Midgley wrote on 06.02.2008 21:33: Hi, I see this documentation item but can't figure out how to use it: http://www.postgresql.org/docs/8.2/interactive/infoschema-columns.html The view columns contains information about all table columns (or view columns) in the database. select

[SQL] Removing whitespace using regexp_replace

2007-10-28 Thread Thomas Kellerer
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). I tried SELECT regexp_replace(myfield, '\A\s*', '') FROM mytable; (for leading whitespace, to start with) But it

Re: [SQL] Removing whitespace using regexp_replace

2007-10-28 Thread Thomas Kellerer
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 (ideally leading and trailing). You can use trim() for that: select 'x' || trim(both '\t' from trim(both '

Re: [SQL] Removing whitespace using regexp_replace

2007-10-28 Thread Thomas Kellerer
Andreas Kretschmer wrote on 28.10.2007 13:32: But it seems my problem was actually caused by something else: SELECT regexp_replace(myfield, '\s*', '', 'g') FROM mytable; you should escape the \, change to ...'\\s*'... Ah! Didn't think this was necessary, as \t or \n did not need to be

Re: [SQL] Make a SQL statement not run trigger

2007-08-21 Thread Thomas Kellerer
Jon Collette wrote on 21.08.2007 23:26: Is it possible to run an insert,update, or delete and have it not launch a trigger like it normally would? For example could I set a value DONOTRUN = True; insert into contacts Where the trigger on contacts would call a function that would have an

Re: [SQL] How to analyse the indexes in postgres?

2007-02-18 Thread Thomas Kellerer
Karthikeyan Sundaram wrote on 18.02.2007 09:15: Hi, I am new to postgres. I need some kind of template script or advise on how to analyse the indexes. In our database, we do delete, insert, update tons of rows. http://www.postgresql.org/docs/8.2/interactive/routine-reindex.html

Re: [SQL] Removing duplicate rows

2007-02-06 Thread Thomas Kellerer
Paul Lambert wrote on 06.02.2007 23:44: Sort on Weenblows is a bastard to work with, and I don't believe it has a unique option. I probably should have mentioned this was on Weenblows. You can get all (or most?) of the *nix/GNU commandline tools for Windows as well. As native Win32

Re: [SQL] SEQUENCES

2006-10-02 Thread Thomas Kellerer
Rodrigo Sakai wrote on 02.10.2006 18:39: Hi all, I need to get all sequences and their respective current values! Is there any catalog table or any other away to get this??? Quote from the manual at: http://www.postgresql.org/docs/8.1/static/catalog-pg-class.html The catalog

Re: [SQL] Updatable views: any decent front-ends?

2005-11-25 Thread Thomas Kellerer
Bath, David wrote on 24.11.2005 23:57: While I can happily create rules on views to allow inserts, updates and deletes, I can't find a GUI front-end that understands that the view allows record edits that I can run on linux (whether through X or web-based doesn't matter) and simply open the

  1   2   >