Re: re-novice coming back to pgsql: porting an SQLite update statement to postgres

2024-09-15 Thread Alban Hertroys
------ [{"a": 1, "b": -2, "c": 1}, {"a": 2, "b": -2, "c": 2}, {"a": 2, "b": -1, "c": 3}, {"a": 2, "b": -2, "c": 4}] (1 row) For understanding both queries better, it probably helps to take out the jsonb_agg calls to see the separate objects from the array. Add the original obj back in for comparison, if you like. I typically use the documentation pages for the JSON functions and the one on aggregate functions, where the JSONB aggregates are located: https://www.postgresql.org/docs/16/functions-json.html https://www.postgresql.org/docs/16/functions-aggregate.html And if you’re not familiar with dollar quoting: https://www.postgresql.org/docs/16/sql-syntax-lexical.html#SQL-SYNTAX-DOLLAR-QUOTING Alban Hertroys -- There is always an exception to always.

Re: re-novice coming back to pgsql: porting an SQLite update statement to postgres

2024-09-14 Thread Alban Hertroys
;2023-06-12T19:54:39Z" } ]$$::text) replacement ) select * from dollar6 cross join lateral jsonb_array_elements(replacement) r where (r->>'start')::timestamptz <= current_timestamp; There are probably other ways to attack this problem, this is the one I came up with. Alban Hertroys -- If you can't see the forest for the trees, cut the trees and you'll find there is no forest.

Re: Column type modification in big tables

2024-08-15 Thread Alban Hertroys
‘default’ partition that gets detached at step 7, after which you can insert+select those from the default into the appropriate partitions? But you were going to test that first anyway, obviously. Alban Hertroys -- There is always an exception to always.

Re: Insert works but fails for merge

2024-08-11 Thread Alban Hertroys
ion for PostgreSQL says this: "You should ensure that the join produces at most one candidate change row for each target row.”, which also seems to imply that you shouldn’t have duplicates. Alban Hertroys -- If you can't see the forest for the trees, cut the trees and you'll find there is no forest.

Re: Column type modification in big tables

2024-08-08 Thread Alban Hertroys
w format, while you can add any new partitions in the new format. I suspect it’s not allowed, but perhaps worth a try. Alban Hertroys -- There is always an exception to always.

Re: Destination Table - Condition Amount 0

2024-08-08 Thread Alban Hertroys
nd), or something in your data changed. My bet is on the latter. For example, in FY25 the value of NCD_EXCL."Order Quantity" is 'NCD Valid FY25’, which doesn’t match your LIKE expression. Even something like a trailing space to the value could be enough. Alban Hertroys -- There is always an exception to always.

Re: Trigger usecase

2024-07-30 Thread Alban Hertroys
aints (which you should probably have on this table anyway), which would allow to handle such in the application. Such constraints can raise exceptions in your code, that need handling. So I say, at least put an exclusion constraint on that table if you didn’t already, and then decide what appro

Re: Memory issues with PostgreSQL 15

2024-07-25 Thread Alban Hertroys
e transactions get aborted and rolled back, putting us back at the 1/4th of space in use situation. Have you been able to catch your shared memory shortage in the act? I suspect that the stats you showed in your message were those after rollback. Alban Hertroys -- If you can't see the forest for the trees, cut the trees and you'll find there is no forest.

Re: Finding error in long input file

2024-07-09 Thread Alban Hertroys
>> Craig > Is this a single INSERT statement with multiple tuples after VALUES? Then perhaps an earlier line (my bet would be on line 487) accidentally ends with a semi-colon instead of a comma? Something like this: INSERT INTO table (col1, col2, ..., coln) VALUES (..., ..., ), (..., ..., ), (..., ..., ); -- <-- This terminates the INSERT (..., ..., ); -- <-- Now this line make no sense Alban Hertroys -- If you can't see the forest for the trees, cut the trees and you'll find there is no forest.

Re: Transaction issue

2024-06-19 Thread Alban Hertroys
nfortunately, there’s no mode in psql that allows you to import an SQL file and step through the statements one by one. That would be helpful in your case I think. But maybe someone on the list has ideas about that? Regards, Alban Hertroys -- If you can't see the forest for the trees, cut

Re: Reset sequence to current maximum value of rows

2024-06-14 Thread Alban Hertroys
entire database from that backup > and then insert all new table rows since I have saved all the scripts. If you end up in the same situation again after doing that, then you know at least it’s repeatable and can analyse how you got there. Alban Hertroys -- If you can't see the forest for the trees, cut the trees and you'll find there is no forest.

Re: Rules and Command Status - update/insert/delete rule with series of commands in action

