Re: [SQL] function array_to_string(text[]) does not exist

2013-08-25 Thread Pavel Stehule
Hello you should to enter separator postgres=# select array_to_string(ARRAY[1,2,3,4], '|'); array_to_string ─ 1|2|3|4 (1 row) Regards Pavel Stehule 2013/8/25 Victor Sterpu > Hello > > When I run : > SELECT array_to_string(array_agg(CONCAT(CAST

[SQL] Re: [SQL] Table indexes in a SELECT with JOIN´s

2013-04-20 Thread Pavel Stehule
Hello 2013/4/20 JORGE MALDONADO > Let´s suppose that I have a SELECT statement that joins more than one > table and such a statement is order by fields that belong not only to the > table in the FROM but also by fields in the tables that are part of the > JOIN´s. How does indexes should be cons

Re: [SQL] From with case

2013-03-26 Thread Pavel Stehule
2013/3/26 Pavel Stehule : > Hello > > 2013/3/26 Ben Morrow : >> Quoth pavel.steh...@gmail.com (Pavel Stehule): >>> Dne 25.3.2013 23:51 "Ben Morrow" napsal(a): >>> > >>> > I would use a view for this: >>> > >>> >

Re: [SQL] From with case

2013-03-26 Thread Pavel Stehule
Hello 2013/3/26 Ben Morrow : > Quoth pavel.steh...@gmail.com (Pavel Stehule): >> Dne 25.3.2013 23:51 "Ben Morrow" napsal(a): >> > >> > I would use a view for this: >> > >> > create view vale_any as >> > select '

Re: [SQL] From with case

2013-03-25 Thread Pavel Stehule
This design has a performance problem. You read both tables everywhere - for large tables can be bad Dne 25.3.2013 23:51 "Ben Morrow" napsal(a): > > Quoth c...@sygecom.com.br (Mauricio Cruz): > > > > I'm working in a PL/SQL and I'd like to use the same > > PL for 2 kinds of tables... > > > > I hav

Re: [SQL] From with case

2013-03-25 Thread Pavel Stehule
SQL FOR r IN EXECUTE format('SELECT .. FROM %I ..', CASE WHEN ctip = 'P' THEN 'valapag' ELSE 'valerec' END) LOOP .. END LOOP; Regards Pavel Stehule 2013/3/25 Mauricio Cruz : > Hi everyone, > > > > I'm working in a PL/SQL and I'

Re: [SQL] xmlelement name

2013-03-12 Thread Pavel Stehule
) RETURNS xml LANGUAGE plpgsql AS $function$ declare result text; begin execute format('SELECT xmlelement(name %I, $1)', nam) USING concat(val::text, '%') INTO result; return result; end; $function$ postgres=# select xpercent('hello', 4); xperc

Re: [SQL] How to put multiples results in just one column

2013-01-31 Thread Pavel Stehule
arge.info/index.php/post/2012/03/31/Profiling-PL/pgsql-functions one note - in your function there is lot of repeated queries to table cms.room_availability_list - if this table is not small, then a function cannot be super fast. A art of writing stored procedures is in minimizing reading from l

Re: [SQL] How to put multiples results in just one column

2013-01-31 Thread Pavel Stehule
Hello select (fce(..)).column from ... or select column from fce() Regards Pavel Stehule 2013/1/31 Nei Rauni Santos : > Hi, > > The problem is, I'm working in a list of hotels which should have > availability of rooms and list the hotel and its rooms on the application

Re: [SQL] returning the number of rows output by a copy command from a function

2013-01-16 Thread Pavel Stehule
ortTable) to MyFile.csv with CSV > HEADER;'; > Execute strSQL; > > Return row_count; > > This returns a null. > > Any way to do this? > not yet it is fixed in 9.3 http://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=7ae1815961c635fd1a6fe72acb89fdef741a45a8 Regards Pavel Stehule > > Thanks in advance, > James > -- 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] returning values from dynamic SQL to a variable

2013-01-15 Thread Pavel Stehule
Hello you can use RETURN QUERY EXECUTE statement http://www.postgresql.org/docs/9.1/interactive/plpgsql-control-structures.html#PLPGSQL-STATEMENTS-RETURNING Regards Pavel Stehule 2013/1/15 kgeographer : > I have a related problem and tried the PERFORM...EXECUTE pattern suggested >

Re: [SQL] Using regexp_matches in the WHERE clause

2012-11-27 Thread Pavel Stehule
2012/11/27 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 >

Re: [SQL] Using regexp_matches in the WHERE clause

