Re: [SQL] Correct Insert SQL syntax?

2008-09-04 Thread Yura Gal
There is no internal dual table in PG unlike Ora:) If you need to invoke non-set-returning function simply execute: SELECT my_func(p1, p2...); -- Best regards, Yuri. -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription:

Re: [SQL] How do I get min and max from an array of floating point values

2008-09-03 Thread Yura Gal
If you use intarray type it is convenient to call buil-in intarray functions for your purpose. http://www.postgresql.org/docs/8.3/static/intarray.html SELECT t.a[1] AS min, t.a[array_upper(t.a, 1)] AS max FROM (SELECT sort(string_to_array('2,3,4,15,6,7',',')::int[]) AS a)t; -- Best regards,

Re: [SQL] Cursors..

2008-08-19 Thread Yura Gal
Take a look at http://www.postgresql.org/docs/8.3/interactive/plpgsql-cursors.html and you'll find answer you need. I need to convert this cursor of Oracle to Postgres... I wait for your help!! -- Best regards, Yuri. -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make

Re: [SQL] How to creat tables using record ID in for loop

2008-08-07 Thread Yura Gal
The function to treate tables is: CREATE OR REPLACE FUNCTION cr_tbls_by_staid() RETURNS INTEGER AS $$ DECLARE stid INTEGER; q TEXT; BEGIN FOR stid IN SELECT staid FROM mytest LOOP q:= 'CREATE TABLE s' || staid || ' (staid varchar(50), val real, dt date);' RAISE NOTICE 'query is: %',

Re: [SQL] How to creat tables using record ID in for loop

2008-08-07 Thread Yura Gal
Oh, I checked the function. There are some syntax errors. Right code listed below: CREATE OR REPLACE FUNCTION cr_tbls_by_staid() RETURNS INTEGER AS $$ DECLARE stid INTEGER; q TEXT; BEGIN FOR stid IN SELECT staid FROM mytest LOOP q:= 'CREATE TABLE s' || staid || ' (staid varchar(50), val

Re: [SQL] enumerate groups given a certain value

2008-08-07 Thread Yura Gal
Hello, Picavet. Anybody for a ray of light on a different approach ? This look like a recurrent problem, isn't there an experienced sql programmer here who tackled this issued a couple of time ? Actually, I'm not very experienced in SQL. But from my point of view this problem could be solved

[SQL] composite type cast and select statement

2008-08-05 Thread Yura Gal
I would like to get effect of selecting table record when construct a composite type. CREATE TYPE chains.foo AS ( id INTEGER, bar INTEGER ); CREATE OR REPLACE FUNCTION construct_foo(INTEGER,INTEGER) RETURNS chains.foo AS $$ DECLARE f chains.foo; BEGIN f.id := $1; f.bar := $2; RETURN f;

[SQL] GiST/GIN index for field of type VARCHAR[]

2008-04-03 Thread Yura Gal
I have following table: CREATE TABLE t1 ( name VARCHAR(500) NOT NULL, lid INTEGER NOT NULL, accs VARCHAR(20)[] NOT NULL CONSTRAINT t1_lid_key UNIQUE(lid) ); I interested in the possibility to speed-up search for rows like this: SELECT lid FROM t1 WHERE accs

Re: [SQL] RETURN QUERY generates error

2008-03-07 Thread Yura Gal
The error sounds suspiciously like what would happen if you tried to use RETURN QUERY in a pre-8.3 version. regards, tom lane Thanks a lot to all. Actually there were a mass of errors in my function. Now I rewrite it so as it works. It would be much more complicated

[SQL] RETURN QUERY generates error

2008-03-05 Thread Yura Gal
Here is my function: CREATE OR REPLACE FUNCTION hg18.get_genomeseq (_chr varchar, _byblocks boolean, _starts integer [], _ends integer []) RETURNS SETOF text AS $body$ DECLARE _startinteger; _end integer; _sequence text[]; _seq50RECORD; _seq text;

[SQL] using copy from in function

2008-03-04 Thread Yura Gal
I'm trying to automate import data using CORY FROM. For this purpose I wrote plpgsql function. As my postgres works on windows vista I need to use E'' syntax for path-to-file. This syntax works fine in SQL queries like: COPY table FROM E'path_to_file_with_double_backslashes'; Following query