2024-05-31 Thread Alban Hertroys
nk there are any open-source initiatives (unfortunately), they’re all commercial products AFAIK, and not cheap. With a suitable use-case they can be rather valuable tools too though. Regards, Alban Hertroys -- Als je de draak wilt steken met iemand, dan helpt het, als die een punthoofd heeft.

Re: Finding "most recent" using daterange

2024-05-22 Thread Alban Hertroys
OR (coalesce(upper(i.dates), 'infinity') = coalesce(upper(e.dates), 'infinity') AND coalesce(lower(i.dates), '-infinity') > coalesce(lower(e.dates), '-infinity')) ) ); id | value | dates +---+- 1 | b | [2010-01-01,) 2 | d | [2010-01-01,2021-01-01) 3 | g | [2013-01-01,) 4 | j | [2010-01-01,2015-01-01) (4 rows) Alban Hertroys -- If you can't see the forest for the trees, cut the trees and you'll find there is no forest.

Re: Updating 457 rows in a table

2024-05-20 Thread Alban Hertroys
the next attempt. In PostgreSQL this also works for almost all DDL statements (CREATE TABLE, DROP TABLE, TRUNCATE TABLE, etc.), which is one of the features about this database that I really appreciate - some big names don’t have that. Regards, Alban Hertroys -- If you can't see the forest for the trees, cut the trees and you'll find there is no forest.

Re: could not open file "global/pg_filenode.map": Operation not permitted

2024-03-22 Thread Alban Hertroys
On Fri, 22 Mar 2024 at 15:01, Nick Renders wrote: > > We now have a second machine with this issue: it is an Intel Mac mini > running macOS Sonoma (14.4) and PostgreSQL 16.2. > This one only has a single Data directory, so there are no multiple > instances running. > I don't think that having a

Re: Inconsistent results in timestamp/interval comparison

2024-03-04 Thread Alban Hertroys
On Mon, 4 Mar 2024 at 13:46, Francisco Olarte wrote: > On Mon, 4 Mar 2024 at 13:10, wrote: > > According to the documentation, Table 9.31, IMHO both comparisons should > > produce the same results, as > > > timestamp - timestamp → interval > > timestamp + interval → timestamp > Your problem may

Re: How to do faster DML

2024-02-04 Thread Alban Hertroys
mn. > So, creating the index itself took ~2hrs+ and the index size now shows as > ~116GB. > > Create index idx1 on TAB1(ID) Are your duplicates exact duplicates? Or is there an order of preference among them? And if so, what really makes those rows unique? That matters for soluti

Re: Time zone offset in to_char()

2024-01-11 Thread Alban Hertroys
de to recreate the caches from scratch from source data. Having custom code in there not under control of the 3rd party application breaks that guideline. If they’re necessary, then so be it, but I can’t shake the feeling that we can achieve this without custom code in the database. Regards, Alban Hertroys -- There is always an exception to always.

Re: Time zone offset in to_char()

2024-01-11 Thread Alban Hertroys
t; " I didn’t succeed in calling SET LOCAL TIMEZONE from within the function. Could be I missed something, then Google (stackoverflow) pointed me to set_config(). I did manage to apply it to the second function header, which I think behaves such that the time zone change stays within func

Re: Issue in compiling postgres on latest macOS 14.1.1

2023-11-13 Thread Alban Hertroys
migrated onto a new ARM-based architecture? In that case the Homebrew uninstall scripts won’t even work anymore - at least not w/o Rosetta 2 - as they’re Intel-based too. A migration assistant can also work too well, I found. Alban Hertroys -- There is always an exception to always.

Re: Strategies for converting UTC data to local windows for arbitrary resolutions and timezones

2023-10-04 Thread Alban Hertroys
obviously. Now of course there are only 2 hours a year where this happens. Our data scientists chose to ignore the problem for simplicity’s sake and be slightly off with their numbers on those dates. Regards, Alban Hertroys -- If you can't see the forest for the trees, cut the trees and you'll find there is no forest.

Re: Strategies for converting UTC data to local windows for arbitrary resolutions and timezones

2023-10-04 Thread Alban Hertroys
alendar and an (quarter of an) hour per UTC day table, but materialising that with some indexes may perform better (at the cost of disk space). I do materialise that currently, but our database server doesn’t have a lot of memory so I’m often not hitting the cache and performance suffers a bit (infrastructure is about to change for the better though). Regards, Alban Hertroys -- There is always an exception to always.

Re: Making Sure Primary and Secondary Keys Alligns

2023-09-11 Thread Alban Hertroys
o i get that all these columns that are joined are aligned, meaning if > it starts with 1 in one column it must be 1 in the other columns. Or how > would you assign unique keys in Postgres? Are you perhaps asking how to define FOREIGN KEY CONSTRAINTs? https://www.postgresql.org/docs/15/

Re: Even if I have a lot of free space PgSQL returns "ERROR: could not extend file - No space left on device"

