Re: [SQL] From with case

2013-03-25 Thread 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 'P'::text "type", v.adiant, v.desc_per, v.cod > &

Re: [SQL] From with case

2013-03-25 Thread Ben Morrow
er, v.cod from valepag v union all select 'R', v.adiant, v.desc_per, v.cod from valerec v; then for rSql in select a.adiant, a.desc_per from vale_any a where a.type = cTip and a.cod = 2 loop You need to cast the constant in the view definitio

Re: [SQL] ZIP function

2013-03-16 Thread Ben Morrow
of the untrusted > languages. or in C you could call zlib. You can call Compress::Zlib or Archive::Zip (depending on which sort of 'zip' you mean) from (trusted) PL/Perl, provided you load the modules from plperl.on_init. Ben -- Sent via pgsql-sql mailing list (pgsql-sql@po

Re: [SQL] UPDATE query with variable number of OR conditions in WHERE

2013-03-14 Thread Ben Morrow
WHERE (field2 = value_1 OR field2 = value_2 OR .OR field2 = value_n) > > I build such a query using a programming language and, after that, I > execute it. Is this a good approach to build such a query? You can use IN for this: UPDATE table1 SET field1 = "some value&qu

[SQL] xmlelement name

2013-03-12 Thread Ben Morgan
Hi, I'm trying to write a function that will take a name as a text value, and return an XML element with that name as name, like so: create function xpercent(nam text, val int) returns xml as $$ begin return ( select xmlelement(name nam, concat(val::text, '%')) ); end; $$ language

Re: [SQL] Need help revoking access WHERE state = 'deleted'

2013-03-02 Thread Ben Morrow
Quoth lists-pg...@useunix.net (Wayne Cuddy): > On Thu, Feb 28, 2013 at 06:02:05PM +0000, Ben Morrow wrote: > > > > (If you wanted to you could instead rename the table, and use rules on > > the view to transform DELETE to UPDATE SET state = 'deleted' and co

Re: [SQL] Need help revoking access WHERE state = 'deleted'

2013-02-28 Thread Ben Morrow
it GRANT on the view? Make sure you've read section 37.4 'Rules and Privileges' in the documentation, since it explains the ways in which this sort of information hiding is not ironclad. Ben -- 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] Creating a new database with a TEMPLATE did not work

2013-02-25 Thread Ben Morrow
ate1). > > So at a guess you are actually creating the new database from template1. Also, SQL names are folded to lowercase unless they are quoted, so TEMPLATE = Default would refer to a database called "default" (if it weren't special syntax for template1), but TEMPL

Re: [SQL] Summing & Grouping in a Hierarchical Structure

2013-02-23 Thread Ben Morrow
x27;t use base64.) If you were going to do that you would need to consider the possibility of an attacker arranging a hash collision: I don't know where you're labels come from, so I don't know if this would be an issue. Ben -- Sent via pgsql-sql mailing list (pgsql-sql@p

Re: [SQL] Volatile functions in WITH

2013-02-20 Thread Ben Morrow
At 12PM -0800 on 20/02/13 you (Sergey Konoplev) wrote: > On Wed, Feb 20, 2013 at 10:16 AM, Ben Morrow wrote: > >> If you got mixed up with plpgsql anyway what is the reason of making > >> this WITH query constructions instead of implementing everything in a > >> pl

Re: [SQL] Volatile functions in WITH

2013-02-20 Thread Ben Morrow
At 8AM -0800 on 20/02/13 you (Sergey Konoplev) wrote: > On Wed, Feb 20, 2013 at 12:19 AM, Ben Morrow wrote: > > That's not reliable. A concurrent txn could insert a conflicting row > > between the update and the insert, which would cause the insert to fail > > with a u

Re: [SQL] Volatile functions in WITH

2013-02-20 Thread Ben Morrow
Quoth gray...@gmail.com (Sergey Konoplev): > On Sat, Feb 16, 2013 at 11:58 PM, Ben Morrow wrote: > > WITH "exp" AS ( -- as before > > ), > > "subst" AS ( > > SELECT add_item(e.basket, e.nref, e.count) > >

Re: [SQL] How to reject overlapping timespans?

2013-02-17 Thread Ben Morrow
date, enddate date, exclude using gist (object_id with =, box(startdate, enddate) with &&) ); You have to use 'box' rather than 'lseg' because there are no indexes for lsegs. I don't know how efficient this will be, and of course

Re: [SQL] Perform Function When The Rows Of A View Change

2013-02-17 Thread Ben Morrow
tential difficulty calculating that time, you would need to be able to wake up that client early if one of the tables changed. Setting triggers on the tables to send a notify to that client (probably a different notify from the one that client then sends out to other clients) should be sufficient, a

Re: [SQL] upsert doesn't seem to work..

2013-02-17 Thread Ben Morrow
select "server_id", "item_id" from "upsert") The third is that upsert is not as simple as you think. It isn't possible (at least, not in Postgres) to take a lock on a row which doesn't exist, so it's possible that a concurrent transaction