2012-11-27 Thread Pavel Stehule
instead postgres=# select * from o where a ~ 'e'; a pavel zdenek (2 rows) postgres=# select * from o where a ~ 'k$'; a zdenek (1 row) you can use regexp_matches, but it is not effective probably postgres=# select * from o where exists (select * from

Re: [SQL] matching a timestamp field

2012-09-22 Thread Pavel Stehule
cally cast to TEXT (Peter, Tom) Regards Pavel Stehule > > > > > Welcome to psql 8.1.19, the PostgreSQL interactive terminal. > > Type: \copyright for distribution terms > >\h for help with SQL commands > >\? for help with psql commands > &g

Re: [SQL] Need to Iterate the record in plpgsql

2012-09-03 Thread Pavel Stehule
Hello http://okbob.blogspot.cz/2010/12/iteration-over-record-in-plpgsql.html http://postgres.cz/wiki/PostgreSQL_SQL_Tricks#Iteration_over_RECORD_variable_inside_trigger Regards Pavel Stehule 2012/8/31 Yelai, Ramkumar IN BLR STS : > Hi All, > > I am facing a issue in Iterating t

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

2012-05-24 Thread Pavel Stehule
> > This was more like what I was thinking, but I still get an error, which I > don't understand.  I have extracted the inner sub-select and it does only > return one record per registration. (The extra criteria is just to ignore old > or cancelled tax requests and doesn't affect the query) > > goo

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

2012-05-23 Thread Pavel Stehule
(select max(ud_id), ud_registration from used_diary group by ud_registration)) x on s.s_registration = x.ud_registration; Regards Pavel Stehule > > > -- > Gary Stainburn > Group I.T. Manager > Ringways Garages > http://www.ringways.co.uk > > -- > Sent via

Re: [SQL] generic crosstab ?

2012-04-24 Thread Pavel Stehule
Hello try to use cursors http://okbob.blogspot.com/2008/08/using-cursors-for-generating-cross.html Regards Pavel Stehule 2012/4/24 Andreas : > Hi, > > is there a generic solution to dump the result of a query as a crosstab, > when I can't know how many columns I will nee

Re: [SQL] plpgsql : adding record variable to table

2012-04-19 Thread Pavel Stehule
e is not required - in pg (it is syntax from Oracle), but it is good to use it to increase readability. Regards Pavel > thanks again > Tom > > > 2012/4/19 Pavel Stehule : >> 2012/4/19 thomas veymont : >>> hi Pavel, >>> >>> thanks for your answer, >

Re: [SQL] plpgsql : adding record variable to table

2012-04-19 Thread Pavel Stehule
y as $$ declare r y; begin for r in select * from y loop return next r; end loop; return; end; you can declare composite type via command CREATE TYPE create type y as (a int, b int) Regards Pavel Stehule > cheers > Tom > > 2012/4/18 Pavel Stehule : >> Hello >&

Re: [SQL] plpgsql : adding record variable to table

2012-04-18 Thread Pavel Stehule
Hello please try: postgres=# create or replace function foo() returns void as $$ declare r x; begin for r in select * from x loop insert into y values(r.*); end loop; end; $$ language plpgsql; Regards Pavel 2012/4/18 thomas veymont : > (sorry my previous email was truncated) > > hi,

Re: [SQL] ERROR: operator does not exist: integer = integer[]

2012-04-16 Thread Pavel Stehule
Hello this is not error, you cannot use predicate IN in this context use =ANY instead postgres=> select 10 = ANY(ARRAY[1,2,3]); ?column? -- f (1 row) postgres=> select 10 = ANY(ARRAY[1,2,3,10]); ?column? -- t (1 row) Regards Pavel Stehule 2012/4/11 cesar_cast : &g

Re: [SQL] How to html-decode a html-encoded field

2012-04-10 Thread Pavel Stehule
Hello see http://postgres.cz/wiki/PostgreSQL_SQL_Tricks#Function_for_decoding_of_url_code Regards Pavel Stehule 2012/4/10 JORGE MALDONADO : > I have a table with a varchar field, such a field is HTML ENCODED. So, for > example, the string "PLAIN WHITE T'S" is saved

Re: [SQL] syntax of joins

2012-04-06 Thread Pavel Stehule
2012/4/6 Rob Sargent : > On 04/06/2012 01:23 PM, Pavel Stehule wrote: >> >> Hello >> >> 2012/4/6 Andreas: >>> >>> hi, >>> >>> is there a disadvantage to write a join as >>> >>> select   * >>> from    a, b &

Re: [SQL] syntax of joins