2023-09-09 Thread Alban Hertroys
_administrative takes up a large part of those 164G, then you probably don’t have enough space for a 10x multiplication in size from the original table to the new table. And that happening looks entirely possible from the information you provided. Regards, Alban Hertroys -- If you can't see the forest for the trees, cut the trees and you'll find there is no forest.

Re: ident auth does not works as usual

2023-08-26 Thread Alban Hertroys
> On 26 Aug 2023, at 11:31, pan snowave wrote: (…) > pg_indent.conf > > test rootcce If that is indeed the name of the file, that would explain your problem. No doubt that it should be named pg_ident.conf instead, without the ’n'. Alban Hertroys -- If you can

Re: How to improve the performance of my SQL query?

2023-07-29 Thread Alban Hertroys
could get a higher cost than using a less optimal (costlier) index that’s already cached. Regarding lowering random_page_cost; If your index files are on SSD storage, lowering that sufficiently (to a realistic value) could then sufficiently lower the cost of loading that uncached index into memory, evicting the index it was using in above plan to make room (unless other active sessions are using it). Alban Hertroys -- There is always an exception to always.

Re: Nu-B here

2023-07-19 Thread Alban Hertroys
’re simply trying to connect to the database named postgres as database user postgres, you can instead use the command 'psql -U postgres postgres’. Alban Hertroys -- If you can't see the forest for the trees, cut the trees and you'll find there is no forest.

Re: How To: A large [2D] matrix, 100,000+ rows/columns

2023-06-09 Thread Alban Hertroys
he data changes seldom. Not in practice, AFAIR, but I was thinking of a solution like this for small matrices (Sudoku’s, I hate the things, but I need some solutions to a few to help me with a number of test scripts). Alban Hertroys -- If you can't see the forest for the trees, cut the trees and you'll find there is no forest.

Re: "PANIC: could not open critical system index 2662" - twice

2023-04-14 Thread Alban Hertroys
current/2023-April/003446.html Regards, Alban Hertroys -- There is always an exception to always.

Re: [EXTERNAL]: Re: UPSERT in Postgres

2023-04-09 Thread Alban Hertroys
r statement violating a not null constraint. It doesn’t matter whether you insert first or update first, either operation is going to violate that constraint. You’re specifying a NULL value for a column that doesn’t accept that because it has a NOT NULL constraint. That is your problem. Alban

Re: Using CTID system column as a "temporary" primary key

2023-03-29 Thread Alban Hertroys
e: Fix your design. Regards, Alban Hertroys -- There is always an exception to always.

Re: Idea: PostgreSQL equivalent to Oracle's KEEP clause

2023-03-14 Thread Alban Hertroys
the same minimum number (namely 0). Should the result be just the first of the maximums (or minimums) through some selection criterium (such as their alphabetical order), should that give each of the tied results, or should there be a means to define that behaviour? I suppose a combination with FIRST and LAST could solve that issue? Regards, Alban Hertroys -- There is always an exception to always.

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 >>

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

2023-03-03 Thread Alban Hertroys
> On 3 Mar 2023, at 0:02, Thorsten Glaser wrote: > > On Tue, 28 Feb 2023, Alban Hertroys wrote: > >> Perhaps you can use a lateral cross join to get the result of >> jsonb_build_object as a jsonb value to pass around? > > I don’t see how. (But then I’ve not

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

2023-02-28 Thread Alban Hertroys
;from_hour', > jsonb_build_object( > 'weekday', cot.weekday, > 'from_hour', cot.from_hour, > 'to_hour', cot.to_hour)->>'to_hour') > ) > > Isn’t that more like it? Perhaps you can use a lateral cross join to get the result of jsonb_build_object as a jsonb value to pass around? Alban Hertroys -- If you can't see the forest for the trees, cut the trees and you'll find there is no forest.

Re: WHERE col = ANY($1) extended to 2 or more columns?

2023-02-10 Thread Alban Hertroys
> On 9 Feb 2023, at 18:35, Dominique Devienne wrote: > > On Thu, Feb 9, 2023 at 5:37 PM David G. Johnston > wrote: > On Thu, Feb 9, 2023 at 9:28 AM Alban Hertroys wrote: > > On 9 Feb 2023, at 16:41, Dominique Devienne wrote: > > Now we'd like to do the same

Re: WHERE col = ANY($1) extended to 2 or more columns?

2023-02-09 Thread Alban Hertroys
ibpq, but a pure SQL or PL/pgSQL demo would > still help (I think). This works: => select (1, 'one'::text) in ((1, 'two'::text), (2, 'one'::text), (1, 'one'::text), (2, 'two'::text)); ?column? -- t (1 row) Alban Hertroys -- If you can't see the forest for the trees, cut the trees and you'll find there is no forest.

Re: Are ZFS snapshots unsafe when PGSQL is spreading through multiple zpools?

2023-01-17 Thread Alban Hertroys
t a 'message' was sent or none received it. Algorithms like Tarry, Lai-Yang or the Echo algorithm solve this by adding communication between those processes about messages in transit. Alban Hertroys -- There is always an exception to always.

Re: Regular expression for lower case to upper case.

2022-12-11 Thread Alban Hertroys
u could just calculate them and even omit storing them in a physical table. Alban Hertroys -- If you can't see the forest for the trees, cut the trees and you'll find there is no forest.

Re: Stored procedure code no longer stored in v14 and v15, changed behaviour

2022-12-04 Thread Alban Hertroys
enised version after the upgrade. It is a bit of a hassle, as you need to remember to do that before an upgrade, but at least you’d have something… Alban Hertroys -- If you can't see the forest for the trees, cut the trees and you'll find there is no forest.

Re: Stored procedure code no longer stored in v14 and v15, changed behaviour

2022-12-03 Thread Alban Hertroys
after of the output of pg_get_functiondef, applied to the stored diff?). I’m not so sure that would work for auditing, but that seems to have been tackled down-thread. Alban Hertroys -- If you can't see the forest for the trees, cut the trees and you'll find there is no forest.

