Re: [SQL] generic crosstab ?

2012-04-24 Thread Joe Conway
you are selecting from a set returning function in the target list rather than the from clause. It should be more like: SELECT * FROM crosstab(text, text) AS ( col1_name col1_type [, colN_name colN_type]* ) HTH, Joe -- Joe Conway credativ LLC: http://www.credativ.us Linux, PostgreSQL

Re: [SQL] Generating Rows from a date and a duration

2010-09-08 Thread Joe Conway
-08 (10 rows) HTH, Joe -- Joe Conway credativ LLC: http://www.credativ.us Linux, PostgreSQL, and general Open Source Training, Service, Consulting, 24x7 Support signature.asc Description: OpenPGP digital signature

Re: [SQL] strangest thing happened

2010-07-07 Thread Joe Conway
|| ' RESTART WITH ' || startval; EXECUTE sql; RAISE NOTICE '%', sql; END IF; END LOOP; RETURN 'OK'; END; $$ LANGUAGE plpgsql STRICT; select adjust_seqs('public'); 8-- HTH, Joe -- Joe Conway

Re: [SQL] [GENERAL] Encrypted column

2007-06-05 Thread Joe Conway
Marko Kreen wrote: On 6/5/07, Brian Mathis [EMAIL PROTECTED] wrote: pgcrypto also supports md5, so I'm not sure what you're referring to here. digest(psw, 'md5') vs. crypt(psw, gen_salt('md5')) As I already mentioned, *salting* before you hash is a very important step. I'm not sure if you

Re: [SQL] Very large IN-clause is slow, but how to rewrite it?

2007-02-25 Thread Joe Conway
Tom Lane wrote: Richard Jones [EMAIL PROTECTED] writes: I've been profiling a PG database / mix of applications and found that one statement which takes a very long time to execute is: PG 8.2 does better with long IN-lists ... although if the list is so long as to be fetching a significant

Re: [SQL] psql -F TAB

2006-11-16 Thread Joe Conway
T E Schmitz wrote: Alvaro Herrera wrote: T E Schmitz wrote: I have written a shell script to export data: psql -A -t -U $DBUSER -d $DB -c $QUERY -F ' ' Currently, I am using spaces as field separator but what I really want is tabs. How can I specify a TAB character with the -F option?

Re: [SQL] query; check for zero and floats

2006-03-31 Thread Joe Conway
[EMAIL PROTECTED] wrote: I'm trying to do a simple query and I'm not sure how to get it to work: SELECT SUM(x0 + y0 + z0) / SUM(x2 + y2) AS A1, SUM(x1 + y1 + z1) / SUM(x3 + y3) AS A2 FROM test Problems: 1. All variables are integers. When it does the division, it returns an integer, but I

Re: [SQL] ARRAY() returning NULL instead of ARRAY[] resp. {}

2005-06-06 Thread Joe Conway
Tom Lane wrote: Markus Bertheau =?UTF-8?Q?=E2=98=AD?= [EMAIL PROTECTED] writes: By analogy, array_upper('{}'::TEXT[], 1) should return 0 instead of NULL. No, that doesn't follow ... we've traditionally considered '{}' to denote a zero-dimensional array. A 1-D array of no elements is

Re: [SQL] ARRAY() returning NULL instead of ARRAY[] resp. {}

2005-06-04 Thread Joe Conway
Bruce Momjian wrote: Joe Conway wrote: Any thoughts on how this should be handled for an empty 1D array? No one responed to this email, so I will try. Is this the one dimmentional array you were talking about? test= select array_dims('{}'::integer[]); array_dims

Re: [SQL] ARRAY() returning NULL instead of ARRAY[] resp. {}

2005-05-26 Thread Joe Conway
Tom Lane wrote: I think he's got a good point, actually. We document the ARRAY-with- parens-around-a-SELECT syntax as The resulting one-dimensional array will have an element for each row in the subquery result, with an element type matching that of the subquery's

Re: [SQL] PGCrypto: Realworld scenario and advice needed

2005-04-11 Thread Joe Conway
Moran.Michael wrote: My initial attack plan was to do the following: 1. Call decrypt() with the old-passphrase to decrypt each table's existing data. 2. Temporarily store the decrypted data in temp tables. 3. Delete all rows of encrypted data from the original tables -- thereby clearing the

Re: [SQL] Calling a table residing in another database from Plpgsql

2005-01-05 Thread Joe Conway
[EMAIL PROTECTED] wrote: SELECT * from dblink('host=192.168.0.50 dbname=AK1 user=akteam','Select userid from user_reg') as t (userid integer); I am getting an error as ERROR: function dblink(unknown, unknown) does not exist Have you installed the dblink functions into your database? See