2012-04-06 Thread Pavel Stehule
specification join predicate and filter predicate * simple adaptability to outer join * increased protection against copy/paste bug that introduce Cartesian product Regards Pavel Stehule > -- > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) > To make changes to your subscription

Re: [SQL] how to write cursors

2012-04-04 Thread Pavel Stehule
Hello use a refcursors http://www.postgresql.org/docs/9.1/static/plpgsql-cursors.html Regards Pavel Stehule 2012/4/4 La Chi : > hi every one > > i have created this simple function which returns a column of table , i have > used simple SELECT statement , i simply want to kn

Re: [SQL] Fill array with series

2012-03-22 Thread Pavel Stehule
Hello no, there is nothing similar. Regards Pavel 2012/3/22 Lee Hachadoorian : > Is there a single function that will generate a series and return an array? > The best I've come up with is to combine array_agg and generate_series: > > SELECT array_agg(generate_series) FROM generate_series(5, 23

Re: [SQL] crosstab

2012-03-12 Thread Pavel Stehule
does? do you have tablefunc extension? http://www.postgresql.org/docs/9.1/interactive/tablefunc.html regards Pavel Stehule > Johnf > On Monday, March 12, 2012 06:01:21 PM Pavel Stehule wrote: >> Hello >> >> maybe this article helps >> http://stackoverflow.com/questi

Re: [SQL] crosstab

2012-03-12 Thread Pavel Stehule
Hello maybe this article helps http://stackoverflow.com/questions/3002499/postgresql-crosstab-query there are more ways Regards Pavel Stehule 2012/3/12 John Fabiani : > Hi, > I don't know if it because I'm as sick as dog or I'm just a plain idiot - most > likely a

Re: [SQL] date arithmetic with columns

2012-03-03 Thread Pavel Stehule
Hello 2012/3/1 Peter Faulks : > Bit more googling and I came up with: > > r.utc + CAST( tz.diffmins || ' ' || 'minutes' AS interval) > > It works, but is it the best way? > r.utc + tz.diffmins * interval '1 minute' regards Pavel Stehule >

Re: [SQL] How to shrink database in postgresql

2012-02-29 Thread Pavel Stehule
Hello the most similar tool in pg is "VACUUM FULL" statemet; Regards Pavel Stehule 2012/2/29 Rehan Saleem : > hi , > how can i shrink database in postgresql here is a MS-SQL store procedure > which shrinks the database. how same task can be achieved in postgresql. >

Re: [SQL] MS-SQL Store Procedure to Postgresql Function

2012-02-02 Thread Pavel Stehule
Hello 2012/2/2 F. BROUARD / SQLpro : > Actullay there is no transaction support in internal PG routines. > So the code you posted is not translatable in PG PL/SQL because it involve a > transaction inside the process. It is not exact in this case - it is error handling - and plpgsql supports it -

Re: [SQL] How to Return Table From Function

2012-01-22 Thread Pavel Stehule
es$# return; postgres$# end; postgres$# $$ language plpgsql; CREATE FUNCTION postgres=# select * from rt2(); a │ b ┼ 10 │ 20 30 │ 40 (2 rows) Regards Pavel Stehule -- 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] PostgreSQL Function

2012-01-18 Thread Pavel Stehule
EPTION 'bad last_name: "%"', lname; END IF; INSERT INTO users(first_name, last_name) VALUES(lname, fname) RETURNING id INTO r; RETURN r; END; $$ LANGUAGE plpgsql; postgres=# select new_user('pavel','stehule'); new_user -- 1 (1 row) post

Re: [SQL] Call function with dynamic schema name

2012-01-15 Thread Pavel Stehule
ACE FUNCTION s2.fx1() RETURNS int AS $$ BEGIN RETURN (SELECT MAX(a) FROM s2.a1); END $$ LANGUAGE plpgsql; SET search_path TO s1; SELECT fx1(); -- returns max from s1.a1; SET search_path TO s2; SELECT fx1(); -- returns max from s2.s1; Regards Pavel Stehule > > Thanks in advance. &g

Re: [SQL] Call function with dynamic schema name

2012-01-15 Thread Pavel Stehule
em to use dynamic > schema name more similiar to Oracle. Another pl language is also ok. There are no similar way to Oracle. You can set a search_path variable, but you have to be careful, because cached plans in PL/pgSQL can do some issues, when function is called again with different search

Re: [SQL] prepared statements

2011-12-07 Thread Pavel Stehule
s? use a array parameter, please regards Pavel Stehule -- 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] Does anyone know of any issues around ARRAY UNNEST

