From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Ken Tanzer <ken.tanzer@gmail.com>
Cc: PG-General Mailing List <pgsql-general@postgresql.org>
Subject: Re: psql UPDATE field [tab] expands to DEFAULT?
Date: Tue, 18 Jun 2019 18:03:18 -0700
Message-ID: <067b8bf7-ff8e-b252-8261-873e22eb76e3@aklaver.com> (raw)
In-Reply-To: <CAD3a31XEaeB2odBznuwv3xfshSAzUMPc1yEzGbZezRfQf-+hCA@mail.gmail.com>
References: <CAD3a31XpXzrZA9TT3BqLSHghdTK+=cXjNCE+oL2Zn4+oWoc=qA@mail.gmail.com>
<b70db19f-d582-0d1a-5b4d-15ea385781a4@aklaver.com>
<CAD3a31XEaeB2odBznuwv3xfshSAzUMPc1yEzGbZezRfQf-+hCA@mail.gmail.com>
On 6/18/19 3:23 PM, Ken Tanzer wrote:
> On Mon, Jun 17, 2019 at 4:24 PM Adrian Klaver <adrian.klaver@aklaver.com
> <mailto:adrian.klaver@aklaver.com>> wrote:
>
>
> My cheat for dealing with many/long column names is:
>
> test=# \d up_test
> Table "public.up_test"
> Column | Type | Collation | Nullable | Default
> --------+---------+-----------+----------+---------
> id | integer | | |
> col1 | boolean | | |
> col2 | integer | | |
>
>
>
> test=# \pset format unaligned
> Output format is unaligned.
> test=# \pset fieldsep ','
> Field separator is ",".
>
> select * from up_test limit 0;
> id,col1,col2
>
> Cut and paste above.
>
> test=# \pset fieldsep '|'
> Field separator is "|".
>
> test=# \pset format 'aligned'
> Output format is aligned.
>
>
> Just curious, but if you really do that often, wouldn't you be better
> off with something like this?
I could/should I just don't do the above enough to get motivated to
build a function. Most cases where I'm doing complicated updates I am
not using psql I am building then in Python from a dict.
>
> CREATE OR REPLACE FUNCTION field_list( name ) RETURNS text AS $$
>
> SELECT array_to_string(array_agg(column_name::text ORDER BY
> ordinal_position),',') FROM information_schema.columns WHERE table_name
> = $1;
>
> $$ LANGUAGE sql STABLE;
>
> Cheers,
> Ken
>
--
Adrian Klaver
adrian.klaver@aklaver.com
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: adrian.klaver@aklaver.com, ken.tanzer@gmail.com
Subject: Re: psql UPDATE field [tab] expands to DEFAULT?
In-Reply-To: <067b8bf7-ff8e-b252-8261-873e22eb76e3@aklaver.com>
References: <CAD3a31XpXzrZA9TT3BqLSHghdTK+=cXjNCE+oL2Zn4+oWoc=qA@mail.gmail.com> <b70db19f-d582-0d1a-5b4d-15ea385781a4@aklaver.com> <CAD3a31XEaeB2odBznuwv3xfshSAzUMPc1yEzGbZezRfQf-+hCA@mail.gmail.com> <067b8bf7-ff8e-b252-8261-873e22eb76e3@aklaver.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox