[GENERAL] How can I interpolate psql variables in function bodies?

2009-06-15 Thread J. Greg Davidson
Hi dear colleagues, I'm trying to pull some platform-specific constants out of my code by using psql variables, e.g.: $ psql -v TypeLength=4 # CREATE TYPE tref ( INTERNALLENGTH = :TRefTypeLength, INPUT = tref_in, OUTPUT = tref_out, PASSEDBYVALUE ); which works fine, but when I need such

Re: [GENERAL] How can I interpolate psql variables in function bodies? - workaround

2009-06-24 Thread J. Greg Davidson
recap the problem: On Mon, 2009-06-15 at 15:28 -0700, J. Greg Davidson wrote: > Hi dear colleagues, > > When I need such a constant in a function > it is not substituted: > $ psql -v foo=10 > # create function foo() returns integer as 'select '(:foo) language sql; &g

Re: [GENERAL] How can I interpolate psql variables in function bodies?

2009-06-24 Thread J. Greg Davidson
ger as :g language sql immutable; g() can be used in the bodies of other functions where it should be inline substituted since it's immutable. I'm concerned as to whether this might break if psql slightly changes how it it does substitution. The documentation does not fully specify how substit

[GENERAL] Can ARRAY( ... ) generate text[][]?

2010-06-10 Thread J. Greg Davidson
RNS xml AS $$ SELECT ( xpath($1,$2,ARRAY( SELECT ARRAY[ $3[i], $3[i+1] ] FROM generate_series(1, array_upper($3,1), 2) i ) ) )[1]::xml $$ LANGUAGE sql; -- END CODE Is there any decent way to do this in SQL, or do I need to write it in a procedural language? Thanks, _Gre

[GENERAL] Need xml element constructor given tag, attribute array & children

2010-06-28 Thread J. Greg Davidson
Hi Everybody, I'm having trouble finding any way to build up XML values from their logical components, e.g. given an XML element tag, an array of attributes in some form, and an xml[] array of children I can't find any SQL function or expression which would construct the XML element. Surely the s

[GENERAL] Danger of idiomatic plpgsql loop for merging data

2010-07-28 Thread J. Greg Davidson
Hi fellow PostgreSQL hackers, I just got burned by the idiomatic loop documented in the PostgreSQL manual as Example 39-2. Exceptions with UPDATE/INSERT I have now replaced this "standard" idiom with a safer one described below. What went wrong: It seems that the table I was either inserting i

Re: [GENERAL] Danger of idiomatic plpgsql loop for merging data

2010-08-03 Thread J. Greg Davidson
os(name_) VALUES($1); EXCEPTION WHEN unique_violation THEN -- another thread? RAISE NOTICE '% "%" unique_violation', this, $1; END; END LOOP; END; $$ LANGUAGE plpgsql; -- end code _Greg P.S. Sorry about the excessive underscores! I've been burned by hav

Re: [GENERAL] Danger of idiomatic plpgsql loop for merging data

2010-08-04 Thread J. Greg Davidson
m_not_from_table() then I could make things even cleaner, but I don't know if that's possible. Here are the omitted definitions needed to make this simplified example code work: CREATE DOMAIN foo_reftype AS INTEGER; CREATE TABLE foos ( ref_ foo_reftype PRIMARY KEY, name_ text UNI

[GENERAL] Seeking expected return type info for SPI function

2009-12-10 Thread J. Greg Davidson
When PostgreSQL calls a C function I get all kinds of interesting information in the struct FunctionCallInfoData and struct FmgrInfo (details at bottom). I was hoping to get the oid of the expected return type somewhere, but I don't see it. Am I missing something? I'm trying to av

[GENERAL] Any need to copy args before SPI C function callls SQL function?

2009-12-24 Thread J. Greg Davidson
PostgreSQL functions from C, which looks easier. I want to use the fastest method possible that will not break with future releases - what do you advise? Thanks for your answers to these questions and thanks for the excellent responses to my earlier questions! Happy New Year, _Greg J. Greg Da

[GENERAL] surprised by non-strict array_append

2010-02-02 Thread J. Greg Davidson
I was caught out today by the non-strict behavior of array_append causing me to get an undesired result for a COALESCE. My subsequent attempt to create a STRICT VARIADIC generalization of array_append led to another surprise. The problem was easily solved, but might be of interest to others. Per

[GENERAL] When are SQL functions inlined & how can I tell?

2012-01-07 Thread J. Greg Davidson
EXPLAIN ... SELECT foo(...); kinds of things where foo() calls bar() and I don't see that I can tell anything about the inline status of either function. Thanks, _Greg J. Greg Davidson -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscriptio

[GENERAL] User-defined-type in C crashing PostgreSQL server: What am I doing wrong?

2006-11-18 Thread J. Greg Davidson
Hello, My user-defined types are crashing the PostgreSQL server and I don't understand why. I've been trying to figure it out on my own for overr a week. I've cooked what I'm doing down to the essentials and I'm asking for help. Help: What am I doing wrong? * Sections of this message: ** Over