Re: [SQL] Create Calendar

2004-12-11 Thread Joe Conway
Muhyiddin A.M Hayat wrote: How to create Calendar using Function/View. For example i would like to display date 2004-12-01 to 2004-12-20. date -- 2004-12-01 2004-12-02 2004-12-03 2004-12-04 2004-12-05 .. .. 2004-12-20 -- Use in Postgres 7.4.x and

Re: [SQL] PL/pgSQL multidimension (matrix) array in function

2004-09-20 Thread Joe Conway
Sergio Fantinel wrote: I found how to use, inside a PL/pgSQL function, a two-dimensions array (matrix). There is a limitation: the number of the 'columns' of the matrix is fixed at declaration time (in DECLARE section) and you need to manually initialize all the elements in the first 'row' of

Re: [SQL] array_in: '{}}'::text[]

2004-08-23 Thread Joe Conway
Markus Bertheau wrote: Is there a reason the array_in parser accepts additional closing braces at the end? oocms=# SELECT '{}}'::text[]; text -- {} (1 ) Hmmm, I was *about* to say that this is fixed in cvs (and indeed, the array_in parser is significantly tightened up compared to previous

Re: [SQL] reply to setting

2004-08-23 Thread Joe Conway
Greg Stark wrote: Just as a side comment, one trick I found very helpful in my mail filters is to treat any message with one of my message-ids in the references as a personal message as far as mail notifications. This way I get notifications for any message on a thread following a post of my own.

Re: [SQL] SQL Challenge: Arbitrary Cross-tab

2004-08-17 Thread Joe Conway
Josh Berkus wrote: The Problem: for each case there are from zero to eight timekeepers authorized to work on the case, out of a pool of 150 timekeepers. This data is stored vertically: authorized_timekeepers: case_id | timekeeper_id 213447 | 047 132113 | 021 132113 | 115 132113 |

Re: [SQL] reply to setting

2004-08-11 Thread Joe Conway
Bruno Wolff III wrote: On Sat, Aug 07, 2004 at 09:33:08 +0530, Kenneth Gonsalves [EMAIL PROTECTED] wrote: any reason why the default reply-to on this list should not be set to the list? I keep replying to postings only to find later that the reply goes to the OP and not to the list. reply-all

Re: [SQL] Wierded error in recursive function; debugging ideas?

2004-08-11 Thread Joe Conway
Josh Berkus wrote: [2] Wrong datatype for second argument in call to in_array SQL: SELECT sf_event_decendants(66645,111) Are you sure this message isn't coming from some PHP middleware, e.g. peardb or something. See: http://us2.php.net/manual/en/function.in-array.php Joe

Re: [SQL] function expression in FROM may not refer to other relations

2004-08-10 Thread Joe Conway
Philippe Lang wrote: But the same query with a parameter returns an error: select id, usr, code, line1, line2 from tbl, get_lines(code); -- ERROR: function expression in FROM may not refer to other relations of same query level This is as expected and required -- you cannot refer to other FROM

Re: [SQL] ERROR: Cross-database references are not implemented

2004-08-10 Thread Joe Conway
Theo Galanakis wrote: How do I explicidly create a cross-database reference? Mind you these databases are on the same server. In MSSQL you could do that through enterprise manager. Any help would be appreciated. You cannot do cross database references per se, but you can use schemas, which

Re: [SQL] contrib/tablefunc crosstab

2004-08-05 Thread Joe Conway
Caleb Simonyi-Gindele wrote: My problem is that the rows are populated from right to left irrespective of the column. So the $561.99 in vet1 actually belongs to vet2. There are never any blank cells in the middle or start of a row - they always come at the end. How do I get the amount for that

Re: [SQL] Converting a plperlu function to a plpgsql function

2004-07-22 Thread Joe Conway
Devin Whalen wrote: First line: my @active_tables=split(/,/,$tables); Is there anyway to split a variable like the perl split above? I'm no perl guru, but in 7.4 I believe this does what you're looking for: regression=# select string_to_array('1,2,3',','); string_to_array -

Re: [SQL] Empty array IS NULL?

2004-06-28 Thread Joe Conway
Markus Bertheau wrote: is the empty array representable in PostgreSQL, and is it distinguishable from NULL? Yes, and yes. regression=# select '{}'::int[]; int4 -- {} (1 row) regression=# select NULL::int[]; int4 -- (1 row) Since NULL array elements are not currently supported,

Re: [SQL] Empty array IS NULL?