[SQL] Volatile functions in WITH

2013-02-16 Thread Ben Morrow
INCT e.msg FROM "exp" e LEFT JOIN "subst" s ON FALSE WITH "exp" AS ( -- as before ) SELECT DISTINCT s.msg FROM ( SELECT e.msg, CASE WHEN e.nref IS NULL THEN NULL ELSE add_item(e.basket, e.nref, e.count)

[SQL] using min|max in where

2010-08-24 Thread Ben Carbery
Hi, I have some sql like so: SELECT min(date) INTO d FROM interest_rate WHERE m_code = NEW.code; UPDATE interest_rate SET date = NEW.start_date, rate = NEW.initial_rate WHERE m_code = NEW.code AND date = d; Actually this is pgsql but I don't think that matters. I am wondering if I can make this

Re: [SQL] strangest thing happened

2010-07-08 Thread Ben Morrow
f the backup isn't done right the backed-up copy may be corrupt.) Have you done a restore recently? - Something I haven't thought of :). - A bug in Pg. While this is *extremely* unlikely, it must be mentioned as a possibility. Ben -- Sent via pgsql-

Re: [SQL] enforcing constraints across multiple tables

2010-06-25 Thread Ben Morrow
create table person_food ( person_id int not null references person, food_id int not null, food_group_id int not null, foreign key (food_id, food_group_id) references food (id, food_group_id), unique (person_id, food_group_id) ); If you wis

[SQL] Casts in foreign schemas

2010-06-08 Thread Ben Morrow
pgSQL functions were compiled at CREATE FUNCTION time, using the SEARCH_PATH currently in effect. Is that wrong? Is there some GRANT I'm missing that will make this work? Ben -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.post

Re: [SQL] Rules and sequences

2010-05-27 Thread Ben Morrow
Quoth t...@sss.pgh.pa.us (Tom Lane): > Ben Morrow writes: > > I am trying to implement a fairly standard 'audit table' setup, but > > using rules instead of triggers (since it should be more efficient). > > Rules are sufficiently tricky that I would never, ever re

[SQL] Rules and sequences

2010-05-26 Thread Ben Morrow
is incremented twice), but is there any way to prevent it? Some way of 'materialising' the NEW row so it is just plain values rather than a list of expressions? Ben -- 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] count function alternative in postgres

2010-04-06 Thread Ben Morrow
nct (id, name, age) as tuple from profile) as profile; Ben -- 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] Help : insert a bytea data into new table

2010-03-11 Thread Ben Morrow
[quoting fixed] Quoth dennis : > Ben Morrow wrote: > > Quoth dennis: > >> Dear Ben > >> > >> thanks for you anwser. > >> I try to add function quote_literal on my sql statement . > >> > >> but it raise other error message

Re: [SQL] Help : insert a bytea data into new table

2010-03-11 Thread Ben Morrow
Quoth dennis : > Dear Ben > > thanks for you anwser. > I try to add function quote_literal on my sql statement . > > but it raise other error message (quote_literal not support bytea format): > function quote_literal(bytea) does not exist Which Postgres versio

Re: [SQL] Help : insert a bytea data into new table

2010-03-10 Thread Ben Morrow
Quoth dennis : > Hi Ben > > here is my function , it's for fix missing chunk problem. > It has same problem ,please take look > > > thank for you help > > -table-- > > > db=# \d usersessiontable; >

Re: [SQL] Help : insert a bytea data into new table

2010-03-09 Thread Ben Morrow
xist: text || bytea > > > But if my sql statement has no column "content" > the sql works. > sql: > create table mail_new as select sender,subject from mail sender='dennis' No, it still doesn't give that error for me. Show us something you've *actual

Re: [SQL] Help : insert a bytea data into new table

2010-03-08 Thread Ben Morrow
* from a where c1=xxx 'AS' isn't valid there. What is xxx? Is it a field you haven't shown us, or is it a quoted string? > error: > operator does not exist: text || bytea That command (with 'xxx' quoted and the AS removed) doesn't give that error with those

Re: [SQL] keeping last 30 entries of a log table

2006-06-21 Thread Ben K.
b' where id=nextval('cy30')::int; UPDATE 30 B) update tc set des='c' where id=currval('cy30'); UPDATE 1 Regards, Ben K. Developer http://benix.tamu.edu ---(end of broadcast)--- TIP 3: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faq

Re: [SQL] Most efficient way to hard-sort records

2006-05-07 Thread Ben K.
Another version along that line ? # create sequence counterseq start 1; -- (set/reset whenever a counter is needed) # select main_table.*, nextval('counterseq') as position2 into sorted_main_table from main_table, keytable where main_table.id = keytable.main_table_id order by value;

Re: [SQL] Most efficient way to hard-sort records

2006-05-06 Thread Ben K.
pdate main_table set position = ( (select oid::int4 from temp_table where id = main_table.id ) - (select min(oid::int4) from temp_table) + 1) ; I read that oid wraps around (after ~ billions) so you might want to check your current oid. Regards, Ben K. Developer h

Re: [SQL] Returning String as Integer

2006-05-06 Thread Ben K.
n was Kashmira Patel. Sorry, I apologize. Regards, Ben K. ---(end of broadcast)--- TIP 3: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faq

Re: [SQL] Returning String as Integer

2006-05-06 Thread Ben K.
nt4(id) ...; worked. I tried int8(id) but java didn't take it as Integer. (It took int8 as something like Long.) Regards, Ben ---(end of broadcast)--- TIP 1: if posting/reading through Usenet, please send an appropriate subscribe-nomail

Re: [SQL] audit table containing Select statements submitted

2006-05-04 Thread Ben K.
Current_user Timestamp "The Select Statement Submitted by the User" http://www.postgresql.org/docs/8.1/static/plpgsql-trigger.html#PLPGSQL-TRIGGER-AUDIT-EXAMPLE might be close to what you want. Regards, Ben K. Developer http://benix.tamu.edu ---(end of

Re: [SQL] i am getting error when i am using copy command