Re: Duda sobre como imprimir un campo INTERVAL

2022-11-19 Thread Alban Hertroys
ert that to a character string yourself. See for example: https://stackoverflow.com/questions/341384/how-to-convert-an-interval-like-1-day-013000-into-253000 That seems unnecessarily complicated, perhaps there is/could be a more convenient method? I’m sort of thinking of a "relative timestamp offset" type, that tracks an exact difference relative to a given timestamp? Alban Hertroys -- There is always an exception to always.

Re: pg_restore creates public schema?

2022-10-07 Thread Alban Hertroys
er1 to > Server2. Bit of a wild idea, I haven’t used SSH tunnels in years, so a bit fuzzy on the details: Can you create an SSH tunnel to the new machine from the VM, then pipe that to an SSH connection from a machine that does have enough space to dump? And then vice versa to the new mac

Re: Getting data from a record variable dynamically

2022-07-05 Thread Alban Hertroys
u could either pass them on or they (probably) don’t make sense in the context of the generic function. Alban Hertroys -- There is always an exception to always.

Re: '{"x": 42, "y": null}'::jsonb != '{"x": 42}'::jsonb ... Really?

2022-06-18 Thread Alban Hertroys
ee section 9.16.2 on: https://www.postgresql.org/docs/current/functions-json.html#FUNCTIONS-SQLJSON-OP-TABLE A recursive query is another possible solution. It would probably perform far worse, but I find them more rewarding to write. Some people prefer Sodoku. Regards, Alban Hertroys -- If you can't see the forest for the trees, cut the trees and you'll find there is no forest.

Re: Puzzline CROSS JOIN when doing RECURSIVE CTE

2022-04-18 Thread Alban Hertroys
select * from cte order by hierarchy; Function parent() is made-up. It would return the parent node of a node, so that there is some way to connect the different parts in the hierarchy. I guess xpath() could fulfil that purpose, but I have no way of testing that hypothesis. I hope that’s a good enough starting point for you? Alban Hertroys -- There is always an exception to always.

Re: Puzzline CROSS JOIN when doing RECURSIVE CTE

2022-04-18 Thread Alban Hertroys
> On 18 Apr 2022, at 11:56, Pól Ua Laoínecháin wrote: (…) > All of the code below is available on the fiddle here: > > https://dbfiddle.uk/?rdbms=postgres_13&fiddle=0cc20c9081867131260e6e3550bd08ab (…) > OK, grand, now I wish to perform a RECURSIVE CTE on it. So, I start by > trying someth

Re: historical log of data records

2021-11-16 Thread Alban Hertroys
be a good idea to store that in a way optimised for that. TimescaleDB comes to mind, or arrays as per Pavel’s suggestion at https://stackoverflow.com/questions/68440130/time-series-data-on-postgresql. Regards, Alban Hertroys -- If you can't see the forest for the trees, cut the trees and you'll find there is no forest.

Re: Determining if a table really changed in a trigger

2021-10-26 Thread Alban Hertroys
s: => with x as ( select '{ "x": 1, "y": 2 }'::jsonb union all select '{ "y": 2, "x": 1 }'::jsonb ) select row(x.jsonb)::text, md5(row(x.jsonb)::text) from x; row| md5 --+-- ("{""x"": 1, ""y"": 2}") | d5a6dbdec7a5bfe0dc99e090db30322e ("{""x"": 1, ""y"": 2}") | d5a6dbdec7a5bfe0dc99e090db30322e (2 rows) Alban Hertroys -- There is always an exception to always.

