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
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 have "valepag" and "valerec" both tables > have the same columns, but one is for debit and the other one is for > credit, the PL will work for both cases > >

Re: [SQL] ZIP function

2013-03-16 Thread Ben Morrow
Quoth ja...@xnet.co.nz (Jasen Betts): > On 2013-03-16, Victor Sterpu wrote: > > > > Is there a function that will give the resulting zip content for a=20 > > string? > > Like SELECT zip('test data');? > > no. you could write one that calls gzip in one of the untrusted > languages. or in C you co

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

2013-03-14 Thread Ben Morrow
Quoth jorgemal1...@gmail.com (JORGE MALDONADO): > > I am building an UPDATE query at run-time and one of the fields I want to > include in the WHERE condition may repeat several times, I do not know how > many. > > UPDATE table1 > SET field1 = "some value" > WHERE (field2 = value_1 OR field2 = va

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
Quoth m...@summersault.com (Mark Stosberg): > > We are working on a project to start storing some data as "soft deleted" > (WHERE state = 'deleted') instead of hard-deleting it. > > To make sure that we never accidentally expose the deleted rows through > the application, I had the idea to use a

Re: [SQL] Creating a new database with a TEMPLATE did not work

2013-02-25 Thread Ben Morrow
Quoth adrian.kla...@gmail.com (Adrian Klaver): > On 02/25/2013 02:49 PM, mkumbale wrote: > > Hi, I am new to PostgreSQL. I have an empty PostgreSQL DB containing tables > > but no data. I issued the following command in PGADMIN SQL editor: > > > > CREATE DATABASE "NewDefault" > >WITH OWNER =

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

2013-02-23 Thread Ben Morrow
Quoth parri...@gmail.com (Don Parris): > > Is it possible to use spaces in the ltree path, like so: > TOP.Groceries.Food.Herbs & Spices > > Or do the elements of the path have to use underscores and dashes? >From the docs: | A label is a sequence of alphanumeric characters and underscores (for

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
Quoth maps...@gmx.net (Andreas): > Am 17.02.2013 19:20, schrieb Andreas Kretschmer: > > Andreas hat am 17. Februar 2013 um 18:02 geschrieben: > >> I need to store data that has a valid timespan with start and enddate. > >> > >> objects ( id, name, ... ) > >> object_data ( object_id referencs objec

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

2013-02-17 Thread Ben Morrow
Quoth adam.mailingli...@gmail.com (Adam): > > I have a rather complicated view that is dependent upon multiple > tables, consisting of several windowing and aggregate functions, as > well as some time intervals. I would like to be able to perform a > function, i.e. pg_notify(), whenever a row is a

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

2013-02-17 Thread Ben Morrow
Quoth bier...@gmail.com (Bert): > > We continuously load data from flat files in our database. > We first insert the data into unlogged tables (in the loadoltp schema), and > then we use the 'upsert' statement to transfer the data from the load table > into the tables we are going to use. > > The

[SQL] Volatile functions in WITH

2013-02-16 Thread Ben Morrow
Suppose I run the following query: WITH "exp" AS ( DELETE FROM "item" i USING "item_expired" e WHERE e.oref = i.ref AND i.basket= $1 RETURNING i.basket, e.oref, e.nref, i.count, e.msg ), "subst" AS ( INSERT INTO "item" ("ba

Re: [SQL] strangest thing happened

2010-07-08 Thread Ben Morrow
Quoth jo...@jfcomputer.com (John): > On Wednesday 07 July 2010 03:14:40 pm Justin Graf wrote: > > I would be looking at the log files for the Inserts into that table as a > > means to track down what is the cause.  If there are no log files or > > don't have enough detail, crank up the logging leve

Re: [SQL] enforcing constraints across multiple tables

2010-06-25 Thread Ben Morrow
Quoth andrew.ge...@gmail.com (Andrew Geery): > > I have a question about checking a constraint that is spread across multiple > (in the example below, two) tables. In the example below, every food (food > table) is in a food group (food_group table). For every person (person > table), I want to

[SQL] Casts in foreign schemas

2010-06-08 Thread Ben Morrow
Is this behaviour expected? (This is with 8.4.3 on FreeBSD.) create schema one; set search_path to one; create type foo as (x integer); create function foo (integer) returns foo language plpgsql as $$ declare y foo; begin

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
I am trying to implement a fairly standard 'audit table' setup, but using rules instead of triggers (since it should be more efficient). However, I'm running into problems when one of the audited tables has a 'serial' column that is allowed to default: create table foo (id serial, bar text);

Re: [SQL] count function alternative in postgres

2010-04-06 Thread Ben Morrow
Quoth junaidmali...@gmail.com (junaidmalik14): > > Is there any alternative of mysql function COUNT(DISTINCT expr,[expr...]) in > postgres. We get error if we > > write count like this count(distinct profile.id, profile.name, profile.age) > but it works well in mysql. Pg does support COUNT(DIST

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 version are you using? Ben --

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; > Table "public.usersessiontable" >Column |

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

2010-03-09 Thread Ben Morrow
Quoth dennis : > here is example > > table name is "mail": > column| type > - > sender|char > subject |char I presume you mean 'varchar'? > content |bytea > > > I want copy some record into new table 'mail_new'. > > sql: > create table mail_new as select

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

2010-03-08 Thread Ben Morrow
Quoth dennis : > > I need to copy some data to new table. > But I encounter some error message. > the table structure > Table A: > c1 char > c2 bytea > > Table B: > c1 char > c2 bytea > > > My sql command: > insert into B as select * from a where c1=xxx 'AS' isn't valid there.