Re: psql UPDATE field [tab] expands to DEFAULT?

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Ken Tanzer <ken(dot)tanzer(at)gmail(dot)com>
Cc: PG-General Mailing List <pgsql-general(at)postgresql(dot)org>
Subject: Re: psql UPDATE field [tab] expands to DEFAULT?
Date: 2019-06-19 01:03:18
Message-ID: 067b8bf7-ff8e-b252-8261-873e22eb76e3@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

On 6/18/19 3:23 PM, Ken Tanzer wrote:
> On Mon, Jun 17, 2019 at 4:24 PM Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com
> <mailto:adrian(dot)klaver(at)aklaver(dot)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(dot)klaver(at)aklaver(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2019-06-19 01:20:11 Re: Inserts restricted to a trigger
Previous Message Ken Tanzer 2019-06-18 22:23:40 Re: psql UPDATE field [tab] expands to DEFAULT?

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2019-06-19 01:06:13 Re: ANALYZE: ERROR: tuple already updated by self
Previous Message Justin Pryzby 2019-06-19 00:38:34 Re: ANALYZE: ERROR: tuple already updated by self