Re: Determining if a table really changed in a trigger

2021-10-26 Thread Alban Hertroys
on’t use this approach with JSON (as opposed to JSONB) type fields though, a single extra space in the JSON structure would already lead to a difference, as would other formatting differences. Regards, Alban Hertroys -- If you can't see the forest for the trees, cut the trees and you'll find there is no forest.

Re: Where is the tsrange() function documented?

2021-10-19 Thread Alban Hertroys
instant| empty range result | instant range result ---+---++-- empty | ["2000-01-10 00:00:00","2000-01-10 00:00:00"] | false | true (1 row) As I re

Re: Growth planning

2021-10-04 Thread Alban Hertroys
on downloading this data to the R script, would it help to rewrite it in PL/R and do (part of) the ML calculations at the DB side? Alban Hertroys -- If you can't see the forest for the trees, cut the trees and you'll find there is no forest.

Re: SELECT FOR UPDATE returns zero rows with CTE

2021-09-17 Thread Alban Hertroys
single-row example, but if you had a table full of data, you would now have locked all rows with the value t1c2 = 100 for update. If that update never happens (or the locking doesn’t get rolled back), well… Regards, Alban Hertroys -- There is always an exception to always.

Re: Help with writing a generate_series(tsmultirange, interval)

2021-08-01 Thread Alban Hertroys
hierarchy on a reference timestamp. That performed adequately on a production data warehouse, as long as you sufficiently constrained the inputs. You can join such a function (laterally) to some other data set too. Regards, Alban Hertroys -- There is always an exception to always.

Re: Recursive Parent-Child Function Bottom Up

2021-07-26 Thread Alban Hertroys
> On 26 Jul 2021, at 17:52, Alban Hertroys wrote: > Something like this: > > with recursive foo (id, parent, children_ids) as ( > select id, parent, null::text > from tree t >where not exists ( > select 1 from tree

Re: Recursive Parent-Child Function Bottom Up

2021-07-26 Thread Alban Hertroys
t.id, t.parent , f.id || case f.children_ids when '' then '' else ',’ end || f.children_ids from foo f join tree t on f.parent = t.id where f.parent <> 0 ; Regards, Alban Hertroys -- If you can't see the forest for the trees, cut the trees and you'll find there is no forest.

Re: Getting "ERROR: upper bound of FOR loop cannot be null" when trying to use a stored proc in a check constraint def.

2021-07-17 Thread Alban Hertroys
e, but that’s the gist of it. If that project_csv column gets populated by some external application, you could keep the link-table updated with insert/update/delete triggers. Alternatively, a writable view replacing public.projects may be a possibility. Regards, Alban Hertroys -- If you can't see the forest for the trees, cut the trees and you'll find there is no forest.

Re: On partitioning, PKs and FKs

2021-07-08 Thread Alban Hertroys
On 2021-07-08 13:30, Ron wrote:> Thus, the bigTable PK must be on id, columnX, (No, I don't like it > either.)That's not entirely true. You can keep the PK on id if you additionally create a unique constraint on (id, columnX).That way, you can at least be certain that the uniqueness of the PK remai

Re: Overlapping timestamptz ranges with priority

2021-06-28 Thread Alban Hertroys
ot;,"2021-06-20 16:00:00+01") You could probably achieve this by using window function lag() over (order by booking_id), in combination with a case statement when the range from the previous row overlaps the current range. That would only solve the case for immediately subsequent ro

Re: Is there a way to replace select * fields in result ?

2021-06-12 Thread Alban Hertroys
ring(qw.mm, 1, 1), '') as mm Or even: select qw.*, coalesce(left(qw.mm, 1), '') as mm Regards, Alban Hertroys -- There is always an exception to always.

Re: index unique

2021-06-10 Thread Alban Hertroys
y key column candidate. Now, of course, the OP could have a case where their geometries are guaranteed to be unique regardless, but they’d better make sure before adding them to the PK. Alban Hertroys -- If you can't see the forest for the trees, cut the trees and you'll find there is no forest.

WARNING: oldest xmin is far in the past

2021-05-28 Thread Alban Hertroys
---  PostgreSQL 11.11 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44), 64-bit (1 row) Regards, Alban Hertroys P.S. Sorry about below company disclaimer, there is nothing I can do about that. Alban Hertroys D: 8776 |M: |T: +31 (0)53 4888 888 | E

Re: How to get CASE statement to recognize null ?

2021-03-10 Thread Alban Hertroys
foo; > > This test is equivalent to "col1 = null" which will always fail. > You could try something like > > CASE WHEN col1 IS NULL THEN ... ELSE ... END > > Although I think the particular thing you're doing here would > be better solved with COALESCE(col1, 'z'). > > regards, tom lane Alban Hertroys -- If you can't see the forest for the trees, cut the trees and you'll find there is no forest.

How to check for existence of nested JSONB property key?

2021-03-10 Thread Alban Hertroys
ary, I'm looking for a generic approach here. We're on PG 11(.9), so the enhancements made to JSONB operations in PG12 are not (yet) available to us. This is a 3TB database w/o replica's, so upgrading it is a little scary and requires a maintenance window that would be sufficient t

Re: How to keep format of views source code as entered?

2021-01-12 Thread Alban Hertroys
ain, this is what I >> get: >> >> >> >> CREATE OR REPLACE VIEW myview >> >> AS SELECT product_id, >> >> product_acronym >> >>FROM products >> >> WHERE product_acronym = 'ABC'::text; >> >> >> >> So, the formatting changed, keywords are capitalized, the comment I added in >> the from-part has gone and the text constant 'ABC' changed to 'ABC'::text. >> >> >> >> >> >> >> >> >> >> >> Verizon Deutschland GmbH - Sebrathweg 20, 44149 Dortmund, Germany - >> Amtsgericht Dortmund, HRB 14952 - Geschäftsführer: Detlef Eppig - >> Vorsitzender des Aufsichtsrats: Francesco de Maio >> > Alban Hertroys -- There is always an exception to always.

Re: Define hash partition for certain column values

2021-01-12 Thread Alban Hertroys
ly trivial to > create 50 or 1000 partitions to break up the range of values allowed by your > field definition. Alban Hertroys -- There is always an exception to always.

Re: Trigger with conditional predicates

2021-01-04 Thread Alban Hertroys
know about the existence of said column; overwriting an existing value that some other application put there looks like a problem to me. But of course, that depends a lot on what you’re trying to achieve. What is your use-case that that is not the desired behaviour? Or are we talking about a mixe

Re: Trigger with conditional predicates

2021-01-02 Thread Alban Hertroys
the common approach > to this problem? > > BR > Dirk Can't you use column defaults to handle these cases? Alban Hertroys -- There is always an exception to always.

Re: SQL group by help

2020-12-12 Thread Alban Hertroys
lap and assign a group number but i'm not sure how to accomplish > that. You could date_trunc those timestamps to the minute and group on that. > there's also no guarantee an entire rack is full of samples so some "cells" > of display might be null. i think that makes the use of tablefunc crosstab a > little harder. if i remember correctly, it does not handle missing values > well. i'm open to any pivoting strategy. Many reporting tools have features to support just that. We use WebFOCUS, which calls those ACROSS columns. It’s a common requirement in reporting. Alban Hertroys -- There is always an exception to always.

Re: Accessing Postgres Server and database from other Machine

2020-12-05 Thread Alban Hertroys
pg_hab_file_rules: > > postgres=# table pg_hba_file_rules; Also: postgres=# show listen_addresses; postgres=# show port; Those will tell you whether the server is listening on the network and on the expected port. Alban Hertroys -- There is always an exception to always.

Re: Is it possible to write a generic UPSERT?

2020-11-12 Thread Alban Hertroys
a function or in a do-block. We do this in plpgsql, but that’s mostly because this code is part of our ETL process and it has to perform some other logic on the same data anyway. I could look up our code for you tomorrow, but that looks to be a busy day, so I can’t promise. Alban Hertroys -- If

Re: Check constraints do not seem to be working!!!

2020-11-11 Thread Alban Hertroys
On 11 Nov 2020, at 11:15, Jitendra Loyal wrote: > >  > Thanks Nikolay > > I read that but is there a way to meet the above requirement. And I will like > to add that IS NULL and IS NOT NULL should evaluate to true/false. These > operators are made for this and should not be returning NULL.

Re: How to update a table with the result of deleting rows in another table

2020-10-06 Thread Alban Hertroys
uld also do this using subqueries instead of CTE’s, that may perform better as CTE’s act as optimisation fences. Alban Hertroys -- If you can't see the forest for the trees, cut the trees and you'll find there is no forest.

Betr: Re: FATAL: terminating connection due to administrator command

2020-10-01 Thread Alban Hertroys
"Srinivasa T N" wrote on 01/10/2020 11:47:33: > On Thu, Oct 1, 2020 at 2:47 PM Alban Hertroys < > alban.hertr...@apollovredestein.com> wrote: > Hi all, > > We're seeing the FATAL error message from the subject pop up in our > logs at regular intervals, b

FATAL: terminating connection due to administrator command

2020-10-01 Thread Alban Hertroys
r 1530646postmaster 6482 postmaster 1530645postmaster 6482 postmaster 1530659postmaster 6482 postmaster 1530658postmaster 6482 postmaster 1530657postmaster 6482 postmaster 15 30656postmaster 6482 postmaster 1530655postmas

