array_agg to array

2018-05-15 Thread Philipp Kraus
Hello, I have got a function with a reg expr to split chemical formulas e.g. H2O -> H2 O. CREATE OR REPLACE FUNCTION daimon.text2sumformula(text) RETURNS text[] AS $$ select array_agg(i::text) as e from ( select unnest( regexp_matches( $1, '[0-9]*[A-Z][a-z]?\d*|\((?:[^()]*(?:\(.*\))?[^()]*)

Re: Control PhoneNumber Via SQL

2018-05-15 Thread tango ward
On Wed, May 16, 2018 at 9:04 AM, tango ward wrote: > Okay, I figured it out. > > cur_t.execute(""" > SELECT > CASE > WHEN mobilenumber ~'^0[1-9]' > THEN regexp_replace(mobilenumber, '0', '+63') > ELSE mobilenumb

Re: Function to set up variable inside it

2018-05-15 Thread Łukasz Jarych
Hi Guys, thank you for your help ! Hmm yes something like this. I was wondering if is possible to pass variable into function: CREATE FUNCTION change_trigger() RETURNS trigger AS $$ BEGIN IF TG_OP = 'INSERT' THEN INSERT IN

Re: Control PhoneNumber Via SQL

2018-05-15 Thread tango ward
Noted thanks Sir. On Wed, May 16, 2018 at 11:55 AM, David G. Johnston < david.g.johns...@gmail.com> wrote: > On Tuesday, May 15, 2018, tango ward wrote: > >> Ah yeah, the concatenation. I was thinking of using "+" but I can't make >> it work and the documentation says not to use it for psycopg2.

Re: Control PhoneNumber Via SQL

2018-05-15 Thread David G. Johnston
On Tuesday, May 15, 2018, tango ward wrote: > Ah yeah, the concatenation. I was thinking of using "+" but I can't make > it work and the documentation says not to use it for psycopg2. > > Sorry what's bottom-post? I see you did that yesterday. Is there a format > for before making a bottom-post?

Re: Control PhoneNumber Via SQL

2018-05-15 Thread tango ward
Ah yeah, the concatenation. I was thinking of using "+" but I can't make it work and the documentation says not to use it for psycopg2. Sorry what's bottom-post? I see you did that yesterday. Is there a format for before making a bottom-post? On Wed, May 16, 2018 at 11:04 AM, David G. Johnston <

Re: Control PhoneNumber Via SQL

2018-05-15 Thread David G. Johnston
On Tuesday, May 15, 2018, tango ward wrote: > Sorry for bumping this email. > > I would just like to clarify regarding regexp_replace: > > WHEN mobilenumber ~'^9[0-9]' AND LENGTH(mobilenumber) = 10 > THEN regexp_replace(mobilenumber, '', '+63') > > If the pattern is empty '', does this mean that

Re: Control PhoneNumber Via SQL

2018-05-15 Thread tango ward
Sorry for bumping this email. I would just like to clarify regarding regexp_replace: WHEN mobilenumber ~'^9[0-9]' AND LENGTH(mobilenumber) = 10 THEN regexp_replace(mobilenumber, '', '+63') If the pattern is empty '', does this mean that the replacement_string param will be added to the value of

Re: Control PhoneNumber Via SQL

2018-05-15 Thread tango ward
Okay, I figured it out. cur_t.execute(""" SELECT CASE WHEN mobilenumber ~'^0[1-9]' THEN regexp_replace(mobilenumber, '0', '+63') ELSE mobilenumber END FROM studeprofile

Re: Control PhoneNumber Via SQL

2018-05-15 Thread tango ward
Did the CASE Statement produce the other columns Sir? On Wed, May 16, 2018 at 8:53 AM, David G. Johnston < david.g.johns...@gmail.com> wrote: > On Tuesday, May 15, 2018, tango ward wrote: >> >> >> I can access the index 1 of the output list to get the +639078638001. I >> think this has been expl

Re: Control PhoneNumber Via SQL

2018-05-15 Thread David G. Johnston
On Tuesday, May 15, 2018, tango ward wrote: > > > I can access the index 1 of the output list to get the +639078638001. I > think this has been explained already by Sir Adrian in my previous question > about the about being shown as list. I'll review that. > Last time you had multiple rows...this

Re: Control PhoneNumber Via SQL

2018-05-15 Thread tango ward
Hi All, Thanks for the suggestions especially the article for formatting international phone numbers. I also implement the suggestion of Sir Wolfgang: cur_t.execute(""" SELECT mobilenumber, CASE WHEN mobilenumber ~'^0[1-9]' THEN

Re: Control PhoneNumber Via SQL

2018-05-15 Thread tango ward
Hi All, Thanks for the suggestions. I really appreciate it specially the article of formatting international phone numbers. I also tried implementing the suggestion of Wolfgang: cur_t.execute(""" SELECT mobilenumber, CASE WHEN mobilenumber ~'^0[1

Re: Control PhoneNumber Via SQL

2018-05-15 Thread raf
haman...@t-online.de wrote: > >> Hi, > >> > >> I would like to know if it is possible to control the phone number in SQL > >> before inserting it to the destination DB? > >> > >> I have a model in Django: > >> > >> class BasePerson(TimeStampedModel): > >> phone_number = PhoneNumberField(max_le

Re: Combining \i and \copy in psql

2018-05-15 Thread David G. Johnston
On Tue, May 15, 2018 at 8:30 AM, Rhys A.D. Stewart wrote: > Greetings, > > I have a query in a .sql file and I'd like to use \i to execute it and > \copy to save it to a csv file. Is there any way to combine the two? > > Something along the lines of: > > \copy \i myquery.sql to 'output.csv' > ​M

Combining \i and \copy in psql

2018-05-15 Thread Rhys A.D. Stewart
Greetings, I have a query in a .sql file and I'd like to use \i to execute it and \copy to save it to a csv file. Is there any way to combine the two? Something along the lines of: \copy \i myquery.sql to 'output.csv' Rhys Peace & Love|Live Long & Prosper

Re: Control PhoneNumber Via SQL

2018-05-15 Thread Alvaro Herrera
On 2018-May-15, John McKown wrote: > I don't have any code for you, if that is what you are soliciting. I did > find a couple of informative web sites which help explain how international > phone numbers are formatted. These are known as E.164 numbers. Michael Glaesemann wrote a e.164 datatype yea

Re: Function to set up variable inside it

2018-05-15 Thread Adrian Klaver
On 05/15/2018 05:28 AM, Łukasz Jarych wrote: Hi Guys, I am using postgres 10.3 (or 4?). IT is possible to set up variable inside function? Like this?: https://www.postgresql.org/docs/10/static/plpgsql-declarations.html Best, Jacek -- Adrian Klaver adrian.kla...@aklaver.com

Re: Function to set up variable inside it

2018-05-15 Thread Pavel Stehule
2018-05-15 14:28 GMT+02:00 Łukasz Jarych : > Hi Guys, > > I am using postgres 10.3 (or 4?). > IT is possible to set up variable inside function? > I don't understand to the question. What do you think? Regards Pavel > > Best, > Jacek >

Re: Query ID Values

2018-05-15 Thread Adrian Klaver
On 05/14/2018 10:04 PM, Ian Zimmerman wrote: On 2018-05-14 21:12, Adrian Klaver wrote: Because you are doing fetchall(). That is going to fetch a list of row tuples. Either iterate over that list or iterate over the cursor: for row in cur_p: print(row) For more info see: http://initd

Re: Control PhoneNumber Via SQL

2018-05-15 Thread John McKown
On Tue, May 15, 2018 at 4:10 AM, tango ward wrote: > > Hi, > > Sorry for asking question again. > > I would like to know if it is possible to control the phone number in SQL > before inserting it to the destination DB? > > I have a model in Django: > > class BasePerson(TimeStampedModel): > phone

Function to set up variable inside it

2018-05-15 Thread Łukasz Jarych
Hi Guys, I am using postgres 10.3 (or 4?). IT is possible to set up variable inside function? Best, Jacek

Re: Control PhoneNumber Via SQL

2018-05-15 Thread hamann . w
>> Hi, >> >> Sorry for asking question again. >> >> I would like to know if it is possible to control the phone number in SQL >> before inserting it to the destination DB? >> >> I have a model in Django: >> >> class BasePerson(TimeStampedModel): >> phone_number = PhoneNumberField(max_length=50

Control PhoneNumber Via SQL

2018-05-15 Thread tango ward
Hi, Sorry for asking question again. I would like to know if it is possible to control the phone number in SQL before inserting it to the destination DB? I have a model in Django: class BasePerson(TimeStampedModel): phone_number = PhoneNumberField(max_length=50, verbose_name=_(u'phone number')

Re: found xmin from before relfrozenxid on pg_catalog.pg_authid

2018-05-15 Thread Maxim Boguk
​Hi everyone, I just got the same issue on 9.6.8: 2018-05-15 11:52:01 MSK 33558 @ from [vxid:317/92895305 txid:0] [] ERROR: found xmin 2808837517 from before relfrozenxid 248712603 2018-05-15 11:52:01 MSK 33558 @ from [vxid:317/92895305 txid:0] [] CONTEXT: automatic vacuum of table "template0.