2004-06-28 Thread Joe Conway
Markus Bertheau wrote: How do I specify an empty array with the standard syntax? Actually, up until the 7.4 release, the array literal syntax was the *only* syntax (i.e. '{...}'). The newer array constructor expression (i.e. ARRAY[...]) does not yet support creating empty arrays -- there are

Re: [SQL] Empty array IS NULL?

2004-06-28 Thread Joe Conway
Markus Bertheau wrote: How do I specify an empty array with the standard syntax? Actually, up until the 7.4 release, the array literal syntax was the *only* syntax (i.e. '{...}'). The newer array constructor expression (i.e. ARRAY[...]) does not yet support creating empty arrays -- there are

Re: [SQL] pivot-like transformation

2004-06-20 Thread Joe Conway
Torsten Lange wrote: Hello, I have a table with measurement values and columns like this: analyses(id, sample_id, parameter[temperatur...], value, unit[?C...], error) With PL/PgSQL at the end I want try to perform a pivot-like arrangement of these data:

Re: [SQL] Last day of month

2004-06-08 Thread Joe Conway
Greg Sabino Mullane wrote: How to find the last sunday/mon/sat of any given month. There is probably a smoother way to do it, but here is a quick little function to do what you ask. Feed it a date and a number, where 0 is Sunday, 1 is Monday, etc. How about this: regression=# select

Re: [SQL] function returning array

2004-04-15 Thread Joe Conway
Dennis wrote: pg 7.4.1 I should have listed the source for the function. Here is a simplified parseString function and the foo that calls it. dennis=# create or replace function parseString (varchar, varchar) dennis-# RETURNS varchar[] AS ' dennis'# DECLARE dennis'#

Re: [SQL] function returning array

2004-04-13 Thread Joe Conway
Dennis wrote: I am trying to return an array from a function and don't seem to be having luck. The function seems to work fine, but if I do assignment to an array variable, I get null in the array elements DECLARE results varchar[]; tmpv varchar; BEGIN -- now call func that returns

Re: [SQL] SQL Standatd

2004-04-07 Thread Joe Conway
Bruce Momjian wrote: Martin Marques wrote: Also, for some reason I can't get to sqlstandards.org. Is there any other place where I can get the SQL200X docs? Not sure. See: http://www.wiscorp.com/sql/sql_2003_standard.zip Joe ---(end of

Re: [SQL] [pgsql-advocacy] SQL Spec Compliance Questions

2004-04-02 Thread Joe Conway
Josh Berkus wrote: 4.16.2 Referenceable tables, subtables, and supertables A table BT whose row type is derived from a structured type ST is called a typed table. Only a base table or a view can be a typed table. A typed table has columns corresponding, in name and

Re: [SQL] Array_append does not work with Array variables in PL/pgSQL?

2004-04-01 Thread Joe Conway
Josh Berkus wrote: v_vals TEXT[]; n_vals TEXT[]; try: v_vals TEXT[] := ''{}''; n_vals TEXT[] := ''{}''; You have to initialize the array to something non-null, even if that be an empty array (note that there is a difference). When trying to append an element to a NULL valued array, you

Re: [SQL] Array_append does not work with Array variables in PL/pgSQL?

2004-04-01 Thread Joe Conway
Josh Berkus wrote: BTW, did you get my e-mail to Hackers about ARRAY[] IS NULL? I saw it, but I've been too swamped to really read it. I'll try to carve out some time this afternoon. Joe ---(end of broadcast)--- TIP 5: Have you checked our

Re: [SQL] [pgsql-advocacy] SQL Spec Compliance Questions

2004-04-01 Thread Joe Conway
Josh Berkus wrote: 6) SQL-99 Distinct Types 7) SQL-99 Structured Types 9) SQL-99 Collection Types 10) SQL-99 Typed tables and views My answers: 6), 7) Not sure what these are. Here's the section in SQL99: 4.8 User-defined types A user-defined type is a schema object, identified by a

Re: [SQL] Encoding bytea

2004-03-03 Thread Joe Conway
Achilleus Mantzios wrote: is there a way to encode a bytea in such a way that the resulting text stream be readily available (\\ escaped for unprintable chars) for usage in an insert statement? None of base64,hex,escape options in encode() seem to produce anything close. This is meant to be

Re: [SQL] returning a recordset from PLpg/SQL

2004-03-01 Thread Joe Conway
Tom Lane wrote: Stephan Szabo [EMAIL PROTECTED] writes: On Tue, 2 Mar 2004, Terence Kearns wrote: Well I haven't yet done anything because I couldn't get anything to compile which returned SETOF RECORD.. As a starting point, SETOF RECORD is different from SETOF RECORD given PostgreSQL's fold case