Re: How to enumerate partitions from a window function?

2020-09-04 Thread Alban Hertroys
On Thu, 3 Sep 2020 at 20:59, Michael Lewis wrote: > It seems like you are maybe wanting this- If the previous row is the same, > then get the previous row's run_nr. If it is different, then increment. > > case when lag( property_A ) over() = property_A and lag( property_B ) > over() = property_B

Re: How to enumerate partitions from a window function?

2020-09-03 Thread Alban Hertroys
On Thu, 3 Sep 2020 at 16:01, Tom Lane wrote: > Alban Hertroys writes: > > As stated above, I want to enumerate the runs, starting at 1 and > > incrementing by 1 every time a partition from the 'run' window closes, > > Is there a way to achieve this through win

How to enumerate partitions from a window function?

2020-09-03 Thread Alban Hertroys
9 | coffee | cappucino | 15:09 | 3 | 0.45 2020-09-03 15:10 | coffee | cappucino | 15:09 | 3 | 0.43 etc. Is there a way to achieve this through window functions, or do we need to wrap the thing in a subquery to achieve this? Regards, Alban Hertroys -- If you can't see the forest for the trees

Re: How to properly query lots of rows based on timestamps?

2020-08-29 Thread Alban Hertroys
mestamps. > I've looked into this topic and found statements about that one > shouldn't put too many rows into the index[1] and stuff like that or > it will be ignored at all. But that doesn't seem to be the case for me > according to the plan. OTOH, my index really simply is about the > column containing the timestamp, no function reducing things to dates > or stuff like that to reduce the number of rows. > >> CREATE INDEX idx_clt_rec_captured_at ON clt_rec USING btree ( captured_at ); Try this: CREATE INDEX idx_clt_rec_captured_at ON clt_rec USING btree ( captured_at, id ); Alban Hertroys -- There is always an exception to always.

Re: Postgres and alias

2020-08-28 Thread Alban Hertroys
ls_price_and_date, 7, 13 ) from articulos art cross join lateral f_art_get_price_str( art.id ) p(ls_price_and_date); Alban Hertroys -- There is always an exception to always.

Re: table name

2020-06-11 Thread Alban Hertroys
it also makes the identifier case-sensitive. That’s probably why Paul suggested to rename the table to no longer require identifier quoting - many people consider it a PITA, but it can be used to get out of trouble like yours - some people insist on it, for example because it makes using camel-caps in identifiers meaningful. Regards, Alban Hertroys -- There is always an exception to always.

Re: Using JSONB with nested key-value structures, and skipping/wildcarding the key

2020-06-02 Thread Alban Hertroys
;table function". Can you kindly clarify? Correct. Thomas already explained the return type, but the plural form of the function name is also an indication that it returns multiple results. Alban Hertroys -- If you can't see the forest for the trees, cut the trees and you'll find there is no forest.

Re: Using JSONB with nested key-value structures, and skipping/wildcarding the key

2020-06-01 Thread Alban Hertroys
idea how to write that in Django): select snapshot->’pay_definition’->k.value->’name’ from MyModel join lateral jsonb_object_keys(snapshot->’pay_definition’) k(value) on true I don’t know how that compares performance-wise to using jsonb_each, but perhaps worth a try. Obviously, the way it’s written above it doesn’t return distinct values of ’name’ yet, but that’s fairly easy to remedy. Alban Hertroys -- If you can't see the forest for the trees, cut the trees and you'll find there is no forest.

Re: Advice request : simultaneous function/data updates on many databases

2020-03-05 Thread Alban Hertroys
y to commit, and the central machine returns an ‘acknowledged’ once the last server sent it’s ‘done’ event. The challenge there is that the ‘ack’ needs to be caught and processed within the same waiting transaction… Not sure how to do that right now - maybe through web services, MQTT or similar. A

Re: Trigger

2020-02-25 Thread Alban Hertroys
uery in a more readable and consistent way, they would spot their error pretty quickly. It’s a simple typo. Alban Hertroys -- If you can't see the forest for the trees, cut the trees and you'll find there is no forest.

Re: UPDATE many records

2020-01-06 Thread Alban Hertroys
hat to do about that; if it fails it will probably fail fast, and if not, then you’re looking at a one-off situation that won’t require more than a few workarounds - after which you can just run the update again. Ad 1). No harm has been done, it’s a single transaction that rolled back. Alban Hertroys -- If you can't see the forest for the trees, cut the trees and you'll find there is no forest.

Re: SQL operator '*='

2019-12-23 Thread Alban Hertroys
> FROM land LEFT JOIN devisen ON land.wkz = devisen.wkz AND land.brgroup = devisen.brgroup > WHERE land.brgroup = :brgroupHost_for_helpland_cursor > ORDER BY stammprio, landbez; > #endif Alban Hertroys -- If you can't