2006-05-03 Thread Ben K.
file '/tmp/penchal.out' for writing: no such file or directory.. _IF_ you're on linux it could be due to selinux. setenforce 0 might solve the problem tempoarily. I would assume there should've been some existing discussion threads. (setenforce 1 afterwards

Re: [SQL] LinkedList

2006-05-02 Thread Ben K.
tupple number seems overly assumptive. If it works for you great, your example may then be useful as a short cut, but I don't believe in leaving things to chance when programming. Regards, Ben K. Developer http://benix.tamu.edu ---(end of broadcast)---

Re: [SQL] Sorting aggregate column contents

2006-05-02 Thread Ben K.
ng(array(select name from city where idstate = s.idstate order by name),',') from state s; == name | array_to_string --+- RP | Gramado,Port Alegre SP | Osasco * I see normal

Re: [SQL]Linked List

2006-04-30 Thread Ben K.
t( $1 ) || '' (SELECT * FROM links WHERE p= $2 )'' CONTEXT: PL/pgSQL function "traverse" line 10 at execute statement LINE 1: SELECT ''INSERT INTO '' || quote_ident( $1 ) || '' (SELECT ... Regards, Ben K. Developer http://benix.tamu.edu ---(end of broadcast)--- TIP 5: don't forget to increase your free space map settings

Re: [SQL]Linked List

2006-04-30 Thread Ben K.
to deliver the templist table name as argument. (Somehow there seemed to be a bug(?) there) Regards, Ben K. Developer http://benix.tamu.edu ---(end of broadcast)--- TIP 3: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faq

Re: [SQL] LinkedList

2006-04-28 Thread Ben K.
ns over keeping one more field. But I think this is more of an exercise, and functions would be the proper way for complex operations. Regards, Ben K. Developer http://benix.tamu.edu ---(end of broadcast)--- TIP 4: Have you searched our list archives? http://archives.postgresql.org

Re: [SQL] LinkedList

2006-04-27 Thread Ben K.
,50); -- TRAVERSE begin; declare mc cursor for select * from linkedlist order by nextnode; fetch 1 from mc; fetch 1 from mc; ... close mc; commit; which is nothing more than, select * from linkedlist order by nextnode; Regards, Ben K. Developer http://benix.tamu.edu

Re: [SQL] find all tables with a specific column name?

2006-04-22 Thread Ben K.
above query included indexes too (relkind=i) while information_schema.tables included only tables and views (r,v). Ben K. Developer http://benix.tamu.edu ---(end of broadcast)--- TIP 5: don't forget to increase your free space map settings

Re: [SQL] how to create rule as on delete

2005-10-24 Thread Stewart Ben (RBAU/EQS4) *
he variable NEW - the NEW variable will store the row being deleted. Best regards, Ben Stewart -- Robert Bosch (Australia) Pty. Ltd. Engineering Quality Services, Student Software Engineer (RBAU/EQS4) Locked Bag 66 - Clayton South, VIC 3169 - AUSTRALIA Tel: +61 3 9541-

Re: [SQL] automatic update or insert

2005-10-24 Thread Stewart Ben (RBAU/EQS4) *
east 50% faster than my stored > procedure, so that would be ok. > > However, this has made me thinking. Couldn't this be done directly in > SQL? You could probably implement this as a trigger on the table for INSERT. Have a squiz through the documentation on triggers. Best regards, Be

Re: [SQL] Problem while using start transaction ans commit;

2005-10-18 Thread Stewart Ben (RBAU/EQS4) *
_UNKNOWN END;$BODY$ LANGUAGE 'plpgsql' VOLATILE SECURITY DEFINER; -- In this code, whenever an exception is raised, the system will rollback to the start of the block (BEGIN). Best regards, Ben Stewart -- Robert Bosch (Australia) Pty. Ltd. Engineering Quality Services,

Re: [SQL] Question about functions

2005-10-17 Thread Stewart Ben (RBAU/EQS4) *
-- <== Problem is here > END LOOP; > RETURN; > END; > $$ LANGUAGE 'plpgsql'; You need to declare this as a set-returning function if you're using RETURN NEXT. Best regards, Ben Stewart -- Robert Bosch (Australia) Pty. Ltd. Engineering Quality Servi

Re: [SQL] Update timestamp on update

2005-10-12 Thread Stewart Ben (RBAU/EQS4) *
ation for $PL is read before creating triggers"? It may also be worth including a comment that explicitly states that all(?) PLs are supported in triggers. Best regards, Ben Stewart -- Robert Bosch (Australia) Pty. Ltd. Engineering Quality Services, Student Software Engineer (RBAU/EQS4) Locked

Re: [SQL] SEVEN cross joins?!?!?

2005-10-12 Thread Stewart Ben (RBAU/EQS4) *
alculate this, then sort by that column. Best regards, Ben Stewart -- Robert Bosch (Australia) Pty. Ltd. Engineering Quality Services, Student Software Engineer (RBAU/EQS4) Locked Bag 66 - Clayton South, VIC 3169 - AUSTRALIA Tel: +61 3 9541-7002 Fax: +61 3 9541-7700 mailto:[EMAIL PROTECTED] http

[SQL] Scripting GRANT on functions

2005-10-05 Thread Stewart Ben (RBAU/EQS4) *
INTO funcname; WHILE FOUND LOOP FETCH curs INTO funcname; EXECUTE 'GRANT EXECUTE ON FUNCTION ' || funcname || ' TO myuser'; END LOOP; CLOSE curs; END; ---END CODE--- Best regards, Ben Stewart -- Robert Bosch (Australia) Pty. Ltd. Engineering Quality Services,

Re: [SQL] Sending function parametars within EXECUTE ''SELECT...

2005-09-28 Thread Stewart Ben (RBAU/EQS4) *
o is: SELECT col2 INTO myValue FROM ....... Best regards, Ben Stewart -- Robert Bosch (Australia) Pty. Ltd. Engineering Quality Services, Student Software Engineer (RBAU/EQS4) Locked Bag 66 - Clayton South, VIC 3169 - AUSTRALIA mailto:[EMAIL PROTECTED] http://www.bosch.com.au/ ---

Re: [SQL] changing a column's position in table, how do you do that

2005-09-27 Thread Stewart Ben (RBAU/EQS4) *
ype; UPDATE mytable SET col_to_move_2 = col_to_move; ALTER TABLE mytable DROP COLUMN col_to_move; ALTER TABLE mytable RENAME col_to_move_2 TO col_to_move; COMMIT WORK; Best regards, Ben Stewart -- Robert Bosch (Australia) Pty. Ltd. Engineering Quality Services, Student Software Engineer (RBAU/EQS4)

Re: [SQL] how to do 'deep queries'?

2005-09-26 Thread Stewart Ben (RBAU/EQS4) *
WHERE table1.user = table3.employeeno AND table1.course = table2.courseid; What errors are you getting? Best regards, Ben Stewart -- Robert Bosch (Australia) Pty. Ltd. Engineering Quality Services, Student Software Engineer (RBAU/EQS4) Locked Bag 66 - Clayton South, VIC 3169 - AUSTRALIA Te

Re: [SQL] Functions, transactions and RETURN

2005-09-22 Thread Stewart Ben (RBAU/EQS4) *
-- E_UNKNOWN END;$BODY$ LANGUAGE 'plpgsql' VOLATILE SECURITY DEFINER; ------ Best regards, Ben Stewart -- Robert Bosch (Australia) Pty. Ltd. Engineering Quality Services, Student Software Engineer (RBAU/EQS4

[SQL] Functions, transactions and RETURN

2005-09-22 Thread Stewart Ben (RBAU/EQS4) *
s and returning distinct values with the BEGIN.. RAISE EXCEPTION.. EXCEPTION.. END method proposed in previous mailing list posts. Are there any suggestions on how to implement this? Best regards, Ben Stewart -- Robert Bosch (Australia) Pty. Ltd. Engineering Quality Services, Software Engineer (RBAU

[SQL] Privileged Position

2005-05-31 Thread Ben Hane
To: pgsql-sql@postgresql.org   We will now place any business with a qualified website at the top of the major search engines: Yahoo!, MSN, Alta Vista, etc. This promotion is not going to last long.  If you are interested in being guaranteed first position in the top search engines at a pr

[SQL] What is PG best practice for storing temporary data in functions?

2004-07-09 Thread Ben
Title: Message There is a very common technique used in other RDBMS (e.g. Sybase) stored procedure programming which I am not sure how best to replicate in Postgres functions.   A Sybase stored procedure can do   select into #temp1   create table #temp2 (…)   call some proc which also u

[SQL] Help with pivoting tables

2003-09-29 Thread Ben Schneider
-05 4 5 0 0 9 Any ideas? Thanks, Ben --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.521 / Virus Database: 319 - Release Date: 9/23/2003 ---(end of broadcast)---

[SQL] SQL to list databases?

2003-01-23 Thread Ben Siders
Is there a query that will return all the databases available, similar to what psql -l does? ---(end of broadcast)--- TIP 6: Have you searched our list archives? http://archives.postgresql.org

[SQL] Problem with Auto Increment

2002-11-04 Thread Ben Kassel
a file which was created using the pg_dump command. I have recently upgraded from 7.2.1 to 7.2.3 using the RPM. Thanks in advance, ben ---(end of broadcast)--- TIP 3: if posting/reading through Usenet, please send an appropriate subscribe-noma

RE: [SQL] Max Size of a text field

2001-03-30 Thread Trewern, Ben
unlimited text fields ;-) Regards Ben > -Original Message- > From: Koen Antonissen [mailto:[EMAIL PROTECTED]] > Sent: 30 March 2001 12:52 > To: [EMAIL PROTECTED] > Subject: [SQL] Max Size of a text field > > > Hi there > > I just recieved this error: >

RE: [SQL] Help with 'now', now(), timestamp 'now', ...

2001-03-30 Thread Trewern, Ben
Title: RE: [SQL] Help with 'now', now(), timestamp 'now', ... try timeofday(), now() gives starttime of transaction :-{. Regards Ben PS this has just been discussed in this mailing list or I would have been clueless > -Original Message- > From: [EMAIL

RE: [SQL] readline ??

2000-12-18 Thread Trewern, Ben
Title: RE: [SQL] readline ?? Try the new RPMs: postgresql-7.0.3-2mdk.  They include readline support. Ben > -Original Message- > From: vs [mailto:[EMAIL PROTECTED]] > Sent: 15 December 2000 10:12 > To: [EMAIL PROTECTED]; [EMAIL PROTECTED] > Cc: [EMAIL PROTECTED]

RE: [SQL] to_char() causes backend to close connection

2000-12-14 Thread Trewern, Ben
Title: RE: [SQL] to_char() causes backend to close connection select to_char(now()-'5 minutes'::interval,'YYMMDDHH24MI') seems to work Ben > -Original Message- > From: Kovacs Zoltan Sandor [mailto:[EMAIL PROTECTED]] > Sent: 14 December 2000 15:49

RE: [SQL] Tree structure

2000-09-12 Thread Trewern, Ben
 6  | Group2-1 |  5 Just for testing.  I can see how it should work but the client side code is defeating me at the moment.  I'm working in delphi with winzeos (cracking components by the way).  Anyone done this. Thanks for any help Ben Trewern > -Original Message

[SQL] Tree structure

2000-09-11 Thread Trewern, Ben
Title: Tree structure Anybody know how to make a tree structure using related tables using Postgres.  Something like a directory structure is what I'm aiming for.  I'm sure there is an easy way but I'm having probs. Any help would be appreciated. Ben.

[SQL] Selecting outside the current DB

2000-06-28 Thread Ben Stringer
Does postgresql allow (or plan to provide) a select outside the current database? Eg. (In Sybase parlance) select * from otherdb..table Thanks, Ben -- _ Ben Stringer[EMAIL PROTECTED] -