Re: [SQL] Trouble with composite types

2004-02-29 Thread Joe Conway
Yasir Malik wrote: [attempts to use a composite type as a field data type of another composite type] When I enter that into the command prompt, I the following message: ERROR: Attribute street has composite type street_type Why is it giving me error message for something I know is true? Also,

Re: [SQL] plpgsql function returning SETOF RECORD Question

2004-02-29 Thread Joe Conway
[EMAIL PROTECTED] wrote: When I run the function below I recieve an error message saying that column definitions need to be specified for a function returing a type RECORD. I was under the impression that the FOR row IN SELECT... loop would assign a column structure to the RECORD type. Am I wrong

Re: [SQL] Scalar in a range (but textual not numeric)

2004-02-25 Thread Joe Conway
Richard Huxton wrote: That's not quite the same though, because it means I need to split ABCAA..ABDBB into ABCAA..ABCZZ and ABDAA..ABDZZ but it's close enough unless someone is feeling clever this evening. Would (a series of) partial indexes help? Joe ---(end of

Re: [SQL] Last day of month

2004-02-25 Thread Joe Conway
Greg Sabino Mullane wrote: How to find the last sunday/mon/sat of any given month. There is probably a smoother way to do it, but here is a quick little function to do what you ask. Feed it a date and a number, where 0 is Sunday, 1 is Monday, etc. oops...forget my last reply...I was a bit

Re: [SQL] crosstabs

2004-02-19 Thread Joe Conway
Philippe Lang wrote: I need to do something similar to a cross tabulation, but without any aggregation. See the crosstab() function found in contrib/tablefunc Joe ---(end of broadcast)--- TIP 2: you can get off all lists at once with the unregister

Re: [SQL] Compiling pl/pgsql functions

2004-02-19 Thread Joe Conway
Rodrigo Sakai wrote: I insist in my question, is there a way to compile the plpgsql codes or something like that no think about writting this postgres functions in C?? yes Joe ---(end of broadcast)--- TIP 9: the planner will ignore your desire

Re: [SQL] arrays and polygons

2004-02-13 Thread Joe Conway
Tom Lane wrote: David [EMAIL PROTECTED] writes: INSERT INTO species (location) VALUES ('{((432,89), (45,87), (89,87)), ((54,78), (34,98))}; I think you'd need to double-quote each polygon within the array literal. '{((432,89), (45,87), (89,87)), ...}' The array parser doesn't think parens are

Re: [SQL] array_lower /array_prepend doubt

2004-02-12 Thread Joe Conway
Bruce Momjian wrote: Is this a TODO? Probably -- something like: Modify array literal representation to handle array index lower bound of other than one Joe ---(end of broadcast)--- TIP 6: Have you searched our list archives?

Re: [SQL] How to retrieve N lines of a text field.

2004-01-29 Thread Joe Conway
Chris Travers wrote: This is a complex issue, and i am tryign to figure out how to use regular expressions to resolve this issue. I need to retrieve the first N lines of a text field. N would be assigned using a parameterized query, if possible. How 'bout something like this: CREATE OR REPLACE

Re: [SQL] array_lower /array_prepend doubt

2004-01-21 Thread Joe Conway
Tom Lane wrote: Rajesh Kumar Mallah [EMAIL PROTECTED] writes: can anyone explain why SELECT array_lower(array_prepend(0, ARRAY[1,2,3]), 1); returns 0 not 1 Because array_prepend keeps the subscripts of the existing array elements the same. This was discussed during development of the code, but I

Re: [SQL] array_lower /array_prepend doubt

2004-01-21 Thread Joe Conway
Tom Lane wrote: The other point about pg_dump failing to correctly restore arrays with nondefault lower bounds is a good one, though. We need to think about how to fix that. I'll put some thought into it, but note that it is hardly a new issue -- it's been possible to create an array with 1

Re: [SQL] array_lower /array_prepend doubt

2004-01-21 Thread Joe Conway
Tom Lane wrote: Of course; I suppose this bug goes back to Berkeley days. We just hadn't recognized it before (or at least I hadn't). Neither had I. But the changes in 7.4 probably make it more likely people will bump into this as a problem. Without looking to confirm, I believe SQL99 defines

Re: [SQL] Fetching a single column from a record returning function

2004-01-20 Thread Joe Conway
Kumar wrote: select * from .fn_email(1) as (email_folder_id int4,email_folder_name varchar,descrip varchar,msgcount int8,unreadcount int8,size int8); Is it possible to fetch only one column (the 'msgcount') from the function. Because I am interested in SUM(msgcount). Please shed some light.

Re: [SQL] Problem with plpgsql function

2004-01-15 Thread Joe Conway
Chris Bowlby wrote: select get_account_info('test.com'); I get this error: ERROR: set-valued function called in context that cannot accept a set This is the classic SRF error -- you need to use an SRF like a relation in the FROM clause, so do this instead: select * FROM

Re: [SQL] Seq Scans when index expected to be used

2003-11-29 Thread Joe Conway
jasiek wrote: On Sat, 29 Nov 2003 08:49:24 -0800 (PST), ow wrote explain select b, c, a from test group by b, c, a having count(*) 1 Why would you expect this to use an index scan when it needs to read the entire table? If you read the whole table (or even a significant fraction of it), a seq

Re: [SQL] Seq Scans when index expected to be used

2003-11-29 Thread Joe Conway
ow wrote: My impression was that the index I_bca covers the query, hence there should not be a need to go to the table itself. Why would it? Postgres always has to go to the table. The ability to read data directly from indexes (ala other RDBMSs) has been discussed, but not implemented. IIRC

Re: [SQL] Equivalent of Reverse() functions

2003-11-27 Thread Joe Conway
Kumar wrote: I am migrating an SQL Server 2000 database to Postgres 7.3.4 running on RH Linux 7.2. While migrating I encounter SQL Server REVERSE( ) function, seems no such functions at Postgres. Is there a equivalent function available at Postgres? Please shed some light How about: create or

Re: [SQL] Scaler forms as function arguments

2003-11-27 Thread Joe Conway
Andreas Tille wrote: test=# select PLpgSQLDepartmentSalaries() ; This should be: regression=# select * from PLpgSQLDepartmentSalaries(); departmentid | totalsalary --+- 1 | 8 2 | 6 (2 rows) HTH, Joe

Re: [SQL] Query Problem

2003-11-10 Thread Joe Conway
Abdul Wahab Dahalan wrote: If I've a table like below. kk kjpngkvote 01 02 c 10 01 02 b 5 How do I make a query so that I can get a result like this? kk kjpngkvote 01 02c,b 15 create or replace function

Re: [SQL] connectby

2003-10-28 Thread Joe Conway
BenLaKnet wrote: I use postgresql 7.2.3 How can I use connectby ?? Must I install files ? or packages ? or it is recommanded to upgrade dataserver ? You need to upgrade. Either install 7.3.4 or wait a few weeks and install 7.4 when it is released. Joe ---(end of

Re: [SQL] Crosstab question

2003-10-20 Thread Joe Conway
Adam Witney wrote: The missing values seemed to have been ignored and so the data is being shifted to the left and so put in the wrong columns. Am I using this function correctly? What is supposed to happen with missing values? Yeah, that's a limitation of the version of crosstab distributed with

Re: [SQL] Oracle 'connect by prior' now eaiser in 7.3?

2003-10-14 Thread Joe Conway
Thomas Wegner wrote: SELECT ID_WINUSER FROM connectby('WINUSER', 'ID_WINUSER', 'REF_ID_WINUSER', 4, 0, '~') AS t(ID_WINUSER integer) and get this error: ERROR: Query-specified return tuple not valid for Connectby: wrong number of columns Please see the documentation (README.tablefunc). You need

Re: [SQL] Mystery function error

2003-09-28 Thread Joe Conway
Tom Lane wrote: Josh Berkus [EMAIL PROTECTED] writes: Also, this will run faster if you do it as a SQL function: CREATE FUNCTION locate ( text, text ) RETURNS INT AS ' SELECT POSITION($2, $1); ' LANGUAGE SQL IMMUTABLE STRICT; This is definitely the solution I'd recommend for 7.4 (because 7.4

Re: [SQL] Mystery function error

2003-09-27 Thread Joe Conway
Richard Sydney-Smith wrote: CREATE OR REPLACE FUNCTION public.locate(bpchar, bpchar) RETURNS int4 AS ' -- search for the position of $2 in $1 declare srcstr alias for $1; searchstr alias for $2; begin return position(searchstr in srcstr); ' LANGUAGE 'plpgsql' VOLATILE; You are missing the end

Re: [SQL] Oracle 'connect by prior' now eaiser in 7.3?

2003-09-22 Thread Joe Conway
Merrall, Graeme wrote: Am I right in thinking that recursive procedures and procs returning row sets would allow us to better emulate this behaviour? As anyone looked at it yet? See connectby() in contrib/tablefunc. Someone was working on SQL99 recursive queries but it didn't get done for 7.4 --

Re: [SQL] How to return a record set from function.

2003-08-28 Thread Joe Conway
Kumar wrote: Create table t1 (c1 int, c2 varchar, c3 varchar); Create or Replace function sel_t1 () returns setof records as ' select c1, c2, c3 from t1; ' Language SQL; It was fine and created a function. while i execute it as select sel_t1; I got the following error. ERROR: Cannot display

Re: [SQL] length of array

2003-08-28 Thread Joe Conway
Chris Faulkner wrote: Is there a function in postgres to return the length of an array field ? I have seen array_dims(array) but this returns a character value. Ideally, I'd like something numeric returned. Afraid not in 7.3.x or earlier. In 7.3.x (but not earlier) you *can* do this (for a

Re: [SQL] SELECT IN Still Broken in 7.4b

2003-08-20 Thread Joe Conway
Mike Winter wrote: On Wed, 20 Aug 2003, Rod Taylor wrote: Ensure your IN list is unique. You might find better times by through an indexed temp table. That is what I ended up doing, but it's not a very elegant solution. MySQL does queries of this type orders of magnitudes faster than Postgres on

Re: [SQL] Table conversion query...

2003-08-20 Thread Joe Conway
George McQuade wrote: date tran glamt 08/20/03 1001 3010 -30.00 08/20/03 1001 1030 -300.00 08/20/03 1001 1060 +330.00 08/20/03 1002 ...next transaction ... and I need to convert to: date glcr gldb amt 08/20/03 1060 3010 30.00 08/20/03 1060 1030 300.00 in other words, the

Re: [SQL] Table conversion query...

2003-08-20 Thread Joe Conway
George McQuade wrote: Interesting, my C is gone a long time ago. Would the table function be fairly complex for someone who's never done one? I'm tempted by the java option, but initial jdbc speed tests don't look very promising (the avg file has 1/2 million records). Well this is a fairly

Re: [SQL] [PERFORM] EXTERNAL storage and substring on long strings

2003-08-06 Thread Joe Conway
Scott Cain wrote: Oh, and I forgot to mention: it's highly compressed (bzip2 -9) and is 109M. Thanks. I'll grab a copy from home later today and see if I can find some time to poke at it. Joe ---(end of broadcast)--- TIP 1: subscribe and

Re: [SQL] [PERFORM] EXTERNAL storage and substring on long strings

2003-08-04 Thread Joe Conway
Scott Cain wrote: On Mon, 2003-08-04 at 11:53, Tom Lane wrote: I find it really, really hard to believe that a crude reimplementation in plpgsql of the TOAST concept could beat the built-in implementation at all, let alone beat it by two orders of magnitude. Either there's something unrealistic

Re: [SQL] function returning setof performance question

2003-07-29 Thread Joe Conway
Mark Bronnimann wrote: I was hoping to eliminate the parse call on the view because I was doing the where clause on the view instead of putting the where in the view. In all, I was hoping to keep a single view called from multiple functions with different where clauses. Yep... I shoulda known

Re: [SQL] How access to array component

2003-07-21 Thread Joe Conway
Cristian Cappo A. wrote: Tried, but... select (foo(10::int2,20::int2))[1]; ERROR: parser: parse error at or near [ at character 32 I'm using the version 7.3.3 Sorry, it works on 7.4devel, so I thought it might on 7.3 as well. In any case, this works on 7.3.3: test=# select f1[1] from

Re: [SQL] How access to array component

2003-07-19 Thread Joe Conway
Cristian Cappo wrote: select __function(10::int2, 20::int2)[1] ^^^ parsing error. Try: create or replace function foo(int2, int2 ) returns _varchar as ' select ''{1,2}''::_varchar ' language 'sql'; regression=# select (foo(10::int2, 20::int2))[1]; foo - 1 (1 row)

Re: [SQL] casting to arrays

2003-07-18 Thread Joe Conway
Mike Rylander wrote: I have a rather odd table structure that I would like to simplify to be a view (for some definition of simplify). The current idea I have is to shovel values from multiple rows in one table into an array in the view. The tables look something like this: snip Is anything

Re: [SQL] casting to arrays

2003-07-18 Thread Joe Conway
Mike Rylander wrote: Thank you! This is great news. Is there a projected release date for 7.4? Not exactly an officially projected date, but in the past IIRC beta/RC has lasted 2 to 3 months, so I'd start looking for a 7.4 release in October. Also, is there a published roadmap, or should I

Re: [SQL] Recursive request ...

2003-07-17 Thread Joe Conway
BenLaKnet wrote: I see connect by in Oracle ??? is there an equivalent in PostgreSQL or not ?? Someone is working on the SQL99 equivalent, but it isn't done yet. Perhaps for 7.5. Joe ---(end of broadcast)--- TIP 8: explain analyze is your friend

Re: [SQL] Functional Indexes

2003-07-15 Thread Joe Conway
David Olbersen wrote: Now the question: is there a single index I can create that will be used when my WHERE clause contains either urlhost or urltld? I could create two functional indexes, but that seems a bit silly to me. I can't think of how to do only one index in 7.3.x and earlier, but

Re: [SQL] Replacing a simple nested query?

2003-07-13 Thread Joe Conway
Steve Wampler wrote: I've got a simple nested query: select * from attributes where id in (select id from attributes where (name='obsid') and (value='oid00066')); that performs abysmally. I've heard this described as the 'classic WHERE IN' problem. I may be missing something, but why

Re: [SQL] Recursive request ...

2003-07-10 Thread Joe Conway
BenoƮt Bournon wrote: I have to make a function that returns a tree with title and link of a table. Recursively, a information depends on a parent information. It is to organise a menu with parent dependance. How is it possible and faster ? in C ? pl/pgsql or other ? On 7.3 and later: see

Re: [SQL] Setuid functions

2003-07-08 Thread Joe Conway
Luis Sousa wrote: How can I set a function as setuid ? I take a look at the documetation, on Reference Manual and the only reference I saw to it was on SET SESSION AUTHORIZATION. See: http://www.postgresql.org/docs/view.php?version=7.3idoc=0file=sql-createfunction.html CREATE [ OR REPLACE ]

Re: [SQL] LEAST and GREATEST functions?

2003-07-01 Thread Joe Conway
Greg Stark wrote: SELECT greatest(a,b) FROM bar would return one tuple for every record in the table with a single value representing the greater of bar.a and bar.b. You could define your own functions to do this but it would be tiresome to define one for every datatype. In 7.4devel (just

Re: [SQL] LEAST and GREATEST functions?

2003-07-01 Thread Joe Conway
Joe Conway wrote: In 7.4devel (just starting beta) you can do this: Actually to correct myself, we just started feature freeze for 7.4, with beta planned to start on or about July 15th. Sorry for any confusion caused. Joe ---(end of broadcast

Re: [SQL] LEAST and GREATEST functions?

2003-07-01 Thread Joe Conway
Josh Berkus wrote: create or replace function greatest(anyelement, anyelement) returns anyelement as 'select case when $1 $2 then $1 else $2 end' language 'sql'; Way cool. I'd have to imagine that it would blow up if you did this, though: select greatest ( 512, now() ); With an Operator is not

Re: [SQL] passing a record as a function argument in pl/pgsql

2003-07-01 Thread Joe Conway
Alon Noy wrote: From what I tried it is possible to create such a function but it is not possible to call it ?! Can anyone provide an example? create table foo (f1 int, f2 text); insert into foo values(1,'a'); insert into foo values(2,'b'); insert into foo values(3,'c'); create or replace

Re: [SQL] Catching DML exceptions in PL/pgSQL

2003-06-17 Thread Joe Conway
Radu-Adrian Popescu wrote: . begin _res.code:=1; select id into iid from log where id=_id; if not found then begin _res.msg:=''insert''; *insert into log (log, data) values (_log, _data); if not found* then begin

Re: [SQL] Join on delimeter aggregate query

2003-06-08 Thread Joe Conway
Michael A Nachbaur wrote: Source Target [EMAIL PROTECTED] [EMAIL PROTECTED],[EMAIL PROTECTED], It isn't clear from your description what you want (to me, anyway), but I'd guess something like this: regression=# select * from src2tgt; source| target

Re: [SQL] Using a RETURN NEXT

2003-06-08 Thread Joe Conway
Mr Weinbach, Larry wrote: But at execution time I am getting thi error : WARNING: Error occurred while executing PL/pgSQL function word_case WARNING: line 5 at return next ERROR: Set-valued function called in context that cannot accept a set You didn't show the execution time SQL statement,

Re: [SQL] generic return for functions

2003-06-01 Thread Joe Conway
Danny Su wrote: I am currently converting everything from SQL Server to PostgreSQL. This is for an application that is going to support Oracle, SQL Server and PostgreSQL at the same time. I have done a lot of the conversion already but I am stuck on functions that returns parts of views or

Re: [SQL] plpgsql + dblink() question

2003-02-07 Thread Joe Conway
Frankie wrote: The case is when I call a function (from Server 1 at psql prompt) that will call dblink to do some operation on another server(it will take certain time), i.e. Server 2, and meanwhile I just unplug the network cable to Server 2. The consequence is that the function will never

Re: [SQL] Postgres MD5 Function

2003-02-02 Thread Joe Conway
David Durst wrote: Is there anywhere I can get these in binary? Or is my only option to compile Postgres from source?? Depends on the type of binary. E.g. there is a postgresql-contrib-7.3.1-1PGDG.i386.rpm binary available here: ftp://ftp.us.postgresql.org/binary/v7.3.1/RPMS/redhat-7.3/ Joe

Re: [SQL] Postgres MD5 Function

2003-01-31 Thread Joe Conway
Larry Rosenman wrote: --On Friday, January 31, 2003 01:34:42 -0800 David Durst [EMAIL PROTECTED] wrote: Does there exsist a MD5 Function I can call??? look at /contrib/pgcrypto in the source distribution. Also worth noting is that 7.4 will have (and cvs HEAD has) a builtin md5 function:

Re: [SQL] Could someone help me fix my array_list function?

2003-01-20 Thread Joe Conway
Guy Fraser wrote: This is what I want to do: select attribute,array_list(values,1,sizeof(values)) as value from av_list; Turn : attr6 | {val3,val7,val4,val5} Into : attr6 | val3 attr6 | val7 attr6 | val4 attr6 | val5 You didn't mention the version of PostgreSQL. If you're using 7.3,

Re: [SQL] Could someone help me fix my array_list function?

2003-01-20 Thread Joe Conway
Michiel Lange wrote: Would the same work for pg_user and pg_group? See: http://www.brasileiro.net:8080/postgres/cookbook/view-one-recipe.adp?recipe_id=11378 With these groups: regression=# select * from pg_group; groname | grosysid |grolist -+--+--- grp1|

Re: [SQL] DB2 to Postgresql conversion help.

2002-12-23 Thread Joe Conway
John Pauley wrote: All, Any suggestions on a Postgresql equivalent to the following DB2 sql query: SELECT * FROM (SELECT ID,NAME,CITY,STATE,PROGRAM,CUST_NAME,CUST_ID,ROWNUMBER() OVER (ORDER BY ID ASC) AS RN FROM MERCHANT_BROWSER_VIEW WHERE CUST_ID = 'A51B8CA2' ) AS RESULT WHERE RN BETWEEN 1 AND

Re: [SQL] SQL syntax for concating values in different rows together

2002-12-10 Thread Joe Conway
Elizabeth O'Neill's Office Mail wrote: I have two tables in my database a complaint table and a resolution table. One complaint may have several resolutions. I am trying to build a report that will give me the complaint details and all the resolution descriptions for a complaint in one text

Re: [SQL] Trees: maintaining pathnames

2002-11-20 Thread Joe Conway
Dan Langille wrote: Given that I'm considering adding a new field path_name to the tree, I can't see the ltree package will give me anything more than I can get from like. My main reason for adding path_name was doing queries such as: select * from tree where path_name like

Re: [SQL] Proposal of hierarchical queries, a la Oracle

2002-11-19 Thread Joe Conway
Evgen Potemkin wrote: Joe, i've made it already,as send first 'Proposal ...' message, but found a small bug. within nearest days i'll fix it, and post the patch to pgsql-patches. Please note that there was no patch attached to your initial proposal (assuming this is the message you are

Re: [SQL] Proposal of hierarchical queries, a la Oracle

2002-11-16 Thread Joe Conway
7.3, as a /contrib module, by Joe Conway. Download 7.3b5 now if you can't wait; Joe would like more people to test his module, anyway. I have it on my personal TODO to approach this for 7.4, but I'll be happy to focus on other things if you'd like to take this on. The connectby() function

Re: [SQL] execute a query in an other db

2002-11-16 Thread Joe Conway
LR wrote: Thank you for your answer. Do you know the name of this package ? Thx Lilian see contrib/dblink. I'd highly recommend using 7.3 (finishing beta, soon to be a release candidate) if you can. It is much better than the one in 7.2 and the syntax has changed some. Joe

Re: [SQL] Multiple Databases

2002-10-23 Thread Joe Conway
Josh Berkus wrote: Is it possible to create a view using tables from two different postgresql servers? No. It isn't possible with plain old SQL, but it is possible (albeit ugly) using contrib/dblink in PostgreSQL 7.2.x. See README.dblink for documentation and examples. In PostgreSQL 7.3

Re: [SQL] Get A Tree from a table

2002-10-07 Thread Joe Conway
Scott Yaung wrote: I like to do something like this:(build a tree from relationship) [snip] How can i make it by sql , and sql functions Thanks lot and regards. There have been quite a few discussions of this topic in the past, so I would suggest you search through the archives. In 7.3

  1   2   >