Re: Conditional return of aggregated data

2019-12-02 Thread Alban Hertroys
On Mon, 2 Dec 2019 at 12:11, Laura Smith wrote: > > My initial idea was something along the lines of : > select (select sum(statcount) from stats_residence) as > aggstat,statcount,short_name_en from stats_residence where > aggstat>some_number; > One option is to move the aggregate to the where-

Re: Range contains element filter not using index of the element column

2019-11-28 Thread Alban Hertroys
ent_timestamp <= t from (values ('-infinity'::timestamp), ('infinity'::timestamp)) x(t); t | ?column? | ?column? -------+--+-- -infinity | t| f infinity | f| t (2 rows) Regards, Alban Hertroys -- If you can't see the forest for the trees, cut the trees and you'll find there is no forest.

Re: Finding out about the dates of table modification

2019-11-23 Thread Alban Hertroys
recreate table files, such as CLUSTER. Then again, if you’re just looking for the table you created last Wednesday, that’s probably not a major concern. Another option is to add a DDL Event trigger on create table statements and log that to some table[3]. Regards, Alban Hertroys [1]: ht

Re: The connection to the server was lost. Attempting reset: Failed.

2019-10-10 Thread Alban Hertroys
ing an attribute of that structure. Personally, I would invert the test like so (and then move it before the idxused test: if (idxcd == NULL) { elog( INFO, "idxcd IS NULL" ); continue; /* Or is that fatal enough to break instead? */ ) if (!idxcd->idxused) continue; Alban Hertroys -- There is always an exception to always.

Re: Arrays and ANY problem

2019-09-25 Thread Alban Hertroys
> On 25 Sep 2019, at 22:50, Alban Hertroys wrote: > > >> On 25 Sep 2019, at 22:25, David Salisbury wrote: >> db=# select name from table_name_ds_tmp where ARRAY[categoryid] = ANY ( >> select string_to_array( '200,400', ',')::bigint[] ); >&g

Re: Arrays and ANY problem

2019-09-25 Thread Alban Hertroys
. Since the left-hand array has only 1 item and the right-hand one has two, there’s not much equality between them. You probably meant: select name from table_name_ds_tmp where categoryid = ANY ( select string_to_array( '200,400', ',')::bigint[] ); Alban Hertroys -- There is always an exception to always.

Re: Question about password character in ECPG's connection string

2019-08-28 Thread Alban Hertroys
> 2) "tcp:postgresql://localhost?user=myuser&password=password" looks like > > "tcp:postgresql://localhost?user=myuser&password=my&pwd" > > and password is parsed on the & and you also end up with an extra parameter > pwd Perhaps it he

Re: A GROUP BY question

2019-08-13 Thread Alban Hertroys
> On 13 Aug 2019, at 15:19, David G. Johnston > wrote: > > On Tuesday, August 13, 2019, Alban Hertroys wrote: > > > On 13 Aug 2019, at 13:10, stan wrote: > > > > select > > project.proj_no , > > Removed columns that get in the way o

Re: A GROUP BY question

2019-08-13 Thread Alban Hertroys
From experience, that either results in people reporting the wrong financial results (several orders too high) or blaming your query. Regards, Alban Hertroys -- If you can't see the forest for the trees, cut the trees and you'll find there is no forest.

Re: adding more space to the existing server

2019-08-05 Thread Alban Hertroys
on its lag. You probably have at least that much down-time to change the connections anyway. Regards, Alban. > From: Alban Hertroys > Sent: Monday, August 5, 2019 5:01 AM > To: Julie Nishimura > Cc: Adrian Klaver ; > pgsql-general@lists.postgresql.org ; > pgsql-genera

Re: adding more space to the existing server

2019-08-05 Thread Alban Hertroys
ons I hope it all makes sense... Thank you It does to me. Now would be a good time for people to chime in if they don't agree ;) From: Alban Hertroys Sent: Saturday, August 3, 2019 3:15 AM To: Julie Nishimura Cc: Adrian Klaver ; pgsql-general@lists.postgresql.org ; pgsql-general Subject:

Re: adding more space to the existing server

2019-08-03 Thread Alban Hertroys
ly removed a database from both a and c, you still have replicas to recover it from. And the backups, of course, but that will not contain the data that came in after replication was paused. I do hope the remaining 3% disk space is enough to cover all that, though... Regards, Alban Hertroys -- If

Re: Request for resolution || Support

2019-07-25 Thread Alban Hertroys
your transaction cannot be allowed to commit without a response from the other peer. In such cases it is appropriate to use plpython, plperl, etc All that said, I am talking about PostgreSQL here. If you’re instead using EnterpriseDB, which does have an Oracle compatibility layer that could pe

  1   2   >