Re: [h2] Re: Duplicate records when order by date?
Understood. Thanks! -- You received this message because you are subscribed to the Google Groups "H2 Database" group. To unsubscribe from this group and stop receiving emails from it, send an email to h2-database+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/h2-database/1009086163.8538532.1713263503387%40mail.yahoo.com.
Re: [h2] Re: Duplicate records when order by date?
I understand your suggested workaround. The workaround involves copying all the records into a temp table via query with an order by and then paginating through the temp table using the _rowid_ as the order by. Gotcha. Evgenij also suggest something a little more simpler that works for me - simply adding the id to the order by like this: SELECT * FROM award_test ORDER BY start_date desc, id LIMIT 50 OFFSET 100;SELECT * FROM award_test ORDER BY start_date desc, id LIMIT 50 OFFSET 150; ...which is what I'll probably end up doing. But I still think that these are just workarounds. I don't think we should be seeing "duplicates" like I reported - esp when there's a unique primary key. But I'll let you guys have the last word on that. Best,Peter -- You received this message because you are subscribed to the Google Groups "H2 Database" group. To unsubscribe from this group and stop receiving emails from it, send an email to h2-database+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/h2-database/180937197.8540181.1713263056357%40mail.yahoo.com.
Re: [h2] Re: Duplicate records when order by date?
Hmm... I kinda have a row id already via the unique primary key. What advantage would a temp table give in my case? -- You received this message because you are subscribed to the Google Groups "H2 Database" group. To unsubscribe from this group and stop receiving emails from it, send an email to h2-database+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/h2-database/118813727.6510502.1713261281401%40mail.yahoo.com.
Re: [h2] Re: Duplicate records when order by date?
I see what you are saying and I can replicate what you're seeing. However the two test cases are slightly different. One difference between my test and yours is that I have a unique primary key. Are they really peers if there's a unique primary key? Try this: create table test(a int, b int, constraint a_key primary key (a)); insert into test values (1, 2), (2, 3), (3, 3), (4, 4), (5, 4), (6, 4), (7, 4); select * from test order by b offset 0 limit 3;select * from test order by b offset 3 limit 3; select * from test order by b offset 6 limit 3; Note the sorting is on b. A finer break point looking at just 2 records at a time looks like this: Does having a unique primary key make any difference? Or should it? -- You received this message because you are subscribed to the Google Groups "H2 Database" group. To unsubscribe from this group and stop receiving emails from it, send an email to h2-database+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/h2-database/30678878.8539905.1713260757079%40mail.yahoo.com.
Re: [h2] Re: Duplicate records when order by date?
I expect to see both rows 217 and 218 at the break point like this: I don't care if 218 appears before 217 or if 217 appears before 218 as long as they both appear. Unfortunately, sometimes I get "duplicate" 217 at the break point, with no 218. Other times, I get "duplicate" 218 at the break point, with no 217 like this: That's point #1. Point #2 regarding consistency is that if I run the same query over and over I get 4 different results. Bear in mind that the table and data is 100% static. -- You received this message because you are subscribed to the Google Groups "H2 Database" group. To unsubscribe from this group and stop receiving emails from it, send an email to h2-database+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/h2-database/1680424668.8523393.1713258847144%40mail.yahoo.com.
Re: [h2] Re: Duplicate records when order by date?
I don't know guys. It looks like a bug to me. The problem is twofold: (1) Whenever I see a "duplicate" record, the database is actually skipping a record. In other words, when I see 218 at the end of the first query and 218 at the start of the second, record 217 is missing. That is bad. (2) The query response is inconsistent. I see 4 different responses coming back from the same query on a static table. I don't think that's right. I'll update my queries to try to circumvent the issue(s) for now but I think this issue should be documented and fixed at some point. Respectfully,Peter -- You received this message because you are subscribed to the Google Groups "H2 Database" group. To unsubscribe from this group and stop receiving emails from it, send an email to h2-database+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/h2-database/1917263963.8514381.1713255567640%40mail.yahoo.com.
Re: [h2] Re: Duplicate records when order by date?
Thanks Evgeni, as always, for your prompt response! So you don't think this is a bug? Pagination using offset and limit is not uncommon. Also, I should have mentioned this earlier but I don't see this behavior in PostgreSQL. Not sure how other RDBMS behave but it would be interesting to compare. Peter -- You received this message because you are subscribed to the Google Groups "H2 Database" group. To unsubscribe from this group and stop receiving emails from it, send an email to h2-database+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/h2-database/1762141233.7723443.1713022482287%40mail.yahoo.com.
[h2] Duplicate records when order by date?
I think I might have found a bug sorting by date but I could use some help confirming. I have attached a csv file with an “id” and “start_date” field which you can load into a into a table like this:CREATE TABLE TEST ( ID BIGSERIAL NOT NULL, START_DATE TIMESTAMP with time zone, CONSTRAINT PK_TEST PRIMARY KEY (ID) ); If I run the following 2 queries, I often see the last row from the first query appear as the first row in the second query: SELECT * FROM test ORDER BY start_date DESC LIMIT 50 OFFSET 100 SELECT * FROM test ORDER BY start_date DESC LIMIT 50 OFFSET 150 The behavior is inconsistent. Sometimes I see 217 at the end of the first query and 218 at the start of the second (good), sometimes I see 218 at the end of the first query and 217 at the start of the second (also valid), sometimes I see 217 at the end of the first query and 217 at the start of the second (bad), sometimes I see 218 at the end of the first query and 218 at the start of the second (bad). I don’t see the same issue when I order by id. Again, this behavior is spurious and you may need to run the same queries multiple times to see different results. Please let me know if anyone else can replicate. Thanks in advance, Peter My environment: Java 21.0.1 Windows 11 H2 2.2.224 (PostgreSQL mode) -- You received this message because you are subscribed to the Google Groups "H2 Database" group. To unsubscribe from this group and stop receiving emails from it, send an email to h2-database+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/h2-database/203854027.7473057.1712942179783%40mail.yahoo.com. test.csv Description: MS-Excel spreadsheet
Re: [h2] Re: create domain text[]
Thanks for confirming that there is currently no way to create a "text[]" domain. Just as an aside, PostgreSQL has supported "text[]" and other arrays using "column_name datatype []" syntax since at least the 7.x release which is also more than 20 years old ;-)https://www.postgresql.org/docs/7.1/arrays.htmlhttps://www.postgresql.org/support/versioning/ Thanks again for all your help. H2 is awesome! Best,Peter On Thursday, March 21, 2024 at 08:17:29 PM EDT, Evgenij Ryazanov wrote: Hello! It isn't going to work, text[] is not an identifier and it cannot be used as domain name. PostgreSQL supports standard arrays for more than 20 years, just use a standard definition in both PostgreSQL and H2. -- You received this message because you are subscribed to the Google Groups "H2 Database" group. To unsubscribe from this group and stop receiving emails from it, send an email to h2-database+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/h2-database/1736586456.179994.171871437%40mail.yahoo.com.
[h2] create domain text[]
Hello, I am using H2 v2.2.224 in PostgreSQL mode. I would like to create a table in H2 with a "text" and "text[]" column. For example, in PostgreSQL I have a table like this: CREATE TABLE COMPANY ( ID BIGSERIAL NOT NULL, NAME text NOT NULL, DESCRIPTION text, NAICS text[] ); I can successfully create a "text" column if I create a custom domain like this:"CREATE domain IF NOT EXISTS text AS varchar" However, if I try to create a domain for "text[]" I get an error:"CREATE domain IF NOT EXISTS text[] AS varchar ARRAY" org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "CREATE domain IF NOT EXISTS text[*][] AS varchar ARRAY"; expected "., AS, data type"; I think the syntax error lays in the brackets because if I replace "text[]" with "blah" it works:"CREATE domain IF NOT EXISTS blah AS varchar ARRAY" Any suggestions for how to get this to work? Maybe a different syntax for the "create domain" statement or a property of some sort? Thanks in advance,Peter -- You received this message because you are subscribed to the Google Groups "H2 Database" group. To unsubscribe from this group and stop receiving emails from it, send an email to h2-database+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/h2-database/392378015.268670.1711039455351%40mail.yahoo.com.
Re: [h2] Year alias in select statement
Thanks for checking Evgenij. I was mistaken - adding "YEAR" to the "NON_KEYWORDS" does indeed work. There was a different issue on my end that was throwing things off. Appreciate everyone's help. Best,Peter On Saturday, February 17, 2024 at 02:19:07 AM EST, Evgenij Ryazanov wrote: Hello! YEAR is a reserved word even in archaic SQL-92, so it was a bad idea to use it as unquoted identifier. BTW, DATE and TRANSACTION are reserved words too, but H2 allows their usage as identifiers. Also there is no YEAR function in the Standard, correct syntax is EXTRACT(YEAR FROM someValue). Newer versions of H2 may have more keywords than old versions and reserved words from the latest version of the SQL Standard (from SQL:2023 for now) are potential candidates. Anyway, the following test case prints 2024 as expected, so NON_KEYWORDS settings works well and you have some other problem in your application, most likely your query is executed from a connection with different settings. Properties p = new Properties(); p.put("MODE", "PostgreSQL"); p.put("DATABASE_TO_LOWER", "TRUE"); p.put("DEFAULT_NULL_ORDERING", "HIGH"); p.put("NON_KEYWORDS", "YEAR"); try (Connection connection = DriverManager.getConnection("jdbc:h2:mem:", p)) { Statement s = connection.createStatement(); s.execute("CREATE TABLE transaction(date DATE) AS VALUES CURRENT_DATE"); ResultSet rs = s.executeQuery("SELECT year(date) AS year FROM transaction"); rs.next(); System.out.println(rs.getInt(1)); } -- You received this message because you are subscribed to the Google Groups "H2 Database" group. To unsubscribe from this group and stop receiving emails from it, send an email to h2-database+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/h2-database/fc4ea7a4-c9f8-47a1-89be-191e9d807f15n%40googlegroups.com. -- You received this message because you are subscribed to the Google Groups "H2 Database" group. To unsubscribe from this group and stop receiving emails from it, send an email to h2-database+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/h2-database/797384501.3014179.1708171658213%40mail.yahoo.com.
Re: [h2] Year alias in select statement
Thank you. I get it. Compatibility mode with PostgreSQL is incomplete and certain regressions are to be expected when jumping major versions. I would be willing to help patch the sw. Whether I would succeed is another matter :-) I'll pull the source and start a new thread as needed. Many thanks to you and the team. Love H2! Best,Peter On Friday, February 16, 2024 at 08:09:52 PM EST, Andreas Reichel wrote: Greetings! On Sat, 2024-02-17 at 00:47 +, 'Peter Borissow' via H2 Database wrote: Hi Andreas, Thanks for the quick reply! As you suggest, quoting "year" as the alias works. Quoting transaction didn't have any effect. Several questions: (1) What doesn't this work? properties.setProperty("NON_KEYWORDS", "YEAR"); Because it really is just a "work around" for uncommon keywords related to more exotic features.The problem is that the parser based on the Grammar needs to be able to distinguish the tokens. Example: -- value can workSELECT Year( date ) value FROM ... vs. -- value can workINSERT INTO table_name VALUE .. Further illustration (unrelated to H2 though): https://manticore-projects.com/JSQLParser/contribution.html#manage-reserved-keywords In short, `YEAR` seems to be a keyword that can not be worked around (for good). (2) I am in PostgreSQL mode. On a PostgreSQL server, I don't have to quote year as an alias in PostgreSQL in a statement like this:select date as year from transaction The Compatibility modes are "certain syntax and functions are emulated" modes. The Developers don't aim or claim full compliance.Example: NEXT VALUE for a sequence is supported for all 3 syntax (Postgres, Oracle and MS SQL Server) as a courtesy (which I find just awesome). But non of those dialect is fully implemented (and will never be). Why do I have to quote year? Why has the behavior changed from 1.x to 2.x? Because H2 has massively evolved since and supports now a more complex Grammar.More Grammar, more restricted keywords. Example: When you don't support `Exclusive` lock modes, then `Exclusive` is not needed as a keyword. But when support is added, then suddenly `Exclusive` becomes a keyword.Thus it is best practise to avoid all SQL:2016 reserved keywords (long list!) and/or to quote identifiers always. (If you have a massive library of existing statements, then you could engage JSQLParser and a) identify all such colliding identifiers and/or b) rewrite your statements quoting the identifiers.) Good luckAndreas -- You received this message because you are subscribed to the Google Groups "H2 Database" group. To unsubscribe from this group and stop receiving emails from it, send an email to h2-database+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/h2-database/d08ac7158a006eb2e514c5d5c54fcdaadcbd47e3.camel%40manticore-projects.com. -- You received this message because you are subscribed to the Google Groups "H2 Database" group. To unsubscribe from this group and stop receiving emails from it, send an email to h2-database+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/h2-database/64293294.2948642.1708138018550%40mail.yahoo.com.
Re: [h2] Year alias in select statement
Hi Andreas, Thanks for the quick reply! As you suggest, quoting "year" as the alias works. Quoting transaction didn't have any effect. Several questions: (1) What doesn't this work? properties.setProperty("NON_KEYWORDS", "YEAR"); (2) I am in PostgreSQL mode. On a PostgreSQL server, I don't have to quote year as an alias in PostgreSQL in a statement like this:select date as year from transaction Why do I have to quote year? Why has the behavior changed from 1.x to 2.x? Thanks in advance!Peter On Friday, February 16, 2024 at 07:31:03 PM EST, Andreas Reichel wrote: Good Morning. `YEAR` is a SQL:2016 reserved keyword: http://www.h2database.com/html/advanced.html?highlight=keyword=keyword#keywordsYou will need to quote your alias: SELECT Year( date ) AS "YEAR" FROM "transaction" ; Similar thing for `TRANSACTION`.It is always advisable to avoid such keywords are object identifiers. CheersAndreas On Sat, 2024-02-17 at 00:25 +, 'Peter Borissow' via H2 Database wrote: Dear H2 Community, I ran into an unexpected error today migrating from 1.x to 2.x. I'm using H2 2.2.224 in PostgreSQL mode using the following parameters properties.setProperty("MODE", "PostgreSQL"); properties.setProperty("DATABASE_TO_LOWER", "TRUE"); properties.setProperty("DEFAULT_NULL_ORDERING", "HIGH"); The following query is failing: select year(date) as year from transaction Error: SELECT year(date) AS [*]year FROM transaction"; expected "identifier" Looks like it doesn't like the year alias in the select statement. The following query works: select year(date) as y from transaction I tried the following but it didn't seem to help: properties.setProperty("NON_KEYWORDS", "YEAR"); Any suggestions? Thanks,Peter -- You received this message because you are subscribed to the Google Groups "H2 Database" group. To unsubscribe from this group and stop receiving emails from it, send an email to h2-database+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/h2-database/1040186991.2923444.1708129516544%40mail.yahoo.com. -- You received this message because you are subscribed to the Google Groups "H2 Database" group. To unsubscribe from this group and stop receiving emails from it, send an email to h2-database+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/h2-database/83c98a852da9a0ef3683051984c612304744c66c.camel%40manticore-projects.com. -- You received this message because you are subscribed to the Google Groups "H2 Database" group. To unsubscribe from this group and stop receiving emails from it, send an email to h2-database+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/h2-database/1548447917.2938581.1708130867832%40mail.yahoo.com.
[h2] Year alias in select statement
Dear H2 Community, I ran into an unexpected error today migrating from 1.x to 2.x. I'm using H2 2.2.224 in PostgreSQL mode using the following parameters properties.setProperty("MODE", "PostgreSQL"); properties.setProperty("DATABASE_TO_LOWER", "TRUE"); properties.setProperty("DEFAULT_NULL_ORDERING", "HIGH"); The following query is failing: select year(date) as year from transaction Error: SELECT year(date) AS [*]year FROM transaction"; expected "identifier" Looks like it doesn't like the year alias in the select statement. The following query works: select year(date) as y from transaction I tried the following but it didn't seem to help: properties.setProperty("NON_KEYWORDS", "YEAR"); Any suggestions? Thanks,Peter -- You received this message because you are subscribed to the Google Groups "H2 Database" group. To unsubscribe from this group and stop receiving emails from it, send an email to h2-database+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/h2-database/1040186991.2923444.1708129516544%40mail.yahoo.com.
Re: [h2] Re: Create Table Problem (Upgrading from 1.4.x)
Thank you Evgenij, Adding the following properties definitely helped: properties.setProperty("MODE", "PostgreSQL");properties.setProperty("DATABASE_TO_LOWER", "TRUE"); properties.setProperty("NON_KEYWORDS", "KEY,VALUE"); properties.setProperty("DEFAULT_NULL_ORDERING", "HIGH"); I am able to create a new database and load my schema :-) I have a new issue in my code related to connection pooling but I'll save that for a new thread if I can't figure it out. Thanks Again,Peter On Wednesday, August 30, 2023 at 08:25:25 PM EDT, Evgenij Ryazanov wrote: Hello. In modern versions of the SQL Standard KEY is really a non-reserved word, but it was a mistake to exclude it from the list of reserved words, because in some contexts you still cannot use it as identifier, even the SQL Standard itself has at least one such documented exclusion appeared in ISO/IEC 9075-2:2016 TECHNICAL CORRIGENDUM 2. Definition of your table also has a VALUE column, but VALUE is a reserved word in the SQL Standard and it is a keyword in H2. If you cannot rename these columns, you can add `;NON_KEYWORDS=KEY,VALUE` to JDBC URL. It also should have `;MODE=PostgreSQL;DATABASE_TO_LOWER=TRUE;DEFAULT_NULL_ORDERING=HIGH` if you want a better compatibility with PostgreSQL. Alternatively you can pass these settings in the map with properties. -- You received this message because you are subscribed to the Google Groups "H2 Database" group. To unsubscribe from this group and stop receiving emails from it, send an email to h2-database+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/h2-database/7756da35-d074-439e-af77-33adc7a4bbd6n%40googlegroups.com. -- You received this message because you are subscribed to the Google Groups "H2 Database" group. To unsubscribe from this group and stop receiving emails from it, send an email to h2-database+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/h2-database/391768309.2471969.1693488629604%40mail.yahoo.com.
[h2] Create Table Problem (Upgrading from 1.4.x)
Dear H2 Community, I have finally carved out some time to upgrade an old project to H2 2.x and ran into a problem with one of my table create statements: CREATE TABLE USER_PREFERENCE ( ID BIGSERIAL NOT NULL, KEY VARCHAR(50) NOT NULL, VALUE text NOT NULL, USER_ID bigint NOT NULL, CONSTRAINT PK_USER_PREFERENCE PRIMARY KEY (ID) ); This statement is throwing a "Syntax error in SQL statement" error in 2.x that I did not see in 1.4.x. In the error message there is something about "expected "identifier"; SQL statement". If I take out or rename the "KEY" column everything works. I see that the list of reserved keywords has been updated at some point and KEY has been added although it is marked as a non-reserved (NR) word in the SQL Standard: http://www.h2database.com/html/advanced.html#keywords Questions: (1) If am running in PostgreSQL compatibility mode, and KEY is a non-reserved keyword in PostgreSQL shouldn't I be allowed to create a KEY column? (2) Is this the correct way to set NON_KEYWORDS? Is it similar to setting mode? java.util.Properties properties = new java.util.Properties(); properties.setProperty("MODE", "PostgreSQL"); properties.setProperty("NON_KEYWORDS", "KEY"); I ask because it doesn't seem to work (i.e. I still can't create my table with the NON_KEYWORDS set). Thanks in advance,Peter -- You received this message because you are subscribed to the Google Groups "H2 Database" group. To unsubscribe from this group and stop receiving emails from it, send an email to h2-database+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/h2-database/194088980.2263119.1693432324441%40mail.yahoo.com.
Re: [h2] Re: When was REGEXP_SUBSTR added to H2?
Thank you! On Saturday, July 1, 2023 at 08:44:54 AM EDT, Evgenij Ryazanov wrote: Hello! It was added in H2 2.0.202. -- You received this message because you are subscribed to the Google Groups "H2 Database" group. To unsubscribe from this group and stop receiving emails from it, send an email to h2-database+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/h2-database/1570088057.983364.1688219083031%40mail.yahoo.com.
[h2] When was REGEXP_SUBSTR added to H2?
Dear H2 community, When was REGEXP_SUBSTR added to H2? I have a really old version of H2 (1.4.197) and I'm getting a RuntimeException: Function "REGEXP_SUBSTR" not found when I try to use it in a query. I have tried searching the change logs but the history seems incomplete:https://www.h2database.com/html/changelog.htmlhttps://github.com/h2database/h2database/releases Thanks,Peter -- You received this message because you are subscribed to the Google Groups "H2 Database" group. To unsubscribe from this group and stop receiving emails from it, send an email to h2-database+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/h2-database/1769368369.572741.1688211746668%40mail.yahoo.com.
[h2] LIMIT[*] inserted into query?
Hello, I just upgraded my h2 jdbc driver from h2-1.4.197.jar to h2-1.4.199.jar and ran into an odd exception. My query is simple: select date,description,amount from transaction offset 0 limit 50 Here's the error: org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "SELECT DATE,DESCRIPTION,AMOUNT FROM TRANSACTION OFFSET 0 LIMIT[*] 50 "; SQL statement: select date,description,amount from transaction offset 0 limit 50 [42000-199] at org.h2.message.DbException.getJdbcSQLException(DbException.java:451) at org.h2.message.DbException.getJdbcSQLException(DbException.java:427) at org.h2.message.DbException.get(DbException.java:205) at org.h2.message.DbException.get(DbException.java:181) at org.h2.message.DbException.getSyntaxError(DbException.java:229) at org.h2.command.Parser.getSyntaxError(Parser.java:989) at org.h2.command.Parser.prepareCommand(Parser.java:686) I'm not sure what's wrong or whether this is a known issue. Downgrading to h2-1.4.197.jar for now. Thanks, Peter -- You received this message because you are subscribed to the Google Groups "H2 Database" group. To unsubscribe from this group and stop receiving emails from it, send an email to h2-database+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/h2-database/2bbcdf0b-8e3d-4bd8-932d-40169d78f54d%40googlegroups.com.