Re: psql \set variables in crosstab queries?

2023-03-04 Thread David G. Johnston
On Sat, Mar 4, 2023 at 10:05 PM Ron wrote: > > Ugh. It's a long and hairy query that would be a nightmare in a format > statement. > > Assuming you can pass this thing into the crosstab function in the first place you must already have put it into a string. Changing "crosstab" to "format", plop

Re: psql \set variables in crosstab queries?

2023-03-04 Thread Ron
On 3/4/23 19:32, David G. Johnston wrote: On Sat, Mar 4, 2023 at 5:20 PM Ron wrote: But crosstab takes text strings as parameters.  How then do you use \set variables in crosstab queries? You need to dynamically write the textual query you want to send to the crosstab function.  In

Re: psql \set variables in crosstab queries?

2023-03-04 Thread Ron
On 3/4/23 19:22, Tom Lane wrote: Ron writes: According to https://www.postgresql.org/docs/12/app-psql.html#APP-PSQL-VARIABLES and experience, variables don't interpolate inside of string literals: " Variable interpolation will not be performed within quoted SQL literals and identifiers. Therefo

Re: psql \set variables in crosstab queries?

2023-03-04 Thread David G. Johnston
On Sat, Mar 4, 2023 at 5:20 PM Ron wrote: > > But crosstab takes text strings as parameters. How then do you use \set > variables in crosstab queries? > > You need to dynamically write the textual query you want to send to the crosstab function. In particular that means writing it using "format

Re: psql \set variables in crosstab queries?

2023-03-04 Thread Tom Lane
Ron writes: > According to > https://www.postgresql.org/docs/12/app-psql.html#APP-PSQL-VARIABLES and > experience, variables don't interpolate inside of string literals: > " > Variable interpolation will not be performed within quoted SQL literals and > identifiers. Therefore, a construction su

psql \set variables in crosstab queries?

2023-03-04 Thread Ron
According to https://www.postgresql.org/docs/12/app-psql.html#APP-PSQL-VARIABLES and experience, variables don't interpolate inside of string literals: " Variable interpolation will not be performed within quoted SQL literals and identifiers. Therefore, a construction such as ':foo' doesn't

Re: Dropping behavior for unique CONSTRAINTs

2023-03-04 Thread Ron
On 3/4/23 05:51, Peter J. Holzer wrote: On 2023-03-04 02:34:02 -0600, Ron wrote: On 3/4/23 02:03, Peter J. Holzer wrote: [snip] So your plan is to create a unique constraint (backed by a unique index) and then to drop the index and keep the constraint? That doesn't work. A unique constraint ca

Re: DISTINCT *and* ORDER BY in aggregate functions on expressions(!)y

2023-03-04 Thread Thorsten Glaser
On Sat, 4 Mar 2023, Alban Hertroys wrote: >> But isn’t that the same as with a regular LEFT JOIN? > >Similar, but not the same, I’d say. > >I do now notice that I made some copying errors there, I was a bit >nauseous at that time. np, I’m under pollen attack currently so also not at my best. >Th

Re: Dropping behavior for unique CONSTRAINTs

2023-03-04 Thread Conner Bean
Ah, my apologies for missing that in the docs. I had previously noticed the CONCURRENTLY option on drop index, but I misread and incorrectly thought that unique indexes themselves could not be dropped concurrently, rather than that being true for only unique indexes backing constraints. Apologie

Re: shp2pgsql error under windows

2023-03-04 Thread Christoph Moench-Tegeder
## Raivo Rebane (raivor...@gmail.com): > Raivo@DESKTOP-69FUU49 /cygdrive/f/3D-data/Kataster > > $ cat kataster.sql | less > > > > S^@E^@T^@ ^@C^@L^@I^@E^@N^@T^@_^@E^@N^@C^@O^@D^@I^@N^@G^@ ^@T^@O^@ That's a BOM and the rest looks like UTF-16 (or UCS-2). You can use recode (also available in Cy

shp2pgsql error under windows

2023-03-04 Thread Raivo Rebane
Hi I am usingPS F:\3D-data\Kataster> shp2pgsql -g piirid SHP_KATASTRIYKSUS kataster > kataster.sql under Windows 10 And it’s output is full of zeroe Cygwin helps to find them out, Raivo@DESKTOP-69FUU49 /cygdrive/f/3D-data/Kataster $ cat kataster.sql | less S^@E^@T^@ ^@C^@L^@I^@E^@N

shp2pgsql generates fake fail full of zeroes

2023-03-04 Thread Raivo Rebane
I am usingPS F:\3D-data\Kataster> shp2pgsql -g piirid SHP_KATASTRIYKSUS kataster > kataster.sql under Windows 10 And it’s output is  full of zeroe Cygwin helps to find them out, Raivo@DESKTOP-69FUU49 /cygdrive/f/3D-data/Kataster$ cat kataster.sql | less S^@E^@T^@ ^@C^@L^@I^@E^@N^@T^@_^@E^@N^@C^@O^@

Re: Dropping behavior for unique CONSTRAINTs

2023-03-04 Thread Peter J. Holzer
On 2023-03-04 02:34:02 -0600, Ron wrote: > On 3/4/23 02:03, Peter J. Holzer wrote: > [snip] > > So your plan is to create a unique constraint (backed by a unique > > index) and then to drop the index and keep the constraint? > > > > That doesn't work. A unique constraint can't exist without a (uni

Re: DISTINCT *and* ORDER BY in aggregate functions on expressions(!)y

2023-03-04 Thread Alban Hertroys
> On 3 Mar 2023, at 20:32, Thorsten Glaser wrote: > > On Fri, 3 Mar 2023, Alban Hertroys wrote: > >> You can rewrite that into something like this: >> >> select jsonb_build_object('opening_times’, >> obj >> ORDER BY >> obj->>'weekday’, >> obj->>'from_hour’, >>

Re: Dropping behavior for unique CONSTRAINTs

2023-03-04 Thread Ron
On 3/4/23 02:03, Peter J. Holzer wrote: [snip] So your plan is to create a unique constraint (backed by a unique index) and then to drop the index and keep the constraint? That doesn't work. A unique constraint can't exist without a (unique) index. Think about it: With a unique constraint Postgr

Re: Dropping behavior for unique CONSTRAINTs

2023-03-04 Thread Peter J. Holzer
On 2023-03-04 13:50:28 +1300, David Rowley wrote: > On Sat, 4 Mar 2023 at 10:55, Ron wrote: > > On 3/3/23 04:54, David Rowley wrote: > > If you have a look at > > https://www.postgresql.org/docs/15/sql-dropindex.html check out the > > CONCURRENTLY option. That option allows an index to be dropped

Re: Dropping behavior for unique CONSTRAINTs

2023-03-04 Thread Peter J. Holzer
On 2023-03-02 20:30:41 -, Conner Bean wrote: > Hi folks,I'm curious if there are any docs supporting the > functionality behind dropping unique constraints. For context, I am > interested in enforcing uniqueness on a column. This table is heavily > used, and I plan on dropping the constraint in