2011-11-24 Thread Pavel Stehule
UPDATE activity SET activity_recency_timestamp = CURRENT_TIMESTAMP WHERE > venue_id IN (SELECT venue_id FROM UNNEST(v_venue_id_list) venue_id); > > This is not effective code try to use UPDATE activity SET activity_recency_timestamp = CURRENT_TIMESTAMP WHERE venue_id = ANY(v_venue_id_list) Re

Re: [SQL] Returning data from multiple functions

2011-11-10 Thread Pavel Stehule
2011/11/10 tlund79 : > I know got this far thanks to Pavle Stehule. The function worked and returned > the data when the variables was predefined after "return query". > > When tried to replace these with variables passed through the function call > I got this message; > ERROR:  syntax error at or

Re: [SQL] Different order by behaviour depending on where clause?

2011-10-27 Thread Pavel Stehule
(not even close; haven't been able to see any pattern). > > Any idea how I can further analyse/diagnose this? > > regards, > Jan > Look on EXPLAIN - these queries will have a different execution plan http://www.postgresql.org/docs/8.4/static/sql-explain.html Regards Pavel Stehu

Re: [SQL] advice on how to store variable attributes

2011-10-22 Thread Pavel Stehule
> > Yeah, thanks for the advice David, if i understand you. this is (much better > explained) my option 3, i have used this format any times for configuration > tables with great success. > > I am not speaking about much data, maybe 200~300 invoices every month so this > should not be a problem in

Re: [SQL] advice on how to store variable attributes

2011-10-22 Thread Pavel Stehule
2011/10/22 David Johnston : > On Oct 22, 2011, at 10:07, Pavel Stehule wrote: >> 2011/10/22 David Johnston : >>> On Oct 22, 2011, at 6:41, Linos wrote: >>> >>>> Hi all, >>>>    i need a little of advice on what could be the best way to store thi

Re: [SQL] advice on how to store variable attributes

2011-10-22 Thread Pavel Stehule
>> but still don't seem a clean solution for me. >> >> For me it seems i am missing something, probably any of you have a much more >> elegant (or correct) way to handle this situation, what would be your advice? >> Thanks. >> >> > > Create a table w

Re: [SQL] where col1 not ilike ('str1%', 'str2%'... 'strN%') support?

2011-08-31 Thread Pavel Stehule
" ilike ('str1', ... 'strN')" is more intuitive, isn't it? >> >> It is not. It is like "where id = (3, 5, 7)". > > > What I mean is ilike ('%str1%', ... '%strN%') > > I just forgot to put % it useless to introdu

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

2011-08-22 Thread Pavel Stehule
RETURN qty; END; $$ LANGUAGE plpgsql IMMUTABLE STRICT; try to read a documentation first, please http://www.postgresql.org/docs/9.0/interactive/plpgsql.html Regards Pavel Stehule > However, this throws a syntax error on to_number. This my first attempt at a > stored procedure in Postgres .

Re: [SQL] sorting months according to fiscal year

2011-08-22 Thread Pavel Stehule
R REPLACE FUNCTION sort_month(int) RETURNS int -- is wrong to use numeric here AS $$ ... $$ LANGUAGE sql; SELECT sort_ month(to_nuber(...)) Regards Pavel Stehule > > > -- > View this message in context: > http://postgresql.1045698.n5.nabble.com/sorting-months-according-to-fisca

Re: [SQL] Cursor names in a self-nested function

2011-08-18 Thread Pavel Stehule
Hello you can use a refcursor type http://developer.postgresql.org/pgdocs/postgres/plpgsql-cursors.html Regards Pavel Stehule 2011/8/18 Kidd, David M : > Hi, > > I am trying to write a function that contains a cursor and iteratively calls > itself. > > It is along the li

Re: [SQL] F_TABLE_NUMBER_RANGE equivalent in Postgresql

2011-08-15 Thread Pavel Stehule
Hello this is not built in MSSQL, but PostgreSQL has a "generate_series" function Regards Pavel Stehule 2011/8/16 msi77 : > > Are you sure that dbo.F_TABLE_NUMBER_RANGE is in SQL Server? > I suppose that this is UDF written by user. > > > 16.08.2011, 08:53, "

Re: [SQL] LTREE extension and "order by"

2011-07-21 Thread Pavel Stehule
der versions you can use http://www.pgsql.cz/index.php/PostgreSQL_SQL_Tricks#Cast_to_varchar Regards Pavel Stehule -- 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] newbie question * compare integer in a "where IN" statement

2011-07-13 Thread Pavel Stehule
Hello you can try SELECT .. FROM .. WHERE id = ANY(string_to_array('1,2,3,4,5',',')) other forms are slow Regards Pavel Stehule 2011/7/13 Jose Ig Mendez > > Hi everybody, > > I'm trying to compare in a sentence like this (using PostGres 8.3) : > >

Re: [SQL] using explain output within pgsql

2011-07-10 Thread Pavel Stehule
th: 46 Filter: "((value)::text = 'a'::text)" DO > best regards, > Uwe > > On 10 July 2011 21:20, Pavel Stehule wrote: >> >> Hello >> >> >> >> 2011/7/10 Uwe Bartels : >> > Hi, >> > >> > I'm sta

Re: [SQL] using explain output within pgsql

2011-07-10 Thread Pavel Stehule
> database. > Now I'd like to store besides the results the dependencies to the tables > which were used to generate the report. with this information i could > invalidate cache results for the tables I'm going to import with my etl Hello try FOR l_explain IN EXPLAIN

Re: [SQL] overload

2011-07-08 Thread Pavel Stehule
Hello using a "window" implemented via LIMIT OFFSET is not good - it is solution on some systems where cursors are not available, but it is bad solution on PostgreSQL. Use a cursor instead - it is significantly more efective with less memory requests. Regards Pavel Stehule 2011/

Re: [SQL] Usage of function retruning record in query

2011-07-05 Thread Pavel Stehule
>> > Hmm.. no takers? I guess not possible then? > Thanks anyway > hello try to wrap your query to subselect, npcps_201=# select 1,2,2,3; ?column? │ ?column? │ ?column? │ ?column? ──┼──┼──┼── 1 │2 │2 │3 (1 row) Ti

Re: [SQL] best performance for simple dml

2011-06-27 Thread Pavel Stehule
t remove a connection cost, but nothing more. You can use a more connections to do paralel inserts - it has a sense. look on pgpool or other similar sw for connection pooling Pavel > > --- On *Mon, 6/27/11, Pavel Stehule * wrote: > > > From: Pavel Stehule > Subject: Re:

Re: [SQL] best performance for simple dml

2011-06-27 Thread Pavel Stehule
) exec("insert into foo values($1), itoa(i)); exec('commit'); Regards Pavel Stehule > > --- On Mon, 6/27/11, Pavel Stehule wrote: > > From: Pavel Stehule > Subject: Re: [SQL] best performance for simple dml > To: "chester c young" > Cc: pgsql-sql@po

Re: [SQL] best performance for simple dml

2011-06-26 Thread Pavel Stehule
Hello try it and you will see. Depends on network speed, hw speed. But the most fast is using a COPY API http://www.postgresql.org/docs/9.0/interactive/libpq-copy.html Regards Pavel Stehule 2011/6/27 chester c young > what is the best performance / best practices for frequently-used sim

Re: [SQL] a strange order by behavior

2011-06-23 Thread Pavel Stehule
2011/6/23 Peter Eisentraut : > On tor, 2011-06-23 at 05:57 +0200, Pavel Stehule wrote: >> 2011/6/22 Peter Eisentraut : >> > On ons, 2011-06-22 at 02:39 -0700, Samuel Gendler wrote: >> >> Pavel suggested using a collation of ucs_basic, but I get an error >&g

Re: [SQL] a strange order by behavior

2011-06-22 Thread Pavel Stehule
2011/6/22 Peter Eisentraut : > On ons, 2011-06-22 at 02:39 -0700, Samuel Gendler wrote: >> Pavel suggested using a collation of ucs_basic, but I get an error >> when I >> try that on linux: >> >> $ createdb -U u1 --lc-collate=ucs_basic -E UTF-8 test >> createdb: database creation failed: ERROR:  in

Re: [SQL] a strange order by behavior

2011-06-22 Thread Pavel Stehule
rád Syn Záruba Šebíšek (6 rows) postgres=# select * from x order by a collate "cs_CZ"; a --- Crha Chromečka Semerád Syn Šebíšek Záruba (6 rows) Regards Pavel Stehule -- 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] a strange order by behavior

2011-06-22 Thread Pavel Stehule
Hello Peter > Pavel suggested using a collation of ucs_basic, but I get an error when I > try that on linux: > $ createdb -U u1 --lc-collate=ucs_basic -E UTF-8 test > createdb: database creation failed: ERROR:  invalid locale name ucs_basic isn't this a bug in collations? Regards Pavel > I wa

Re: [SQL] a strange order by behavior

2011-06-22 Thread Pavel Stehule
Hello a equalent of C collate for UTF8 is ucs_basic Regards Pavel Stehule 2011/6/22 Samuel Gendler : > > > On Tue, Jun 21, 2011 at 3:37 AM, Eyal Wilde wrote: >> >> the database collation is: en_US.UTF-8 >> drop table t1; >> create table t1 (recid int ,f1 varch

Re: [SQL] problem with selecting from a function

2011-06-20 Thread Pavel Stehule
> 7, (14, 'bla') > 7, (17, 'blu') > 7, (21, 'ble') <--- round brackets > This looks like an array but how can I split it up to columns or at least > extract the number-column? > this is composite value you can try SELECT object_id, (fctX(object_id

Re: [SQL] FOR EACH STATEMENT trigger ?

2011-05-09 Thread Pavel Stehule
Hello it isn't bug. PostgreSQL doesn't support NEW and OLD tables like MSSQL does for statement triggers. Regards Pavel Stehule 2011/5/6 Frédéric BROUARD : > Hi there > > I am trying to get an example of SET BASED trigger logic with FOR EACH > STATEMENT, but I cannot find

Re: [SQL] FOR EACH STATEMENT trigger ?

2011-05-06 Thread Pavel Stehule
support NEW or OLD tables in statement triggers. You should to use ROW triggers. Regards Pavel Stehule > Let me give you a real life example. > > Suppose we have the above table : > > CREATE TABLE T_PRODUIT_DISPO_PDD > (PRD_ID         INT         NOT NULL, >  PDD_BEGIN  

Re: [SQL] PLpgSQL variables persistance between several functions calls

2011-05-02 Thread Pavel Stehule
Hello no, it's not possible Regards Pavel Stehule 2011/5/2 Charles N. Charotti : > Hello everybody ! > > I want to know if I could share PLpgSQL variables between different > functions and within different calls just using memory (not tables or other > methods). > >

Re: [SQL] update with recursive query

2011-04-14 Thread Pavel Stehule
Hello it is possible in 9.1. In older version you have to use a temp table. Regards Pavel Stehule 2011/4/14 Steven Dahlin : > Is it possible to execute an update using recursion?  I need to update a set > of records and also update their children with the same value.  I tried the >

Re: [SQL] Obscure behavior of ORDER BY

2011-03-23 Thread Pavel Stehule
his is correct, because spaces and white chars are ignored. Regards Pavel Stehule. 2011/3/21 Tambet Matiisen : > Hi everyone! > > I recently noticed obscure behavior of ORDER BY. Consider this example: > > select email from > ( > select '@'::text as email > union

Re: [SQL] Retrieve the column values of a record without knowing the names

2011-02-18 Thread Pavel Stehule
Hello you can't simply iterate over record in plpgsql. You can use a some toolkits like PLToolkit, or different PL language like PLPerl, or some dirty trick http://okbob.blogspot.com/2010/12/iteration-over-record-in-plpgsql.html regards Pavel Stehule 2011/2/16 arthur_info : >

Re: [SQL] Function compile error

2011-02-16 Thread Pavel Stehule
/plpgsql.html Regards Pavel Stehule 2011/2/16 Sivannarayanreddy > Hello, > I am trying to create the function as below but it is throwing error > 'ERROR: syntax error at or near "DECLARE"', Could some one help me please > > CREATE FUNCTION check_password(databasen

Re: [SQL] Oracle Equivalent queries in Postgres

2011-02-16 Thread Pavel Stehule
2011/2/16 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 >

Re: [SQL] Oracle Equivalent queries in Postgres

2011-02-16 Thread Pavel Stehule
gards Pavel Stehule 2011/2/16 Sivannarayanreddy > Hi Pavel, > In the given link, there are no views which can give information about > indexes. > > Is it possible for you to give me the equivalent queries in postgres? > > *Sivannarayanareddy Nusum** **| **System Analyst(Mone

Re: [SQL] Oracle Equivalent queries in Postgres

2011-02-16 Thread Pavel Stehule
Hello PostgreSQL uses a different system tables than Oracle. Try to use a standardized information_schema instead - these views are same on PostgreSQL and Oracle. http://www.postgresql.org/docs/current/static/information-schema.html Regards Pavel Stehule 2011/2/16 Sivannarayanreddy

Re: [SQL] PL/SQL block error

2011-02-16 Thread Pavel Stehule
Hello you should to wrap code to function or inline function everywhere. psql doesn't support PL/SQL and doesn't support inlined PL/SQL blocks. Regards Pavel Stehule 2011/2/16 Sivannarayanreddy > Hello, > I am very new to the postgres sql, i am trying to execute below p

Re: [SQL] Determine length of numeric field

2011-02-15 Thread Pavel Stehule
Hello probably you have to use a explicit cast postgres=# select length(10::numeric::text); length 2 (1 row) Regards Pavel Stehule 2011/2/15 Tony Capobianco : > I'm altering datatypes in several tables from numeric to integer.  In > doing so, I get the following er

Re: [SQL] "select c1, method(c2) group by c1" returns all values of c2 for c1

2011-02-08 Thread Pavel Stehule
> > array_to_string() + array() is exactly what I am looking for! > > I just wonder that array_to_string() + array() will provide me good > performance, right? If the calculation will be based on millions records. it depend on number of groups. This is correlated subquery - it must not be

Re: [SQL] "select c1, method(c2) group by c1" returns all values of c2 for c1

2011-02-08 Thread Pavel Stehule
Hello you can use a string%agg function if you have a 9.0. On older version there is a array_agg function select c1, array_to_string(array_agg(c2),',') from T1 group by c1 regards Pavel Stehule 2011/2/8 Emi Lu : > Good afternoon, > > Is there a method to retrieve the follow

Re: [SQL] UTF characters compromising data import.

2011-02-08 Thread Pavel Stehule
rder to import  / use the data. > is impossible to import data without knowledge of encoding. you can use a some utils, that try to select a encoding http://linux.die.net/man/1/enca Regards Pavel Stehule > As always - thanks in advance for any help you might be able to provide. &g

Re: [SQL] using of select (myfunction()).* is so slow

2011-02-04 Thread Pavel Stehule
>> > > M ok Thanks...So there is no workaround/alternative to this? > yes, (SELECT x.* from func(...) x) instead SELECT (func(...)).* regards Pavel Stehule > Gerardo > > -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to

Re: [SQL] how control update rows

2011-02-03 Thread Pavel Stehule
gt;    UPDATE "T" SET >        "C" = 1 >    WHERE "ID" > 100 >    RETURNING * > ) x > It's not implemented yet. You can use a stored procedure or temp tables instead. Regards Pavel Stehule > TIA, > Sabin > > > > -

Re: [SQL] using of select (myfunction()).* is so slow

2011-02-03 Thread Pavel Stehule
Hello If you use a record expansion over function's result, then function is called once for record's field. so don't do it on slow functions. Regards Pavel 2011/2/3 Gerardo Herzig : > Hi all, im using a function of my own in a subquery, and when wonderig > about the slowliness of this one, y

Re: [SQL] aggregation of setof

2011-01-31 Thread Pavel Stehule
Hello use a array constructor instead SELECT ARRAY(SELECT ...) Regards Pavel Stehule 2011/1/31 Andreas Gaab : > Functions apparently cannot take setof arguments. > > > > Postgres 8.4: > > > > CREATE OR REPLACE FUNCTION testtable(IN setof anyarray) > >

Re: [SQL] create function problem

2010-12-30 Thread Pavel Stehule
Hello you badly use a IF statement. It's not C. Every IF must to finish with END IF this is IF .. THEN ELSEIF .. THEN .. ELSE END IF Regards Pavel Stehule 2010/12/30 Gary Stainburn : > Hi folks, > > I'm writing my first plpsql function in ages and I'm going blind tryi

Re: [SQL] data import

2010-12-21 Thread Pavel Stehule
Hello 2010/12/21 Viktor Bojović : > Hi, > > can anyone recommend me a windows and linux free tools for importing data > into postgre. > Source files are CSV or excel. PostgreSQL can read a CVS files via a COPY statement. You can use a \copy metacommand too from psql Regards

Re: [SQL] How to convert string to integer

2010-12-15 Thread Pavel Stehule
Hello you can use a ::int for converting to integer. Or better - you can alter column to integer. It will be faster and more correct. Regards Pavel Stehule 2010/12/15 venkat : > Dear All, >   How do i convert string to int > select SUM(pan_1) from customers1 where name='101

Re: [SQL] conditional aggregates

2010-12-08 Thread Pavel Stehule
Hello use a CASE statement http://www.postgresql.org/docs/7.4/static/functions-conditional.html Regards Pavel Stehule 2010/12/8 Marcin Krawczyk : > Hi list, > Can anyone advise me on creating an aggregate that would take additional > parameter as a condition ? For example, say I hav

Re: [SQL] error null value in column" concat_id" violates not-null constraint

2010-11-25 Thread Pavel Stehule
cname(parameters) so if I would to fill table auxiliar from some function, then I'll use a statement INSERT INTO auxilar SELECT * FROM funcname(..) Regards Pavel Stehule > > I get "error null value in column"concat_id" violatres not null > constraint > > &g

Re: [SQL] Need help with plpgsql function.

2010-11-14 Thread Pavel Stehule
2010/11/14 Adrian Klaver : > On Saturday 13 November 2010 11:15:51 pm Pavel Stehule wrote: > >> > } >> >> Hello >> >> you can use a RETURN QUERY statement - some like >> >> CREATE OR REPLACE FUNCTION foo(IN i int, OUT a int, OUT b int) >&g

Re: [SQL] Need help with plpgsql function.

2010-11-13 Thread Pavel Stehule
SELECT 30,40; ELSE RETURN QUERY SELECT 60,70 UNION ALL SELECT 80,90; END IF; RETURN; END; $$ LANGUAGE plpgsql; SELECT * FROM foo(1); SELECT * FROM foo(2); Regards Pavel Stehule > > > > > > -- > View this message in context: > http://postgresql.1045698.n5.nab

Re: [SQL] Trailing spaces - is there an easier way?

2010-11-04 Thread Pavel Stehule
| ''; ?column? -- (1 row) Time: 2.710 ms nic=# SELECT ''::char(6)::cstring || ''; ?column? (1 row) regards Pavel Stehule -- 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] insert into table from list or array ?

2010-10-18 Thread Pavel Stehule
Hello 2010/10/18 Andreas : >  Hi, > > is it possible to insert into a table from list or an array ? > yes, it's possible INSERT INTO tmptab SELECT v FROM unnest(string_to_array('1,2,4,2,1',',')) g(v) Regards Pavel Stehule > Suppose there

Re: [SQL] Is there a conditional string-concatenation ?

2010-10-12 Thread Pavel Stehule
Hello more simply postgres=# CREATE OR REPLACE FUNCTION public.foo(a text, b text, c text) RETURNS text LANGUAGE sql AS $function$ SELECT coalesce($1 || $2 || $3, $1 || $2, $2 || $3) $function$ Regards Pavel Stehule 2010/10/12 Osvaldo Kussama : > 2010/10

Re: [SQL] backup and document views and user functions

2010-08-30 Thread Pavel Stehule
;ll see the query PG uses. > there is much more easy way to get a function source code SELECT pg_catalog.pg_get_functiondef(oid) Regards Pavel Stehule > ex. > production=# \df+ myschema.* > > * QUERY ** > SELECT n.nspname as "Schema", >   p.proname as

Re: [SQL] backup and document views and user functions

2010-08-30 Thread Pavel Stehule
Hello 2010/8/30 David Harel : > Hi, > > I am looking for an easy way to backup views and functions. I want to store > them in our version control system. > move your functions and view to separate schema - and do backup with pg_dump -n schema regards Pavel Stehule > U

Re: [SQL] Boolean output representation.

2010-08-26 Thread Pavel Stehule
' or its possible to change the output representation, > e.g., to "true" or "false" ("1", "0")? > no, it isn't possible - you can write a simple formating function or own custom data type. Regards Pavel Stehule > Regards, > Dmi

Re: [SQL] plpgsql out parameter with select into

2010-08-17 Thread Pavel Stehule
nteger as $$ begin _status := 10; end; $$ language plpgsql; create or replace function test3() returns void as $$ declare status integer; begin select into status _status from test1(); raise notice '%', status; end; $$ language plpgsql; this working for me. postgres=# select test3()

Re: [SQL] How would I store little key-Nr to text lists?

2010-07-10 Thread Pavel Stehule
, you can use a hstore contrib module, but what you doing is best regards Pavel Stehule > > -- > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-sql > -- Sent via pgsql-sql mail

Re: [SQL]

2010-07-05 Thread Pavel Stehule
2010/7/5 silly sad : > On 07/05/10 11:18, Pavel Stehule wrote: > >>> P.S. >>> Practically for storing pictures i prefer regular files. >>> >> >> how I say - it depends on application - sometime can be useful have to >> access to all data only

Re: [SQL]

2010-07-05 Thread Pavel Stehule
2010/7/5 silly sad : > On 07/05/10 11:03, Pavel Stehule wrote: >> >> 2010/7/5 silly sad: >>> >>> On 07/05/10 10:43, Pavel Stehule wrote: >>> >>>> The good size for text or bytea is less than 100M and real max isn't >>>> 2G but

Re: [SQL]

2010-07-05 Thread Pavel Stehule
2010/7/5 silly sad : > On 07/05/10 10:43, Pavel Stehule wrote: > >> The good size for text or bytea is less than 100M and real max isn't >> 2G but it is 1G. LO isn't these limits because it isn't accessable on >> SQL level. > > any regular file on my

  1   2   3   >